int editor_db_open (int map_id) { char name[100]; const char *map_path; char file_name[512]; int do_read = 0; editor_log_push ("editor_db_open"); #ifndef IPHONE map_path = roadmap_db_map_path(); #else map_path = roadmap_path_preferred("maps"); #endif //IPHONE if (!map_path) { editor_log (ROADMAP_ERROR, "Can't find editor path"); editor_log_pop (); return -1; } snprintf (name, sizeof(name), "edt%05d.dat", map_id); roadmap_path_format (file_name, sizeof (file_name), map_path, name); if (roadmap_file_exists (map_path, name)) { EditorDataFile = roadmap_file_open(file_name, "rw"); do_read = 1; } else { roadmap_path_create (map_path); EditorDataFile = roadmap_file_open(file_name, "w"); roadmap_file_write (EditorDataFile, &DB_SIGNATURE, sizeof (int)); } do { if (!ROADMAP_FILE_IS_VALID(EditorDataFile)) { editor_log (ROADMAP_ERROR, "Can't open/create new database: %s/%s", map_path, name); editor_log_pop (); return -1; } if (do_read) { do_read = 0; if (editor_db_read () == -1) { editor_db_free (); //roadmap_messagebox("Error", "Offline data file is currupt: Re-Initializing data"); roadmap_log (ROADMAP_ERROR, "Offline data file is currupt: Re-Initializing data"); roadmap_file_close (EditorDataFile); roadmap_file_remove (NULL, file_name); EditorDataFile = roadmap_file_open(file_name, "w"); roadmap_file_write (EditorDataFile, &DB_SIGNATURE, sizeof (int)); } } } while (do_read); EditorActiveMap = map_id; editor_log_pop (); return 0; }
int editor_db_open (int map_id) { char name[100]; const char *map_path; char *file_name; int do_read = 0; editor_log_push ("editor_db_open"); map_path = roadmap_db_map_path(); if (!map_path) { editor_log (ROADMAP_ERROR, "Can't find editor path"); editor_log_pop (); return -1; } snprintf (name, sizeof(name), "edt%05d.dat", map_id); file_name = roadmap_path_join(map_path, name); if (roadmap_file_exists (map_path, name)) { EditorDataFile = roadmap_file_open(file_name, "rw"); do_read = 1; } else { roadmap_path_create (map_path); EditorDataFile = roadmap_file_open(file_name, "w"); } #ifdef WIN32 roadmap_path_free(map_path); #endif do { if (!ROADMAP_FILE_IS_VALID(EditorDataFile)) { editor_log (ROADMAP_ERROR, "Can't open/create new database: %s/%s", map_path, name); roadmap_path_free(file_name); editor_log_pop (); return -1; } if (do_read) { do_read = 0; if (editor_db_read () == -1) { editor_db_free (); roadmap_messagebox("Error", "Offline data file is currupt: Re-Initializing data"); roadmap_file_close (EditorDataFile); roadmap_file_remove (NULL, file_name); EditorDataFile = roadmap_file_open(file_name, "w"); } } } while (do_read); roadmap_path_free(file_name); EditorActiveMap = map_id; editor_log_pop (); return 0; }
int editor_track_known_end_segment (PluginLine *previous_line, int last_point_id, PluginLine *line, RoadMapTracking *street, int is_new_track) { //TODO: add stuff //Notice that previous_line may not be valid (only at first) // //check for low confidence & in static update, do not use a trkseg with low confidence! RoadMapPosition from; RoadMapPosition to; RoadMapPosition *current; int trkseg; int trkseg_line_id; int trkseg_plugin_id; int trkseg_square; int line_length; int segment_length; int percentage; int flags = 0; editor_log_push ("editor_track_end_known_segment"); assert (last_point_id != 0); if (!last_point_id) return 0; if (editor_db_activate (line->fips) == -1) { editor_db_create (line->fips); if (editor_db_activate (line->fips) == -1) { editor_log_pop (); return 0; } } roadmap_street_extend_line_ends (line, &from, &to, FLAG_EXTEND_BOTH, NULL, NULL); trkseg_plugin_id = roadmap_plugin_get_id (line); trkseg_line_id = roadmap_plugin_get_line_id (line); trkseg_square = roadmap_plugin_get_square (line); line_length = editor_track_util_get_line_length (line); segment_length = editor_track_util_length (0, last_point_id); editor_log (ROADMAP_INFO, "Ending line %d (plugin_id:%d). Line length:%d, Segment length:%d", trkseg_line_id, trkseg_plugin_id, line_length, segment_length); /* End current segment if we really passed through it * and not only touched a part of it. */ /*SRUL*: avoid this problem, see above comment assert (line_length > 0); if (line_length == 0) { editor_log (ROADMAP_ERROR, "line %d (plugin_id:%d) has length of zero.", trkseg_line_id, trkseg_plugin_id); editor_log_pop (); return 0; } */ if (line_length <= 0) line_length = 1; current = track_point_pos (last_point_id); if (roadmap_math_distance (current, &to) > roadmap_math_distance (current, &from)) { flags = ED_TRKSEG_OPPOSITE_DIR; #if DEBUG_TRACKS printf ("Closing trkseg from %d.%06d,%d.%06d to %d.%06d,%d.%06d", to.longitude / 1000000, to.longitude % 1000000, to.latitude / 1000000, to.latitude % 1000000, from.longitude / 1000000, from.longitude % 1000000, from.latitude / 1000000, from.latitude % 1000000); } else { printf ("Closing trkseg from %d.%06d,%d.%06d to %d.%06d,%d.%06d", from.longitude / 1000000, from.longitude % 1000000, from.latitude / 1000000, from.latitude % 1000000, to.longitude / 1000000, to.longitude % 1000000, to.latitude / 1000000, to.latitude % 1000000); #endif } #if DEBUG_TRACKS printf (" %d/%d", segment_length, line_length); #endif if (is_new_track) { flags |= ED_TRKSEG_NEW_TRACK; #if DEBUG_TRACKS printf (" NEW"); #endif } if (!editor_ignore_new_roads ()) { flags |= ED_TRKSEG_RECORDING_ON; } percentage = 100 * segment_length / line_length; if (percentage < 70) { editor_log (ROADMAP_INFO, "segment is too small to consider: %d%%", percentage); if (segment_length > (editor_track_point_distance ()*1.5)) { trkseg = editor_track_util_create_trkseg (trkseg_square, trkseg_line_id, trkseg_plugin_id, 0, last_point_id, flags|ED_TRKSEG_LOW_CONFID); editor_track_add_trkseg (line, trkseg, ROUTE_DIRECTION_NONE, ROUTE_CAR_ALLOWED); editor_log_pop (); #if DEBUG_TRACKS printf (" LOW (percentage)\n"); #endif return 1; } else { trkseg = editor_track_util_create_trkseg (trkseg_square, trkseg_line_id, trkseg_plugin_id, 0, last_point_id, flags|ED_TRKSEG_IGNORE); editor_track_add_trkseg (line, trkseg, ROUTE_DIRECTION_NONE, ROUTE_CAR_ALLOWED); editor_log_pop (); #if DEBUG_TRACKS printf (" IGNORE\n"); #endif return 0; } } #if 0 if (!roadmap_fuzzy_is_good (street->entry_fuzzyfied) || !roadmap_fuzzy_is_good (street->cur_fuzzyfied)) { flags |= ED_TRKSEG_LOW_CONFID; #if DEBUG_TRACKS printf (" LOW"); if (!roadmap_fuzzy_is_good (street->entry_fuzzyfied)) printf (" (entry)"); if (!roadmap_fuzzy_is_good (street->cur_fuzzyfied)) printf (" (cur)"); #endif } #endif if (trkseg_plugin_id != ROADMAP_PLUGIN_ID) flags |= ED_TRKSEG_LOW_CONFID; trkseg = editor_track_util_create_trkseg (trkseg_square, trkseg_line_id, trkseg_plugin_id, 0, last_point_id, flags); if (flags & ED_TRKSEG_OPPOSITE_DIR) { editor_log (ROADMAP_INFO, "Updating route direction: to -> from"); editor_track_add_trkseg (line, trkseg, ROUTE_DIRECTION_AGAINST_LINE, ROUTE_CAR_ALLOWED); } else { editor_log (ROADMAP_INFO, "Updating route direction: from -> to"); editor_track_add_trkseg (line, trkseg, ROUTE_DIRECTION_WITH_LINE, ROUTE_CAR_ALLOWED); } editor_log_pop (); #if DEBUG_TRACKS printf ("\n"); #endif return 1; }