Skip to content

Commit

Permalink
fix bugs with gpx passthrough.
Browse files Browse the repository at this point in the history
with gpx 1.0, any extension data that was a child of rte or trk
was lost.  I beleive this used to work but has been broken for quite
a while.

with gpx 1.0 extension data that was a child of gpx could be
erroneously rewritten as part of the final wpt/rtept/trkpt.

with gpx 1.1 extension data that was a chile of trkseg could be
erroneously rewritten as part of the final wpt/rtept/trkpt.

I note we currently drop any extension data that is a child of gpx,
,a child of trkseg, or a child of metadata.
  • Loading branch information
tsteven4 committed Oct 26, 2023
1 parent c668916 commit 02d5925
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 42 deletions.
94 changes: 52 additions & 42 deletions gpx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ GpxFormat::gpx_end(QStringView /*unused*/)
logpoint_ct = 0;
cur_tag = nullptr;
wpt_tmp = nullptr;
fs_ptr = nullptr;
break;
case tt_cache_name:
wpt_tmp->notes = cdatastr;
Expand Down Expand Up @@ -616,6 +617,7 @@ GpxFormat::gpx_end(QStringView /*unused*/)
delete rh_link_;
rh_link_ = nullptr;
}
fs_ptr = nullptr;
break;
case tt_rte_rtept:
if (link_) {
Expand All @@ -631,6 +633,7 @@ GpxFormat::gpx_end(QStringView /*unused*/)
}
route_add_wpt(rte_head, wpt_tmp);
wpt_tmp = nullptr;
fs_ptr = nullptr;
break;
case tt_rte_desc:
rte_head->rte_desc = cdatastr;
Expand Down Expand Up @@ -661,9 +664,11 @@ GpxFormat::gpx_end(QStringView /*unused*/)
delete rh_link_;
rh_link_ = nullptr;
}
fs_ptr = nullptr;
break;
case tt_trk_trkseg:
next_trkpt_is_new_seg = 1;
fs_ptr = nullptr;
break;
case tt_trk_trkseg_trkpt:
if (link_) {
Expand All @@ -679,6 +684,7 @@ GpxFormat::gpx_end(QStringView /*unused*/)
}
track_add_wpt(trk_head, wpt_tmp);
wpt_tmp = nullptr;
fs_ptr = nullptr;
break;
case tt_trk_desc:
trk_head->rte_desc = cdatastr;
Expand Down Expand Up @@ -920,7 +926,7 @@ GpxFormat::wr_init(const QString& fname)
// normalization makes them null.
if (gpx_write_version.isNull() || (gpx_write_version < gpx_1_0)) {
fatal(FatalMsg() << MYNAME ": gpx version number"
<< gpx_write_version << "not valid.");
<< gpx_write_version << "not valid.");
}

writer->setAutoFormatting(true);
Expand Down Expand Up @@ -1092,9 +1098,9 @@ GpxFormat::read()

if (reader->hasError()) {
fatal(FatalMsg() << MYNAME << "Read error:" << reader->errorString()
<< "File:" << iqfile->fileName()
<< "Line:" << reader->lineNumber()
<< "Column:" << reader->columnNumber());
<< "File:" << iqfile->fileName()
<< "Line:" << reader->lineNumber()
<< "Column:" << reader->columnNumber());
}
}

Expand Down Expand Up @@ -1369,7 +1375,7 @@ void GpxFormat::gpx_write_common_core(const Waypoint* waypointp,
const gpx_point_type point_type) const
{
const auto* fs_gpxwpt = reinterpret_cast<gpx_wpt_fsdata*>(waypointp->fs.FsChainFind(kFsGpxWpt));

gpx_write_common_position(waypointp, point_type, fs_gpxwpt);
gpx_write_common_description(waypointp, point_type, fs_gpxwpt);
gpx_write_common_acc(waypointp, fs_gpxwpt);
Expand All @@ -1389,7 +1395,15 @@ GpxFormat::gpx_waypt_pr(const Waypoint* waypointp) const
auto* gmsd = garmin_fs_t::find(waypointp); /* gARmIN sPECIAL dATA */
if (fs_gpx) {
if (! gmsd) {
fprint_xml_chain(fs_gpx->tag);
if (fs_gpx->tag) {
if (gpx_write_version > gpx_1_0) {
writer->writeStartElement("extensions");
}
fprint_xml_chain(fs_gpx->tag);
if (gpx_write_version > gpx_1_0) {
writer->writeEndElement();
}
}
}
}
if (gmsd && (gpx_write_version > gpx_1_0)) {
Expand All @@ -1416,23 +1430,21 @@ GpxFormat::gpx_track_hdr(const route_head* rte)
writer->writeTextElement(QStringLiteral("number"), QString::number(rte->rte_num));
}

if (gpx_write_version > gpx_1_0) {
if (!(opt_humminbirdext || opt_garminext)) {
const auto* fs_gpx = reinterpret_cast<fs_xml*>(rte->fs.FsChainFind(kFsGpx));
if (fs_gpx) {
fprint_xml_chain(fs_gpx->tag);
}
} else if (opt_garminext) {
if (rte->line_color.bbggrr > unknown_color) {
int ci = gt_color_index_by_rgb(rte->line_color.bbggrr);
if (ci > 0) {
writer->writeStartElement(QStringLiteral("extensions"));
writer->writeStartElement(QStringLiteral("gpxx:TrackExtension"));
writer->writeTextElement(QStringLiteral("gpxx:DisplayColor"), QStringLiteral("%1")
.arg(gt_color_name(ci)));
writer->writeEndElement(); // Close gpxx:TrackExtension tag
writer->writeEndElement(); // Close extensions tag
}
if (!(opt_humminbirdext || opt_garminext)) {
const auto* fs_gpx = reinterpret_cast<fs_xml*>(rte->fs.FsChainFind(kFsGpx));
if (fs_gpx) {
fprint_xml_chain(fs_gpx->tag);
}
} else if (opt_garminext && (gpx_write_version > gpx_1_0)) {
if (rte->line_color.bbggrr > unknown_color) {
int ci = gt_color_index_by_rgb(rte->line_color.bbggrr);
if (ci > 0) {
writer->writeStartElement(QStringLiteral("extensions"));
writer->writeStartElement(QStringLiteral("gpxx:TrackExtension"));
writer->writeTextElement(QStringLiteral("gpxx:DisplayColor"), QStringLiteral("%1")
.arg(gt_color_name(ci)));
writer->writeEndElement(); // Close gpxx:TrackExtension tag
writer->writeEndElement(); // Close extensions tag
}
}
}
Expand Down Expand Up @@ -1506,25 +1518,23 @@ GpxFormat::gpx_route_hdr(const route_head* rte) const
writer->writeTextElement(QStringLiteral("number"), QString::number(rte->rte_num));
}

if (gpx_write_version > gpx_1_0) {
if (!(opt_humminbirdext || opt_garminext)) {
const auto* fs_gpx = reinterpret_cast<fs_xml*>(rte->fs.FsChainFind(kFsGpx));
if (fs_gpx) {
fprint_xml_chain(fs_gpx->tag);
}
} else if (opt_garminext) {
if (rte->line_color.bbggrr > unknown_color) {
int ci = gt_color_index_by_rgb(rte->line_color.bbggrr);
if (ci > 0) {
writer->writeStartElement(QStringLiteral("extensions"));
writer->writeStartElement(QStringLiteral("gpxx:RouteExtension"));
// FIXME: the value to use for IsAutoNamed is questionable.
writer->writeTextElement(QStringLiteral("gpxx:IsAutoNamed"), rte->rte_name.isEmpty()? QStringLiteral("true") : QStringLiteral("false")); // Required element
writer->writeTextElement(QStringLiteral("gpxx:DisplayColor"), QStringLiteral("%1")
.arg(gt_color_name(ci)));
writer->writeEndElement(); // Close gpxx:RouteExtension tag
writer->writeEndElement(); // Close extensions tag
}
if (!(opt_humminbirdext || opt_garminext)) {
const auto* fs_gpx = reinterpret_cast<fs_xml*>(rte->fs.FsChainFind(kFsGpx));
if (fs_gpx) {
fprint_xml_chain(fs_gpx->tag);
}
} else if (opt_garminext && (gpx_write_version > gpx_1_0)) {
if (rte->line_color.bbggrr > unknown_color) {
int ci = gt_color_index_by_rgb(rte->line_color.bbggrr);
if (ci > 0) {
writer->writeStartElement(QStringLiteral("extensions"));
writer->writeStartElement(QStringLiteral("gpxx:RouteExtension"));
// FIXME: the value to use for IsAutoNamed is questionable.
writer->writeTextElement(QStringLiteral("gpxx:IsAutoNamed"), rte->rte_name.isEmpty()? QStringLiteral("true") : QStringLiteral("false")); // Required element
writer->writeTextElement(QStringLiteral("gpxx:DisplayColor"), QStringLiteral("%1")
.arg(gt_color_name(ci)));
writer->writeEndElement(); // Close gpxx:RouteExtension tag
writer->writeEndElement(); // Close extensions tag
}
}
}
Expand Down
61 changes: 61 additions & 0 deletions reference/gpxpassthrough10.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xmlns:foreign="http://www.gpsbabel.org/testonlyschema" version="1.0" creator="hand crafted" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
<time>2010-10-16T14:27:17Z</time>
<wpt lat="36.339560000" lon="-117.422570000">
<ele>479.300</ele>
<name>Head east on CA-190 E/Nadeau Trail Continue to follow CA-190 E</name>
<cmt>Head east on CA-190 E/Nadeau Trail Continue to follow CA-190 E</cmt>
<desc>Head east on CA-190 E/Nadeau Trail Continue to follow CA-190 E</desc>
</wpt>
<wpt lat="36.460850000" lon="-116.865460000">
<ele>-55.600</ele>
<name>Turn right at Airport Rd</name>
<cmt>Turn right at Airport Rd</cmt>
<desc>Turn right at Airport Rd</desc>
<foreign:something>wpt</foreign:something>
</wpt>
<wpt lat="36.463640000" lon="-116.879200000">
<ele>-67.300</ele>
<name>Arrive at: Furnace Creek Airport-L06, Death Valley National Park, Death Valley, CA 92328</name>
<cmt>Arrive at: Furnace Creek Airport-L06, Death Valley National Park, Death Valley, CA 92328</cmt>
<desc>Arrive at: Furnace Creek Airport-L06, Death Valley National Park, Death Valley, CA 92328</desc>
</wpt>
<rte>
<name>Low Road</name>
<desc>Generated from track Route</desc>
<foreign:something>rte</foreign:something>
<rtept lat="36.339560000" lon="-117.422570000">
<ele>479.300</ele>
<name>RPT001</name>
</rtept>
<rtept lat="36.345010000" lon="-117.354270000">
<ele>624.300</ele>
<name>RPT005</name>
<foreign:something>rtept</foreign:something>
</rtept>
<rtept lat="36.344640000" lon="-117.349030000">
<ele>663.700</ele>
<name>RPT011</name>
</rtept>
</rte>
<trk>
<name>meridian</name>
<foreign:something>trk</foreign:something>
<trkseg>
<trkpt lat="30.062183333" lon="-91.610350000">
<ele>1.000</ele>
<time>2002-05-25T17:06:21.250Z</time>
</trkpt>
<trkpt lat="30.062783333" lon="-91.610566667">
<ele>0.000</ele>
<time>2002-05-25T17:09:55.190Z</time>
<foreign:something>trkpt</foreign:something>
</trkpt>
<trkpt lat="30.062700000" lon="-91.608266667">
<ele>0.000</ele>
<time>2002-05-25T17:12:00.200Z</time>
</trkpt>
</trkseg>
</trk>
<foreign:something>eof</foreign:something>
</gpx>
61 changes: 61 additions & 0 deletions reference/gpxpassthrough10~gpx.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.0" creator="GPSBabel - https://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:foreign="http://www.gpsbabel.org/testonlyschema">
<time>1970-01-01T00:00:00Z</time>
<bounds minlat="30.062183333" minlon="-117.422570000" maxlat="36.463640000" maxlon="-91.608266667"/>
<wpt lat="36.339560000" lon="-117.422570000">
<ele>479.300</ele>
<name>Head east on CA-190 E/Nadeau Trail Continue to follow CA-190 E</name>
<cmt>Head east on CA-190 E/Nadeau Trail Continue to follow CA-190 E</cmt>
<desc>Head east on CA-190 E/Nadeau Trail Continue to follow CA-190 E</desc>
</wpt>
<wpt lat="36.460850000" lon="-116.865460000">
<ele>-55.600</ele>
<name>Turn right at Airport Rd</name>
<cmt>Turn right at Airport Rd</cmt>
<desc>Turn right at Airport Rd</desc>
<foreign:something>wpt</foreign:something>
</wpt>
<wpt lat="36.463640000" lon="-116.879200000">
<ele>-67.300</ele>
<name>Arrive at: Furnace Creek Airport-L06, Death Valley National Park, Death Valley, CA 92328</name>
<cmt>Arrive at: Furnace Creek Airport-L06, Death Valley National Park, Death Valley, CA 92328</cmt>
<desc>Arrive at: Furnace Creek Airport-L06, Death Valley National Park, Death Valley, CA 92328</desc>
</wpt>
<rte>
<name>Low Road</name>
<desc>Generated from track Route</desc>
<foreign:something>rte</foreign:something>
<rtept lat="36.339560000" lon="-117.422570000">
<ele>479.300</ele>
<name>RPT001</name>
</rtept>
<rtept lat="36.345010000" lon="-117.354270000">
<ele>624.300</ele>
<name>RPT005</name>
<foreign:something>rtept</foreign:something>
</rtept>
<rtept lat="36.344640000" lon="-117.349030000">
<ele>663.700</ele>
<name>RPT011</name>
</rtept>
</rte>
<trk>
<name>meridian</name>
<foreign:something>trk</foreign:something>
<trkseg>
<trkpt lat="30.062183333" lon="-91.610350000">
<ele>1.000</ele>
<time>2002-05-25T17:06:21.250Z</time>
</trkpt>
<trkpt lat="30.062783333" lon="-91.610566667">
<ele>0.000</ele>
<time>2002-05-25T17:09:55.190Z</time>
<foreign:something>trkpt</foreign:something>
</trkpt>
<trkpt lat="30.062700000" lon="-91.608266667">
<ele>0.000</ele>
<time>2002-05-25T17:12:00.200Z</time>
</trkpt>
</trkseg>
</trk>
</gpx>
81 changes: 81 additions & 0 deletions reference/gpxpassthrough11.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xmlns:foreign="http://www.gpsbabel.org/testonlyschema" version="1.1" creator="hand crafted" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<time>2010-10-16T14:27:17Z</time>
<extensions>
<foreign:something>metadata</foreign:something>
</extensions>
</metadata>
<wpt lat="36.339560000" lon="-117.422570000">
<ele>479.300</ele>
<name>Head east on CA-190 E/Nadeau Trail Continue to follow CA-190 E</name>
<cmt>Head east on CA-190 E/Nadeau Trail Continue to follow CA-190 E</cmt>
<desc>Head east on CA-190 E/Nadeau Trail Continue to follow CA-190 E</desc>
</wpt>
<wpt lat="36.460850000" lon="-116.865460000">
<ele>-55.600</ele>
<name>Turn right at Airport Rd</name>
<cmt>Turn right at Airport Rd</cmt>
<desc>Turn right at Airport Rd</desc>
<extensions>
<foreign:something>wpt</foreign:something>
</extensions>
</wpt>
<wpt lat="36.463640000" lon="-116.879200000">
<ele>-67.300</ele>
<name>Arrive at: Furnace Creek Airport-L06, Death Valley National Park, Death Valley, CA 92328</name>
<cmt>Arrive at: Furnace Creek Airport-L06, Death Valley National Park, Death Valley, CA 92328</cmt>
<desc>Arrive at: Furnace Creek Airport-L06, Death Valley National Park, Death Valley, CA 92328</desc>
</wpt>
<rte>
<name>Low Road</name>
<desc>Generated from track Route</desc>
<extensions>
<foreign:something>rte</foreign:something>
</extensions>
<rtept lat="36.339560000" lon="-117.422570000">
<ele>479.300</ele>
<name>RPT001</name>
</rtept>
<rtept lat="36.345010000" lon="-117.354270000">
<ele>624.300</ele>
<name>RPT005</name>
<extensions>
<foreign:something>rtept</foreign:something>
</extensions>
</rtept>
<rtept lat="36.344640000" lon="-117.349030000">
<ele>663.700</ele>
<name>RPT011</name>
</rtept>
</rte>
<trk>
<name>meridian</name>
<extensions>
<foreign:something>trk</foreign:something>
</extensions>
<trkseg>
<trkpt lat="30.062183333" lon="-91.610350000">
<ele>1.000</ele>
<time>2002-05-25T17:06:21.250Z</time>
</trkpt>
<trkpt lat="30.062783333" lon="-91.610566667">
<ele>0.000</ele>
<time>2002-05-25T17:09:55.190Z</time>
<extensions>
<foreign:something>trkpt</foreign:something>
</extensions>
</trkpt>
<trkpt lat="30.062700000" lon="-91.608266667">
<ele>0.000</ele>
<time>2002-05-25T17:12:00.200Z</time>
</trkpt>
<extensions>
<foreign:something>trkseg</foreign:something>
</extensions>
</trkseg>
</trk>
<extensions>
<foreign:something>eof</foreign:something>
</extensions>
</gpx>
Loading

0 comments on commit 02d5925

Please sign in to comment.