/* ***************************************************************************** */ void route_next_target () { //gchar str[100]; gchar buf[200]; gdouble d; /* test for new route point */ if (strcmp (current.target, " ")) { if (route.active) d = calcdist ((routelist + route.pointer)->lon, (routelist + route.pointer)->lat); else d = calcdist (coords.target_lon, coords.target_lat); if (d <= ROUTEREACH || route.forcenext) { route.forcenext = FALSE; if ((route.pointer != (route.items - 1)) && (route.active)) { route.pointer++; /* let's say the waypoint description */ saytargettext (local_config.wp_file, current.target); setroutetarget (NULL, -1); } else { /* route endpoint reached */ if (saytarget) { #ifdef SPEECH g_snprintf (buf, sizeof (buf), _("You reached the target %s."), current.target); speech_saytext (buf, 3); #endif /* let's say the waypoint description */ saytargettext (local_config.wp_file, current.target); } route.edit = FALSE; route.active = FALSE; saytarget = FALSE; route.pointer = route.items = 0; } } } }
/* ***************************************************************************** */ void insertallroutepoints () { gint i, j; gchar *text[5], text0[20], text1[20], text2[20], text3[20]; for (i = 0; i < maxwp; i++) { (wayp + i)->dist = calcdist ((wayp + i)->lon, (wayp + i)->lat); text[1] = (wayp + i)->name; g_snprintf (text0, sizeof (text0), "%d", i + 1); coordinate2gchar(text1, sizeof(text1), (wayp+i)->lat, TRUE, local_config.coordmode); coordinate2gchar(text2, sizeof(text2), (wayp+i)->lon, FALSE, local_config.coordmode); g_snprintf (text3, sizeof (text3), "%9.3f", (wayp + i)->dist); text[0] = text0; text[2] = text1; text[3] = text2; text[4] = text3; j = gtk_clist_append (GTK_CLIST (myroutelist), (gchar **) text); gtk_clist_set_foreground (GTK_CLIST (myroutelist), j, &colors.black); g_strlcpy ((routelist + route.items)->name, (wayp + i)->name, 40); (routelist + route.items)->lat = (wayp + i)->lat; (routelist + route.items)->lon = (wayp + i)->lon; route.items++; } gtk_widget_set_sensitive (select_route_button, TRUE); gtk_widget_set_sensitive (menuitem_saveroute, TRUE); }
/* dijkstra template */ int dijkstra_template(int start,int goal) { static int dist[]; /* array of distances */ static char vis[]; /* array indicating visited (processed) nodes */ int val,w,cur; if(start==goal) return 0; /* set visited to 0 */ /* set distances to INF */ dist[start]=0; /* set distance to start to 0 */ heapn=1; heapinsert(0,start); /* insert start node to heap */ while(heapn>1) { heapremove(&val,&cur); if(vis[cur]) continue; /* if current node is already done: continue */ if(cur==goal) return val; /* done! */ vis[cur]=1; for(neighbours to cur) { x2=potential neighbour; if(x2 is out of bounds) continue; if(vis[x2]) continue; w=val+calcdist(cur,x2); if(dist[x2]>w) { dist[x2]=w; heapinsert(w,x2); } } }
// Connect the closest children of two internal nodes void connect_closest_children(FS_TREE * T, Graph * G, fsp_t a, fsp_t b) { while (T->tree[a].c2>0 || T->tree[b].c2>0) { //find closest points: while we still have an internal node, if ( T->tree[a].c2 > 0 ) { //if a isn't leaf if (calcdist(T, T->tree[a].c1, b) < calcdist(T, T->tree[a].c2, b)) { //if c1 closer than c2 a = T->tree[a].c1; //move down the tree } else { //c2 is closer to B a = T->tree[a].c2; //move down the tree } } if ( T->tree[b].c2 > 0 ) { //if b isn't leaf if (calcdist(T, T->tree[b].c1, a) < calcdist(T, T->tree[b].c2, a)) { //if c1 closer than c2 b = T->tree[b].c1; //move down the tree } else { //c2 is closer to B b = T->tree[b].c2; //move down the tree } } } ALG_ADD_EDGE(G, T->tree[a].c1, T->tree[b].c1, calcdist(T, a, b)); //add edge to algraph }
/* ******************************************************* * update route, if the current position has changed: */ void update_route (void) { gdouble d; /* in waypoint mode call the old function */ if (!local_config.use_database) { route_next_target (); return; } /* check if current target is reached, and select next */ if (route.active) { d = calcdist (coords.target_lon, coords.target_lat); if (d <= ROUTEREACH || route.forcenext) { route.forcenext = FALSE; if (route.pointer != (route.items - 1)) { /* set target to next route item */ route.pointer++; route_settarget (-1); } else { /* endpoint reached, stop routing */ route.active = FALSE; route.pointer = route.items = 0; gtk_widget_hide_all (routeinfo_evbox); } } } /* recalculate trip /distance data if values are displayed */ if (route.items && GTK_IS_WIDGET (route_window)) { // TODO: add functionality... } }
/* ***************************************************************************** * core function to add a new point to the current routes * used by several other functions */ void add_routepoint (glong t_id, gchar *t_name, gchar *t_cmt, gchar *t_type, gdouble t_lon, gdouble t_lat) { gchar t_dist[15], t_trip[15]; gdouble last_lon, last_lat, t_dist_num; gchar *t_path; GdkPixbuf *t_icon; GtkTreeIter iter_route, iter_type; GtkTreePath *path_route; /* get an icon for the routepoint. if an icon for the given poi_type * is not available, take the generic route icon */ t_path = g_hash_table_lookup (poi_types_hash, t_type); if (t_path == NULL) t_path = g_hash_table_lookup (poi_types_hash, "waypoint.route"); gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (poi_types_tree), &iter_type, t_path); gtk_tree_model_get (GTK_TREE_MODEL (poi_types_tree), &iter_type, POITYPE_ICON, &t_icon, -1); gtk_list_store_append (route_list_tree, &iter_route); route.items +=1; coords.dest_lon = t_lon; coords.dest_lat = t_lat; /* calculate route trip distance */ if (route.items > 1) { path_route = gtk_tree_model_get_path (GTK_TREE_MODEL (route_list_tree), &iter_route); gtk_tree_path_prev (path_route); gtk_tree_model_get_iter (GTK_TREE_MODEL (route_list_tree), &iter_route, path_route); gtk_tree_model_get (GTK_TREE_MODEL (route_list_tree), &iter_route, ROUTE_LON, &last_lon, ROUTE_LAT, &last_lat, -1); route.distance += calc_wpdist (last_lon, last_lat, t_lon, t_lat, FALSE); gtk_tree_path_next (path_route); gtk_tree_model_get_iter (GTK_TREE_MODEL (route_list_tree), &iter_route, path_route); if (mydebug>25) { fprintf (stderr, "add_routepoint: Path: %s\n", gtk_tree_path_to_string (path_route)); } } else if (route.items == 1) { route.distance =+ calcdist (t_lon, t_lat); } g_snprintf (t_trip, sizeof (t_trip), "%9.3f", route.distance); t_dist_num = calcdist (t_lon, t_lat); g_snprintf (t_dist, sizeof (t_dist), "%9.3f", t_dist_num); if (mydebug>25) { fprintf (stderr, "add_point_to_route: (%d) ID: %ld |" " NAME: %s | LON: %f | LAT: %f | ICON: %p\n", route.items, t_id, t_name, t_lon, t_lat, t_icon); } gtk_list_store_set (route_list_tree, &iter_route, ROUTE_ID, t_id, ROUTE_NUMBER, route.items, ROUTE_ICON, t_icon, ROUTE_NAME, t_name, ROUTE_DISTANCE, t_dist, ROUTE_TRIP, t_trip, ROUTE_LON, t_lon, ROUTE_LAT, t_lat, ROUTE_CMT, t_cmt, ROUTE_TYPE, t_type, -1); current.needtosave = TRUE; }
/* ****************************************************************** * */ gint create_route_cb (GtkWidget * widget, guint datum) { GtkWidget *window; gchar *tabeltitel1[] = { "#", _("Waypoint"), _("Latitude"), _("Longitude"), _("Distance"), NULL }; GtkWidget *scrwindow, *vbox, *button, *button3, *hbox, *hbox_displays, *l1; gint i, j; gchar *text[5], text0[20], text1[20], text2[20], text3[20]; GtkTooltips *tooltips; route.edit = TRUE; window = gtk_dialog_new (); routewindow = window; /* gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, TRUE); */ gtk_window_set_title (GTK_WINDOW (window), _("Define route")); gtk_window_set_default_size (GTK_WINDOW (window), 320, 320); myroutelist = gtk_clist_new_with_titles (5, tabeltitel1); gtk_signal_connect (GTK_OBJECT (GTK_CLIST (myroutelist)), "select-row", GTK_SIGNAL_FUNC (setroutetarget), GTK_OBJECT (myroutelist)); select_route_button = gtk_button_new_with_label (_("Start route")); gtk_widget_set_sensitive (select_route_button, FALSE); GTK_WIDGET_SET_FLAGS (select_route_button, GTK_CAN_DEFAULT); gtk_signal_connect (GTK_OBJECT (select_route_button), "clicked", GTK_SIGNAL_FUNC (do_route_cb), 0); gtk_window_set_default (GTK_WINDOW (window), select_route_button); create_route2_button = gtk_button_new_with_label (_("Take all WP as route")); GTK_WIDGET_SET_FLAGS (create_route2_button, GTK_CAN_DEFAULT); gtk_signal_connect (GTK_OBJECT (create_route2_button), "clicked", GTK_SIGNAL_FUNC (insertallroutepoints), 0); button = gtk_button_new_with_label (_("Abort route")); GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (sel_routecancel_cb), GTK_OBJECT (window)); gtk_signal_connect_object (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (sel_routeclose_cb), GTK_OBJECT (window)); /* button3 = gtk_button_new_with_label (_("Close")); */ button3 = gtk_button_new_from_stock (GTK_STOCK_CLOSE); GTK_WIDGET_SET_FLAGS (button3, GTK_CAN_DEFAULT); gtk_signal_connect_object (GTK_OBJECT (button3), "clicked", GTK_SIGNAL_FUNC (sel_routeclose_cb), GTK_OBJECT (window)); /* Font �ndern falls PDA-Mode und Touchscreen */ if (local_config.guimode == GUI_PDA) { if (onemousebutton) { /* Change default font throughout the widget */ PangoFontDescription *font_desc; font_desc = pango_font_description_from_string ("Sans 10"); gtk_widget_modify_font (myroutelist, font_desc); pango_font_description_free (font_desc); } } gtk_clist_set_column_justification (GTK_CLIST (myroutelist), 4, GTK_JUSTIFY_RIGHT); gtk_clist_set_column_justification (GTK_CLIST (myroutelist), 0, GTK_JUSTIFY_RIGHT); gtk_clist_set_column_auto_resize (GTK_CLIST (myroutelist), 0, TRUE); gtk_clist_set_column_auto_resize (GTK_CLIST (myroutelist), 1, TRUE); gtk_clist_set_column_auto_resize (GTK_CLIST (myroutelist), 2, TRUE); gtk_clist_set_column_auto_resize (GTK_CLIST (myroutelist), 3, TRUE); gtk_clist_set_column_auto_resize (GTK_CLIST (myroutelist), 4, TRUE); scrwindow = gtk_scrolled_window_new (NULL, NULL); gtk_container_add (GTK_CONTAINER (scrwindow), myroutelist); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrwindow), (GtkPolicyType) GTK_POLICY_AUTOMATIC, (GtkPolicyType) GTK_POLICY_AUTOMATIC); vbox = gtk_vbox_new (FALSE, 2); /* gtk_container_add (GTK_CONTAINER (window), vbox); */ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE, 2); gtk_box_pack_start (GTK_BOX (vbox), scrwindow, TRUE, TRUE, 2); hbox = gtk_hbox_new (TRUE, 2); hbox_displays = gtk_hbox_new (TRUE, 2); if (!route.active) l1 = gtk_label_new (_ ("Click on waypoints list\nto add waypoints")); else l1 = gtk_label_new (_ ("Click on list item\nto select next waypoint")); gtk_box_pack_start (GTK_BOX (vbox), l1, FALSE, FALSE, 2); /* gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2); */ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), hbox, TRUE, TRUE, 2); gtk_box_pack_start (GTK_BOX (hbox), select_route_button, TRUE, TRUE, 2); gtk_box_pack_start (GTK_BOX (hbox), create_route2_button, TRUE, TRUE, 2); gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 2); gtk_box_pack_start (GTK_BOX (vbox), hbox_displays, FALSE, FALSE, 2); gtk_box_pack_start (GTK_BOX (hbox), button3, TRUE, TRUE, 2); gtk_widget_set_sensitive (create_route_button, FALSE); if (route.active) { gtk_widget_set_sensitive (select_route_button, FALSE); gtk_clist_clear (GTK_CLIST (myroutelist)); for (i = 0; i < route.items; i++) { (routelist + i)->dist = calcdist ((routelist + i)->lon, (routelist + i)->lat); text[1] = (routelist + i)->name; g_snprintf (text0, sizeof (text0), "%d", i + 1); g_snprintf (text1, sizeof (text1), "%8.5f", (routelist + i)->lat); g_snprintf (text2, sizeof (text2), "%8.5f", (routelist + i)->lon); g_snprintf (text3, sizeof (text3), "%9.3f", (routelist + i)->dist); text[0] = text0; text[2] = text1; text[3] = text2; text[4] = text3; j = gtk_clist_append (GTK_CLIST (myroutelist), (gchar **) text); gtk_clist_set_foreground (GTK_CLIST (myroutelist), j, &colors.black); } } else route.items = 0; tooltips = gtk_tooltips_new (); gtk_tooltips_set_tip (GTK_TOOLTIPS (tooltips), create_route2_button, _ ("Create a route from all waypoints. Sorted with order in file, not distance."), NULL); gtk_tooltips_set_tip (GTK_TOOLTIPS (tooltips), select_route_button, _ ("Click here to start your journey. GpsDrive guides you through the waypoints in this list."), NULL); gtk_tooltips_set_tip (GTK_TOOLTIPS (tooltips), button, _("Abort your journey"), NULL); gtk_widget_show_all (window); return TRUE; }