1 |
/**
|
2 |
* Navit, a modular navigation system.
|
3 |
* Copyright (C) 2005-2008 Navit Team
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
#include "gpx2navit_txt.h"
|
21 |
|
22 |
void startElementControl(parsedata * pdata, const char *element,
|
23 |
const char **attr);
|
24 |
void endElementControl(parsedata * pdata, const char *element);
|
25 |
|
26 |
/*
|
27 |
* This method controls tag start event.
|
28 |
* It corrects attributes.
|
29 |
*/
|
30 |
void
|
31 |
startElementControl(parsedata * pdata, const char *element,
|
32 |
const char **attr)
|
33 |
{
|
34 |
int i;
|
35 |
static int isFirstTrk = 1;
|
36 |
static int isFirstRte = 1;
|
37 |
static int isFirstPathpt = 1;
|
38 |
for (i = 0; attr[i]; i += 2) {
|
39 |
if (!strcmp(attr[i], "lon")) {
|
40 |
pdata->attr->lon = atof(attr[i + 1]);
|
41 |
}
|
42 |
if (!strcmp(attr[i], "lat")) {
|
43 |
pdata->attr->lat = atof(attr[i + 1]);
|
44 |
}
|
45 |
if (!strcmp(attr[i], "minlon")) {
|
46 |
pdata->attr->minlon = atof(attr[i + 1]);
|
47 |
}
|
48 |
if (!strcmp(attr[i], "minlat")) {
|
49 |
pdata->attr->minlat = atof(attr[i + 1]);
|
50 |
}
|
51 |
if (!strcmp(attr[i], "maxlon")) {
|
52 |
pdata->attr->maxlon = atof(attr[i + 1]);
|
53 |
}
|
54 |
if (!strcmp(attr[i], "maxlat")) {
|
55 |
pdata->attr->maxlat = atof(attr[i + 1]);
|
56 |
}
|
57 |
if (!strcmp(attr[i], "author")) {
|
58 |
strcpy(pdata->attr->author, attr[i + 1]);
|
59 |
}
|
60 |
}
|
61 |
if (pdata->prop->parseTrk) {
|
62 |
if (!strcmp(element, "trk")) {
|
63 |
if (isFirstTrk) {
|
64 |
isFirstTrk = 0;
|
65 |
}
|
66 |
}
|
67 |
if (!strcmp(element, "trkseg")) {
|
68 |
isFirstPathpt = 1;
|
69 |
}
|
70 |
if (!strcmp(element, "trkpt")) {
|
71 |
if (isFirstPathpt) {
|
72 |
initPathAttr(pdata->pattr, pdata->attr);
|
73 |
isFirstPathpt = 0;
|
74 |
}
|
75 |
}
|
76 |
}
|
77 |
if (pdata->prop->parseRte) {
|
78 |
if (!strcmp(element, "rte")) {
|
79 |
if (isFirstRte) {
|
80 |
isFirstRte = 0;
|
81 |
isFirstPathpt = 1;
|
82 |
}
|
83 |
}
|
84 |
if (!strcmp(element, "rtept")) {
|
85 |
if (isFirstPathpt) {
|
86 |
initPathAttr(pdata->pattr, pdata->attr);
|
87 |
isFirstPathpt = 0;
|
88 |
}
|
89 |
}
|
90 |
}
|
91 |
}
|
92 |
|
93 |
/**
|
94 |
* This method is kicked by tag end event.
|
95 |
* It corrects char elements when the element tag has some data,
|
96 |
* then start to convert when tag is top level tag like <wpt>.
|
97 |
*/
|
98 |
void endElementControl(parsedata * pdata, const char *element)
|
99 |
{
|
100 |
static int isFirstWpt = 1;
|
101 |
static int isFirstTrkAsPoint = 1;
|
102 |
static int isFirstRteAsPoint = 1;
|
103 |
/* common elements */
|
104 |
if (!strcmp(element, "name")) {
|
105 |
strcpy(pdata->attr->name, pdata->databuf);
|
106 |
}
|
107 |
if (!strcmp(element, "cmt")) {
|
108 |
strcpy(pdata->attr->cmt, pdata->databuf);
|
109 |
}
|
110 |
if (!strcmp(element, "desc")) {
|
111 |
strcpy(pdata->attr->desc, pdata->databuf);
|
112 |
}
|
113 |
if (!strcmp(element, "src")) {
|
114 |
strcpy(pdata->attr->src, pdata->databuf);
|
115 |
}
|
116 |
if (!strcmp(element, "link")) {
|
117 |
strcpy(pdata->attr->link, pdata->databuf);
|
118 |
}
|
119 |
if (!strcmp(element, "type")) {
|
120 |
strcpy(pdata->attr->type, pdata->databuf);
|
121 |
}
|
122 |
/* waypoint and metadata elements */
|
123 |
if (!strcmp(element, "time")) {
|
124 |
strcpy(pdata->attr->time, pdata->databuf);
|
125 |
}
|
126 |
/* route and track point elements */
|
127 |
if (!strcmp(element, "number")) {
|
128 |
pdata->attr->number = atoi(pdata->databuf);
|
129 |
}
|
130 |
/* waypoint elements */
|
131 |
if (!strcmp(element, "ele")) {
|
132 |
pdata->attr->ele = atof(pdata->databuf);
|
133 |
}
|
134 |
if (!strcmp(element, "magvar")) {
|
135 |
pdata->attr->magvar = atof(pdata->databuf);
|
136 |
}
|
137 |
if (!strcmp(element, "geoidheight")) {
|
138 |
pdata->attr->geoidheight = atof(pdata->databuf);
|
139 |
}
|
140 |
if (!strcmp(element, "sym")) {
|
141 |
strcpy(pdata->attr->sym, pdata->databuf);
|
142 |
}
|
143 |
if (!strcmp(element, "fix")) {
|
144 |
strcpy(pdata->attr->fix, pdata->databuf);
|
145 |
}
|
146 |
if (!strcmp(element, "sat")) {
|
147 |
pdata->attr->sat = atoi(pdata->databuf);
|
148 |
}
|
149 |
if (!strcmp(element, "hdop")) {
|
150 |
pdata->attr->hdop = atof(pdata->databuf);
|
151 |
}
|
152 |
if (!strcmp(element, "vdop")) {
|
153 |
pdata->attr->vdop = atof(pdata->databuf);
|
154 |
}
|
155 |
if (!strcmp(element, "pdop")) {
|
156 |
pdata->attr->pdop = atof(pdata->databuf);
|
157 |
}
|
158 |
if (!strcmp(element, "ageofdgpsdata")) {
|
159 |
pdata->attr->ageofdgpsdata = atof(pdata->databuf);
|
160 |
}
|
161 |
/* metadata elements */
|
162 |
if (!strcmp(element, "author")) {
|
163 |
strcpy(pdata->attr->author, pdata->databuf);
|
164 |
}
|
165 |
if (!strcmp(element, "keywords")) {
|
166 |
strcpy(pdata->attr->keywords, pdata->databuf);
|
167 |
}
|
168 |
if (!strcmp(element, "copyright")) {
|
169 |
strcpy(pdata->attr->copyright, pdata->databuf);
|
170 |
}
|
171 |
if (!strcmp(element, "year")) {
|
172 |
pdata->attr->year = atoi(pdata->databuf);
|
173 |
}
|
174 |
if (!strcmp(element, "license")) {
|
175 |
strcpy(pdata->attr->license, pdata->databuf);
|
176 |
}
|
177 |
if (!strcmp(element, "bounds")) {
|
178 |
/* none */
|
179 |
}
|
180 |
/* top elements */
|
181 |
/* set waypoint data */
|
182 |
if (!strcmp(element, "wpt")) {
|
183 |
if (pdata->prop->parseWpt) {
|
184 |
if (isFirstWpt) {
|
185 |
isFirstWpt = 0;
|
186 |
}
|
187 |
//todo
|
188 |
if (DEBUG) {
|
189 |
fprintf(stderr,"\neectrl wpt %s %s",
|
190 |
pdata->attr->desc,pdata->attr->name);
|
191 |
}
|
192 |
setWpt(pdata);
|
193 |
wipeAttr(pdata->attr);
|
194 |
}
|
195 |
}
|
196 |
/* set trackpoint data */
|
197 |
if (!strcmp(element, "trkpt")) {
|
198 |
if (pdata->prop->parseTrk) {
|
199 |
setPathData(pdata->pattr, pdata->attr);
|
200 |
if (!pdata->prop->isFast)
|
201 |
setPathInterval(pdata);
|
202 |
}
|
203 |
/* set trackpoint data as point */
|
204 |
if (pdata->prop->isPoint) {
|
205 |
if (isFirstTrkAsPoint) {
|
206 |
isFirstTrkAsPoint = 0;
|
207 |
}
|
208 |
setWpt(pdata);
|
209 |
}
|
210 |
wipeAttr(pdata->attr);
|
211 |
}
|
212 |
/* write trackpoint */
|
213 |
if (!strcmp(element, "trkseg")) {
|
214 |
if (pdata->prop->parseTrk) {
|
215 |
setPath( pdata);
|
216 |
}
|
217 |
}
|
218 |
/* set route data */
|
219 |
if (!strcmp(element, "rtept")) {
|
220 |
if (pdata->prop->parseRte) {
|
221 |
setPathData(pdata->pattr, pdata->attr);
|
222 |
if (!pdata->prop->isFast)
|
223 |
setPathInterval(pdata);
|
224 |
}
|
225 |
/* set route data as point */
|
226 |
if (pdata->prop->isPoint) {
|
227 |
if (isFirstRteAsPoint) {
|
228 |
isFirstRteAsPoint = 0;
|
229 |
}
|
230 |
setWpt( pdata);
|
231 |
}
|
232 |
wipeAttr(pdata->attr);
|
233 |
}
|
234 |
/* write route */
|
235 |
if (!strcmp(element, "rte")) {
|
236 |
if (pdata->prop->parseRte) {
|
237 |
setPath( pdata);
|
238 |
}
|
239 |
}
|
240 |
if (!strcmp(element, "metadata")) {
|
241 |
setMetadata(pdata);
|
242 |
wipeAttr(pdata->attr);
|
243 |
}
|
244 |
pdata->bufptr = NULL; //reset bufptr now
|
245 |
}
|