Re: [Gpsbabel-code] [Gpsbabel-misc] Gpsbabel and 1.4.2 and 1.4.4 incorrectly handling gpxtpx extens
Brought to you by:
robertl
From: tsteven4 <tst...@gm...> - 2013-03-04 14:25:44
|
Index: gpx.cc =================================================================== --- gpx.cc (revision 4338) +++ gpx.cc (working copy) @@ -99,7 +99,7 @@ #define FLT_FMT_T "%0.9lf" #define FLT_FMT_R "%0.9lf" -typedef enum { +typedef enum { tt_unknown = 0, tt_gpx, @@ -348,8 +348,8 @@ {type, 1, "/gpx/wpt/geocache/" name, 0UL } /* opencaching.de */ #define GARMIN_WPT_EXT "/gpx/wpt/extensions/gpxx:WaypointExtension" -#define GARMIN_TRK_EXT "/gpx/trk/trkseg/trkpt/extensions/gpxtpx:TrackPointExtension" -#define GARMIN_RTE_EXT "/gpx/rte/rtept/extensions/gpxxx:RoutePointExtension" +#define GARMIN_TRKPT_EXT "/gpx/trk/trkseg/trkpt/extensions/gpxtpx:TrackPointExtension" +#define GARMIN_RTEPT_EXT "/gpx/rte/rtept/extensions/gpxxx:RoutePointExtension" // GEOTAG( tt_cache, "cache"), { tt_cache, 1, "/gpx/wpt/groundspeak:cache" }, @@ -378,7 +378,7 @@ { tt_garmin_wpt_extensions, 0, GARMIN_WPT_EXT, 0UL }, { tt_garmin_wpt_proximity, 0, GARMIN_WPT_EXT "/gpxx:Proximity", 0UL }, { tt_garmin_wpt_temperature, 0, GARMIN_WPT_EXT "/gpxx:Temperature", 0UL }, - { tt_garmin_wpt_temperature, 0, GARMIN_TRK_EXT "/gpxtpx:atemp", 0UL }, + { tt_garmin_wpt_temperature, 1, GARMIN_TRKPT_EXT "/gpxtpx:atemp", 0UL }, { tt_garmin_wpt_depth, 0, GARMIN_WPT_EXT "/gpxx:Depth", 0UL }, { tt_garmin_wpt_display_mode, 0, GARMIN_WPT_EXT "/gpxx:DisplayMode", 0UL }, { tt_garmin_wpt_categories, 0, GARMIN_WPT_EXT "/gpxx:Categories", 0UL }, @@ -391,8 +391,8 @@ { tt_garmin_wpt_phone_nr, 0, GARMIN_WPT_EXT "/gpxx:PhoneNumber", 0UL }, // In Garmin space, but in core of waypoint. - { tt_trk_trkseg_trkpt_heartrate, 0, GARMIN_TRK_EXT "/gpxtpx:hr", 0UL }, - { tt_trk_trkseg_trkpt_cadence, 0, GARMIN_TRK_EXT "/gpxtpx:cad", 0UL }, + { tt_trk_trkseg_trkpt_heartrate, 1, GARMIN_TRKPT_EXT "/gpxtpx:hr", 0UL }, + { tt_trk_trkseg_trkpt_cadence, 1, GARMIN_TRKPT_EXT "/gpxtpx:cad", 0UL }, { tt_humminbird_wpt_depth, 0, "/gpx/wpt/extensions/h:depth", 0UL }, // in centimeters. { tt_humminbird_wpt_status, 0, "/gpx/wpt/extensions/h:status", 0UL }, @@ -1405,24 +1405,24 @@ #if XDEBUG qDebug() << ostring; #else - // TODO: technically, &apos is almost never required to be encoded, but + // TODO: technically, &apos is almost never required to be encoded, but // the pre-Qt version of our serializer did, so we'll manually do it here // for now, in the early days, just to keep things as we've always done it. - ostring.replace("'", "'"); + ostring.replace("'", "'"); // TODO: The old writer would more aggressively protect you from control - // character nonsense. The control-Z (032)is the only thing that appears in + // character nonsense. The control-Z (032)is the only thing that appears in // our test suite, but let's toss things we know aren't allowed in GPX. // Let's just carpet-bomb the whole range for now. I have a feeling we'll // revisit this in time... - ostring.replace(QRegExp("[\014-\032]"), " "); + ostring.replace(QRegExp("[\014-\032]"), " "); gbfputs(ostring, ofd); gbfclose(ofd); ofd = NULL; #endif #endif - + mkshort_del_handle(&mkshort_handle); } @@ -1587,10 +1587,11 @@ char* otmp_ent, *tmp_ent = NULL; otmp_ent = xml_entitize(tag->parentcdata); - if (otmp_ent[0] == '\n') + if (otmp_ent[0] == '\n') { tmp_ent = otmp_ent+1; - else + } else { tmp_ent = otmp_ent; + } gbfprintf(ofd, "%s", tmp_ent); xfree(otmp_ent); #else @@ -1738,7 +1739,9 @@ gbfprintf(ofd, "%s<pdop>%f</pdop>\n", indent, waypointp->pdop); } #else - if (fix) writer.writeTextElement("fix", fix); + if (fix) { + writer.writeTextElement("fix", fix); + } if (waypointp->sat > 0) { writer.writeTextElement("sat", QString::number(waypointp->sat)); } @@ -1784,6 +1787,12 @@ static void gpx_write_common_extensions(const waypoint* waypointp, const char* indent) { + // FIXME: gpxx:Temperature must be a child of gpxx:WaypointExtension or gpxx:TrackPointExtension. + // FIXME: gpxx:Depth must be a child of gpxx:WaypointExtension or gpxx:TrackPointExtension. + // FIXME: Although not required it seems gpxx:WaypointExtension should only be used as a child of gpx:wpt + // FIXME: Although not required it seems gpxx:RoutePointExtension should only be used as a child of gpx:rtept + // FIXME: Although not required it seems gpxx:TrackPointExtension should only be used as a child of gpx:trkpt + // FIXME: Although not required it seems gpxtpx:TrackPointExtension should only be used as a child of gpx:trkpt if (((opt_humminbirdext || opt_garminext) && (waypointp->depth != 0 || waypointp->temperature != 0)) || (opt_garminext && (waypointp->heartrate != 0 || waypointp->cadence != 0))) { #if OLDGPX @@ -1901,18 +1910,21 @@ gpx_write_common_description(waypointp, " ", oname); gpx_write_common_acc(waypointp, " "); - fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); - gmsd = GMSD_FIND(waypointp); - if (fs_gpx) { - if (! gmsd) { - fprint_xml_chain(fs_gpx->tag, waypointp); + if (!(opt_humminbirdext || opt_garminext)) { + fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); + gmsd = GMSD_FIND(waypointp); + if (fs_gpx) { + if (! gmsd) { + fprint_xml_chain(fs_gpx->tag, waypointp); + } } + if (gmsd && (gpx_wversion_num > 10)) { + /* MapSource doesn't accepts extensions from 1.0 */ + garmin_fs_xml_fprint(ofd, waypointp, writer); + } + } else { + gpx_write_common_extensions(waypointp, " "); } - if (gmsd && (gpx_wversion_num > 10)) { - /* MapSource doesn't accepts extensions from 1.0 */ - garmin_fs_xml_fprint(ofd, waypointp, writer); - } - gpx_write_common_extensions(waypointp, " "); #if OLDGPX gbfprintf(ofd, "</wpt>\n"); #else @@ -1980,7 +1992,7 @@ writer.writeStartElement("trkpt"); writer.writeAttribute("lat", QString::number(waypointp->latitude, 'f', 9)); writer.writeAttribute("lon", QString::number(waypointp->longitude, 'f', 9)); - // FIXME: this is technically not needed. + // FIXME: this is technically not needed. // Our Pre-Qt XML writer would write // <trkpt lat=X lon=Y> // </trkpt> @@ -2023,12 +2035,14 @@ NULL : oname); gpx_write_common_acc(waypointp, " "); - fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); - if (fs_gpx) { - fprint_xml_chain(fs_gpx->tag, waypointp); + if (!(opt_humminbirdext || opt_garminext)) { + fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); + if (fs_gpx) { + fprint_xml_chain(fs_gpx->tag, waypointp); + } + } else { + gpx_write_common_extensions(waypointp, " "); } - - gpx_write_common_extensions(waypointp, " "); #if OLDGPX gbfprintf(ofd, "</trkpt>\n"); #else @@ -2118,12 +2132,14 @@ gpx_write_common_description(waypointp, " ", oname); gpx_write_common_acc(waypointp, " "); - fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); - if (fs_gpx) { - fprint_xml_chain(fs_gpx->tag, waypointp); + if (!(opt_humminbirdext || opt_garminext)) { + fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); + if (fs_gpx) { + fprint_xml_chain(fs_gpx->tag, waypointp); + } + } else { + gpx_write_common_extensions(waypointp, " "); } - - gpx_write_common_extensions(waypointp, " "); #if OLDGPX gbfprintf(ofd, " </rtept>\n"); #else @@ -2138,7 +2154,7 @@ gbfprintf(ofd, "</rte>\n"); #else // FIXME This is to force empty tracks to not be self-closing. This is - // lame, but it's for compatibilty with our old writer to minimize thrash + // lame, but it's for compatibility with our old writer to minimize thrash // on the Qt transition. writer.writeCharacters("\n"); writer.writeEndElement(); // Close rte tag. @@ -2195,9 +2211,9 @@ if (! gpx_wversion) { if (! gpx_version) { - gpx_wversion = (char *)"1.0"; + gpx_wversion = (char*)"1.0"; } else { - gpx_wversion = (char *)gpx_version; + gpx_wversion = (char*)gpx_version; } } @@ -2220,7 +2236,7 @@ #else // FIXME: This write of a blank line is needed for Qt 4.6 (as on Centos 6.3) // to include just enough whitespace between <xml/> and <gpx...> to pass - // diff -w. It's here for now to shim compatibility with our zillion + // diff -w. It's here for now to shim compatibility with our zillion // reference files, but this blank link can go away some day. writer.writeCharacters("\n"); @@ -2231,6 +2247,8 @@ writer.writeAttribute("\n xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); #endif + // FIXME: If we pass elements from an optional declared namespace, e.g. gpxx, gpxtpx, or h through with fprint_xml_chain, we won't have declared the namespace. + // This is a schema violation. if (opt_humminbirdext) { #if OLDGPX gbfprintf(ofd, " xmlns:h=\"http://humminbird.com\"\n"); @@ -2265,8 +2283,8 @@ gpx_wversion[0], gpx_wversion[2], gpx_wversion[0], gpx_wversion[2]); #else - writer.writeAttribute("\n xsi:schemaLocation", - QString("http://www.topografix.com/GPX/%1/%2 http://www.topografix.com/GPX/%1/%2/gpx.xsd").arg(gpx_wversion[0]).arg(gpx_wversion[2])); + writer.writeAttribute("\n xsi:schemaLocation", + QString("http://www.topografix.com/GPX/%1/%2 http://www.topografix.com/GPX/%1/%2/gpx.xsd").arg(gpx_wversion[0]).arg(gpx_wversion[2])); #endif } Index: reference/track/gpx_garmin_extensions.gpx =================================================================== --- reference/track/gpx_garmin_extensions.gpx (revision 4338) +++ reference/track/gpx_garmin_extensions.gpx (working copy) @@ -17,12 +17,6 @@ <name>LAP001</name> <cmt>LAP001</cmt> <desc>LAP001</desc> - <extensions> - <gpxtpx:TrackPointExtension> - <gpxtpx:hr>111</gpxtpx:hr> - <gpxtpx:cad>151</gpxtpx:cad> - </gpxtpx:TrackPointExtension> - </extensions> </wpt> <trk> <name>2008-08-20T07:04:47Z</name> Index: testo.d/gpx.test =================================================================== --- testo.d/gpx.test (revision 4338) +++ testo.d/gpx.test (working copy) @@ -8,3 +8,8 @@ rm -f ${TMPDIR}/gtrnctr_power.gpx gpsbabel -i gtrnctr -f ${REFERENCE}/track/gtrnctr_power.tcx -o gpx,garminextensions=1 -F ${TMPDIR}/gtrnctr_power.gpx compare ${REFERENCE}/track/gtrnctr_power.gpx ${TMPDIR}/gtrnctr_power.gpx + +rm -f ${TMPDIR}/tpx-sample.gpx +gpsbabel -i gpx -f ${REFERENCE}/track/gpx_garmin_extensions.gpx -o gpx,garminextensions -F ${TMPDIR}/tpx-sample.gpx +compare ${REFERENCE}/track/gpx_garmin_extensions.gpx ${TMPDIR}/tpx-sample.gpx + |