]> git.street.me.uk Git - andy/viking.git/blame - src/gpsmapper.c
Draw a compass and bearing while using the ruler
[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 {
104 vik_coord_to_latlon ( &(wp->coord), &ll );
105 fprintf ( f, "Data0=(%f,%f)\n", ll.lat, ll.lon );
106 fprintf ( f, "[END-%.5s]\n\n", wp->comment+len+1 );
107 }
108}
109
110static void write_trackpoint ( VikTrackpoint *tp, FILE *f )
111{
112 static struct LatLon ll;
113 vik_coord_to_latlon ( &(tp->coord), &ll );
114
115 fprintf ( f, "(%f,%f),", ll.lat, ll.lon );
116}
117
118static void write_track ( const gchar *name, VikTrack *t, FILE *f )
119{
120 guint len = print_rgn_stuff ( t->comment, f );
121 if ( len )
122 {
123 fprintf ( f, "Data0=" );
124 g_list_foreach ( t->trackpoints, (GFunc) write_trackpoint, f );
125 fprintf ( f, "\n[END-%.5s]\n\n", t->comment+len+1 );
126 }
127}
128
129void a_gpsmapper_write_file ( VikTrwLayer *trw, FILE *f )
130{
131 GHashTable *tracks = vik_trw_layer_get_tracks ( trw );
132 GHashTable *waypoints = vik_trw_layer_get_waypoints ( trw );
133
134 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",
135 VIK_LAYER(trw)->name, VIK_LAYER(trw)->name );
136
137 g_hash_table_foreach ( waypoints, (GHFunc) write_waypoint, f );
138 g_hash_table_foreach ( tracks, (GHFunc) write_track, f );
139}
140
141