path.h \
position.c \
position.h \
+ route.c \
+ route.h \
image-cache.c \
image-cache.h \
poi-gui.c \
gboolean
menu_cb_route_reset(GtkAction *action)
{
-route_find_nearest_point(_route);
+path_find_nearest_point(_route);
gtk_map_refresh(_map);
MACRO_QUEUE_DRAW_AREA();
return TRUE;
* stop searching when we find a point that is farther away.
*/
gboolean
-path_update_nears(Path *route, Point *point, gboolean quick)
+path_update_nears(Path *path, Point *point, gboolean quick)
{
gboolean ret = FALSE;
Point *curr, *near;
WayPoint *wcurr, *wnext;
guint64 near_dist_squared;
-g_return_val_if_fail(route, FALSE);
+g_return_val_if_fail(path, FALSE);
/* If we have waypoints (_next_way != NULL), then determine the "next
* waypoint", which is defined as the waypoint after the nearest point,
* UNLESS we've passed that waypoint, in which case the waypoint after
* that waypoint becomes the "next" waypoint. */
-if (route->next_way) {
+if (path->next_way) {
/* First, set near_dist_squared with the new distance from
* near_point. */
- near = route->near_point;
+ near = path->near_point;
near_dist_squared = DISTANCE_SQUARED(*point, *near);
- /* Now, search route for a closer point. If quick is TRUE, then we'll
+ /* Now, search path for a closer point. If quick is TRUE, then we'll
* only search forward, only as long as we keep finding closer points.
*/
- for (curr = route->near_point; curr++ != route->tail;) {
+ for (curr = path->near_point; curr++ != path->tail;) {
if (curr->unity) {
guint dist_squared = DISTANCE_SQUARED(*point, *curr);
if (dist_squared <= near_dist_squared) {
}
/* Update _near_point. */
- route->near_point = near;
- route->near_point_dist_squared = near_dist_squared;
+ path->near_point = near;
+ path->near_point_dist_squared = near_dist_squared;
- for (wnext = wcurr = route->next_way; wcurr != route->wtail; wcurr++) {
+ for (wnext = wcurr = path->next_way; wcurr != path->wtail; wcurr++) {
if (wcurr->point < near || (wcurr->point == near && quick
- && (route->next_wpt && (DISTANCE_SQUARED(*point, *near) > route->next_way_dist_squared
- && DISTANCE_SQUARED(*point, *route->next_wpt) < route->next_wpt_dist_squared))))
+ && (path->next_wpt && (DISTANCE_SQUARED(*point, *near) > path->next_way_dist_squared
+ && DISTANCE_SQUARED(*point, *path->next_wpt) < path->next_wpt_dist_squared))))
/* Okay, this else if expression warrants explanation. If the
* nearest track point happens to be a waypoint, then we want to
* check if we have "passed" that waypoint. To check this, we
break;
}
- if (wnext == route->wtail && (wnext->point < near || (wnext->point == near && quick
- && (route->next_wpt && (DISTANCE_SQUARED (*point, *near) > route->next_way_dist_squared
- && DISTANCE_SQUARED(*point, *route->next_wpt) < route->next_wpt_dist_squared)))))
+ if (wnext == path->wtail && (wnext->point < near || (wnext->point == near && quick
+ && (path->next_wpt && (DISTANCE_SQUARED (*point, *near) > path->next_way_dist_squared
+ && DISTANCE_SQUARED(*point, *path->next_wpt) < path->next_wpt_dist_squared)))))
{
- route->next_way = NULL;
- route->next_wpt = NULL;
- route->next_way_dist_squared = -1;
- route->next_wpt_dist_squared = -1;
+ path->next_way = NULL;
+ path->next_wpt = NULL;
+ path->next_way_dist_squared = -1;
+ path->next_wpt_dist_squared = -1;
ret = TRUE;
}
/* Only update next_way (and consequently _next_wpt) if _next_way is
* different, and record that fact for return. */
else {
- if (!quick || route->next_way != wnext) {
- route->next_way = wnext;
- route->next_wpt = wnext->point;
- if (route->next_wpt == route->tail)
- route->next_wpt = NULL;
+ if (!quick || path->next_way != wnext) {
+ path->next_way = wnext;
+ path->next_wpt = wnext->point;
+ if (path->next_wpt == path->tail)
+ path->next_wpt = NULL;
else {
- while (!(++route->next_wpt)->unity) {
- if (route->next_wpt == route->tail) {
- route->next_wpt = NULL;
+ while (!(++path->next_wpt)->unity) {
+ if (path->next_wpt == path->tail) {
+ path->next_wpt = NULL;
break;
}
}
}
ret = TRUE;
}
- route->next_way_dist_squared = DISTANCE_SQUARED(*point, *wnext->point);
- if (route->next_wpt)
- route->next_wpt_dist_squared = DISTANCE_SQUARED(*point, *route->next_wpt);
+ path->next_way_dist_squared = DISTANCE_SQUARED(*point, *wnext->point);
+ if (path->next_wpt)
+ path->next_wpt_dist_squared = DISTANCE_SQUARED(*point, *path->next_wpt);
}
}
return ret;
}
+/**
+ * Reset the near_point data by searching the entire path for the nearest point and waypoint.
+ */
+void
+path_find_nearest_point(Path *path)
+{
+g_return_if_fail(path);
+
+/* Initialize near_point to first non-zero point. */
+path->near_point=path->head;
+while (!path->near_point->unity && path->near_point != path->tail)
+ path->near_point++;
+
+/* Initialize next_way. */
+if (path->wtail == path->whead - 1 || (_autopath_data.enabled && path->wtail == path->whead))
+ path->next_way = NULL;
+else
+ /* We have at least one waypoint. */
+ path->next_way = (_autoroute_data.enabled ? path->whead + 1 : path->whead);
+
+path->next_way_dist_squared = -1;
+
+/* Initialize _next_wpt. */
+path->next_wpt = NULL;
+path->next_wpt_dist_squared = -1;
+
+}
+
/******************************************************************************/
gdouble
/******************************************************************************/
+gboolean
+path_set_destination_from_last(Path *path, Position *pos)
+{
+Point *p;
+gdouble lat,lon;
+
+g_return_val_if_fail(route, FALSE);
+g_return_val_if_fail(pos, FALSE);
+
+if (path->head==path->tail) {
+ position_set(pos, FALSE, NAN, NAN, NAN);
+ return FALSE;
+}
+
+p=path_find_last_point(route);
+if (p) {
+ unit2latlon(p->unitx, p->unity, &lat, &lon);
+ position_set(pos, TRUE, lat, lon, 0);
+} else {
+ position_set(pos, FALSE, NAN, NAN, NAN);
+ return FALSE;
+}
+return TRUE;
+}
+
gboolean
path_get_waypoint_latlon(WayPoint *way, gdouble *lat, gdouble *lon)
{
gtk_tree_model_get(model, &iter, ITEM_LAT, &lat, -1);
gtk_tree_model_get(model, &iter, ITEM_LON, &lon, -1);
-map_center_latlon(lat, lon);
-map_update_location_from_center();
+gtk_map_set_center_latlon(_map, &lat, &lon);
return TRUE;
}
return NULL;
}
-/**
- * Updates near_point, next_way, and next_wpt. If quick is FALSE (as
- * it is when this function is called from route_find_nearest_point), then
- * the entire list (starting from near_point) is searched. Otherwise, we
- * stop searching when we find a point that is farther away.
- */
-gboolean
-route_update_nears(Path *route, gboolean quick)
-{
-gboolean ret = FALSE;
-Point *curr, *near;
-WayPoint *wcurr, *wnext;
-guint64 near_dist_squared;
-
-g_return_val_if_fail(route, FALSE);
-
-/* If we have waypoints (_next_way != NULL), then determine the "next
- * waypoint", which is defined as the waypoint after the nearest point,
- * UNLESS we've passed that waypoint, in which case the waypoint after
- * that waypoint becomes the "next" waypoint. */
-if (route->next_way) {
- /* First, set near_dist_squared with the new distance from
- * near_point. */
- near = route->near_point;
- near_dist_squared = DISTANCE_SQUARED(_gps->data, *near);
-
- /* Now, search route for a closer point. If quick is TRUE, then we'll
- * only search forward, only as long as we keep finding closer points.
- */
- for (curr = route->near_point; curr++ != route->tail;) {
- if (curr->unity) {
- guint dist_squared = DISTANCE_SQUARED(_gps->data, *curr);
- if (dist_squared <= near_dist_squared) {
- near = curr;
- near_dist_squared = dist_squared;
- } else if (quick)
- break;
- }
- }
-
- /* Update _near_point. */
- route->near_point = near;
- route->near_point_dist_squared = near_dist_squared;
-
- for (wnext = wcurr = route->next_way; wcurr != route->wtail; wcurr++) {
- if (wcurr->point < near || (wcurr->point == near && quick
- && (route->next_wpt && (DISTANCE_SQUARED(_gps->data, *near) > route->next_way_dist_squared
- && DISTANCE_SQUARED(_gps->data, *route->next_wpt) < route->next_wpt_dist_squared))))
- /* Okay, this else if expression warrants explanation. If the
- * nearest track point happens to be a waypoint, then we want to
- * check if we have "passed" that waypoint. To check this, we
- * test the distance from _gps to the waypoint and from _gps to
- * _next_wpt, and if the former is increasing and the latter is
- * decreasing, then we have passed the waypoint, and thus we
- * should skip it. Note that if there is no _next_wpt, then
- * there is no next waypoint, so we do not skip it in that case. */
- wnext = wcurr + 1;
- else
- break;
- }
-
- if (wnext == route->wtail && (wnext->point < near || (wnext->point == near && quick
- && (route->next_wpt && (DISTANCE_SQUARED (_gps->data, *near) > route->next_way_dist_squared
- && DISTANCE_SQUARED(_gps->data, *route->next_wpt) < route->next_wpt_dist_squared)))))
- {
- route->next_way = NULL;
- route->next_wpt = NULL;
- route->next_way_dist_squared = -1;
- route->next_wpt_dist_squared = -1;
- ret = TRUE;
- }
- /* Only update next_way (and consequently _next_wpt) if _next_way is
- * different, and record that fact for return. */
- else {
- if (!quick || route->next_way != wnext) {
- route->next_way = wnext;
- route->next_wpt = wnext->point;
- if (route->next_wpt == route->tail)
- route->next_wpt = NULL;
- else {
- while (!(++route->next_wpt)->unity) {
- if (route->next_wpt == route->tail) {
- route->next_wpt = NULL;
- break;
- }
- }
- }
- ret = TRUE;
- }
- route->next_way_dist_squared = DISTANCE_SQUARED(_gps->data, *wnext->point);
- if (route->next_wpt)
- route->next_wpt_dist_squared = DISTANCE_SQUARED(_gps->data, *route->next_wpt);
- }
-}
-return ret;
-}
-
-/**
- * Reset the near_point data by searching the entire route for the nearest
- * route point and waypoint.
- */
-void
-route_find_nearest_point(Path *route)
-{
-g_return_if_fail(route);
-
-/* Initialize near_point to first non-zero point. */
-route->near_point = route->head;
-while (!route->near_point->unity && route->near_point != route->tail)
- route->near_point++;
-
-/* Initialize next_way. */
-if (route->wtail == route->whead - 1 || (_autoroute_data.enabled && route->wtail == route->whead))
- route->next_way = NULL;
-else
- /* We have at least one waypoint. */
- route->next_way = (_autoroute_data.enabled ? route->whead + 1 : route->whead);
-
-route->next_way_dist_squared = -1;
-
-/* Initialize _next_wpt. */
-route->next_wpt = NULL;
-route->next_wpt_dist_squared = -1;
-
-route_update_nears(route, FALSE);
-}
-
/**
* Show the distance from the current GPS location to the given point,
* following the route. If point is NULL, then the distance is shown to the
}
void
-route_show_distance_to_next(Path *route)
+route_show_distance_to_next_waypoint(Path *route)
{
g_return_if_fail(route);
MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
}
-gboolean
-route_set_destination_from_last(Path *route, Position *pos)
-{
-Point *p;
-gdouble lat,lon;
-
-g_return_val_if_fail(route, FALSE);
-g_return_val_if_fail(pos, FALSE);
-
-if (route->head==route->tail) {
- position_set(pos, FALSE, NAN, NAN, NAN);
- return FALSE;
-}
-
-p=path_find_last_point(route);
-if (p) {
- unit2latlon(p->unitx, p->unity, lat, lon);
- position_set(pos, TRUE, lat, lon, 0);
-}
-return TRUE;
-}
-
void
route_show_distance_to_last(Path *route)
{
gtk_tree_model_get(model, &iter, ITEM_LAT, &lat, -1);
gtk_tree_model_get(model, &iter, ITEM_LON, &lon, -1);
-gtk_map_center_latlon(_map, lat, lon);
+gtk_map_set_center_latlon(_map, lat, lon);
}
gboolean
popup_error(sd.dialog, _("Select a location from the list."));
#endif
} else {
- gtk_map_center_latlon(_map, lat, lon);
+ gtk_map_set_center_latlon(_map, lat, lon);
}
continue;
break;