static void a_gpspoint_write_track ( const gpointer id, const VikTrack *trk, FILE *f ) { // Sanity clauses if ( !trk ) return; if ( !(trk->name) ) return; gchar *tmp_name = slashdup(trk->name); fprintf ( f, "type=\"%s\" name=\"%s\"", trk->is_route ? "route" : "track", tmp_name ); g_free ( tmp_name ); if ( trk->comment ) { gchar *tmp = slashdup(trk->comment); fprintf ( f, " comment=\"%s\"", tmp ); g_free ( tmp ); } if ( trk->description ) { gchar *tmp = slashdup(trk->description); fprintf ( f, " description=\"%s\"", tmp ); g_free ( tmp ); } if ( trk->source ) { gchar *tmp = slashdup(trk->source); fprintf ( f, " source=\"%s\"", tmp ); g_free ( tmp ); } if ( trk->type ) { gchar *tmp = slashdup(trk->type); fprintf ( f, " xtype=\"%s\"", tmp ); g_free ( tmp ); } if ( trk->has_color ) { fprintf ( f, " color=#%.2x%.2x%.2x", (int)(trk->color.red/256),(int)(trk->color.green/256),(int)(trk->color.blue/256)); } if ( trk->draw_name_mode > 0 ) fprintf ( f, " draw_name_mode=\"%d\"", trk->draw_name_mode ); if ( trk->max_number_dist_labels > 0 ) fprintf ( f, " number_dist_labels=\"%d\"", trk->max_number_dist_labels ); if ( ! trk->visible ) { fprintf ( f, " visible=\"n\"" ); } fprintf ( f, "\n" ); TP_write_info_type tp_write_info = { f, trk->is_route }; g_list_foreach ( trk->trackpoints, (GFunc) a_gpspoint_write_trackpoint, &tp_write_info ); fprintf ( f, "type=\"%send\"\n", trk->is_route ? "route" : "track" ); }
static void a_gpspoint_write_track ( const gchar *name, VikTrack *t, FILE *f ) { if ( t->comment ) { gchar *tmp_comment = slashdup(t->comment); fprintf ( f, "type=\"track\" name=\"%s\" comment=\"%s\"%s\n", name, tmp_comment, t->visible ? "" : " visible=\"n\"" ); g_free ( tmp_comment ); } else fprintf ( f, "type=\"track\" name=\"%s\"%s\n", name, t->visible ? "" : " visible=\"n\"" ); g_list_foreach ( t->trackpoints, (GFunc) a_gpspoint_write_trackpoint, f ); fprintf ( f, "type=\"trackend\"\n" ); }
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 ); 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); fprintf ( f, " comment=\"%s\"", tmp_comment ); g_free ( tmp_comment ); } if ( wp->image ) { gchar *tmp_image = slashdup(wp->image); 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" ); }
static void a_gpspoint_write_trackpoint ( VikTrackpoint *tp, TP_write_info_type *write_info ) { struct LatLon ll; gchar s_lat[COORDS_STR_BUFFER_SIZE]; gchar s_lon[COORDS_STR_BUFFER_SIZE]; gchar s_alt[COORDS_STR_BUFFER_SIZE]; vik_coord_to_latlon ( &(tp->coord), &ll ); FILE *f = write_info->f; a_coords_dtostr_buffer ( ll.lat, s_lat ); a_coords_dtostr_buffer ( ll.lon, s_lon ); fprintf ( f, "type=\"%spoint\" latitude=\"%s\" longitude=\"%s\"", write_info->is_route ? "route" : "track", s_lat, s_lon ); if ( tp->name ) { gchar *name = slashdup(tp->name); fprintf ( f, " name=\"%s\"", name ); g_free(name); } if ( tp->altitude != VIK_DEFAULT_ALTITUDE ) { a_coords_dtostr_buffer ( tp->altitude, s_alt ); fprintf ( f, " altitude=\"%s\"", s_alt ); } if ( tp->has_timestamp ) fprintf ( f, " unixtime=\"%ld\"", tp->timestamp ); if ( tp->newsegment ) fprintf ( f, " newsegment=\"yes\"" ); if (!isnan(tp->speed) || !isnan(tp->course) || tp->nsats > 0) { fprintf ( f, " extended=\"yes\"" ); if (!isnan(tp->speed)) { gchar s_speed[COORDS_STR_BUFFER_SIZE]; a_coords_dtostr_buffer ( tp->speed, s_speed ); fprintf ( f, " speed=\"%s\"", s_speed ); } if (!isnan(tp->course)) { gchar s_course[COORDS_STR_BUFFER_SIZE]; a_coords_dtostr_buffer ( tp->course, s_course ); fprintf ( f, " course=\"%s\"", s_course ); } if (tp->nsats > 0) fprintf ( f, " sat=\"%d\"", tp->nsats ); if (tp->fix_mode > 0) fprintf ( f, " fix=\"%d\"", tp->fix_mode ); if ( tp->hdop != VIK_DEFAULT_DOP ) { gchar ss[COORDS_STR_BUFFER_SIZE]; a_coords_dtostr_buffer ( tp->hdop, ss ); fprintf ( f, " hdop=\"%s\"", ss ); } if ( tp->vdop != VIK_DEFAULT_DOP ) { gchar ss[COORDS_STR_BUFFER_SIZE]; a_coords_dtostr_buffer ( tp->vdop, ss ); fprintf ( f, " vdop=\"%s\"", ss ); } if ( tp->pdop != VIK_DEFAULT_DOP ) { gchar ss[COORDS_STR_BUFFER_SIZE]; a_coords_dtostr_buffer ( tp->pdop, ss ); fprintf ( f, " pdop=\"%s\"", ss ); } } fprintf ( f, "\n" ); }
static void a_gpspoint_write_waypoint ( const gpointer id, const VikWaypoint *wp, FILE *f ) { struct LatLon ll; gchar s_lat[COORDS_STR_BUFFER_SIZE]; gchar s_lon[COORDS_STR_BUFFER_SIZE]; // Sanity clauses if ( !wp ) return; if ( !(wp->name) ) return; vik_coord_to_latlon ( &(wp->coord), &ll ); a_coords_dtostr_buffer ( ll.lat, s_lat ); a_coords_dtostr_buffer ( ll.lon, s_lon ); gchar *tmp_name = slashdup(wp->name); fprintf ( f, "type=\"waypoint\" latitude=\"%s\" longitude=\"%s\" name=\"%s\"", s_lat, s_lon, tmp_name ); g_free ( tmp_name ); if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) { gchar s_alt[COORDS_STR_BUFFER_SIZE]; a_coords_dtostr_buffer ( wp->altitude, s_alt ); fprintf ( f, " altitude=\"%s\"", s_alt ); } if ( wp->has_timestamp ) fprintf ( f, " unixtime=\"%ld\"", wp->timestamp ); if ( wp->comment ) { gchar *tmp_comment = slashdup(wp->comment); fprintf ( f, " comment=\"%s\"", tmp_comment ); g_free ( tmp_comment ); } if ( wp->description ) { gchar *tmp_description = slashdup(wp->description); fprintf ( f, " description=\"%s\"", tmp_description ); g_free ( tmp_description ); } if ( wp->source ) { gchar *tmp_source = slashdup(wp->source); fprintf ( f, " source=\"%s\"", tmp_source ); g_free ( tmp_source ); } if ( wp->type ) { gchar *tmp_type = slashdup(wp->type); fprintf ( f, " xtype=\"%s\"", tmp_type ); g_free ( tmp_type ); } if ( wp->image ) { gchar *tmp_image = NULL; gchar *cwd = NULL; if ( a_vik_get_file_ref_format() == VIK_FILE_REF_FORMAT_RELATIVE ) { cwd = g_get_current_dir(); if ( cwd ) tmp_image = g_strdup ( file_GetRelativeFilename ( cwd, wp->image ) ); } // if cwd not available - use image filename as is // this should be an absolute path as set in thumbnails if ( !cwd ) tmp_image = slashdup(wp->image); if ( tmp_image ) fprintf ( f, " image=\"%s\"", tmp_image ); g_free ( cwd ); g_free ( tmp_image ); } if ( wp->symbol ) { // Due to changes in garminsymbols - the symbol name is now in Title Case // However to keep newly generated .vik files better compatible with older Viking versions // The symbol names will always be lowercase gchar *tmp_symbol = g_utf8_strdown(wp->symbol, -1); fprintf ( f, " symbol=\"%s\"", tmp_symbol ); g_free ( tmp_symbol ); } if ( ! wp->visible ) fprintf ( f, " visible=\"n\"" ); fprintf ( f, "\n" ); }