]> git.street.me.uk Git - andy/viking.git/blame - src/gpsmapper.c
[DOC] Improve reference documentation for babel.c
[andy/viking.git] / src / gpsmapper.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>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21#include "viking.h"
22
23#include <string.h>
24
25/* Name of layer -> RGN type and Type
26 format: Name RGN40 0x40
27 or: Name RGN10 0x2f06
28*/
29/* returns 0 if invalid/no rgn stuff, else returns len of */
30static guint print_rgn_stuff ( const gchar *nm, FILE *f )
31{
32 guint len;
33 gchar *layers;
34 gchar *name;
35
36 if (!nm)
37 return 0;
38
39 name = g_strdup ( nm );
40
41 len = strlen(name);
42
43
44
45 /* --------------------------------------------- */
46 /* added by oddgeir@oddgeirkvien.com, 2005.02.02 */
47 /* Format may also be: Name RGN40 0x40 Layers=1 */
48 /* or: Name RGN10 0x2f06 Layers=1 */
49
50 if ( len > 20 && strncasecmp(name+len-8,"LAYERS=",7) == 0 ) /* Layers is added to the description */
51 {
52 layers=name+len-8;
53 *(name+len-9)=0;
54 len = strlen(name);
55 }
56 else
57 {
58 layers=0;
59 }
60 /* --------------------------------------------- */
61
62
63
64 if ( len > 11 && strncasecmp(name+len-10,"RGN",3) == 0 &&
65strncasecmp(name+len-4,"0x",2) == 0 )
66 {
67 fprintf ( f, "[%.5s]\nType=%.4s\nLabel=", name+len-10, name+len-4 );
68 fwrite ( name, sizeof(gchar), len - 11, f );
69 fprintf ( f, "\n" );
70
71/* added by oddgeir@oddgeirkvien.com, 2005.02.02 */
72 if (layers) fprintf( f, "%s\n",layers);
73
74 g_free ( name );
75
76 return len - 11;
77 }
78 else if ( len > 13 && strncasecmp(name+len-12,"RGN",3) == 0 &&
79strncasecmp(name+len-6,"0x",2) == 0 )
80 {
81 fprintf ( f, "[%.5s]\nType=%.6s\nLabel=", name+len-12, name+len-6 );
82 fwrite ( name, sizeof(gchar), len - 13, f );
83 fprintf ( f, "\n" );
84
85/* added by oddgeir@oddgeirkvien.com, 2005.02.02 */
86 if (layers) fprintf( f, "%s\n",layers);
87
88 g_free ( name );
89
90 return len - 13;
91 }
92 else {
93 g_free ( name );
94 return 0;
95 }
96}
97
98static void write_waypoint ( const gchar *name, VikWaypoint *wp, FILE *f )
99{
100 static struct LatLon ll;
101 guint len = print_rgn_stuff ( wp->comment, f );
102 if ( len )
103 {
161aa492 104 gchar *s_lat, *s_lon;
50a14534 105 vik_coord_to_latlon ( &(wp->coord), &ll );
161aa492
EB
106 s_lat = a_coords_dtostr(ll.lat);
107 s_lon = a_coords_dtostr(ll.lon);
108 fprintf ( f, "Data0=(%s,%s)\n", s_lat, s_lon );
109 g_free ( s_lat );
110 g_free ( s_lon );
50a14534
EB
111 fprintf ( f, "[END-%.5s]\n\n", wp->comment+len+1 );
112 }
113}
114
115static void write_trackpoint ( VikTrackpoint *tp, FILE *f )
116{
117 static struct LatLon ll;
161aa492
EB
118 gchar *s_lat, *s_lon;
119 vik_coord_to_latlon ( &(tp->coord), &ll );
120 s_lat = a_coords_dtostr(ll.lat);
121 s_lon = a_coords_dtostr(ll.lon);
122 fprintf ( f, "(%s,%s),", s_lat, s_lon );
123 g_free ( s_lat );
124 g_free ( s_lon );
50a14534
EB
125}
126
127static void write_track ( const gchar *name, VikTrack *t, FILE *f )
128{
129 guint len = print_rgn_stuff ( t->comment, f );
130 if ( len )
131 {
132 fprintf ( f, "Data0=" );
133 g_list_foreach ( t->trackpoints, (GFunc) write_trackpoint, f );
134 fprintf ( f, "\n[END-%.5s]\n\n", t->comment+len+1 );
135 }
136}
137
138void a_gpsmapper_write_file ( VikTrwLayer *trw, FILE *f )
139{
140 GHashTable *tracks = vik_trw_layer_get_tracks ( trw );
141 GHashTable *waypoints = vik_trw_layer_get_waypoints ( trw );
142
143 fprintf ( f, "[IMG ID]\nID=%s\nName=%s\nTreSize=1000\nRgnLimit=700\nLevels=2\nLevel0=22\nLevel1=18\nZoom0=0\nZoom1=1\n[END-IMG ID]\n\n",
144 VIK_LAYER(trw)->name, VIK_LAYER(trw)->name );
145
146 g_hash_table_foreach ( waypoints, (GHFunc) write_waypoint, f );
147 g_hash_table_foreach ( tracks, (GHFunc) write_track, f );
148}
149
150