]> err.no Git - mapper/commitdiff
Path: Emit signals when near or at waypoint
authorKaj-Michael Lang <milang@tal.org>
Tue, 10 Jun 2008 14:08:37 +0000 (17:08 +0300)
committerKaj-Michael Lang <milang@tal.org>
Tue, 10 Jun 2008 14:08:37 +0000 (17:08 +0300)
src/path.c
src/path.h

index b9808edf988048229646f74ce51d2e2d0eb1a701..ea6991af4a9727cb3fa0843c76569e0f2daa8c86 100644 (file)
@@ -66,8 +66,8 @@ enum {
        NEW_POINT,                              /* A new point was appended to track track */
        NEW_BREAK,                              /* A break was appended to the track */
        NEW_WAYPOINT,                   /* A new waypoint/marker has been added */
-       NEAR_WAYPOINT,                  /* We are near the next route waypoint */
-       REACHED_WAYPOINT,               /* We have reached the next route waypoint */
+       NEAR_WAYPOINT,                  /* We are near the next route waypoint, announce it */
+       REACHED_WAYPOINT,               /* We have reached the next route waypoint, announce it */
        REACHED_DESTINATION,    /* We have reached the last route waypoint */
        CLEARED,                                /* Path was cleared */
        LAST_SIGNAL
@@ -76,7 +76,7 @@ static guint32 signals[LAST_SIGNAL] = {0};
 
 G_DEFINE_TYPE(Path, path, G_TYPE_OBJECT);
 
-/* #define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PATH_TYPE, PathPrivate)) */
+#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PATH_TYPE, PathPrivate))
 
 static void
 path_dispose(GObject *object)
@@ -476,8 +476,6 @@ if (wcurr && wcurr->point && wcurr!=path->wtail) {
 }
 
 if (wnear && wnear->point) {
-       /* Only use the waypoint if it is within a 6*_draw_width square drawn
-        * around the position. This is consistent with select_poi(). */
        if (abs(unitx - wnear->point->unitx) < pixel2unit(3 * path->sensitivity) && abs(unity - wnear->point->unity) < pixel2unit(3 * path->sensitivity))
                return wnear;
 }
@@ -485,6 +483,31 @@ if (wnear && wnear->point) {
 return NULL;
 }
 
+/**
+ * Check if we should announce upcoming waypoint. 
+ */
+void
+path_check_waypoint_announce(Path *route, GpsData *gps)
+{
+guint a_thres_near, a_thre_at;
+
+g_return_if_fail(path);
+g_return_if_fail(gps);
+
+if (!path->next_way)
+       return;
+
+a_thres_near=(20+(guint)gps->speed)*path->announce_notice_ratio*3;
+a_thres_at=(20+(guint)gps->speed);
+
+if (path->next_way_dist_squared<(a_thres_near * a_thres_near) && path->next_way!=path->announced_waypoint) {
+       g_signal_emit(G_OBJECT(path), signals[NEAR_WAYPOINT], 0, NULL);
+       announced_waypoint=route->next_way;
+} else if (path->next_way_dist_squared<(a_thres_at * a_thres_at) && path->next_way!=path->announced_waypoint) {
+       g_signal_emit(G_OBJECT(path), signals[REACHED_WAYPOINT], 0, NULL);
+       announced_waypoint=route->next_way;
+}
+
 /******************************************************************************/
 
 gdouble
index d21200911a639fa7f7e0bd932dcfc4dfd87dbf41..1c437debcaeb2a0acc45fdd6b13ec71460395067 100644 (file)
@@ -125,6 +125,9 @@ struct _Path {
        Point *next_wpt;
        guint64 next_wpt_dist_squared;
 
+       /* The waypoint we last announced */
+       WayPoint *announced_waypoint;
+
        /* Path statistics */
        guint32 points;
        guint32 wpcnt;          /* Auto waypoint number counter */