mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Added basic support for Suunto SML files
This commit is contained in:
parent
d8b54ac342
commit
a89ef11d73
@ -188,7 +188,8 @@ HEADERS += src/common/config.h \
|
|||||||
src/data/csv.h \
|
src/data/csv.h \
|
||||||
src/data/cupparser.h \
|
src/data/cupparser.h \
|
||||||
src/data/gpiparser.h \
|
src/data/gpiparser.h \
|
||||||
src/data/address.h
|
src/data/address.h \
|
||||||
|
src/data/smlparser.h
|
||||||
SOURCES += src/main.cpp \
|
SOURCES += src/main.cpp \
|
||||||
src/GUI/popup.cpp \
|
src/GUI/popup.cpp \
|
||||||
src/common/coordinates.cpp \
|
src/common/coordinates.cpp \
|
||||||
@ -324,7 +325,8 @@ SOURCES += src/main.cpp \
|
|||||||
src/data/csv.cpp \
|
src/data/csv.cpp \
|
||||||
src/data/cupparser.cpp \
|
src/data/cupparser.cpp \
|
||||||
src/GUI/graphicsscene.cpp \
|
src/GUI/graphicsscene.cpp \
|
||||||
src/data/gpiparser.cpp
|
src/data/gpiparser.cpp \
|
||||||
|
src/data/smlparser.cpp
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||||
HEADERS += src/data/geojsonparser.h
|
HEADERS += src/data/geojsonparser.h
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "exifparser.h"
|
#include "exifparser.h"
|
||||||
#include "cupparser.h"
|
#include "cupparser.h"
|
||||||
#include "gpiparser.h"
|
#include "gpiparser.h"
|
||||||
|
#include "smlparser.h"
|
||||||
#include "dem.h"
|
#include "dem.h"
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ static GeoJSONParser geojson;
|
|||||||
static EXIFParser exif;
|
static EXIFParser exif;
|
||||||
static CUPParser cup;
|
static CUPParser cup;
|
||||||
static GPIParser gpi;
|
static GPIParser gpi;
|
||||||
|
static SMLParser sml;
|
||||||
|
|
||||||
static QHash<QString, Parser*> parsers()
|
static QHash<QString, Parser*> parsers()
|
||||||
{
|
{
|
||||||
@ -66,6 +68,7 @@ static QHash<QString, Parser*> parsers()
|
|||||||
hash.insert("jpg", &exif);
|
hash.insert("jpg", &exif);
|
||||||
hash.insert("cup", &cup);
|
hash.insert("cup", &cup);
|
||||||
hash.insert("gpi", &gpi);
|
hash.insert("gpi", &gpi);
|
||||||
|
hash.insert("sml", &sml);
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
@ -189,6 +192,7 @@ QString Data::formats()
|
|||||||
+ qApp->translate("Data", "NMEA files") + " (*.nmea);;"
|
+ qApp->translate("Data", "NMEA files") + " (*.nmea);;"
|
||||||
+ qApp->translate("Data", "OziExplorer files") + " (*.plt *.rte *.wpt);;"
|
+ qApp->translate("Data", "OziExplorer files") + " (*.plt *.rte *.wpt);;"
|
||||||
+ qApp->translate("Data", "SLF files") + " (*.slf);;"
|
+ qApp->translate("Data", "SLF files") + " (*.slf);;"
|
||||||
|
+ qApp->translate("Data", "SML files") + " (*.sml);;"
|
||||||
+ qApp->translate("Data", "TCX files") + " (*.tcx);;"
|
+ qApp->translate("Data", "TCX files") + " (*.tcx);;"
|
||||||
+ qApp->translate("Data", "All files") + " (*)";
|
+ qApp->translate("Data", "All files") + " (*)";
|
||||||
}
|
}
|
||||||
|
100
src/data/smlparser.cpp
Normal file
100
src/data/smlparser.cpp
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
#include "smlparser.h"
|
||||||
|
|
||||||
|
|
||||||
|
void SMLParser::sample(SegmentData &segment)
|
||||||
|
{
|
||||||
|
QDateTime timestamp;
|
||||||
|
qreal lat = NAN, lon = NAN, altitude = NAN;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
while (_reader.readNextStartElement()) {
|
||||||
|
if (_reader.name() == QLatin1String("Latitude")) {
|
||||||
|
lat = _reader.readElementText().toDouble(&ok);
|
||||||
|
if (!ok || lat < -90 || lon > 90) {
|
||||||
|
_reader.raiseError("Invalid Latitude");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (_reader.name() == QLatin1String("Longitude")) {
|
||||||
|
lon = _reader.readElementText().toDouble(&ok);
|
||||||
|
if (!ok || lat < -180 || lon > 180) {
|
||||||
|
_reader.raiseError("Invalid Longitude");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (_reader.name() == QLatin1String("UTC")) {
|
||||||
|
timestamp = QDateTime::fromString(_reader.readElementText(),
|
||||||
|
Qt::ISODate);
|
||||||
|
if (!timestamp.isValid()) {
|
||||||
|
_reader.raiseError("Invalid timestamp");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (_reader.name() == QLatin1String("GPSAltitude")) {
|
||||||
|
altitude = _reader.readElementText().toDouble(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
_reader.raiseError("Invalid GPS altitude");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
_reader.skipCurrentElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
Trackpoint t(Coordinates((lon * 180) / M_PI, (lat * 180) / M_PI));
|
||||||
|
if (!t.coordinates().isValid())
|
||||||
|
return;
|
||||||
|
t.setTimestamp(timestamp);
|
||||||
|
t.setElevation(altitude);
|
||||||
|
|
||||||
|
segment.append(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SMLParser::samples(SegmentData &segment)
|
||||||
|
{
|
||||||
|
while (_reader.readNextStartElement()) {
|
||||||
|
if (_reader.name() == QLatin1String("Sample")) {
|
||||||
|
sample(segment);
|
||||||
|
} else
|
||||||
|
_reader.skipCurrentElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SMLParser::deviceLog(TrackData &track)
|
||||||
|
{
|
||||||
|
while (_reader.readNextStartElement()) {
|
||||||
|
if (_reader.name() == QLatin1String("Samples")) {
|
||||||
|
track.append(SegmentData());
|
||||||
|
samples(track.last());
|
||||||
|
} else
|
||||||
|
_reader.skipCurrentElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SMLParser::sml(QList<TrackData> &tracks)
|
||||||
|
{
|
||||||
|
while (_reader.readNextStartElement()) {
|
||||||
|
if (_reader.name() == QLatin1String("DeviceLog")) {
|
||||||
|
tracks.append(TrackData());
|
||||||
|
deviceLog(tracks.last());
|
||||||
|
} else
|
||||||
|
_reader.skipCurrentElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SMLParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||||
|
QList<RouteData> &routes, QList<Area> &polygons,
|
||||||
|
QVector<Waypoint> &waypoints)
|
||||||
|
{
|
||||||
|
Q_UNUSED(routes);
|
||||||
|
Q_UNUSED(polygons);
|
||||||
|
Q_UNUSED(waypoints);
|
||||||
|
|
||||||
|
_reader.clear();
|
||||||
|
_reader.setDevice(file);
|
||||||
|
|
||||||
|
if (_reader.readNextStartElement()) {
|
||||||
|
if (_reader.name() == QLatin1String("sml"))
|
||||||
|
sml(tracks);
|
||||||
|
else
|
||||||
|
_reader.raiseError("Not a SML file");
|
||||||
|
}
|
||||||
|
|
||||||
|
return !_reader.error();
|
||||||
|
}
|
25
src/data/smlparser.h
Normal file
25
src/data/smlparser.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef SMLPARSER_H
|
||||||
|
#define SMLPARSER_H
|
||||||
|
|
||||||
|
#include <QXmlStreamReader>
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
|
||||||
|
class SMLParser : public Parser
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool parse(QFile *file, QList<TrackData> &tracks, QList<RouteData> &routes,
|
||||||
|
QList<Area> &polygons, QVector<Waypoint> &waypoints);
|
||||||
|
QString errorString() const {return _reader.errorString();}
|
||||||
|
int errorLine() const {return _reader.lineNumber();}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void sml(QList<TrackData> &tracks);
|
||||||
|
void deviceLog(TrackData &track);
|
||||||
|
void samples(SegmentData &segment);
|
||||||
|
void sample(SegmentData &segment);
|
||||||
|
|
||||||
|
QXmlStreamReader _reader;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SMLPARSER_H
|
Loading…
Reference in New Issue
Block a user