From: Kaj-Michael Lang Date: Tue, 20 May 2008 14:00:23 +0000 (+0300) Subject: More map widget integration work X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e13679a8ef23ec0019f700df70777a2f5e09e3a8;p=mapper More map widget integration work --- diff --git a/src/cb.c b/src/cb.c index 5b654f9..50dae34 100644 --- a/src/cb.c +++ b/src/cb.c @@ -45,8 +45,6 @@ #include "utils.h" #include "poi.h" #include "path.h" -#include "route.h" -#include "track.h" #include "settings.h" #include "gps.h" #include "mapper-types.h" @@ -320,10 +318,11 @@ gboolean menu_cb_goto_destination(GtkAction *action) { if (gtk_map_goto_position(_dest)==FALSE) { - MACRO_BANNER_SHOW_INFO(_window, _("Destination not set.")); + MACRO_BANNER_SHOW_INFO(_window, _("Destination has not been set.")); } else { - gtk_map_set_zoom(_map, 3); - MACRO_BANNER_SHOW_INFO(_window, _("At destination")); + if (gtk_map_get_zoom(_map)>3) + gtk_map_set_zoom(_map, 3); + MACRO_BANNER_SHOW_INFO(_window, _("At destination point")); } return TRUE; } @@ -331,22 +330,30 @@ return TRUE; gboolean menu_cb_goto_gps(GtkAction *action) { -gtk_map_set_center_mode(_map, CENTER_LATLON); -MACRO_BANNER_SHOW_INFO(_window, _("At GPS coordinates.")); -map_update_location_from_center(); +if (gtk_map_set_center_mode(_map, CENTER_LATLON)) { + MACRO_BANNER_SHOW_INFO(_window, _("At GPS track coordinates.")); + map_update_location_from_center(); +} else { + MACRO_BANNER_SHOW_INFO(_window, _("No active GPS track.")); +} return TRUE; } gboolean menu_cb_goto_nextway(GtkAction *action) { +GtkMapCenterMode *cm; + g_return_val_if_fail(_route, TRUE); if (_route->next_way && _route->next_way->point->unity) { - if (gtk_map_get_center_mode(_map) > 0) + g_object_get(_map, "center-mode", &cm); + if (cm>0) set_action_activate("autocenter_none", TRUE); - gtk_map_set_center_unit(_route->next_way->point->unitx, _route->next_way->point->unity); + gtk_map_set_center_unit(_map, _route->next_way->point->unitx, _route->next_way->point->unity); + if (gtk_map_get_zoom(_map)>3) + gtk_map_set_zoom(_map, 3); } else { MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint.")); } @@ -357,19 +364,13 @@ return TRUE; gboolean menu_cb_goto_nearpoi(GtkAction *action) { +GtkMapCenterMode *cm; gdouble lat, lon; poi_info *p; -if (gtk_map_get_center_mode(_map)!=CENTER_MANUAL) { - /* Auto-Center is enabled - use the GPS position. */ - lat=_gps->data.lat; - lon=_gps->data.lon; -} else { - gtk_map_get_center_latlon(_map, &lat, &lon); -} +gtk_map_get_center_latlon(_map, &lat, &lon); p=poi_find_nearest(lat, lon); - if (p) { gchar *banner; @@ -1102,8 +1103,11 @@ gboolean cmenu_cb_way_distance_to(GtkAction *action) { WayPoint *way; +gdouble lat, lon; -if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) +gtk_map_get_menu_latlon(_map, &lat, &lon); + +if ((way = route_find_nearest_waypoint(_route, lat, lon))) route_show_distance_to(_route, way->point); return TRUE; @@ -1113,8 +1117,11 @@ gboolean cmenu_cb_way_delete(GtkAction *action) { WayPoint *way; +gdouble lat, lon; + +gtk_map_get_menu_latlon(_map, &lat, &lon); -if ((way = route_find_nearest_waypoint(_route, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) { +if ((way = route_find_nearest_waypoint(_route, lat, lon))) { gchar buffer[BUFFER_SIZE]; GtkWidget *confirm; diff --git a/src/mapper.c b/src/mapper.c index a38ff4c..c4a613c 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -441,10 +441,10 @@ switch (mis) { w="UI"; break; case MAPPER_INIT_GOTO: - if (map_goto_position(&_home)==FALSE) + if (gtk_map_goto_position(_map, &_home)==FALSE) g_printerr("Home is not set.\n"); else - gtk_map_center_latlon(64.25, 22.00); /* XXX */ + gtk_map_center_latlon(_map, 60.45, 22.25); mis=MAPPER_INIT_DONE; p=1.0; w="Done"; diff --git a/src/path.c b/src/path.c index 9d0698e..eba74dd 100644 --- a/src/path.c +++ b/src/path.c @@ -343,14 +343,14 @@ 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); + 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); + guint dist_squared = DISTANCE_SQUARED(*point, *curr); if (dist_squared <= near_dist_squared) { near = curr; near_dist_squared = dist_squared; @@ -365,8 +365,8 @@ if (route->next_way) { 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)))) + && (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 @@ -381,8 +381,8 @@ if (route->next_way) { } 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_wpt && (DISTANCE_SQUARED (*point, *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; @@ -408,9 +408,9 @@ if (route->next_way) { } ret = TRUE; } - route->next_way_dist_squared = DISTANCE_SQUARED(_gps->data, *wnext->point); + route->next_way_dist_squared = DISTANCE_SQUARED(*point, *wnext->point); if (route->next_wpt) - route->next_wpt_dist_squared = DISTANCE_SQUARED(_gps->data, *route->next_wpt); + route->next_wpt_dist_squared = DISTANCE_SQUARED(*point, *route->next_wpt); } } return ret; diff --git a/src/path.h b/src/path.h index b70fc66..213724a 100644 --- a/src/path.h +++ b/src/path.h @@ -55,6 +55,10 @@ struct _Point { gfloat altitude; }; +#define DISTANCE_SQUARED(a, b) \ + ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx)) \ + + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity))) + /** * A latitude/longitue pair */ @@ -151,6 +155,8 @@ gboolean path_wresize(Path *path, guint wsize); gdouble path_get_distance_to(Path *path, Point *point, gdouble lat, gdouble lon); +gboolean path_update_nears(Path *route, Point *point, gboolean quick); + gboolean path_insert_break(Path *path); void path_insert_mark_text(Path *path, gchar *text); void path_insert_mark_autonumber(Path *path); diff --git a/src/poi-gui.c b/src/poi-gui.c index 70e5baf..bae17fd 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -98,8 +98,7 @@ GtkWidget *dialog; guint i; gchar *buffer; -buffer = g_strdup_printf("%s\n\t%s\n%s", _("Delete category?"), - dpoi->txt_label, _("WARNING: All POIs in that category will also be deleted!")); +buffer = g_strdup_printf("%s\n\t%s\n%s", _("Delete category?"), dpoi->txt_label, _("WARNING: All POIs in that category will also be deleted!")); dialog = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer); g_free(buffer); i = gtk_dialog_run(GTK_DIALOG(dialog)); @@ -109,8 +108,7 @@ if (i == GTK_RESPONSE_OK) { if (poi_category_delete(dpoi->id)==FALSE) popup_error(_window, _("Problem deleting category or POI")); gtk_widget_hide_all(dpoi->dialog); - map_poi_cache_clear(); - map_force_redraw(); + gtk_map_refresh(_map); } return TRUE; diff --git a/src/search.c b/src/search.c index ae113bd..7601ffa 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); -map_center_latlon(lat, lon); +gtk_map_center_latlon(_map, lat, lon); g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_update_location_from_center, NULL, NULL); #if 0 gtk_widget_destroy(s->dialog); diff --git a/src/ui-common.c b/src/ui-common.c index 51d8d6d..12b87b5 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -24,8 +24,6 @@ #include "utils.h" #include "poi.h" #include "path.h" -#include "route.h" -#include "track.h" #include "settings.h" #include "gps.h" #include "gtkmap.h" @@ -694,7 +692,7 @@ gtk_box_pack_start(GTK_BOX(mapvbox), hbox, TRUE, TRUE, 0); ui_notebook.map=gtk_notebook_append_page(notebook, mapvbox, label); /* Map widget */ -_map=gtkmap_new(); +_map=gtk_map_new(); gtk_paned_add2(GTK_PANED(hbox), _map); #ifndef WITH_DEVICE_770 diff --git a/src/ui-common.h b/src/ui-common.h index 0f50144..4a0b55d 100644 --- a/src/ui-common.h +++ b/src/ui-common.h @@ -20,6 +20,7 @@ #include "mapper-types.h" #include "ui-maemo.h" #include "hildon-wrappers.h" +#include "path.h" #define SCALE_WIDTH (200) @@ -121,9 +122,10 @@ GtkMenu *_menu_map; GtkWidget *route_tree_view; GtkWidget *track_tree_view; -/** Context menu click location on map */ -guint _cmenu_position_x; -guint _cmenu_position_y; +Path *_route; +Path *_track; + +AutoRouteDownloadData _autoroute_data; void mapper_ui_init(void); gboolean window_present();