[go: up one dir, main page]

Menu

[e39a77]: / src / gpsmapper.c  Maximize  Restore  History

Download this file

151 lines (124 with data), 4.2 kB

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