static void gpx_write_track ( const gchar *name, VikTrack *t, GpxWritingContext *context ) { FILE *f = context->file; gchar *tmp; gboolean first_tp_is_newsegment = FALSE; /* must temporarily make it not so, but we want to restore state. not that it matters. */ tmp = entitize ( name ); fprintf ( f, "<trk%s>\n <name>%s</name>\n", t->visible ? "" : " hidden=\"hidden\"", tmp ); g_free ( tmp ); if ( t->comment ) { tmp = entitize ( t->comment ); fprintf ( f, " <desc>%s</desc>\n", tmp ); g_free ( tmp ); } fprintf ( f, " <trkseg>\n" ); if ( t->trackpoints && t->trackpoints->data ) { first_tp_is_newsegment = VIK_TRACKPOINT(t->trackpoints->data)->newsegment; VIK_TRACKPOINT(t->trackpoints->data)->newsegment = FALSE; /* so we won't write </trkseg><trkseg> already */ g_list_foreach ( t->trackpoints, (GFunc) gpx_write_trackpoint, context ); VIK_TRACKPOINT(t->trackpoints->data)->newsegment = first_tp_is_newsegment; /* restore state */ } fprintf ( f, "</trkseg>\n</trk>\n" ); }
static void gpx_write_track ( VikTrack *t, GpxWritingContext *context ) { // Don't write invisible tracks when specified if (context->options && !context->options->hidden && !t->visible) return; FILE *f = context->file; gchar *tmp; gboolean first_tp_is_newsegment = FALSE; /* must temporarily make it not so, but we want to restore state. not that it matters. */ // Sanity clause if ( t->name ) tmp = entitize ( t->name ); else tmp = g_strdup ("track"); // NB 'hidden' is not part of any GPX standard - this appears to be a made up Viking 'extension' // luckily most other GPX processing software ignores things they don't understand fprintf ( f, "<%s%s>\n <name>%s</name>\n", t->is_route ? "rte" : "trk", t->visible ? "" : " hidden=\"hidden\"", tmp ); g_free ( tmp ); if ( t->comment ) { tmp = entitize ( t->comment ); fprintf ( f, " <cmt>%s</cmt>\n", tmp ); g_free ( tmp ); } if ( t->description ) { tmp = entitize ( t->description ); fprintf ( f, " <desc>%s</desc>\n", tmp ); g_free ( tmp ); } /* No such thing as a rteseg! */ if ( !t->is_route ) fprintf ( f, " <trkseg>\n" ); if ( t->trackpoints && t->trackpoints->data ) { first_tp_is_newsegment = VIK_TRACKPOINT(t->trackpoints->data)->newsegment; VIK_TRACKPOINT(t->trackpoints->data)->newsegment = FALSE; /* so we won't write </trkseg><trkseg> already */ g_list_foreach ( t->trackpoints, (GFunc) gpx_write_trackpoint, context ); VIK_TRACKPOINT(t->trackpoints->data)->newsegment = first_tp_is_newsegment; /* restore state */ } /* NB apparently no such thing as a rteseg! */ if (!t->is_route) fprintf ( f, " </trkseg>\n"); fprintf ( f, "</%s>\n", t->is_route ? "rte" : "trk" ); }
static void gpx_write_waypoint ( const gchar *name, VikWaypoint *wp, GpxWritingContext *context ) { FILE *f = context->file; static struct LatLon ll; gchar *s_lat,*s_lon; gchar *tmp; vik_coord_to_latlon ( &(wp->coord), &ll ); s_lat = a_coords_dtostr( ll.lat ); s_lon = a_coords_dtostr( ll.lon ); fprintf ( f, "<wpt lat=\"%s\" lon=\"%s\"%s>\n", s_lat, s_lon, wp->visible ? "" : " hidden=\"hidden\"" ); g_free ( s_lat ); g_free ( s_lon ); tmp = entitize ( name ); fprintf ( f, " <name>%s</name>\n", tmp ); g_free ( tmp); if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) { tmp = a_coords_dtostr ( wp->altitude ); fprintf ( f, " <ele>%s</ele>\n", tmp ); g_free ( tmp ); } if ( wp->comment ) { tmp = entitize(wp->comment); fprintf ( f, " <desc>%s</desc>\n", tmp ); g_free ( tmp ); } if ( wp->image ) { tmp = entitize(wp->image); fprintf ( f, " <link>%s</link>\n", tmp ); g_free ( tmp ); } if ( wp->symbol ) { tmp = entitize(wp->symbol); fprintf ( f, " <sym>%s</sym>\n", tmp); g_free ( tmp ); } fprintf ( f, "</wpt>\n" ); }
static void gpx_write_trackpoint ( VikTrackpoint *tp, GpxWritingContext *context ) { FILE *f = context->file; static struct LatLon ll; gchar *s_lat,*s_lon, *s_alt, *s_dop; gchar *time_iso8601; vik_coord_to_latlon ( &(tp->coord), &ll ); // No such thing as a rteseg! So make sure we don't put them in if ( context->options && !context->options->is_route && tp->newsegment ) fprintf ( f, " </trkseg>\n <trkseg>\n" ); s_lat = a_coords_dtostr( ll.lat ); s_lon = a_coords_dtostr( ll.lon ); fprintf ( f, " <%spt lat=\"%s\" lon=\"%s\">\n", (context->options && context->options->is_route) ? "rte" : "trk", s_lat, s_lon ); g_free ( s_lat ); s_lat = NULL; g_free ( s_lon ); s_lon = NULL; if (tp->name) { gchar *s_name = entitize(tp->name); fprintf ( f, " <name>%s</name>\n", s_name ); g_free(s_name); } s_alt = NULL; if ( tp->altitude != VIK_DEFAULT_ALTITUDE ) { s_alt = a_coords_dtostr ( tp->altitude ); } else if ( context->options != NULL && context->options->force_ele ) { s_alt = a_coords_dtostr ( 0 ); } if (s_alt != NULL) fprintf ( f, " <ele>%s</ele>\n", s_alt ); g_free ( s_alt ); s_alt = NULL; time_iso8601 = NULL; if ( tp->has_timestamp ) { GTimeVal timestamp; timestamp.tv_sec = tp->timestamp; timestamp.tv_usec = 0; time_iso8601 = g_time_val_to_iso8601 ( ×tamp ); } else if ( context->options != NULL && context->options->force_time ) { GTimeVal current; g_get_current_time ( ¤t ); time_iso8601 = g_time_val_to_iso8601 ( ¤t ); } if ( time_iso8601 != NULL ) fprintf ( f, " <time>%s</time>\n", time_iso8601 ); g_free(time_iso8601); time_iso8601 = NULL; if (!isnan(tp->course)) { gchar *s_course = a_coords_dtostr(tp->course); fprintf ( f, " <course>%s</course>\n", s_course ); g_free(s_course); } if (!isnan(tp->speed)) { gchar *s_speed = a_coords_dtostr(tp->speed); fprintf ( f, " <speed>%s</speed>\n", s_speed ); g_free(s_speed); } if (tp->fix_mode == VIK_GPS_MODE_2D) fprintf ( f, " <fix>2d</fix>\n"); if (tp->fix_mode == VIK_GPS_MODE_3D) fprintf ( f, " <fix>3d</fix>\n"); if (tp->nsats > 0) fprintf ( f, " <sat>%d</sat>\n", tp->nsats ); s_dop = NULL; if ( tp->hdop != VIK_DEFAULT_DOP ) { s_dop = a_coords_dtostr ( tp->hdop ); } if (s_dop != NULL) fprintf ( f, " <hdop>%s</hdop>\n", s_dop ); g_free ( s_dop ); s_dop = NULL; if ( tp->vdop != VIK_DEFAULT_DOP ) { s_dop = a_coords_dtostr ( tp->vdop ); } if (s_dop != NULL) fprintf ( f, " <vdop>%s</vdop>\n", s_dop ); g_free ( s_dop ); s_dop = NULL; if ( tp->pdop != VIK_DEFAULT_DOP ) { s_dop = a_coords_dtostr ( tp->pdop ); } if (s_dop != NULL) fprintf ( f, " <pdop>%s</pdop>\n", s_dop ); g_free ( s_dop ); s_dop = NULL; fprintf ( f, " </%spt>\n", (context->options && context->options->is_route) ? "rte" : "trk" ); }
static void gpx_write_waypoint ( VikWaypoint *wp, GpxWritingContext *context ) { // Don't write invisible waypoints when specified if (context->options && !context->options->hidden && !wp->visible) return; FILE *f = context->file; static struct LatLon ll; gchar *s_lat,*s_lon; gchar *tmp; vik_coord_to_latlon ( &(wp->coord), &ll ); s_lat = a_coords_dtostr( ll.lat ); s_lon = a_coords_dtostr( ll.lon ); // NB 'hidden' is not part of any GPX standard - this appears to be a made up Viking 'extension' // luckily most other GPX processing software ignores things they don't understand fprintf ( f, "<wpt lat=\"%s\" lon=\"%s\"%s>\n", s_lat, s_lon, wp->visible ? "" : " hidden=\"hidden\"" ); g_free ( s_lat ); g_free ( s_lon ); // Sanity clause if ( wp->name ) tmp = entitize ( wp->name ); else tmp = g_strdup ("waypoint"); fprintf ( f, " <name>%s</name>\n", tmp ); g_free ( tmp); if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) { tmp = a_coords_dtostr ( wp->altitude ); fprintf ( f, " <ele>%s</ele>\n", tmp ); g_free ( tmp ); } if ( wp->has_timestamp ) { GTimeVal timestamp; timestamp.tv_sec = wp->timestamp; timestamp.tv_usec = 0; gchar *time_iso8601 = g_time_val_to_iso8601 ( ×tamp ); if ( time_iso8601 != NULL ) fprintf ( f, " <time>%s</time>\n", time_iso8601 ); g_free ( time_iso8601 ); } if ( wp->comment ) { tmp = entitize(wp->comment); fprintf ( f, " <cmt>%s</cmt>\n", tmp ); g_free ( tmp ); } if ( wp->description ) { tmp = entitize(wp->description); fprintf ( f, " <desc>%s</desc>\n", tmp ); g_free ( tmp ); } if ( wp->url ) { tmp = entitize(wp->url); fprintf ( f, " <url>%s</url>\n", tmp ); g_free ( tmp ); } if ( wp->image ) { tmp = entitize(wp->image); fprintf ( f, " <link>%s</link>\n", tmp ); g_free ( tmp ); } if ( wp->symbol ) { tmp = entitize(wp->symbol); if ( a_vik_gpx_export_wpt_sym_name ( ) ) { // Lowercase the symbol name gchar *tmp2 = g_utf8_strdown ( tmp, -1 ); fprintf ( f, " <sym>%s</sym>\n", tmp2 ); g_free ( tmp2 ); } else fprintf ( f, " <sym>%s</sym>\n", tmp); g_free ( tmp ); } fprintf ( f, "</wpt>\n" ); }
void a_gpx_write_file ( VikTrwLayer *vtl, FILE *f, GpxWritingOptions *options ) { GpxWritingContext context = { options, f }; gpx_write_header ( f ); gchar *tmp; const gchar *name = vik_layer_get_name(VIK_LAYER(vtl)); if ( name ) { tmp = entitize ( name ); fprintf ( f, " <name>%s</name>\n", tmp ); g_free ( tmp ); } VikTRWMetadata *md = vik_trw_layer_get_metadata (vtl); if ( md ) { if ( md->author ) { tmp = entitize ( md->author ); fprintf ( f, " <author>%s</author>\n", tmp ); g_free ( tmp ); } if ( md->description ) { tmp = entitize ( md->description ); fprintf ( f, " <desc>%s</desc>\n", tmp ); g_free ( tmp ); } if ( md->timestamp ) { tmp = entitize ( md->timestamp ); fprintf ( f, " <time>%s</time>\n", tmp ); g_free ( tmp ); } if ( md->keywords ) { tmp = entitize ( md->keywords ); fprintf ( f, " <keywords>%s</keywords>\n", tmp ); g_free ( tmp ); } } if ( vik_trw_layer_get_waypoints_visibility(vtl) || (options && options->hidden) ) { // gather waypoints in a list, then sort GList *gl = g_hash_table_get_values ( vik_trw_layer_get_waypoints ( vtl ) ); gl = g_list_sort ( gl, gpx_waypoint_compare ); for (GList *iter = g_list_first (gl); iter != NULL; iter = g_list_next (iter)) { gpx_write_waypoint ( (VikWaypoint*)iter->data, &context ); } g_list_free ( gl ); } GList *gl = NULL; if ( vik_trw_layer_get_tracks_visibility(vtl) || (options && options->hidden) ) { //gl = g_hash_table_get_values ( vik_trw_layer_get_tracks ( vtl ) ); // Forming the list manually seems to produce one that is more likely to be nearer to the creation order gpointer key, value; GHashTableIter ght_iter; g_hash_table_iter_init ( &ght_iter, vik_trw_layer_get_tracks ( vtl ) ); while ( g_hash_table_iter_next (&ght_iter, &key, &value) ) { gl = g_list_prepend ( gl ,value ); } gl = g_list_reverse ( gl ); // Sort method determined by preference if ( a_vik_get_gpx_export_trk_sort() == VIK_GPX_EXPORT_TRK_SORT_TIME ) gl = g_list_sort ( gl, vik_track_compare_timestamp ); else if ( a_vik_get_gpx_export_trk_sort() == VIK_GPX_EXPORT_TRK_SORT_ALPHA ) gl = g_list_sort ( gl, gpx_track_compare_name ); } GList *glrte = NULL; // Routes sorted by name if ( vik_trw_layer_get_tracks_visibility(vtl) || (options && options->hidden) ) { glrte = g_hash_table_get_values ( vik_trw_layer_get_routes ( vtl ) ); glrte = g_list_sort ( glrte, gpx_track_compare_name ); } // g_list_concat doesn't copy memory properly // so process each list separately GpxWritingContext context_tmp = context; GpxWritingOptions opt_tmp = { FALSE, FALSE, FALSE, FALSE }; // Force trackpoints on tracks if ( !context.options ) context_tmp.options = &opt_tmp; context_tmp.options->is_route = FALSE; // Loop around each list and write each one for (GList *iter = g_list_first (gl); iter != NULL; iter = g_list_next (iter)) { gpx_write_track ( (VikTrack*)iter->data, &context_tmp ); } // Routes (to get routepoints) context_tmp.options->is_route = TRUE; for (GList *iter = g_list_first (glrte); iter != NULL; iter = g_list_next (iter)) { gpx_write_track ( (VikTrack*)iter->data, &context_tmp ); } g_list_free ( gl ); g_list_free ( glrte ); gpx_write_footer ( f ); }
static void createDescription( const QValueList<Widget> &l, QTextStream &ts ) { int indent = 0; ts << "<!DOCTYPE CW><CW>" << endl; ts << makeIndent( indent ) << "<customwidgets>" << endl; indent++; for ( QValueList<Widget>::ConstIterator it = l.begin(); it != l.end(); ++it ) { Widget w = *it; ts << makeIndent( indent ) << "<customwidget>" << endl; indent++; ts << makeIndent( indent ) << "<class>" << w.w->className() << "</class>" << endl; ts << makeIndent( indent ) << "<header location=\"" << w.location << "\">" << w.include << "</header>" << endl; ts << makeIndent( indent ) << "<sizehint>" << endl; indent++; ts << makeIndent( indent ) << "<width>" << w.w->sizeHint().width() << "</width>" << endl; ts << makeIndent( indent ) << "<height>" << w.w->sizeHint().height() << "</height>" << endl; indent--; ts << makeIndent( indent ) << "</sizehint>" << endl; ts << makeIndent( indent ) << "<container>" << ( w.w->inherits( "QGroupBox" ) || w.w->inherits( "QWidgetStack" ) ) << "</container>" << endl; ts << makeIndent( indent ) << "<sizepolicy>" << endl; indent++; ts << makeIndent( indent ) << "<hordata>" << (int)w.w->sizePolicy().horData() << "</hordata>" << endl; ts << makeIndent( indent ) << "<verdata>" << (int)w.w->sizePolicy().verData() << "</verdata>" << endl; indent--; ts << makeIndent( indent ) << "</sizepolicy>" << endl; QStrList sigs = w.w->metaObject()->signalNames( TRUE ); if ( !sigs.isEmpty() ) { for ( int i = 0; i < (int)sigs.count(); ++i ) ts << makeIndent( indent ) << "<signal>" << entitize( sigs.at( i ) ) << "</signal>" << endl; } QStrList slts = w.w->metaObject()->slotNames( TRUE ); if ( !slts.isEmpty() ) { for ( int i = 0; i < (int)slts.count(); ++i ) { QMetaData::Access data = w.w->metaObject()->slot( i, TRUE )->access; if ( data == QMetaData::Private ) continue; ts << makeIndent( indent ) << "<slot access=\"" << ( data == QMetaData::Protected ? "protected" : "public" ) << "\">" << entitize( slts.at( i ) ) << "</slot>" << endl; } } QStrList props = w.w->metaObject()->propertyNames( TRUE ); if ( !props.isEmpty() ) { for ( int i = 0; i < (int)props.count(); ++i ) { const QMetaProperty *p = w.w->metaObject()-> property( w.w->metaObject()-> findProperty( props.at( i ), TRUE ), TRUE ); if ( !p ) continue; if ( !p->writable() || !p->designable( w.w ) ) continue; ts << makeIndent( indent ) << "<property type=\"" << convert_type( p->type() ) << "\">" << entitize( p->name() ) << "</property>" << endl; } } indent--; ts << makeIndent( indent ) << "</customwidget>" << endl; } indent--; ts << makeIndent( indent ) << "</customwidgets>" << endl; ts << "</CW>" << endl; }