From 740a5739561fd26426d3979cc8a87e1d25cf8452 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 13 Mar 2008 14:55:56 +0200 Subject: [PATCH] Route, track and menu changes. Move route specific operations from track.c to route.c, handle waypoint announce check in gps position cb. Move poi search menu enty under Poi menu. --- src/cb.c | 9 ++++--- src/route.c | 49 ++++++++++++++++++++++++++++++------ src/route.h | 11 +++++++-- src/track.c | 66 +++++++++++++++++-------------------------------- src/track.h | 2 +- src/ui-common.c | 17 +++++++------ 6 files changed, 89 insertions(+), 65 deletions(-) diff --git a/src/cb.c b/src/cb.c index 17dc91f..4a0c394 100644 --- a/src/cb.c +++ b/src/cb.c @@ -152,8 +152,11 @@ return TRUE; gboolean menu_cb_track_insert_mark(GtkAction * action) { -track_insert_mark(); -path_tree_view_update_store(track_tree_view, &_track); +if (track_insert_mark()) { + map_render_paths(); + MACRO_QUEUE_DRAW_AREA(); + path_tree_view_update_store(track_tree_view, &_track); +} return TRUE; } @@ -1079,9 +1082,9 @@ _gps->data.unity = y2unit(_cmenu_position_y); unit2latlon(_gps->data.unitx, _gps->data.unity, _gps->data.lat, _gps->data.lon); /* Move mark to new location. */ -map_refresh_mark(); _gps->data.time=time(NULL); track_add(&_gps->data); +map_refresh_mark(); return TRUE; } diff --git a/src/route.c b/src/route.c index 3144f60..8c61c36 100644 --- a/src/route.c +++ b/src/route.c @@ -35,10 +35,7 @@ ((guint64)((((gint64)(b).unitx)-(a).unitx)*(((gint64)(b).unitx)-(a).unitx))\ + (guint64)((((gint64)(b).unity)-(a).unity)*(((gint64)(b).unity)-(a).unity))) -void route_find_nearest_point(void); -void cancel_autoroute(gboolean temporary); -void route_show_distance_to_last(void); -void route_set_destination_from_last(void); +static gboolean show_directions=TRUE; typedef struct _OriginToggleInfo OriginToggleInfo; struct _OriginToggleInfo { @@ -50,6 +47,11 @@ struct _OriginToggleInfo { GtkWidget *txt_to; }; +void route_find_nearest_point(void); +void route_cancel_autoroute(gboolean temporary); +void route_show_distance_to_last(void); +void route_set_destination_from_last(void); + void route_init(void) { @@ -71,7 +73,7 @@ GtkWidget *confirm; confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), _("Really clear the route?")); if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) { - cancel_autoroute(FALSE); + route_cancel_autoroute(FALSE); route_deinit(); route_init(); route_find_nearest_point(); @@ -81,6 +83,37 @@ _dest.valid=FALSE; gtk_widget_destroy(confirm); } +/** + * Check if we should announce upcoming waypoints. + */ +void +route_check_waypoint_announce(GpsData *gps) +{ +guint announce_thres_unsquared; + +if (!gps) + return; + +announce_thres_unsquared=(20+(guint)gps->speed)*_announce_notice_ratio*3; + +if (_next_way_dist_squared < (announce_thres_unsquared * announce_thres_unsquared)) + announce_waypoint(_next_way->desc); +} + +/** + * Check if we should re-calculate route + */ +void +route_autoroute_check(void) +{ +if (_autoroute_data.enabled && !_autoroute_data.in_progress && _near_point_dist_squared > 400) { + MACRO_BANNER_SHOW_INFO(_window, _("Recalculating directions...")); + _autoroute_data.in_progress = TRUE; + show_directions = FALSE; + g_idle_add((GSourceFunc)auto_route_dl_idle, NULL); +} +} + gboolean route_open_file(void) { @@ -90,7 +123,7 @@ gint size; if (file_open_get_contents(&_route_dir_uri, &buffer, &size)) { /* If auto is enabled, append the route, otherwise replace it. */ if (parse_gpx(&_route, buffer, size, _autoroute_data.enabled ? 0 : 1)) { - cancel_autoroute(FALSE); + route_cancel_autoroute(FALSE); MACRO_BANNER_SHOW_INFO(_window, _("Route Opened")); /* Find the nearest route point, if we're connected. */ @@ -169,7 +202,7 @@ return TRUE; * Cancel the current auto-route. */ void -cancel_autoroute(gboolean temporary) +route_cancel_autoroute(gboolean temporary) { if (_autoroute_data.enabled) { if (!temporary) { @@ -437,7 +470,7 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { route_find_nearest_point(); /* Cancel any autoroute that might be occurring. */ - cancel_autoroute(FALSE); + route_cancel_autoroute(FALSE); map_force_redraw(); diff --git a/src/route.h b/src/route.h index 2cba12a..31a65bf 100644 --- a/src/route.h +++ b/src/route.h @@ -45,13 +45,20 @@ void route_deinit(void); gboolean route_open_file(void); gboolean route_save(void); +gboolean route_download(gchar * to); void route_clear(void); + +void route_check_waypoint_announce(GpsData *gps); +void route_autoroute_check(void); + gboolean auto_route_dl_idle(); -gboolean route_download(gchar * to); + WayPoint *find_nearest_waypoint(guint unitx, guint unity); + gboolean route_update_nears(gboolean quick); + +gboolean route_show_distance_to(Point * point); void route_show_distance_to_last(); void route_show_distance_to_next(); -gboolean route_show_distance_to(Point * point); #endif diff --git a/src/track.c b/src/track.c index db223f8..c1797ac 100644 --- a/src/track.c +++ b/src/track.c @@ -28,6 +28,9 @@ struct sql_select_stmt { }; static struct sql_select_stmt sql; +/* Add sensitivity */ +static gint sensitivity=3; + void track_init(void) { @@ -116,29 +119,22 @@ if (_track.head != _track.tail) { } /** - * Add a point to the _track list. This function is slightly overloaded, - * since it is what houses the check for "have we moved - * significantly": it also initiates the re-calculation of the _near_point - * data, as well as calling osso_display_state_on() when we have the focus. + * Add a point to the _track list. * - * If a non-zero time is given, then the current position (as taken from the - * _gps variable) is appended to _track with the given time. If time is zero, - * then _point_null is appended to _track with time zero (this produces a "break" - * in the track). + * If a non-null gps is given, then the current position is appended + * to _track with the given time. If gps is null, then _point_null is + * appended to _track with time zero (this produces a "break" in the track). */ -void +gboolean track_add(GpsData *gps) { -gboolean show_directions = TRUE; -gint announce_thres_unsquared; - if (!gps) { MACRO_PATH_INCREMENT_TAIL(_track); *_track.tail=_point_null; - return; + return FALSE; } -if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->unity-_track.tail->unity) > _draw_width) { +if (abs((gint)gps->unitx-_track.tail->unitx) > sensitivity || abs((gint)gps->unity-_track.tail->unity) > sensitivity) { /* If gps is available, update the nearest-waypoint data. */ if (gps && _route.head != _route.tail && (gps->newly_fixed ? (route_find_nearest_point(), TRUE) : route_update_nears(TRUE))) { @@ -152,8 +148,8 @@ if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->uni /* Instead of calling map_render_paths(), we'll draw the new line * ourselves and call gtk_widget_queue_draw_area(). */ - map_render_segment(_gc[COLORABLE_TRACK], _gc[COLORABLE_TRACK_BREAK], - _track.tail->unitx, _track.tail->unity, gps->unitx, gps->unity); + map_render_segment(_gc[COLORABLE_TRACK], _gc[COLORABLE_TRACK_BREAK], + _track.tail->unitx, _track.tail->unity, gps->unitx, gps->unity); if (_track.tail->unity && _track.tail->unitx) { tx1 = unit2x(_track.tail->unitx); @@ -192,27 +188,9 @@ if (abs((gint)gps->unitx-_track.tail->unitx) > _draw_width || abs((gint)gps->uni _track.points++; } -if (_autoroute_data.enabled && !_autoroute_data.in_progress && _near_point_dist_squared > 400) { - MACRO_BANNER_SHOW_INFO(_window, _("Recalculating directions...")); - _autoroute_data.in_progress = TRUE; - show_directions = FALSE; - g_idle_add((GSourceFunc)auto_route_dl_idle, NULL); -} - -announce_thres_unsquared=(20+(guint)gps->speed)*_announce_notice_ratio*3; - -/* Check if we should announce upcoming waypoints. */ -if (gps && show_directions && _next_way_dist_squared < (announce_thres_unsquared * announce_thres_unsquared)) { - if (_enable_voice && strcmp(_next_way->desc, _last_spoken_phrase)) { - g_free(_last_spoken_phrase); - _last_spoken_phrase=g_strdup(_next_way->desc); - speak_text(_last_spoken_phrase); - } - MACRO_BANNER_SHOW_INFO(_window, _next_way->desc); -} - /* Keep the display on if we are moving. */ KEEP_DISPLAY_ON(); +return TRUE; } gboolean @@ -289,13 +267,13 @@ GtkWidget *table; GtkWidget *label; GtkWidget *txt_scroll; GtkWidget *txt_desc; +gboolean ret; dialog = gtk_dialog_new_with_buttons(_("Insert Mark"), - GTK_WINDOW(_window), - GTK_DIALOG_MODAL, GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, NULL); + GTK_WINDOW(_window), GTK_DIALOG_MODAL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, + NULL); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0); @@ -323,10 +301,11 @@ txt_desc = gtk_text_view_new(); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD); gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc); -gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 450, 80); +gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 450, 100); gtk_widget_show_all(dialog); +ret=FALSE; while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { GtkTextBuffer *tbuf; GtkTextIter ti1, ti2; @@ -342,10 +321,9 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { continue; } - map_render_paths(); - MACRO_QUEUE_DRAW_AREA(); + ret=TRUE; break; } gtk_widget_destroy(dialog); -return TRUE; +return ret; } diff --git a/src/track.h b/src/track.h index 5bba3a3..ffd179e 100644 --- a/src/track.h +++ b/src/track.h @@ -26,7 +26,7 @@ struct { void track_init(void); void track_deinit(void); -void track_add(GpsData *gps); +gboolean track_add(GpsData *gps); gboolean track_insert_break(void); gboolean track_insert_mark(void); gboolean track_save(void); diff --git a/src/ui-common.c b/src/ui-common.c index 821c9ab..eded8ba 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -58,10 +58,10 @@ static GtkActionGroup *map_repos_action_group; static GtkUIManager *ui; struct ui_notebook_struct { - GtkWidget *notebook; - gint map; - gint gps; - gint heading; + GtkWidget *notebook; + gint map; + gint gps; + gint heading; gint route; gint track; gint qpoi; @@ -116,7 +116,6 @@ static const gchar *mapper_ui = " " " " " " -" " " " " " " " @@ -145,6 +144,7 @@ static const gchar *mapper_ui = " " " " " " +" " #if 0 " " " " @@ -256,11 +256,11 @@ static GtkActionEntry ui_entries[] = { {"poi_settings", GTK_STOCK_PREFERENCES, N_("_Settings..."), NULL, NULL, NULL }, {"poi_add", GTK_STOCK_ADD, N_("_Add"), "A", NULL, G_CALLBACK(cb_poi_add) }, {"poi_quick_add", GTK_STOCK_ABOUT, N_("_Quick Add"), "E", NULL, G_CALLBACK(cb_poi_add) }, + {"poi_search", GTK_STOCK_FIND, N_("_Search..."), NULL, NULL, G_CALLBACK(cb_poi_search) }, {"poi_import", GTK_STOCK_OPEN, N_("_Import..."), NULL, NULL, NULL }, {"poi_export", GTK_STOCK_SAVE, N_("_Export..."), NULL, NULL, NULL }, {"search", NULL, N_("_Search"), NULL, NULL, NULL }, - {"poi_search", GTK_STOCK_FIND, N_("_Search..."), "P", NULL, G_CALLBACK(cb_poi_search) }, {"search_address", GTK_STOCK_FIND, N_("Address..."), "F", NULL, G_CALLBACK(menu_cb_search_address) }, {"map", NULL, N_("_Map"), NULL, NULL, NULL }, @@ -805,7 +805,10 @@ gps_location_update(Gps *gps) { g_assert(gps); if (filter_check(&filter, &gps->data, &map_loc)==TRUE) { - track_add(&_gps->data); + if (track_add(&_gps->data)) { + route_check_waypoint_announce(&_gps->data); + route_autoroute_check(); + } map_refresh_mark(); } return FALSE; -- 2.39.5