2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
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.
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.
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
25 /* Name of layer -> RGN type and Type
26 format: Name RGN40 0x40
29 /* returns 0 if invalid/no rgn stuff, else returns len of */
30 static guint
print_rgn_stuff ( const gchar
*nm
, FILE *f
)
39 name
= g_strdup ( nm
);
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 */
50 if ( len
> 20 && strncasecmp(name
+len
-8,"LAYERS=",7) == 0 ) /* Layers is added to the description */
60 /* --------------------------------------------- */
64 if ( len
> 11 && strncasecmp(name
+len
-10,"RGN",3) == 0 &&
65 strncasecmp(name
+len
-4,"0x",2) == 0 )
67 fprintf ( f
, "[%.5s]\nType=%.4s\nLabel=", name
+len
-10, name
+len
-4 );
68 fwrite ( name
, sizeof(gchar
), len
- 11, f
);
71 /* added by oddgeir@oddgeirkvien.com, 2005.02.02 */
72 if (layers
) fprintf( f
, "%s\n",layers
);
78 else if ( len
> 13 && strncasecmp(name
+len
-12,"RGN",3) == 0 &&
79 strncasecmp(name
+len
-6,"0x",2) == 0 )
81 fprintf ( f
, "[%.5s]\nType=%.6s\nLabel=", name
+len
-12, name
+len
-6 );
82 fwrite ( name
, sizeof(gchar
), len
- 13, f
);
85 /* added by oddgeir@oddgeirkvien.com, 2005.02.02 */
86 if (layers
) fprintf( f
, "%s\n",layers
);
98 static void write_waypoint ( const gchar
*name
, VikWaypoint
*wp
, FILE *f
)
100 static struct LatLon ll
;
101 guint len
= print_rgn_stuff ( wp
->comment
, f
);
104 gchar
*s_lat
, *s_lon
;
105 vik_coord_to_latlon ( &(wp
->coord
), &ll
);
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
);
111 fprintf ( f
, "[END-%.5s]\n\n", wp
->comment
+len
+1 );
115 static void write_trackpoint ( VikTrackpoint
*tp
, FILE *f
)
117 static struct LatLon ll
;
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
);
127 static void write_track ( const gchar
*name
, VikTrack
*t
, FILE *f
)
129 guint len
= print_rgn_stuff ( t
->comment
, f
);
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 );
138 void a_gpsmapper_write_file ( VikTrwLayer
*trw
, FILE *f
)
140 GHashTable
*tracks
= vik_trw_layer_get_tracks ( trw
);
141 GHashTable
*waypoints
= vik_trw_layer_get_waypoints ( trw
);
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
);
146 g_hash_table_foreach ( waypoints
, (GHFunc
) write_waypoint
, f
);
147 g_hash_table_foreach ( tracks
, (GHFunc
) write_track
, f
);