1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 19:52:09 +01:00

Added support for Garmin route extension

Resolves #112
This commit is contained in:
Martin Tůma 2018-05-16 21:53:06 +02:00
parent 81a5c712c6
commit 0cd6a82a0f
2 changed files with 42 additions and 9 deletions

View File

@ -51,6 +51,17 @@ Coordinates GPXParser::coordinates()
return Coordinates(lon, lat);
}
void GPXParser::rpExtension(TrackData *autoRoute)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "rpt") {
autoRoute->append(Trackpoint(coordinates()));
trackpointData(autoRoute->last());
} else
_reader.skipCurrentElement();
}
}
void GPXParser::tpExtension(Trackpoint &trackpoint)
{
while (_reader.readNextStartElement()) {
@ -63,7 +74,17 @@ void GPXParser::tpExtension(Trackpoint &trackpoint)
}
}
void GPXParser::extensions(Trackpoint &trackpoint)
void GPXParser::rteptExtensions(TrackData *autoRoute)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "RoutePointExtension")
rpExtension(autoRoute);
else
_reader.skipCurrentElement();
}
}
void GPXParser::trkptExtensions(Trackpoint &trackpoint)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "speed")
@ -95,7 +116,7 @@ void GPXParser::trackpointData(Trackpoint &trackpoint)
else if (_reader.name() == "geoidheight")
gh = number();
else if (_reader.name() == "extensions")
extensions(trackpoint);
trkptExtensions(trackpoint);
else
_reader.skipCurrentElement();
}
@ -104,7 +125,7 @@ void GPXParser::trackpointData(Trackpoint &trackpoint)
trackpoint.setElevation(trackpoint.elevation() - gh);
}
void GPXParser::waypointData(Waypoint &waypoint)
void GPXParser::waypointData(Waypoint &waypoint, TrackData *autoRoute)
{
qreal gh = NAN;
@ -119,6 +140,8 @@ void GPXParser::waypointData(Waypoint &waypoint)
gh = number();
else if (_reader.name() == "time")
waypoint.setTimestamp(time());
else if (autoRoute && _reader.name() == "extensions")
rteptExtensions(autoRoute);
else
_reader.skipCurrentElement();
}
@ -138,12 +161,14 @@ void GPXParser::trackpoints(TrackData &track)
}
}
void GPXParser::routepoints(RouteData &route)
void GPXParser::routepoints(RouteData &route, QList<TrackData> &tracks)
{
TrackData autoRoute;
while (_reader.readNextStartElement()) {
if (_reader.name() == "rtept") {
route.append(Waypoint(coordinates()));
waypointData(route.last());
waypointData(route.last(), &autoRoute);
} else if (_reader.name() == "name")
route.setName(_reader.readElementText());
else if (_reader.name() == "desc")
@ -151,6 +176,12 @@ void GPXParser::routepoints(RouteData &route)
else
_reader.skipCurrentElement();
}
if (!autoRoute.isEmpty()) {
autoRoute.setName(route.name());
autoRoute.setDescription(route.description());
tracks.append(autoRoute);
}
}
void GPXParser::track(TrackData &track)
@ -176,7 +207,7 @@ void GPXParser::gpx(QList<TrackData> &tracks, QList<RouteData> &routes,
track(tracks.back());
} else if (_reader.name() == "rte") {
routes.append(RouteData());
routepoints(routes.back());
routepoints(routes.back(), tracks);
} else if (_reader.name() == "wpt") {
waypoints.append(Waypoint(coordinates()));
waypointData(waypoints.last());

View File

@ -18,11 +18,13 @@ private:
QList<Waypoint> &waypoints);
void track(TrackData &track);
void trackpoints(TrackData &track);
void routepoints(RouteData &route);
void routepoints(RouteData &route, QList<TrackData> &tracks);
void rpExtension(TrackData *autoRoute);
void tpExtension(Trackpoint &trackpoint);
void extensions(Trackpoint &trackpoint);
void trkptExtensions(Trackpoint &trackpoint);
void rteptExtensions(TrackData *autoRoute);
void trackpointData(Trackpoint &trackpoint);
void waypointData(Waypoint &waypoint);
void waypointData(Waypoint &waypoint, TrackData *autoRoute = 0);
qreal number();
QDateTime time();
Coordinates coordinates();