From: Kaj-Michael Lang Date: Wed, 21 May 2008 16:02:13 +0000 (+0300) Subject: MapWidgetIntegration: A bit more work X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77c6c951a4beaa24fa50949942ee2d2b1006f5c2;p=mapper MapWidgetIntegration: A bit more work --- diff --git a/src/Makefile.am b/src/Makefile.am index ab3b60d..97bacfd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -87,6 +87,8 @@ mapper_SOURCES = \ path.h \ position.c \ position.h \ + route.c \ + route.h \ image-cache.c \ image-cache.h \ poi-gui.c \ diff --git a/src/cb.c b/src/cb.c index 103dea9..57979e7 100644 --- a/src/cb.c +++ b/src/cb.c @@ -123,7 +123,7 @@ return TRUE; 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; diff --git a/src/path.c b/src/path.c index eba74dd..0be31a2 100644 --- a/src/path.c +++ b/src/path.c @@ -326,29 +326,29 @@ return p; * 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) { @@ -360,13 +360,13 @@ if (route->next_way) { } /* 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 @@ -380,42 +380,70 @@ if (route->next_way) { 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 @@ -508,6 +536,31 @@ return TRUE; /******************************************************************************/ +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) { diff --git a/src/poi-gui.c b/src/poi-gui.c index 34cdd1a..639beed 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -520,8 +520,7 @@ if (!model) 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; } diff --git a/src/route.c b/src/route.c index 6ef68cd..04173ad 100644 --- a/src/route.c +++ b/src/route.c @@ -524,133 +524,6 @@ MACRO_BANNER_SHOW_INFO(_window, _("There are no waypoints.")); 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 @@ -675,7 +548,7 @@ return TRUE; } void -route_show_distance_to_next(Path *route) +route_show_distance_to_next_waypoint(Path *route) { g_return_if_fail(route); @@ -683,28 +556,6 @@ if (!route_show_distance_to(route, NULL)) 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) { diff --git a/src/search.c b/src/search.c index ef6f598..4b15f09 100644 --- a/src/search.c +++ b/src/search.c @@ -226,7 +226,7 @@ if (!model) 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 @@ -352,7 +352,7 @@ while ((res=gtk_dialog_run(GTK_DIALOG(sd.dialog)))!=GTK_RESPONSE_REJECT) { 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;