X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/3a96ce6ba879551f48c9d517d0466d104bb65edb..700b0908d71f64c9449ba372d0b9a8363257afb1:/src/gpspoint.c?ds=inline diff --git a/src/gpspoint.c b/src/gpspoint.c index e7f2d320..f6344a5e 100644 --- a/src/gpspoint.c +++ b/src/gpspoint.c @@ -64,6 +64,7 @@ static struct LatLon line_latlon; static gchar *line_name; static gchar *line_comment; static gchar *line_image; +static gchar *line_symbol; static gboolean line_newsegment = FALSE; static gboolean line_has_timestamp = FALSE; static time_t line_timestamp = 0; @@ -131,12 +132,13 @@ static gchar *deslashndup ( const gchar *str, guint16 len ) void a_gpspoint_read_file(VikTrwLayer *trw, FILE *f ) { VikCoordMode coord_mode = vik_trw_layer_get_coord_mode ( trw ); gchar *tag_start, *tag_end; - GHashTable *tracks = vik_trw_layer_get_tracks ( trw ); - GHashTable *waypoints = vik_trw_layer_get_waypoints ( trw ); g_assert ( f != NULL && trw != NULL ); line_type = 0; line_timestamp = 0; line_newsegment = FALSE; + line_image = NULL; + line_symbol = NULL; + current_track = NULL; while (fgets(line_buffer, 2048, f)) { @@ -193,7 +195,9 @@ void a_gpspoint_read_file(VikTrwLayer *trw, FILE *f ) { vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &line_latlon ); - g_hash_table_insert ( waypoints, line_name, wp ); + vik_trw_layer_filein_add_waypoint ( trw, line_name, wp ); + g_free ( line_name ); + line_name = NULL; if ( line_comment ) { @@ -207,7 +211,11 @@ void a_gpspoint_read_file(VikTrwLayer *trw, FILE *f ) { line_image = NULL; } - line_name = NULL; /* will be freed automatically */ + if ( line_symbol ) + { + vik_waypoint_set_symbol ( wp, line_symbol ); + line_symbol = NULL; + } } else if (line_type == GPSPOINT_TYPE_TRACK && line_name) { @@ -229,8 +237,9 @@ void a_gpspoint_read_file(VikTrwLayer *trw, FILE *f ) { } pl->trackpoints = NULL; - g_hash_table_insert ( tracks, line_name, pl ); - line_name = NULL; /* will be freed automatically */ + vik_trw_layer_filein_add_track ( trw, line_name, pl ); + g_free ( line_name ); + line_name = NULL; current_track = pl; } @@ -252,14 +261,18 @@ void a_gpspoint_read_file(VikTrwLayer *trw, FILE *f ) { g_free ( line_comment ); if (line_image) g_free ( line_image ); + if (line_symbol) + g_free ( line_symbol ); line_comment = NULL; line_image = NULL; + line_symbol = NULL; line_type = GPSPOINT_TYPE_NONE; line_newsegment = FALSE; line_has_timestamp = FALSE; line_timestamp = 0; line_altitude = VIK_DEFAULT_ALTITUDE; line_visible = TRUE; + line_symbol = NULL; } } @@ -363,6 +376,10 @@ static void gpspoint_process_key_and_value ( const gchar *key, gint key_len, con { line_visible = FALSE; } + else if (key_len == 6 && strncasecmp( key, "symbol", key_len ) == 0 && value != NULL) + { + line_symbol = g_strndup ( value, value_len ); + } else if (key_len == 8 && strncasecmp( key, "unixtime", key_len ) == 0 && value != NULL) { line_timestamp = g_strtod(value, NULL); @@ -378,10 +395,19 @@ static void gpspoint_process_key_and_value ( const gchar *key, gint key_len, con static void a_gpspoint_write_waypoint ( const gchar *name, VikWaypoint *wp, FILE *f ) { static struct LatLon ll; + gchar *s_lat, *s_lon; vik_coord_to_latlon ( &(wp->coord), &ll ); - fprintf ( f, "type=\"waypoint\" latitude=\"%f\" longitude=\"%f\" name=\"%s\"", ll.lat, ll.lon, name ); - if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) - fprintf ( f, " altitude=\"%f\"", wp->altitude ); + s_lat = a_coords_dtostr(ll.lat); + s_lon = a_coords_dtostr(ll.lon); + fprintf ( f, "type=\"waypoint\" latitude=\"%s\" longitude=\"%s\" name=\"%s\"", s_lat, s_lon, name ); + g_free ( s_lat ); + g_free ( s_lon ); + + if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) { + gchar *s_alt = a_coords_dtostr(wp->altitude); + fprintf ( f, " altitude=\"%s\"", s_alt ); + g_free(s_alt); + } if ( wp->comment ) { gchar *tmp_comment = slashdup(wp->comment); @@ -394,6 +420,10 @@ static void a_gpspoint_write_waypoint ( const gchar *name, VikWaypoint *wp, FILE fprintf ( f, " image=\"%s\"", tmp_image ); g_free ( tmp_image ); } + if ( wp->symbol ) + { + fprintf ( f, " symbol=\"%s\"", wp->symbol ); + } if ( ! wp->visible ) fprintf ( f, " visible=\"n\"" ); fprintf ( f, "\n" ); @@ -402,12 +432,20 @@ static void a_gpspoint_write_waypoint ( const gchar *name, VikWaypoint *wp, FILE static void a_gpspoint_write_trackpoint ( VikTrackpoint *tp, FILE *f ) { static struct LatLon ll; + gchar *s_lat, *s_lon; vik_coord_to_latlon ( &(tp->coord), &ll ); - fprintf ( f, "type=\"trackpoint\" latitude=\"%f\" longitude=\"%f\"", ll.lat, ll.lon ); + s_lat = a_coords_dtostr(ll.lat); + s_lon = a_coords_dtostr(ll.lon); + fprintf ( f, "type=\"trackpoint\" latitude=\"%s\" longitude=\"%s\"", s_lat, s_lon ); + g_free ( s_lat ); + g_free ( s_lon ); - if ( tp->altitude != VIK_DEFAULT_ALTITUDE ) - fprintf ( f, " altitude=\"%f\"", tp->altitude ); + if ( tp->altitude != VIK_DEFAULT_ALTITUDE ) { + gchar *s_alt = a_coords_dtostr(tp->altitude); + fprintf ( f, " altitude=\"%s\"", s_alt ); + g_free(s_alt); + } if ( tp->has_timestamp ) fprintf ( f, " unixtime=\"%ld\"", tp->timestamp ); if ( tp->newsegment )