From: Ehud S. <esh...@us...> - 2006-08-18 17:52:56
|
Update of /cvsroot/roadmap/roadmap_editor/src/navigate In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv7481 Modified Files: navigate_dglib.c navigate_graph.h navigate_main.c navigate_main.h Log Message: Ignore turn restrictions if no valid route is available. Index: navigate_main.c =================================================================== RCS file: /cvsroot/roadmap/roadmap_editor/src/navigate/navigate_main.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** navigate_main.c 9 Aug 2006 07:34:30 -0000 1.12 --- navigate_main.c 18 Aug 2006 17:52:50 -0000 1.13 *************** *** 52,57 **** --- 52,61 ---- #include "roadmap_adjust.h" #include "roadmap_lang.h" + #include "roadmap_address.h" #include "roadmap_sound.h" + //FIXME remove when navigation will support plugin lines + #include "editor/editor_plugin.h" + #include "navigate_plugin.h" #include "navigate_graph.h" *************** *** 67,70 **** --- 71,75 ---- static int NavigateTrackFollowGPS = 0; static RoadMapPen NavigatePen; + static RoadMapPen NavigatePenEst; static void navigate_update (RoadMapPosition *position, PluginLine *current); *************** *** 78,81 **** --- 83,87 ---- static int NavigateDistanceToTurn; static int NavigateETAToTurn; + static int NavigateFlags; RoadMapNavigateRouteCB NavigateCallbacks = { *************** *** 111,118 **** --- 117,128 ---- *from_point = -1; + if (NavigateTrackFollowGPS) { RoadMapGpsPosition pos; + //FIXME remove when navigation will support plugin lines + editor_plugin_set_override (0); + if (roadmap_navigate_get_current (&pos, &line, &direction) != -1) { *************** *** 134,137 **** --- 144,150 ---- } + //FIXME remove when navigation will support plugin lines + editor_plugin_set_override (1); + } else { *************** *** 144,151 **** --- 157,170 ---- if (!position) return -1; + //FIXME remove when navigation will support plugin lines + editor_plugin_set_override (0); + if ((roadmap_navigate_retrieve_line (position, 20, &line, &distance, LAYER_ALL_ROADS) == -1) || (roadmap_plugin_get_id (&line) != ROADMAP_PLUGIN_ID)) { + //FIXME remove when navigation will support plugin lines + editor_plugin_set_override (1); + roadmap_messagebox ("Error", "Can't find a road near departure point."); *************** *** 154,157 **** --- 173,179 ---- } + //FIXME remove when navigation will support plugin lines + editor_plugin_set_override (1); + } *************** *** 196,199 **** --- 218,224 ---- NavigateDestPos = *position; + //FIXME remove when navigation will support plugin lines + editor_plugin_set_override (0); + if ((roadmap_navigate_retrieve_line (position, 20, &line, &distance, LAYER_ALL_ROADS) == -1) || *************** *** 201,207 **** --- 226,237 ---- roadmap_messagebox ("Error", "Can't find a road near destination point."); + //FIXME remove when navigation will support plugin lines + editor_plugin_set_override (1); + return -1; } + //FIXME remove when navigation will support plugin lines + editor_plugin_set_override (1); *to_line = line; *************** *** 239,242 **** --- 269,273 ---- PluginLine from_line; int from_point; + int result_flags; NavigateNumSegments = MAX_NAV_SEGEMENTS; *************** *** 256,260 **** navigate_get_route_segments (&from_line, from_point, &NavigateDestination, NavigateDestPoint, ! NavigateSegments, &NavigateNumSegments); if (track_time <= 0) { --- 287,291 ---- navigate_get_route_segments (&from_line, from_point, &NavigateDestination, NavigateDestPoint, ! NavigateSegments, &NavigateNumSegments, &result_flags); if (track_time <= 0) { *************** *** 262,265 **** --- 293,298 ---- } + NavigateFlags = result_flags; + navigate_instr_prepare_segments (NavigateSegments, NavigateNumSegments, &NavigateSrcPos, &NavigateDestPos); *************** *** 305,308 **** --- 338,351 ---- + static int navigate_address_cb (const RoadMapPosition *point, + const PluginLine *line, + int direction) { + + roadmap_trip_set_point ("Destination", point); + + return navigate_main_calc_route (); + } + + void navigate_update (RoadMapPosition *position, PluginLine *current) { *************** *** 418,421 **** --- 461,465 ---- if (NavigateDistanceToTurn > ANNOUNCES[i]) { NavigateNextAnnounce = ANNOUNCES[i]; + break; } } *************** *** 593,601 **** roadmap_canvas_set_thickness (ROUTE_PEN_WIDTH); navigate_bar_initialize (); navigate_main_set (1); ! NextMessageUpdate = ! roadmap_message_register (navigate_main_format_messages); NavigatePluginID = navigate_plugin_register (); --- 637,652 ---- roadmap_canvas_set_thickness (ROUTE_PEN_WIDTH); + NavigatePenEst = roadmap_canvas_create_pen ("NavigatePen2"); + roadmap_canvas_set_foreground ("red"); + roadmap_canvas_set_opacity (160); + roadmap_canvas_set_thickness (ROUTE_PEN_WIDTH); + navigate_bar_initialize (); navigate_main_set (1); ! NextMessageUpdate = ! roadmap_message_register (navigate_main_format_messages); ! ! roadmap_address_register_nav (navigate_address_cb); NavigatePluginID = navigate_plugin_register (); *************** *** 615,626 **** ! void navigate_main_calc_route () { int track_time; PluginLine from_line; int from_point; ! NavigateTrackFollowGPS = ! (strcmp (roadmap_trip_get_focus_name (), "GPS") == 0); NavigateDestination.plugin_id = INVALID_PLUGIN_ID; --- 666,689 ---- ! int navigate_main_calc_route () { int track_time; PluginLine from_line; int from_point; + int result_flags; ! const char *focus = roadmap_trip_get_focus_name (); ! ! NavigateTrackFollowGPS = focus && !strcmp (focus, "GPS"); ! ! if (NavigateTrackFollowGPS) { ! if (roadmap_trip_get_position ("Departure")) { ! roadmap_trip_remove_point ("Departure"); ! } ! } ! ! if (!NavigateTrackFollowGPS && !roadmap_trip_get_position ("Departure")) { ! NavigateTrackFollowGPS = 1; ! } NavigateDestination.plugin_id = INVALID_PLUGIN_ID; *************** *** 630,639 **** NavigateNumSegments = MAX_NAV_SEGEMENTS; ! if (navigate_load_data () < 0) return; if (navigate_find_track_points (&from_line, &from_point, &NavigateDestination, &NavigateDestPoint)) { ! return; } --- 693,706 ---- NavigateNumSegments = MAX_NAV_SEGEMENTS; ! if (navigate_load_data () < 0) { ! ! roadmap_messagebox("Error", "Error loading navigation data."); ! return -1; ! } if (navigate_find_track_points (&from_line, &from_point, &NavigateDestination, &NavigateDestPoint)) { ! return -1; } *************** *** 641,645 **** navigate_get_route_segments (&from_line, from_point, &NavigateDestination, NavigateDestPoint, ! NavigateSegments, &NavigateNumSegments); if (track_time <= 0) { --- 708,712 ---- navigate_get_route_segments (&from_line, from_point, &NavigateDestination, NavigateDestPoint, ! NavigateSegments, &NavigateNumSegments, &result_flags); if (track_time <= 0) { *************** *** 651,656 **** roadmap_messagebox("Error", "Can't find a route."); } } else { ! char msg[200]; int i; int length = 0; --- 718,725 ---- roadmap_messagebox("Error", "Can't find a route."); } + + return -1; } else { ! char msg[200] = {0}; int i; int length = 0; *************** *** 663,667 **** } ! snprintf(msg, sizeof(msg), "%s: %.1f %s\n%s: %.1f %s", roadmap_lang_get ("Length"), length/1000.0, --- 732,744 ---- } ! NavigateFlags = result_flags; ! ! if (result_flags & GRAPH_IGNORE_TURNS) { ! snprintf(msg, sizeof(msg), "%s\n", ! roadmap_lang_get ("The calculated route may have incorrect turn instructions.")); ! } ! ! snprintf(msg + strlen(msg), sizeof(msg) - strlen(msg), ! "%s: %.1f %s\n%s: %.1f %s", roadmap_lang_get ("Length"), length/1000.0, *************** *** 684,687 **** --- 761,766 ---- roadmap_messagebox ("Route found", msg); } + + return 0; } *************** *** 691,697 **** --- 770,783 ---- int current_width = -1; int last_cfcc = -1; + RoadMapPen pen; if (!NavigateTrackEnabled) return; + if (NavigateFlags & GRAPH_IGNORE_TURNS) { + pen = NavigatePenEst; + } else { + pen = NavigatePen; + } + if (!NavigateTrackFollowGPS && !strcmp (roadmap_trip_get_focus_name (), "GPS")) { *************** *** 700,703 **** --- 786,793 ---- roadmap_trip_stop (); + + if (roadmap_trip_get_position ("Departure")) { + roadmap_trip_remove_point ("Departure"); + } roadmap_navigate_route (NavigateCallbacks); } *************** *** 708,713 **** if (segment->line.cfcc != last_cfcc) { ! RoadMapPen pen = roadmap_layer_get_pen (segment->line.cfcc, 0); ! int width = roadmap_canvas_get_thickness (pen); if (width < ROUTE_PEN_WIDTH) { --- 798,803 ---- if (segment->line.cfcc != last_cfcc) { ! RoadMapPen layer_pen = roadmap_layer_get_pen (segment->line.cfcc, 0); ! int width = roadmap_canvas_get_thickness (layer_pen); if (width < ROUTE_PEN_WIDTH) { *************** *** 718,722 **** RoadMapPen previous_pen; ! previous_pen = roadmap_canvas_select_pen (NavigatePen); roadmap_canvas_set_thickness (width); current_width = width; --- 808,812 ---- RoadMapPen previous_pen; ! previous_pen = roadmap_canvas_select_pen (pen); roadmap_canvas_set_thickness (width); current_width = width; *************** *** 737,741 **** segment->last_shape, segment->shape_itr, ! NavigatePen, NULL, NULL, --- 827,831 ---- segment->last_shape, segment->shape_itr, ! pen, NULL, NULL, Index: navigate_main.h =================================================================== RCS file: /cvsroot/roadmap/roadmap_editor/src/navigate/navigate_main.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** navigate_main.h 9 Aug 2006 07:35:56 -0000 1.6 --- navigate_main.h 18 Aug 2006 17:52:50 -0000 1.7 *************** *** 61,65 **** int navigate_main_reload_data (void); void navigate_main_set (int status); ! void navigate_main_calc_route (void); void navigate_main_screen_repaint (int max_pen); --- 61,65 ---- int navigate_main_reload_data (void); void navigate_main_set (int status); ! int navigate_main_calc_route (void); void navigate_main_screen_repaint (int max_pen); Index: navigate_graph.h =================================================================== RCS file: /cvsroot/roadmap/roadmap_editor/src/navigate/navigate_graph.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** navigate_graph.h 9 Aug 2006 07:35:56 -0000 1.3 --- navigate_graph.h 18 Aug 2006 17:52:50 -0000 1.4 *************** *** 28,31 **** --- 28,33 ---- #include "navigate_main.h" + #define GRAPH_IGNORE_TURNS 1 + int navigate_reload_data (void); int navigate_load_data (void); *************** *** 36,40 **** int to_point, NavigateSegment *segments, ! int *size); #endif /* _NAVIGATE_GRAPH_H_ */ --- 38,43 ---- int to_point, NavigateSegment *segments, ! int *size, ! int *result); #endif /* _NAVIGATE_GRAPH_H_ */ Index: navigate_dglib.c =================================================================== RCS file: /cvsroot/roadmap/roadmap_editor/src/navigate/navigate_dglib.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** navigate_dglib.c 9 Aug 2006 07:35:56 -0000 1.5 --- navigate_dglib.c 18 Aug 2006 17:52:50 -0000 1.6 *************** *** 47,50 **** --- 47,57 ---- static dglSPCache_s spCache; + typedef struct { + PluginLine from_line; + int turn_restrictions; + } NavigateClip; + + NavigateClip NavigateClipData; + static int clipper ( dglGraph_s * pgraph , *************** *** 54,57 **** --- 61,80 ---- ) { + NavigateClip *info = (NavigateClip *)pvarg; + int to_line = dglEdgeGet_Id(pgraph, pIn->pnEdge); + int from_line; + + if (pIn->pnPrevEdge != NULL) { + + from_line = dglEdgeGet_Id(pgraph, pIn->pnPrevEdge); + } else { + from_line = roadmap_plugin_get_line_id (&info->from_line); + } + + /* no U turns */ + if (from_line == -to_line) return 1; + + if (!info->turn_restrictions) return 0; + if ( roadmap_turns_find_restriction ( dglNodeGet_Id(pgraph, pIn->pnNodeFrom), *************** *** 141,145 **** int to_point, NavigateSegment *segments, ! int *size) { int i; --- 164,169 ---- int to_point, NavigateSegment *segments, ! int *size, ! int *result) { int i; *************** *** 150,159 **** if (fips_data_loaded != roadmap_locator_active ()) return -1; /* save places for start & end lines */ *size -= 2; nret = dglShortestPath (&graph, &pReport, from_point, to_point, ! clipper, (void *)from_line->line_id, NULL); ! if (nret <= 0) return nret; if (pReport->cArc > *size) return -1; --- 174,198 ---- if (fips_data_loaded != roadmap_locator_active ()) return -1; + *result = 0; + /* save places for start & end lines */ *size -= 2; + NavigateClipData.from_line = *from_line; + NavigateClipData.turn_restrictions = 1; + nret = dglShortestPath (&graph, &pReport, from_point, to_point, ! clipper, &NavigateClipData, NULL); ! if (nret <= 0) { ! ! *result = GRAPH_IGNORE_TURNS; ! ! NavigateClipData.turn_restrictions = 0; ! nret = dglShortestPath (&graph, &pReport, from_point, to_point, ! clipper, &NavigateClipData, NULL); ! if (nret <= 0) { ! return nret; ! } ! } if (pReport->cArc > *size) return -1; |