]> err.no Git - mapper/commitdiff
MapWidgetIntegration: Yay, it compiles.. sort-of
authorKaj-Michael Lang <milang@tal.org>
Tue, 20 May 2008 09:36:04 +0000 (12:36 +0300)
committerKaj-Michael Lang <milang@tal.org>
Tue, 20 May 2008 09:36:04 +0000 (12:36 +0300)
src/Makefile.am
src/path.c
src/ui-common.c

index a76e0cb60a0423898725c63f1c4a829458cf8aee..f39d2218d46feb056ee5283dfda9b9b181125b8c 100644 (file)
@@ -93,8 +93,6 @@ mapper_SOURCES = \
        poi-gui.h \
        poi.c \
        poi.h \
-       route.c \
-       route.h \
        search.c \
        search.h \
        settings-gui.c \
@@ -102,8 +100,6 @@ mapper_SOURCES = \
        speak.c \
        speak.h \
        speed-display.c \
-       track.c \
-       track.h \
        ui-common.c \
        ui-common.h \
        ui-maemo.h \
index 55cdf9b80f45234fb83cbe3d0d5688077be872d3..9d0698e8c598c52a52ac93d20c00ee8cec1675ea 100644 (file)
@@ -319,6 +319,105 @@ for (p=path->tail; !p->unity; p--) {
 return p;
 }
 
+/**
+ * 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 
+path_update_nears(Path *route, Point *point, 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(point, *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(point, *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(point, *near) > route->next_way_dist_squared
+                               && DISTANCE_SQUARED(point, *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(point, *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;
+}
+
+/******************************************************************************/
+
 gdouble
 path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon)
 {
@@ -368,6 +467,8 @@ if (point > path->near_point) {
 return sum;
 }
 
+/******************************************************************************/
+
 gboolean
 path_load(Path *path, const gchar *config_dir, const gchar *file)
 {
@@ -405,6 +506,8 @@ g_free(tfile);
 return TRUE;
 }
 
+/******************************************************************************/
+
 gboolean
 path_get_waypoint_latlon(WayPoint *way, gdouble *lat, gdouble *lon)
 {
@@ -442,6 +545,7 @@ if (text) {
 g_signal_emit(G_OBJECT(path), signals[NEW_WAYPOINT], 0, NULL);
 }
 
+/******************************************************************************/
 #if 0
 static void
 path_store_append_waypoint(GtkListStore *, WayPoint *w)
index bc89a0c2745fb80fe8f50c55d0e61b02d823840f..51d8d6d67b86e33b97b630df98737ed1642ae576 100644 (file)
@@ -72,6 +72,8 @@ struct ui_notebook_struct ui_notebook;
 
 static poi_quick_data tqp;
 
+osm_location map_loc;
+
 /* A GPS icon would be nice.. anyone ? */
 
 #ifndef GTK_STOCK_INFO
@@ -612,18 +614,10 @@ g_assert(actions);
 ui = gtk_ui_manager_new ();
 g_assert(ui);
 
-gtk_action_group_add_actions (actions, ui_entries, n_ui_entries, NULL);
-gtk_action_group_add_toggle_actions (actions, ui_toggle_entries, n_ui_toggle_entries, NULL);
-gtk_action_group_add_radio_actions (actions, ui_autocenter_entries, 
-       n_ui_autocenter_entries, _center_mode, G_CALLBACK(menu_cb_autocenter),  NULL);
-
-gtk_ui_manager_insert_action_group (ui, actions, 0);
-g_object_unref (actions);
-
 /* N810 has keyboard so set this up on hildon too */
-gtk_window_add_accel_group (GTK_WINDOW(_window), gtk_ui_manager_get_accel_group (ui));
+gtk_window_add_accel_group(GTK_WINDOW(_window), gtk_ui_manager_get_accel_group (ui));
 
-if (!gtk_ui_manager_add_ui_from_string (ui, mapper_ui, -1, &error)) {
+if (!gtk_ui_manager_add_ui_from_string(ui, mapper_ui, -1, &error)) {
        g_message ("building menus failed: %s", error->message);
        g_error_free(error);
        g_assert(FALSE);
@@ -707,6 +701,14 @@ gtk_paned_add2(GTK_PANED(hbox), _map);
 gtk_map_set_cache_size(_map, 256);
 #endif
 
+gtk_action_group_add_actions(actions, ui_entries, n_ui_entries, NULL);
+gtk_action_group_add_toggle_actions(actions, ui_toggle_entries, n_ui_toggle_entries, NULL);
+gtk_action_group_add_radio_actions(actions, ui_autocenter_entries, 
+       n_ui_autocenter_entries, gtk_map_get_center_mode(_map), G_CALLBACK(menu_cb_autocenter),  NULL);
+
+gtk_ui_manager_insert_action_group(ui, actions, 0);
+g_object_unref(actions);
+
 /* GPS Tab */
 vbox = gtk_vbox_new(FALSE, 0);
 label = gtk_label_new("Gps");
@@ -830,12 +832,13 @@ gps_location_update(Gps *gps)
 {
 g_assert(gps);
 if (filter_check(&filter, &gps->data, &map_loc)==TRUE) {
-       if (track_add(_track, &_gps->data)) {
-               KEEP_DISPLAY_ON();
-               route_check_waypoint_announce(_route, &_gps->data);
+       if (path_add(_track, &_gps->data)) {
+               path_check_waypoint_announce(_route, &_gps->data);
+#if 0
                route_autoroute_check(_route);
+#endif
+               KEEP_DISPLAY_ON();
        }
-       map_refresh_mark();
 }
 return FALSE;
 }