[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [marble] src/plugins/runner/gpx: implement parsing heartrate data
From: Niko Sams <niko.sams () gmail ! com>
Date: 2011-12-31 15:16:59
Message-ID: 20111231151659.3441E580B5 () git ! kde ! org
[Download RAW message or body]
Git commit b91d867e282a1d793178de7c70dfd54ad4f91da0 by Niko Sams.
Committed on 20/11/2011 at 13:34.
Pushed by nsams into branch 'master'.
implement parsing heartrate data from gpx files recorded using garmin device
M +3 -0 src/plugins/runner/gpx/CMakeLists.txt
M +2 -1 src/plugins/runner/gpx/GpxParser.cpp
M +5 -0 src/plugins/runner/gpx/handlers/GPXElementDictionary.cpp
M +6 -0 src/plugins/runner/gpx/handlers/GPXElementDictionary.h
A +58 -0 src/plugins/runner/gpx/handlers/GPXTrackPointExtensionTagHandler.cpp \
[License: LGPL (v2.1+)] A +39 -0 \
src/plugins/runner/gpx/handlers/GPXTrackPointExtensionTagHandler.h [License: LGPL \
(v2.1+)] A +58 -0 src/plugins/runner/gpx/handlers/GPXextensionsTagHandler.cpp \
[License: LGPL (v2.1+)] A +39 -0 \
src/plugins/runner/gpx/handlers/GPXextensionsTagHandler.h [License: LGPL (v2.1+)] \
A +60 -0 src/plugins/runner/gpx/handlers/GPXhrTagHandler.cpp [License: LGPL \
(v2.1+)] A +39 -0 src/plugins/runner/gpx/handlers/GPXhrTagHandler.h \
[License: LGPL (v2.1+)] M +96 -0 src/plugins/runner/gpx/tests/TestTrack.cpp
http://commits.kde.org/marble/b91d867e282a1d793178de7c70dfd54ad4f91da0
diff --git a/src/plugins/runner/gpx/CMakeLists.txt \
b/src/plugins/runner/gpx/CMakeLists.txt index cd444c1..257e0f8 100644
--- a/src/plugins/runner/gpx/CMakeLists.txt
+++ b/src/plugins/runner/gpx/CMakeLists.txt
@@ -20,6 +20,9 @@ set( gpx_handlers_SRCS
handlers/GPXwptTagHandler.cpp
handlers/GPXtimeTagHandler.cpp
handlers/GPXeleTagHandler.cpp
+ handlers/GPXextensionsTagHandler.cpp
+ handlers/GPXTrackPointExtensionTagHandler.cpp
+ handlers/GPXhrTagHandler.cpp
)
set( gpx_SRCS GpxParser.cpp GpxPlugin.cpp GpxRunner.cpp )
diff --git a/src/plugins/runner/gpx/GpxParser.cpp \
b/src/plugins/runner/gpx/GpxParser.cpp index 61a749f..d1a32c2 100644
--- a/src/plugins/runner/gpx/GpxParser.cpp
+++ b/src/plugins/runner/gpx/GpxParser.cpp
@@ -33,7 +33,8 @@ bool GpxParser::isValidElement(const QString& tagName) const
return false;
return ( namespaceUri() == gpx::gpxTag_nameSpace10
- || namespaceUri() == gpx::gpxTag_nameSpace11);
+ || namespaceUri() == gpx::gpxTag_nameSpace11
+ || namespaceUri() == gpx::gpxTag_nameSpaceGarminTrackPointExt1);
}
GeoDocument* GpxParser::createDocument() const
diff --git a/src/plugins/runner/gpx/handlers/GPXElementDictionary.cpp \
b/src/plugins/runner/gpx/handlers/GPXElementDictionary.cpp index 13c30a3..82cc119 \
100644
--- a/src/plugins/runner/gpx/handlers/GPXElementDictionary.cpp
+++ b/src/plugins/runner/gpx/handlers/GPXElementDictionary.cpp
@@ -32,6 +32,7 @@ const char* gpxTag_nameSpace10 = \
"http://www.topografix.com/GPX/1/0"; const char* gpxTag_nameSpace11 = \
"http://www.topografix.com/GPX/1/1";
const char* gpxTag_ele = "ele";
+const char* gpxTag_extensions = "extensions";
const char* gpxTag_gpx = "gpx";
const char* gpxTag_lat = "lat";
const char* gpxTag_lon = "lon";
@@ -42,5 +43,9 @@ const char* gpxTag_trkpt = "trkpt";
const char* gpxTag_trkseg = "trkseg";
const char* gpxTag_wpt = "wpt";
+const char* gpxTag_nameSpaceGarminTrackPointExt1 = \
"http://www.garmin.com/xmlschemas/TrackPointExtension/v1"; +const char* \
gpxTag_TrackPointExtension = "TrackPointExtension"; +const char* gpxTag_hr = "hr";
+
}
}
diff --git a/src/plugins/runner/gpx/handlers/GPXElementDictionary.h \
b/src/plugins/runner/gpx/handlers/GPXElementDictionary.h index 29e6a8e..d0dd0d7 \
100644
--- a/src/plugins/runner/gpx/handlers/GPXElementDictionary.h
+++ b/src/plugins/runner/gpx/handlers/GPXElementDictionary.h
@@ -33,6 +33,7 @@ namespace gpx
extern const char* gpxTag_nameSpace11;
extern const char* gpxTag_ele;
+ extern const char* gpxTag_extensions;
extern const char* gpxTag_gpx;
extern const char* gpxTag_lat;
extern const char* gpxTag_lon;
@@ -43,11 +44,16 @@ namespace gpx
extern const char* gpxTag_trkseg;
extern const char* gpxTag_wpt;
// TODO: add all remaining tags!
+
+ extern const char* gpxTag_nameSpaceGarminTrackPointExt1;
+ extern const char* gpxTag_TrackPointExtension;
+ extern const char* gpxTag_hr;
}
// Helper macros
#define GPX_DEFINE_TAG_HANDLER_10(Name) GEODATA_DEFINE_TAG_HANDLER(gpx, GPX, Name, \
gpxTag_nameSpace10) #define GPX_DEFINE_TAG_HANDLER_11(Name) \
GEODATA_DEFINE_TAG_HANDLER(gpx, GPX, Name, gpxTag_nameSpace11) +#define \
GPX_DEFINE_TAG_HANDLER_GARMIN_TRACKPOINTEXT1(Name) GEODATA_DEFINE_TAG_HANDLER(gpx, \
GPX, Name, gpxTag_nameSpaceGarminTrackPointExt1)
#define GPX_DEFINE_TAG_HANDLER(Name) \
GPX_DEFINE_TAG_HANDLER_10(Name) \
diff --git a/src/plugins/runner/gpx/handlers/GPXTrackPointExtensionTagHandler.cpp \
b/src/plugins/runner/gpx/handlers/GPXTrackPointExtensionTagHandler.cpp new file mode \
100644 index 0000000..9095715
--- /dev/null
+++ b/src/plugins/runner/gpx/handlers/GPXTrackPointExtensionTagHandler.cpp
@@ -0,0 +1,58 @@
+/*
+ This file is part of the Marble Virtual Globe.
+
+ This library is free software you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 Niko Sams <niko.sams@gmail.com>
+*/
+
+#include "GPXTrackPointExtensionTagHandler.h"
+
+#include "MarbleDebug.h"
+
+#include "GPXElementDictionary.h"
+#include "GeoParser.h"
+#include "GeoDataDocument.h"
+#include "GeoDataPlacemark.h"
+#include "GeoDataPoint.h"
+#include "GeoDataTrack.h"
+#include "GeoDataExtendedData.h"
+
+namespace Marble
+{
+namespace gpx
+{
+GPX_DEFINE_TAG_HANDLER_GARMIN_TRACKPOINTEXT1(TrackPointExtension)
+
+GeoNode* GPXTrackPointExtensionTagHandler::parse( GeoParser& parser ) const
+{
+ Q_ASSERT( parser.isStartElement() && parser.isValidElement( \
gpxTag_TrackPointExtension ) ); + GeoStackItem parentItem = \
parser.parentElement(); +
+ if ( parentItem.is<GeoDataTrack>() )
+ {
+ GeoDataTrack* track = parentItem.nodeAs<GeoDataTrack>();
+#ifdef DEBUG_TAGS
+ mDebug() << "Parsed <" << gpxTag_TrackPointExtension << ">";
+#endif
+ return track;
+ }
+
+ mDebug() << "TrackPointExtension parsing with parentitem" << \
parentItem.qualifiedName(); + return 0;
+}
+
+} // namespace gpx
+
+} // namespace Marble
diff --git a/src/plugins/runner/gpx/handlers/GPXTrackPointExtensionTagHandler.h \
b/src/plugins/runner/gpx/handlers/GPXTrackPointExtensionTagHandler.h new file mode \
100644 index 0000000..e3779de
--- /dev/null
+++ b/src/plugins/runner/gpx/handlers/GPXTrackPointExtensionTagHandler.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of the Marble Virtual Globe.
+
+ This library is free software you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 Niko Sams <niko.sams@gmail.com>
+*/
+
+#ifndef MARBLE_GPX_TRACKPOINTEXTENSIONTAGHANDLER_H
+#define MARBLE_GPX_TRACKPOINTEXTENSIONTAGHANDLER_H
+
+#include "GeoTagHandler.h"
+
+namespace Marble
+{
+namespace gpx
+{
+
+class GPXTrackPointExtensionTagHandler : public GeoTagHandler
+{
+public:
+ virtual GeoNode* parse(GeoParser&) const;
+};
+
+}
+}
+
+#endif
diff --git a/src/plugins/runner/gpx/handlers/GPXextensionsTagHandler.cpp \
b/src/plugins/runner/gpx/handlers/GPXextensionsTagHandler.cpp new file mode 100644
index 0000000..527bd8e
--- /dev/null
+++ b/src/plugins/runner/gpx/handlers/GPXextensionsTagHandler.cpp
@@ -0,0 +1,58 @@
+/*
+ This file is part of the Marble Virtual Globe.
+
+ This library is free software you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 Niko Sams <niko.sams@gmail.com>
+*/
+
+#include "GPXextensionsTagHandler.h"
+
+#include "MarbleDebug.h"
+
+#include "GPXElementDictionary.h"
+#include "GeoParser.h"
+#include "GeoDataDocument.h"
+#include "GeoDataPlacemark.h"
+#include "GeoDataPoint.h"
+#include "GeoDataTrack.h"
+#include "GeoDataExtendedData.h"
+
+namespace Marble
+{
+namespace gpx
+{
+GPX_DEFINE_TAG_HANDLER(extensions)
+
+GeoNode* GPXextensionsTagHandler::parse( GeoParser& parser ) const
+{
+ Q_ASSERT( parser.isStartElement() && parser.isValidElement( gpxTag_extensions ) \
); + GeoStackItem parentItem = parser.parentElement();
+
+ if ( parentItem.represents( gpxTag_trkpt ) )
+ {
+ GeoDataTrack* track = parentItem.nodeAs<GeoDataTrack>();
+#ifdef DEBUG_TAGS
+ mDebug() << "Parsed <" << gpxTag_extensions << ">";
+#endif
+ return track;
+ }
+
+ mDebug() << "extensions parsing with parentitem" << parentItem.qualifiedName();
+ return 0;
+}
+
+} // namespace gpx
+
+} // namespace Marble
diff --git a/src/plugins/runner/gpx/handlers/GPXextensionsTagHandler.h \
b/src/plugins/runner/gpx/handlers/GPXextensionsTagHandler.h new file mode 100644
index 0000000..e04a336
--- /dev/null
+++ b/src/plugins/runner/gpx/handlers/GPXextensionsTagHandler.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of the Marble Virtual Globe.
+
+ This library is free software you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 Niko Sams <niko.sams@gmail.com>
+*/
+
+#ifndef MARBLE_GPX_EXTENSIONSTAGHANDLER_H
+#define MARBLE_GPX_TRACKPOINTEXTENSIONTAGHANDLER_H
+
+#include "GeoTagHandler.h"
+
+namespace Marble
+{
+namespace gpx
+{
+
+class GPXextensionsTagHandler : public GeoTagHandler
+{
+public:
+ virtual GeoNode* parse(GeoParser&) const;
+};
+
+}
+}
+
+#endif
diff --git a/src/plugins/runner/gpx/handlers/GPXhrTagHandler.cpp \
b/src/plugins/runner/gpx/handlers/GPXhrTagHandler.cpp new file mode 100644
index 0000000..c3b2020
--- /dev/null
+++ b/src/plugins/runner/gpx/handlers/GPXhrTagHandler.cpp
@@ -0,0 +1,60 @@
+/*
+ This file is part of the Marble Virtual Globe.
+
+ This library is free software you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 Niko Sams <niko.sams@gmail.com>
+*/
+
+#include "GPXhrTagHandler.h"
+
+#include "MarbleDebug.h"
+
+#include "GPXElementDictionary.h"
+#include "GeoParser.h"
+#include "GeoDataDocument.h"
+#include "GeoDataExtendedData.h"
+#include "GeoDataTrack.h"
+#include "GeoDataSimpleArrayData.h"
+
+namespace Marble
+{
+namespace gpx
+{
+GPX_DEFINE_TAG_HANDLER_GARMIN_TRACKPOINTEXT1(hr)
+
+GeoNode* GPXhrTagHandler::parse(GeoParser& parser) const
+{
+ Q_ASSERT( parser.isStartElement() && parser.isValidElement( gpxTag_hr ) );
+ GeoStackItem parentItem = parser.parentElement();
+
+ if ( parentItem.is<GeoDataTrack>() )
+ {
+ GeoDataSimpleArrayData* arrayData = &parentItem.nodeAs<GeoDataTrack>()
+ ->extendedData().simpleArrayData( "heartrate" );
+ QVariant value( parser.readElementText().toInt() );
+ arrayData->append( value );
+#ifdef DEBUG_TAGS
+ mDebug() << "Parsed <" << gpxTag_hr << "> value" << value;
+#endif
+ return 0;
+ }
+
+ mDebug() << "hr parsing with parentitem" << parentItem.qualifiedName();
+ return 0;
+}
+
+} // namespace gpx
+
+} // namespace Marble
diff --git a/src/plugins/runner/gpx/handlers/GPXhrTagHandler.h \
b/src/plugins/runner/gpx/handlers/GPXhrTagHandler.h new file mode 100644
index 0000000..c08edbc
--- /dev/null
+++ b/src/plugins/runner/gpx/handlers/GPXhrTagHandler.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of the Marble Virtual Globe.
+
+ This library is free software you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2011 Niko Sams <niko.sams@gmail.com>
+*/
+
+#ifndef MARBLE_GPX_HRTAGHANDLER_H
+#define MARBLE_GPX_HRTAGHANDLER_H
+
+#include "GeoTagHandler.h"
+
+namespace Marble
+{
+namespace gpx
+{
+
+class GPXhrTagHandler : public GeoTagHandler
+{
+public:
+ virtual GeoNode* parse(GeoParser&) const;
+};
+
+}
+}
+
+#endif
diff --git a/src/plugins/runner/gpx/tests/TestTrack.cpp \
b/src/plugins/runner/gpx/tests/TestTrack.cpp index 5ad7f29..10ed4cd 100644
--- a/src/plugins/runner/gpx/tests/TestTrack.cpp
+++ b/src/plugins/runner/gpx/tests/TestTrack.cpp
@@ -33,6 +33,7 @@ private slots:
void initTestCase();
void simpleParseTest();
void withoutTimeTest();
+ void extendedDataHeartRateTest();
};
@@ -189,6 +190,101 @@ void TestTrack::withoutTimeTest()
delete document;
}
+
+void TestTrack::extendedDataHeartRateTest()
+{
+ //example track recorded using a Garmin Oregon 450 and downloading using it's \
USB mass storare mode + QString content(
+"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
+"<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" "
+" xmlns:gpxx=\"http://www.garmin.com/xmlschemas/WaypointExtension/v1\" "
+" xmlns:gpxtrx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\" "
+" xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\" "
+" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+" creator=\"Oregon 450\" "
+" version=\"1.1\" "
+" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 "
+ "http://www.topografix.com/GPX/1/1/gpx.xsd "
+ "http://www.garmin.com/xmlschemas/WaypointExtension/v1 "
+ "http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd \
" + "http://www.garmin.com/xmlschemas/TrackPointExtension/v1 \
" + \
"http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd\" " +" >"
+" <metadata>"
+" <link href=\"http://www.garmin.com\">"
+" <text>Garmin International</text>"
+" </link>"
+" <time>2011-10-29T15:29:19Z</time>"
+" </metadata>"
+" <trk>"
+" <name>29-OKT-11 17:29:17</name>"
+" <extensions>"
+" <gpxtrx:TrackExtension>"
+" <gpxtrx:DisplayColor>Black</gpxtrx:DisplayColor>"
+" </gpxtrx:TrackExtension>"
+" </extensions>"
+" <trkseg>"
+" <trkpt lat=\"47.951347\" lon=\"13.228035\">"
+" <ele>571.16</ele>"
+" <time>2011-10-29T08:35:31Z</time>"
+" <extensions>"
+" <gpxtpx:TrackPointExtension>"
+" <gpxtpx:hr>108</gpxtpx:hr>"
+" </gpxtpx:TrackPointExtension>"
+" </extensions>"
+" </trkpt>"
+" <trkpt lat=\"47.951348\" lon=\"13.228035\">"
+" <ele>573.56</ele>"
+" <time>2011-10-29T08:35:37Z</time>"
+" <extensions>"
+" <gpxtpx:TrackPointExtension>"
+" <gpxtpx:hr>109</gpxtpx:hr>"
+" </gpxtpx:TrackPointExtension>"
+" </extensions>"
+" </trkpt>"
+" <trkpt lat=\"47.951349\" lon=\"13.228036\">"
+" <ele>572.12</ele>"
+" <time>2011-10-29T08:35:43Z</time>"
+" <extensions>"
+" <gpxtpx:TrackPointExtension>"
+" <gpxtpx:hr>110</gpxtpx:hr>"
+" </gpxtpx:TrackPointExtension>"
+" </extensions>"
+" </trkpt>"
+" </trkseg>"
+" </trk>"
+"</gpx>"
+);
+
+ GpxParser parser;
+
+ QByteArray array( content.toUtf8() );
+ QBuffer buffer( &array );
+ buffer.open( QIODevice::ReadOnly );
+ qDebug() << "Buffer content:" << endl << buffer.buffer();
+ if ( !parser.read( &buffer ) ) {
+ QFAIL( "Could not parse data!" );
+ return;
+ }
+ GeoDocument* document = parser.releaseDocument();
+ QVERIFY( document );
+ GeoDataDocument *dataDocument = static_cast<GeoDataDocument*>( document );
+ GeoDataPlacemark* placemark = dataDocument->placemarkList().at( 0 );
+ QCOMPARE( placemark->geometry()->geometryId(), GeoDataMultiGeometryId );
+ GeoDataMultiGeometry* multiGeo = static_cast<GeoDataMultiGeometry*>( \
placemark->geometry() ); + GeoDataTrack* track = static_cast<GeoDataTrack*>( \
&multiGeo->at( 0 ) ); + QCOMPARE( track->size(), 3 );
+
+ {
+ GeoDataSimpleArrayData hr = track->extendedData().simpleArrayData( \
"heartrate" ); + QCOMPARE( hr.size(), 3 );
+ QCOMPARE( hr.valueAt( 0 ), QVariant( "108" ) );
+ QCOMPARE( hr.valueAt( 2 ), QVariant( "110" ) );
+ }
+
+ delete document;
+}
+
QTEST_MAIN( TestTrack )
#include "TestTrack.moc"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic