]> git.street.me.uk Git - andy/viking.git/blame - src/gpspoint.c
Add getting Wikipedia Waypoints via the File->Acquire menu method.
[andy/viking.git] / src / gpspoint.c
CommitLineData
50a14534
EB
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
c9570f86 5 * Copyright (C) 2012, Rob Norris <rw_norris@hotmail.com>
50a14534
EB
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
8c00358d
GB
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
50a14534 25
8c00358d 26#ifdef HAVE_MATH_H
a2817d3c 27#include <math.h>
8c00358d
GB
28#endif
29
50a14534
EB
30#include "viking.h"
31
32#include <ctype.h>
8c00358d 33#ifdef HAVE_STRING_H
50a14534 34#include <string.h>
8c00358d 35#endif
50a14534
EB
36
37#include <stdlib.h>
38/* strtod */
39
0d2b891f
RN
40typedef struct {
41 FILE *f;
42 gboolean is_route;
43} TP_write_info_type;
50a14534 44
ce4bd1cf 45static void a_gpspoint_write_track ( const gpointer id, const VikTrack *t, FILE *f );
0d2b891f 46static void a_gpspoint_write_trackpoint ( VikTrackpoint *tp, TP_write_info_type *write_info );
c9570f86 47static void a_gpspoint_write_waypoint ( const gpointer id, const VikWaypoint *wp, FILE *f );
50a14534
EB
48
49
50/* outline for file gpspoint.c
51
52reading file:
53
54take a line.
55get first tag, if not type, skip it.
56if type, record type. if waypoint list, etc move on. if track, make a new track, make it current track, add it, etc.
57if waypoint, read on and store to the waypoint.
58if trackpoint, make trackpoint, store to current track (error / skip if none)
59
60*/
61
62/* Thanks to etrex-cache's gpsbabel's gpspoint.c for starting me off! */
63
64static char line_buffer[2048];
65
66#define GPSPOINT_TYPE_NONE 0
67#define GPSPOINT_TYPE_WAYPOINT 1
68#define GPSPOINT_TYPE_TRACKPOINT 2
0d2b891f 69#define GPSPOINT_TYPE_ROUTEPOINT 3
50a14534 70#define GPSPOINT_TYPE_TRACK 4
0d2b891f 71#define GPSPOINT_TYPE_ROUTE 5
50a14534
EB
72
73static VikTrack *current_track; /* pointer to pointer to first GList */
74
75static gint line_type = GPSPOINT_TYPE_NONE;
76static struct LatLon line_latlon;
77static gchar *line_name;
78static gchar *line_comment;
6b2f262e 79static gchar *line_description;
b1453c16 80static gchar *line_color;
50a14534 81static gchar *line_image;
acaf7113 82static gchar *line_symbol;
50a14534
EB
83static gboolean line_newsegment = FALSE;
84static gboolean line_has_timestamp = FALSE;
85static time_t line_timestamp = 0;
86static gdouble line_altitude = VIK_DEFAULT_ALTITUDE;
87static gboolean line_visible = TRUE;
a2817d3c
QT
88
89static gboolean line_extended = FALSE;
90static gdouble line_speed = NAN;
91static gdouble line_course = NAN;
92static gint line_sat = 0;
93static gint line_fix = 0;
50a14534
EB
94/* other possible properties go here */
95
96
97static void gpspoint_process_tag ( const gchar *tag, gint len );
98static void gpspoint_process_key_and_value ( const gchar *key, gint key_len, const gchar *value, gint value_len );
99
100static gchar *slashdup(const gchar *str)
101{
102 guint16 len = strlen(str);
103 guint16 need_bs_count, i, j;
104 gchar *rv;
105 for ( i = 0, need_bs_count = 0; i < len; i++ )
106 if ( str[i] == '\\' || str[i] == '"' )
107 need_bs_count++;
108 rv = g_malloc ( (len+need_bs_count+1) * sizeof(gchar) );
109 for ( i = 0, j = 0; i < len; i++, j++ )
110 {
111 if ( str[i] == '\\' || str[i] == '"' )
112 rv[j++] = '\\';
113 rv[j] = str[i];
114 }
115 rv[j] = '\0';
116 return rv;
117}
118
119static gchar *deslashndup ( const gchar *str, guint16 len )
120{
121 guint16 i,j, bs_count, new_len;
122 gboolean backslash = FALSE;
123 gchar *rv;
124
125 if ( len < 1 )
126 return NULL;
127
128 for ( i = 0, bs_count = 0; i < len; i++ )
129 if ( str[i] == '\\' )
130 {
131 bs_count++;
132 i++;
133 }
134
135 if ( str[i-1] == '\\' && (len == 1 || str[i-2] != '\\') )
136 bs_count--;
137
138 new_len = len - bs_count;
139 rv = g_malloc ( (new_len+1) * sizeof(gchar) );
140 for ( i = 0, j = 0; i < len && j < new_len; i++ )
141 if ( str[i] == '\\' && !backslash )
142 backslash = TRUE;
143 else
144 {
145 rv[j++] = str[i];
146 backslash = FALSE;
147 }
148
149 rv[new_len] = '\0';
150 return rv;
151}
152
cb5ec7a8
RN
153/*
154 * Returns whether file read was a success
155 * No obvious way to test for a 'gpspoint' file,
156 * thus set a flag if any actual tag found during processing of the file
157 */
158gboolean a_gpspoint_read_file(VikTrwLayer *trw, FILE *f ) {
50a14534
EB
159 VikCoordMode coord_mode = vik_trw_layer_get_coord_mode ( trw );
160 gchar *tag_start, *tag_end;
50a14534
EB
161 g_assert ( f != NULL && trw != NULL );
162 line_type = 0;
163 line_timestamp = 0;
164 line_newsegment = FALSE;
acaf7113
AF
165 line_image = NULL;
166 line_symbol = NULL;
50a14534 167 current_track = NULL;
cb5ec7a8
RN
168 gboolean have_read_something = FALSE;
169
50a14534
EB
170 while (fgets(line_buffer, 2048, f))
171 {
172 gboolean inside_quote = 0;
173 gboolean backslash = 0;
174
175 line_buffer[strlen(line_buffer)-1] = '\0'; /* chop off newline */
176
177 /* for gpspoint files wrapped inside */
119ada4c
RN
178 if ( strlen(line_buffer) >= 13 && strncmp ( line_buffer, "~EndLayerData", 13 ) == 0 ) {
179 // Even just a blank TRW is ok when in a .vik file
180 have_read_something = TRUE;
50a14534 181 break;
119ada4c 182 }
50a14534 183
cb5ec7a8 184 /* each line: nullify stuff, make thing if nes, free name if ness */
50a14534
EB
185 tag_start = line_buffer;
186 for (;;)
187 {
188 /* my addition: find first non-whitespace character. if the null, skip line. */
189 while (*tag_start != '\0' && isspace(*tag_start))
190 tag_start++;
191 if (tag_start == '\0')
192 break;
193
194 if (*tag_start == '#')
195 break;
196
197 tag_end = tag_start;
198 if (*tag_end == '"')
199 inside_quote = !inside_quote;
200 while (*tag_end != '\0' && (!isspace(*tag_end) || inside_quote)) {
201 tag_end++;
202 if (*tag_end == '\\' && !backslash)
203 backslash = TRUE;
204 else if (backslash)
205 backslash = FALSE;
206 else if (*tag_end == '"')
207 inside_quote = !inside_quote;
208 }
209
210 gpspoint_process_tag ( tag_start, tag_end - tag_start );
211
212 if (*tag_end == '\0' )
213 break;
214 else
215 tag_start = tag_end+1;
216 }
217 if (line_type == GPSPOINT_TYPE_WAYPOINT && line_name)
218 {
cb5ec7a8 219 have_read_something = TRUE;
50a14534 220 VikWaypoint *wp = vik_waypoint_new();
50a14534
EB
221 wp->visible = line_visible;
222 wp->altitude = line_altitude;
50a14534
EB
223
224 vik_coord_load_from_latlon ( &(wp->coord), coord_mode, &line_latlon );
225
805d282e
EB
226 vik_trw_layer_filein_add_waypoint ( trw, line_name, wp );
227 g_free ( line_name );
228 line_name = NULL;
50a14534
EB
229
230 if ( line_comment )
231 {
232 vik_waypoint_set_comment ( wp, line_comment );
233 line_comment = NULL;
234 }
235
6b2f262e
RN
236 if ( line_description )
237 {
238 vik_waypoint_set_description ( wp, line_description );
239 line_description = NULL;
240 }
241
50a14534
EB
242 if ( line_image )
243 {
244 vik_waypoint_set_image ( wp, line_image );
245 line_image = NULL;
246 }
247
acaf7113
AF
248 if ( line_symbol )
249 {
250 vik_waypoint_set_symbol ( wp, line_symbol );
251 line_symbol = NULL;
252 }
50a14534 253 }
0d2b891f 254 else if ((line_type == GPSPOINT_TYPE_TRACK || line_type == GPSPOINT_TYPE_ROUTE) && line_name)
50a14534 255 {
cb5ec7a8 256 have_read_something = TRUE;
50a14534 257 VikTrack *pl = vik_track_new();
50a14534
EB
258
259 /* Thanks to Peter Jones for this Fix */
260 if (!line_name) line_name = g_strdup("UNK");
261
262 pl->visible = line_visible;
0d2b891f 263 pl->is_route = (line_type == GPSPOINT_TYPE_ROUTE);
50a14534 264
50a14534
EB
265 if ( line_comment )
266 {
267 vik_track_set_comment ( pl, line_comment );
268 line_comment = NULL;
269 }
270
6b2f262e
RN
271 if ( line_description )
272 {
273 vik_track_set_description ( pl, line_description );
274 line_description = NULL;
275 }
276
b1453c16
RN
277 if ( line_color )
278 {
279 if ( gdk_color_parse ( line_color, &(pl->color) ) )
280 pl->has_color = TRUE;
281 }
282
50a14534 283 pl->trackpoints = NULL;
805d282e
EB
284 vik_trw_layer_filein_add_track ( trw, line_name, pl );
285 g_free ( line_name );
286 line_name = NULL;
50a14534
EB
287
288 current_track = pl;
289 }
0d2b891f 290 else if ((line_type == GPSPOINT_TYPE_TRACKPOINT || line_type == GPSPOINT_TYPE_ROUTEPOINT) && current_track)
50a14534 291 {
cb5ec7a8 292 have_read_something = TRUE;
a2817d3c 293 VikTrackpoint *tp = vik_trackpoint_new();
50a14534
EB
294 vik_coord_load_from_latlon ( &(tp->coord), coord_mode, &line_latlon );
295 tp->newsegment = line_newsegment;
296 tp->has_timestamp = line_has_timestamp;
297 tp->timestamp = line_timestamp;
298 tp->altitude = line_altitude;
a2817d3c 299 if (line_extended) {
a2817d3c
QT
300 tp->speed = line_speed;
301 tp->course = line_course;
302 tp->nsats = line_sat;
303 tp->fix_mode = line_fix;
304 }
50a14534
EB
305 current_track->trackpoints = g_list_append ( current_track->trackpoints, tp );
306 }
307
308 if (line_name)
309 g_free ( line_name );
310 line_name = NULL;
6b2f262e 311 if (line_comment)
50a14534 312 g_free ( line_comment );
6b2f262e
RN
313 if (line_description)
314 g_free ( line_description );
b1453c16
RN
315 if (line_color)
316 g_free ( line_color );
50a14534
EB
317 if (line_image)
318 g_free ( line_image );
acaf7113
AF
319 if (line_symbol)
320 g_free ( line_symbol );
50a14534 321 line_comment = NULL;
6b2f262e 322 line_description = NULL;
b1453c16 323 line_color = NULL;
50a14534 324 line_image = NULL;
acaf7113 325 line_symbol = NULL;
50a14534
EB
326 line_type = GPSPOINT_TYPE_NONE;
327 line_newsegment = FALSE;
328 line_has_timestamp = FALSE;
329 line_timestamp = 0;
330 line_altitude = VIK_DEFAULT_ALTITUDE;
331 line_visible = TRUE;
acaf7113 332 line_symbol = NULL;
a2817d3c
QT
333
334 line_extended = FALSE;
335 line_speed = NAN;
336 line_course = NAN;
337 line_sat = 0;
338 line_fix = 0;
50a14534 339 }
cb5ec7a8
RN
340
341 return have_read_something;
50a14534
EB
342}
343
344/* Tag will be of a few defined forms:
345 ^[:alpha:]*=".*"$
346 ^[:alpha:]*=.*$
347
348 <invalid tag>
349
350So we must determine end of tag name, start of value, end of value.
351*/
352static void gpspoint_process_tag ( const gchar *tag, gint len )
353{
354 const gchar *key_end, *value_start, *value_end;
355
356 /* Searching for key end */
357 key_end = tag;
358
359 while (++key_end - tag < len)
360 if (*key_end == '=')
361 break;
362
363 if (key_end - tag == len)
364 return; /* no good */
365
366 if (key_end - tag == len + 1)
367 value_start = value_end = 0; /* size = 0 */
368 else
369 {
370 value_start = key_end + 1; /* equal_sign plus one */
371
372 if (*value_start == '"')
373 {
374 value_start++;
375 if (*value_start == '"')
376 value_start = value_end = 0; /* size = 0 */
377 else
378 {
379 if (*(tag+len-1) == '"')
380 value_end = tag + len - 1;
381 else
382 return; /* bogus */
383 }
384 }
385 else
386 value_end = tag + len; /* value start really IS value start. */
387
388 gpspoint_process_key_and_value(tag, key_end - tag, value_start, value_end - value_start);
389 }
390}
391
392/*
393value = NULL for none
394*/
395static void gpspoint_process_key_and_value ( const gchar *key, gint key_len, const gchar *value, gint value_len )
396{
397 if (key_len == 4 && strncasecmp( key, "type", key_len ) == 0 )
398 {
399 if (value == NULL)
400 line_type = GPSPOINT_TYPE_NONE;
401 else if (value_len == 5 && strncasecmp( value, "track", value_len ) == 0 )
402 line_type = GPSPOINT_TYPE_TRACK;
403 else if (value_len == 10 && strncasecmp( value, "trackpoint", value_len ) == 0 )
404 line_type = GPSPOINT_TYPE_TRACKPOINT;
405 else if (value_len == 8 && strncasecmp( value, "waypoint", value_len ) == 0 )
406 line_type = GPSPOINT_TYPE_WAYPOINT;
0d2b891f
RN
407 else if (value_len == 5 && strncasecmp( value, "route", value_len ) == 0 )
408 line_type = GPSPOINT_TYPE_ROUTE;
409 else if (value_len == 10 && strncasecmp( value, "routepoint", value_len ) == 0 )
410 line_type = GPSPOINT_TYPE_ROUTEPOINT;
50a14534
EB
411 else
412 /* all others are ignored */
413 line_type = GPSPOINT_TYPE_NONE;
414 }
415 else if (key_len == 4 && strncasecmp( key, "name", key_len ) == 0 && value != NULL)
416 {
417 if (line_name == NULL)
418 {
419 line_name = g_strndup ( value, value_len );
420 }
421 }
422 else if (key_len == 7 && strncasecmp( key, "comment", key_len ) == 0 && value != NULL)
423 {
424 if (line_comment == NULL)
425 line_comment = deslashndup ( value, value_len );
426 }
6b2f262e
RN
427 else if (key_len == 11 && strncasecmp( key, "description", key_len ) == 0 && value != NULL)
428 {
429 if (line_description == NULL)
430 line_description = deslashndup ( value, value_len );
431 }
b1453c16
RN
432 else if (key_len == 5 && strncasecmp( key, "color", key_len ) == 0 && value != NULL)
433 {
434 if (line_color == NULL)
435 line_color = deslashndup ( value, value_len );
436 }
50a14534
EB
437 else if (key_len == 5 && strncasecmp( key, "image", key_len ) == 0 && value != NULL)
438 {
439 if (line_image == NULL)
440 line_image = deslashndup ( value, value_len );
441 }
442 else if (key_len == 8 && strncasecmp( key, "latitude", key_len ) == 0 && value != NULL)
443 {
d1cd12c0 444 line_latlon.lat = g_ascii_strtod(value, NULL);
50a14534
EB
445 }
446 else if (key_len == 9 && strncasecmp( key, "longitude", key_len ) == 0 && value != NULL)
447 {
d1cd12c0 448 line_latlon.lon = g_ascii_strtod(value, NULL);
50a14534
EB
449 }
450 else if (key_len == 8 && strncasecmp( key, "altitude", key_len ) == 0 && value != NULL)
451 {
d1cd12c0 452 line_altitude = g_ascii_strtod(value, NULL);
50a14534
EB
453 }
454 else if (key_len == 7 && strncasecmp( key, "visible", key_len ) == 0 && value[0] != 'y' && value[0] != 'Y' && value[0] != 't' && value[0] != 'T')
455 {
456 line_visible = FALSE;
457 }
acaf7113
AF
458 else if (key_len == 6 && strncasecmp( key, "symbol", key_len ) == 0 && value != NULL)
459 {
460 line_symbol = g_strndup ( value, value_len );
461 }
50a14534
EB
462 else if (key_len == 8 && strncasecmp( key, "unixtime", key_len ) == 0 && value != NULL)
463 {
d1cd12c0 464 line_timestamp = g_ascii_strtod(value, NULL);
50a14534
EB
465 if ( line_timestamp != 0x80000000 )
466 line_has_timestamp = TRUE;
467 }
468 else if (key_len == 10 && strncasecmp( key, "newsegment", key_len ) == 0 && value != NULL)
469 {
470 line_newsegment = TRUE;
471 }
a2817d3c
QT
472 else if (key_len == 8 && strncasecmp( key, "extended", key_len ) == 0 && value != NULL)
473 {
474 line_extended = TRUE;
475 }
476 else if (key_len == 5 && strncasecmp( key, "speed", key_len ) == 0 && value != NULL)
477 {
d1cd12c0 478 line_speed = g_ascii_strtod(value, NULL);
a2817d3c
QT
479 }
480 else if (key_len == 6 && strncasecmp( key, "course", key_len ) == 0 && value != NULL)
481 {
d1cd12c0 482 line_course = g_ascii_strtod(value, NULL);
a2817d3c
QT
483 }
484 else if (key_len == 3 && strncasecmp( key, "sat", key_len ) == 0 && value != NULL)
485 {
486 line_sat = atoi(value);
487 }
488 else if (key_len == 3 && strncasecmp( key, "fix", key_len ) == 0 && value != NULL)
489 {
490 line_fix = atoi(value);
491 }
50a14534
EB
492}
493
c9570f86 494static void a_gpspoint_write_waypoint ( const gpointer id, const VikWaypoint *wp, FILE *f )
50a14534
EB
495{
496 static struct LatLon ll;
161aa492 497 gchar *s_lat, *s_lon;
c9570f86
RN
498 // Sanity clause
499 if ( wp && !(wp->name) ) {
500 return;
501 }
50a14534 502 vik_coord_to_latlon ( &(wp->coord), &ll );
161aa492
EB
503 s_lat = a_coords_dtostr(ll.lat);
504 s_lon = a_coords_dtostr(ll.lon);
c9570f86 505 fprintf ( f, "type=\"waypoint\" latitude=\"%s\" longitude=\"%s\" name=\"%s\"", s_lat, s_lon, wp->name );
161aa492
EB
506 g_free ( s_lat );
507 g_free ( s_lon );
508
509 if ( wp->altitude != VIK_DEFAULT_ALTITUDE ) {
510 gchar *s_alt = a_coords_dtostr(wp->altitude);
511 fprintf ( f, " altitude=\"%s\"", s_alt );
512 g_free(s_alt);
513 }
50a14534
EB
514 if ( wp->comment )
515 {
516 gchar *tmp_comment = slashdup(wp->comment);
517 fprintf ( f, " comment=\"%s\"", tmp_comment );
518 g_free ( tmp_comment );
519 }
6b2f262e
RN
520 if ( wp->description )
521 {
522 gchar *tmp_description = slashdup(wp->description);
523 fprintf ( f, " description=\"%s\"", tmp_description );
524 g_free ( tmp_description );
525 }
50a14534
EB
526 if ( wp->image )
527 {
528 gchar *tmp_image = slashdup(wp->image);
529 fprintf ( f, " image=\"%s\"", tmp_image );
530 g_free ( tmp_image );
531 }
acaf7113
AF
532 if ( wp->symbol )
533 {
534 fprintf ( f, " symbol=\"%s\"", wp->symbol );
535 }
50a14534
EB
536 if ( ! wp->visible )
537 fprintf ( f, " visible=\"n\"" );
538 fprintf ( f, "\n" );
539}
540
0d2b891f 541static void a_gpspoint_write_trackpoint ( VikTrackpoint *tp, TP_write_info_type *write_info )
50a14534
EB
542{
543 static struct LatLon ll;
161aa492 544 gchar *s_lat, *s_lon;
50a14534
EB
545 vik_coord_to_latlon ( &(tp->coord), &ll );
546
0d2b891f
RN
547 FILE *f = write_info->f;
548
a2817d3c
QT
549 /* TODO: modify a_coords_dtostr() to accept (optional) buffer
550 * instead of doing malloc/free everytime */
161aa492
EB
551 s_lat = a_coords_dtostr(ll.lat);
552 s_lon = a_coords_dtostr(ll.lon);
0d2b891f 553 fprintf ( f, "type=\"%spoint\" latitude=\"%s\" longitude=\"%s\"", write_info->is_route ? "route" : "track", s_lat, s_lon );
161aa492
EB
554 g_free ( s_lat );
555 g_free ( s_lon );
50a14534 556
161aa492
EB
557 if ( tp->altitude != VIK_DEFAULT_ALTITUDE ) {
558 gchar *s_alt = a_coords_dtostr(tp->altitude);
559 fprintf ( f, " altitude=\"%s\"", s_alt );
560 g_free(s_alt);
561 }
50a14534
EB
562 if ( tp->has_timestamp )
563 fprintf ( f, " unixtime=\"%ld\"", tp->timestamp );
564 if ( tp->newsegment )
565 fprintf ( f, " newsegment=\"yes\"" );
a2817d3c 566
376c9177 567 if (!isnan(tp->speed) || !isnan(tp->course) || tp->nsats > 0) {
a2817d3c
QT
568 fprintf ( f, " extended=\"yes\"" );
569 if (!isnan(tp->speed)) {
570 gchar *s_speed = a_coords_dtostr(tp->speed);
571 fprintf ( f, " speed=\"%s\"", s_speed );
572 g_free(s_speed);
573 }
574 if (!isnan(tp->course)) {
575 gchar *s_course = a_coords_dtostr(tp->course);
576 fprintf ( f, " course=\"%s\"", s_course );
577 g_free(s_course);
578 }
579 if (tp->nsats > 0)
580 fprintf ( f, " sat=\"%d\"", tp->nsats );
581 if (tp->fix_mode > 0)
582 fprintf ( f, " fix=\"%d\"", tp->fix_mode );
583 }
50a14534
EB
584 fprintf ( f, "\n" );
585}
586
587
6b2f262e 588static void a_gpspoint_write_track ( const gpointer id, const VikTrack *trk, FILE *f )
50a14534 589{
e979bdab 590 // Sanity clauses
6b2f262e 591 if ( !trk )
ce4bd1cf 592 return;
6b2f262e 593 if ( !(trk->name) )
e979bdab
RN
594 return;
595
0d2b891f 596 fprintf ( f, "type=\"%s\" name=\"%s\"", trk->is_route ? "route" : "track", trk->name);
6b2f262e
RN
597
598 if ( trk->comment ) {
599 gchar *tmp = slashdup(trk->comment);
600 fprintf ( f, " comment=\"%s\"", tmp );
601 g_free ( tmp );
50a14534 602 }
6b2f262e
RN
603
604 if ( trk->description ) {
605 gchar *tmp = slashdup(trk->description);
606 fprintf ( f, " description=\"%s\"", tmp );
607 g_free ( tmp );
608 }
609
b1453c16
RN
610 if ( trk->has_color ) {
611 fprintf ( f, " color=#%.2x%.2x%.2x", (int)(trk->color.red/256),(int)(trk->color.green/256),(int)(trk->color.blue/256));
612 }
613
6b2f262e
RN
614 if ( ! trk->visible ) {
615 fprintf ( f, " visible=\"n\"" );
616 }
617 fprintf ( f, "\n" );
618
0d2b891f
RN
619 TP_write_info_type tp_write_info = { f, trk->is_route };
620 g_list_foreach ( trk->trackpoints, (GFunc) a_gpspoint_write_trackpoint, &tp_write_info );
621 fprintf ( f, "type=\"%send\"\n", trk->is_route ? "route" : "track" );
50a14534
EB
622}
623
624void a_gpspoint_write_file ( VikTrwLayer *trw, FILE *f )
625{
626 GHashTable *tracks = vik_trw_layer_get_tracks ( trw );
0d2b891f 627 GHashTable *routes = vik_trw_layer_get_routes ( trw );
50a14534
EB
628 GHashTable *waypoints = vik_trw_layer_get_waypoints ( trw );
629
630 fprintf ( f, "type=\"waypointlist\"\n" );
631 g_hash_table_foreach ( waypoints, (GHFunc) a_gpspoint_write_waypoint, f );
632 fprintf ( f, "type=\"waypointlistend\"\n" );
633 g_hash_table_foreach ( tracks, (GHFunc) a_gpspoint_write_track, f );
0d2b891f 634 g_hash_table_foreach ( routes, (GHFunc) a_gpspoint_write_track, f );
50a14534 635}