* viking -- GPS Data and Topo Analyzer, Explorer, and Manager
*
* Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ * Copyright (c) 2012, Rob Norris <rw_norris@hotmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
tr->comment = NULL;
}
+void vik_track_set_description(VikTrack *tr, const gchar *description)
+{
+ if ( tr->description )
+ g_free ( tr->description );
+
+ if ( description && description[0] != '\0' )
+ tr->description = g_strdup(description);
+ else
+ tr->description = NULL;
+}
+
void vik_track_ref(VikTrack *tr)
{
tr->ref_count++;
g_free ( tr->name );
if ( tr->comment )
g_free ( tr->comment );
+ if ( tr->description )
+ g_free ( tr->description );
g_list_foreach ( tr->trackpoints, (GFunc) g_free, NULL );
g_list_free( tr->trackpoints );
if (tr->property_dialog)
g_free ( tr );
}
-VikTrack *vik_track_copy ( const VikTrack *tr )
+/**
+ * vik_track_copy:
+ * @tr: The Track to copy
+ * @copy_points: Whether to copy the track points or not
+ *
+ * Normally for copying the track it's best to copy all the trackpoints
+ * However for some operations such as splitting tracks the trackpoints will be managed separately, so no need to copy them.
+ *
+ * Returns: the copied VikTrack
+ */
+VikTrack *vik_track_copy ( const VikTrack *tr, gboolean copy_points )
{
VikTrack *new_tr = vik_track_new();
VikTrackpoint *new_tp;
GList *tp_iter = tr->trackpoints;
new_tr->visible = tr->visible;
+ new_tr->is_route = tr->is_route;
+ new_tr->has_color = tr->has_color;
+ new_tr->color = tr->color;
new_tr->trackpoints = NULL;
- while ( tp_iter )
+ if ( copy_points )
{
- new_tp = g_malloc ( sizeof ( VikTrackpoint ) );
- *new_tp = *((VikTrackpoint *)(tp_iter->data));
- new_tr->trackpoints = g_list_append ( new_tr->trackpoints, new_tp );
- tp_iter = tp_iter->next;
+ while ( tp_iter )
+ {
+ new_tp = g_malloc ( sizeof ( VikTrackpoint ) );
+ *new_tp = *((VikTrackpoint *)(tp_iter->data));
+ new_tr->trackpoints = g_list_append ( new_tr->trackpoints, new_tp );
+ tp_iter = tp_iter->next;
+ }
}
vik_track_set_name(new_tr,tr->name);
vik_track_set_comment(new_tr,tr->comment);
+ vik_track_set_description(new_tr,tr->description);
return new_tr;
}
return num;
}
+/*
+ * Deletes all 'extra' trackpoint information
+ * such as time stamps, speed, course etc...
+ */
+void vik_track_to_routepoints ( VikTrack *tr )
+{
+ GList *iter = tr->trackpoints;
+ while ( iter ) {
+
+ // c.f. with vik_trackpoint_new()
+
+ VIK_TRACKPOINT(iter->data)->has_timestamp = FALSE;
+ VIK_TRACKPOINT(iter->data)->timestamp = 0;
+ VIK_TRACKPOINT(iter->data)->speed = NAN;
+ VIK_TRACKPOINT(iter->data)->course = NAN;
+ VIK_TRACKPOINT(iter->data)->hdop = VIK_DEFAULT_DOP;
+ VIK_TRACKPOINT(iter->data)->vdop = VIK_DEFAULT_DOP;
+ VIK_TRACKPOINT(iter->data)->pdop = VIK_DEFAULT_DOP;
+ VIK_TRACKPOINT(iter->data)->nsats = 0;
+ VIK_TRACKPOINT(iter->data)->fix_mode = VIK_GPS_MODE_NOT_SEEN;
+
+ iter = iter->next;
+ }
+}
+
guint vik_track_get_segment_count(const VikTrack *tr)
{
guint num = 1;
}
rv = g_malloc ( segs * sizeof(VikTrack *) );
- tr = vik_track_copy ( t );
+ tr = vik_track_copy ( t, TRUE );
rv[0] = tr;
iter = tr->trackpoints;
{
iter->prev->next = NULL;
iter->prev = NULL;
- rv[i] = vik_track_new();
- // TODO: consider new naming strategy here
- if ( tr->name )
- vik_track_set_name ( rv[i], tr->name );
- if ( tr->comment )
- vik_track_set_comment ( rv[i], tr->comment );
- rv[i]->visible = tr->visible;
+ rv[i] = vik_track_copy ( tr, FALSE );
rv[i]->trackpoints = iter;
i++;
}
}
*(guint *)(b->data + intp) = ntp;
- len = (tr->name) ? strlen(tr->name)+1 : 0;
- g_byte_array_append(b, (guint8 *)&len, sizeof(len));
- if (tr->name) g_byte_array_append(b, (guint8 *)tr->name, len);
+ // This allocates space for variant sized strings
+ // and copies that amount of data from the track to byte array
+#define vtm_append(s) \
+ len = (s) ? strlen(s)+1 : 0; \
+ g_byte_array_append(b, (guint8 *)&len, sizeof(len)); \
+ if (s) g_byte_array_append(b, (guint8 *)s, len);
- len = (tr->comment) ? strlen(tr->comment)+1 : 0;
- g_byte_array_append(b, (guint8 *)&len, sizeof(len));
- if (tr->comment) g_byte_array_append(b, (guint8 *)tr->comment, len);
+ vtm_append(tr->name);
+ vtm_append(tr->comment);
+ vtm_append(tr->description);
*data = b->data;
*datalen = b->len;
g_byte_array_free(b, FALSE);
}
+/*
+ * Take a byte array and convert it into a Track
+ */
VikTrack *vik_track_unmarshall (guint8 *data, guint datalen)
{
guint len;
guint ntp;
gint i;
- /* only the visibility is needed */
+ /* basic properties: */
new_tr->visible = ((VikTrack *)data)->visible;
+ new_tr->is_route = ((VikTrack *)data)->is_route;
+ new_tr->has_color = ((VikTrack *)data)->has_color;
+ new_tr->color = ((VikTrack *)data)->color;
+
data += sizeof(*new_tr);
ntp = *(guint *)data;
new_tr->trackpoints = g_list_append(new_tr->trackpoints, new_tp);
}
- len = *(guint *)data;
- data += sizeof(len);
- if (len) {
- new_tr->name = g_strdup((gchar *)data);
- }
+#define vtu_get(s) \
+ len = *(guint *)data; \
+ data += sizeof(len); \
+ if (len) { \
+ (s) = g_strdup((gchar *)data); \
+ } else { \
+ (s) = NULL; \
+ } \
data += len;
- len = *(guint *)data;
- data += sizeof(len);
- if (len) {
- new_tr->comment = g_strdup((gchar *)data);
- }
+ vtu_get(new_tr->name);
+ vtu_get(new_tr->comment);
+ vtu_get(new_tr->description);
+
return new_tr;
}
}
}
-/*
+/**
+ * vik_track_apply_dem_data_last_trackpoint:
+ *
* Apply DEM data (if available) - to only the last trackpoint
*/
void vik_track_apply_dem_data_last_trackpoint ( VikTrack *tr )
}
}
-/* appends t2 to t1, leaving t2 with no trackpoints */
+/**
+ * vik_track_steal_and_append_trackpoints:
+ *
+ * appends t2 to t1, leaving t2 with no trackpoints
+ */
void vik_track_steal_and_append_trackpoints ( VikTrack *t1, VikTrack *t2 )
{
if ( t1->trackpoints ) {
t2->trackpoints = NULL;
}
-/* starting at the end, looks backwards for the last "double point", a duplicate trackpoint.
+/**
+ * vik_track_cut_back_to_double_point:
+ *
+ * starting at the end, looks backwards for the last "double point", a duplicate trackpoint.
* If there is no double point, deletes all the trackpoints.
- * Returns the new end of the track (or the start if there are no double points)
+ *
+ * Returns: the new end of the track (or the start if there are no double points)
*/
VikCoord *vik_track_cut_back_to_double_point ( VikTrack *tr )
{