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);
}
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 );
- if ( tr->description )
- vik_track_set_description ( rv[i], tr->description );
- rv[i]->visible = tr->visible;
- rv[i]->is_route = tr->is_route;
+ rv[i] = vik_track_copy ( tr, FALSE );
rv[i]->trackpoints = iter;
i++;
}
/* 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);
}
}
-/*
+/**
+ * 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 )
{