From: Kaj-Michael Lang Date: Tue, 10 Jun 2008 14:08:37 +0000 (+0300) Subject: Path: Emit signals when near or at waypoint X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c94c5e9d1e9033de6181f4f54c1c54615e445634;p=mapper Path: Emit signals when near or at waypoint --- diff --git a/src/path.c b/src/path.c index b9808ed..ea6991a 100644 --- a/src/path.c +++ b/src/path.c @@ -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 diff --git a/src/path.h b/src/path.h index d212009..1c437de 100644 --- a/src/path.h +++ b/src/path.h @@ -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 */