From d31bf80885270160ad17773becb946a9e446d751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 15 Apr 2018 10:08:50 +0200 Subject: [PATCH] Merget the OziExplorer parsers to a single source file --- gpxsee.pro | 9 +- src/data/data.cpp | 4 +- src/data/date.h | 14 --- src/data/oziparsers.cpp | 273 ++++++++++++++++++++++++++++++++++++++++ src/data/oziparsers.h | 51 ++++++++ src/data/pltparser.cpp | 89 ------------- src/data/pltparser.h | 21 ---- src/data/rteparser.cpp | 99 --------------- src/data/rteparser.h | 21 ---- src/data/wptparser.cpp | 90 ------------- src/data/wptparser.h | 21 ---- 11 files changed, 327 insertions(+), 365 deletions(-) delete mode 100644 src/data/date.h create mode 100644 src/data/oziparsers.cpp create mode 100644 src/data/oziparsers.h delete mode 100644 src/data/pltparser.cpp delete mode 100644 src/data/pltparser.h delete mode 100644 src/data/rteparser.cpp delete mode 100644 src/data/rteparser.h delete mode 100644 src/data/wptparser.cpp delete mode 100644 src/data/wptparser.h diff --git a/gpxsee.pro b/gpxsee.pro index b3f9030c..96cc0183 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -124,10 +124,7 @@ HEADERS += src/config.h \ src/map/wms.h \ src/map/crs.h \ src/map/coordinatesystem.h \ - src/data/pltparser.h \ - src/data/date.h \ - src/data/wptparser.h \ - src/data/rteparser.h + src/data/oziparsers.h SOURCES += src/main.cpp \ src/common/coordinates.cpp \ src/common/rectc.cpp \ @@ -221,9 +218,7 @@ SOURCES += src/main.cpp \ src/map/wms.cpp \ src/map/crs.cpp \ src/map/coordinatesystem.cpp \ - src/data/pltparser.cpp \ - src/data/wptparser.cpp \ - src/data/rteparser.cpp + src/data/oziparsers.cpp RESOURCES += gpxsee.qrc TRANSLATIONS = lang/gpxsee_cs.ts \ lang/gpxsee_sv.ts \ diff --git a/src/data/data.cpp b/src/data/data.cpp index 6a7be5e9..dd374b6a 100644 --- a/src/data/data.cpp +++ b/src/data/data.cpp @@ -8,9 +8,7 @@ #include "fitparser.h" #include "igcparser.h" #include "nmeaparser.h" -#include "pltparser.h" -#include "wptparser.h" -#include "rteparser.h" +#include "oziparsers.h" #include "data.h" diff --git a/src/data/date.h b/src/data/date.h deleted file mode 100644 index 971244b3..00000000 --- a/src/data/date.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef DATE_H -#define DATE_H - -#include - -namespace Date -{ - inline qint64 delphi2unixMS(double date) - { - return (qint64)((date - 25569.0) * 86400000); - } -} - -#endif // DATE_H diff --git a/src/data/oziparsers.cpp b/src/data/oziparsers.cpp new file mode 100644 index 00000000..cca2f734 --- /dev/null +++ b/src/data/oziparsers.cpp @@ -0,0 +1,273 @@ +#include "map/gcs.h" +#include "oziparsers.h" + +static qint64 delphi2unixMS(double date) +{ + return (qint64)((date - 25569.0) * 86400000); +} + +bool PLTParser::parse(QFile *file, QList &tracks, + QList &routes, QList &waypoints) +{ + Q_UNUSED(waypoints); + Q_UNUSED(routes); + bool res; + const GCS *gcs = 0; + + _errorLine = 1; + _errorString.clear(); + + tracks.append(TrackData()); + TrackData &track = tracks.last(); + + while (!file->atEnd()) { + QByteArray line = file->readLine(); + + if (_errorLine == 1) { + if (!line.trimmed().startsWith("OziExplorer Track Point File")) { + _errorString = "Not a PLT file"; + return false; + } + } else if (_errorLine == 2) { + if (!(gcs = GCS::gcs(QString(line.trimmed())))) { + _errorString = "Invalid/unknown datum"; + return false; + } + } else if (_errorLine == 5) { + QList list = line.split(','); + if (list.size() >= 4) + track.setName(list.at(3)); + } else if (_errorLine > 6) { + QList list = line.split(','); + if (list.size() < 2) { + _errorString = "Parse error"; + return false; + } + + qreal lat = list.at(0).trimmed().toDouble(&res); + if (!res || (lat < -90.0 || lat > 90.0)) { + _errorString = "Invalid latitude"; + return false; + } + qreal lon = list.at(1).trimmed().toDouble(&res); + if (!res || (lon < -180.0 || lon > 180.0)) { + _errorString = "Invalid longitude"; + return false; + } + + Trackpoint tp(gcs->toWGS84(Coordinates(lon, lat))); + + if (list.size() >= 4) { + QByteArray field(list.at(3).trimmed()); + if (!field.isEmpty()) { + double elevation = field.toDouble(&res); + if (!res) { + _errorString = "Invalid elevation"; + return false; + } + if (elevation != -777) + tp.setElevation(elevation * 0.3048); + } + } + if (list.size() >= 5) { + QByteArray field(list.at(4).trimmed()); + if (!field.isEmpty()) { + double date = field.toDouble(&res); + if (!res) { + _errorString = "Invalid date"; + return false; + } + tp.setTimestamp(QDateTime::fromMSecsSinceEpoch( + delphi2unixMS(date))); + } + } + + track.append(tp); + } + + _errorLine++; + } + + return true; +} + +bool RTEParser::parse(QFile *file, QList &tracks, + QList &routes, QList &waypoints) +{ + Q_UNUSED(waypoints); + Q_UNUSED(tracks); + bool res, record = false; + const GCS *gcs = 0; + + _errorLine = 1; + _errorString.clear(); + + + while (!file->atEnd()) { + QByteArray line = file->readLine(); + + if (_errorLine == 1) { + if (!line.trimmed().startsWith("OziExplorer Route File")) { + _errorString = "Not a RTE file"; + return false; + } + } else if (_errorLine == 2) { + if (!(gcs = GCS::gcs(QString(line.trimmed())))) { + _errorString = "Invalid/unknown datum"; + return false; + } + } else if (_errorLine > 4) { + QList list = line.split(','); + if (list.size() < 2) { + _errorString = "Parse error"; + return false; + } + + if (list.at(0).trimmed() == "R") { + routes.append(RouteData()); + record = true; + + if (list.size() >= 3) + routes.last().setName(list.at(2).trimmed() + .replace('\xD1', ',')); + if (list.size() >= 4) + routes.last().setDescription(list.at(3).trimmed() + .replace('\xD1', ',')); + } else if (list.at(0).trimmed() == "W") { + if (!record || list.size() < 7) { + _errorString = "Parse error"; + return false; + } + + qreal lat = list.at(5).trimmed().toDouble(&res); + if (!res || (lat < -90.0 || lat > 90.0)) { + _errorString = "Invalid latitude"; + return false; + } + qreal lon = list.at(6).trimmed().toDouble(&res); + if (!res || (lon < -180.0 || lon > 180.0)) { + _errorString = "Invalid longitude"; + return false; + } + + Waypoint wp(gcs->toWGS84(Coordinates(lon, lat))); + + QString name(list.at(4).trimmed().replace('\xD1', ',')); + if (!name.isEmpty()) + wp.setName(name); + if (list.size() >= 8) { + QByteArray field(list.at(7).trimmed()); + if (!field.isEmpty()) { + double date = field.toDouble(&res); + if (!res) { + _errorString = "Invalid date"; + return false; + } + wp.setTimestamp(QDateTime::fromMSecsSinceEpoch( + delphi2unixMS(date))); + } + } + if (list.size() >= 14) { + QString desc(list.at(13).trimmed().replace('\xD1', ',')); + if (!desc.isEmpty()) + wp.setDescription(desc); + } + + routes.last().append(wp); + } else { + _errorString = "Parse error"; + return false; + } + } + + _errorLine++; + } + + return true; +} + +bool WPTParser::parse(QFile *file, QList &tracks, + QList &routes, QList &waypoints) +{ + Q_UNUSED(tracks); + Q_UNUSED(routes); + bool res; + const GCS *gcs = 0; + + _errorLine = 1; + _errorString.clear(); + + while (!file->atEnd()) { + QByteArray line = file->readLine(); + + if (_errorLine == 1) { + if (!line.trimmed().startsWith("OziExplorer Waypoint File")) { + _errorString = "Not a WPT file"; + return false; + } + } else if (_errorLine == 2) { + if (!(gcs = GCS::gcs(QString(line.trimmed())))) { + _errorString = "Invalid/unknown datum"; + return false; + } + } else if (_errorLine > 4) { + QList list = line.split(','); + if (list.size() < 4) { + _errorString = "Parse error"; + return false; + } + + qreal lat = list.at(2).trimmed().toDouble(&res); + if (!res || (lat < -90.0 || lat > 90.0)) { + _errorString = "Invalid latitude"; + return false; + } + qreal lon = list.at(3).trimmed().toDouble(&res); + if (!res || (lon < -180.0 || lon > 180.0)) { + _errorString = "Invalid longitude"; + return false; + } + + Waypoint wp(gcs->toWGS84(Coordinates(lon, lat))); + + QString name(list.at(1).trimmed().replace('\xD1', ',')); + if (!name.isEmpty()) + wp.setName(name); + if (list.size() >= 5) { + QByteArray field(list.at(4).trimmed()); + if (!field.isEmpty()) { + double date = field.toDouble(&res); + if (!res) { + _errorString = "Invalid date"; + return false; + } + wp.setTimestamp(QDateTime::fromMSecsSinceEpoch( + delphi2unixMS(date))); + } + } + if (list.size() >= 11) { + QString desc(list.at(10).trimmed().replace('\xD1', ',')); + if (!desc.isEmpty()) + wp.setDescription(desc); + } + if (list.size() >= 15) { + QByteArray field(list.at(14).trimmed()); + if (!field.isEmpty()) { + double elevation = list.at(14).trimmed().toDouble(&res); + if (!res) { + _errorString = "Invalid elevation"; + return false; + } + if (elevation != -777) + wp.setElevation(elevation * 0.3048); + } + } + + waypoints.append(wp); + } + + _errorLine++; + } + + return true; +} diff --git a/src/data/oziparsers.h b/src/data/oziparsers.h new file mode 100644 index 00000000..54fccecf --- /dev/null +++ b/src/data/oziparsers.h @@ -0,0 +1,51 @@ +#ifndef OZIPARSERS_H +#define OZIPARSERS_H + +#include "parser.h" + +class PLTParser : public Parser +{ +public: + PLTParser() : _errorLine(0) {} + + bool parse(QFile *file, QList &tracks, QList &routes, + QList &waypoints); + QString errorString() const {return _errorString;} + int errorLine() const {return _errorLine;} + +private: + QString _errorString; + int _errorLine; +}; + +class RTEParser : public Parser +{ +public: + RTEParser() : _errorLine(0) {} + + bool parse(QFile *file, QList &tracks, QList &routes, + QList &waypoints); + QString errorString() const {return _errorString;} + int errorLine() const {return _errorLine;} + +private: + QString _errorString; + int _errorLine; +}; + +class WPTParser : public Parser +{ +public: + WPTParser() : _errorLine(0) {} + + bool parse(QFile *file, QList &tracks, QList &routes, + QList &waypoints); + QString errorString() const {return _errorString;} + int errorLine() const {return _errorLine;} + +private: + QString _errorString; + int _errorLine; +}; + +#endif // OZIPARSERS_H diff --git a/src/data/pltparser.cpp b/src/data/pltparser.cpp deleted file mode 100644 index abaceda9..00000000 --- a/src/data/pltparser.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "map/gcs.h" -#include "date.h" -#include "pltparser.h" - - -bool PLTParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) -{ - Q_UNUSED(waypoints); - Q_UNUSED(routes); - bool res; - const GCS *gcs; - - _errorLine = 1; - _errorString.clear(); - - tracks.append(TrackData()); - TrackData &track = tracks.last(); - - while (!file->atEnd()) { - QByteArray line = file->readLine(); - - if (_errorLine == 1) { - if (!line.trimmed().startsWith("OziExplorer Track Point File")) { - _errorString = "Not a PLT file"; - return false; - } - } else if (_errorLine == 2) { - if (!(gcs = GCS::gcs(QString(line.trimmed())))) { - _errorString = "Invalid/unknown datum"; - return false; - } - } else if (_errorLine == 5) { - QList list = line.split(','); - if (list.size() >= 4) - track.setName(list.at(3)); - } else if (_errorLine > 6) { - QList list = line.split(','); - if (list.size() < 2) { - _errorString = "Parse error"; - return false; - } - - qreal lat = list.at(0).trimmed().toDouble(&res); - if (!res || (lat < -90.0 || lat > 90.0)) { - _errorString = "Invalid latitude"; - return false; - } - qreal lon = list.at(1).trimmed().toDouble(&res); - if (!res || (lon < -180.0 || lon > 180.0)) { - _errorString = "Invalid longitude"; - return false; - } - - Trackpoint tp(gcs->toWGS84(Coordinates(lon, lat))); - - if (list.size() >= 4) { - QByteArray field(list.at(3).trimmed()); - if (!field.isEmpty()) { - double elevation = field.toDouble(&res); - if (!res) { - _errorString = "Invalid elevation"; - return false; - } - if (elevation != -777) - tp.setElevation(elevation * 0.3048); - } - } - if (list.size() >= 5) { - QByteArray field(list.at(4).trimmed()); - if (!field.isEmpty()) { - double date = field.toDouble(&res); - if (!res) { - _errorString = "Invalid date"; - return false; - } - tp.setTimestamp(QDateTime::fromMSecsSinceEpoch( - Date::delphi2unixMS(date))); - } - } - - track.append(tp); - } - - _errorLine++; - } - - return true; -} diff --git a/src/data/pltparser.h b/src/data/pltparser.h deleted file mode 100644 index 0bec1f1c..00000000 --- a/src/data/pltparser.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef PLTPARSER_H -#define PLTPARSER_H - -#include "parser.h" - -class PLTParser : public Parser -{ -public: - PLTParser() : _errorLine(0) {} - - bool parse(QFile *file, QList &tracks, QList &routes, - QList &waypoints); - QString errorString() const {return _errorString;} - int errorLine() const {return _errorLine;} - -private: - QString _errorString; - int _errorLine; -}; - -#endif // PLTPARSER_H diff --git a/src/data/rteparser.cpp b/src/data/rteparser.cpp deleted file mode 100644 index 691a1ef3..00000000 --- a/src/data/rteparser.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "map/gcs.h" -#include "date.h" -#include "rteparser.h" - - -bool RTEParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) -{ - Q_UNUSED(waypoints); - Q_UNUSED(tracks); - bool res, record = false; - const GCS *gcs; - - _errorLine = 1; - _errorString.clear(); - - - while (!file->atEnd()) { - QByteArray line = file->readLine(); - - if (_errorLine == 1) { - if (!line.trimmed().startsWith("OziExplorer Route File")) { - _errorString = "Not a RTE file"; - return false; - } - } else if (_errorLine == 2) { - if (!(gcs = GCS::gcs(QString(line.trimmed())))) { - _errorString = "Invalid/unknown datum"; - return false; - } - } else if (_errorLine > 4) { - QList list = line.split(','); - if (list.size() < 2) { - _errorString = "Parse error"; - return false; - } - - if (list.at(0).trimmed() == "R") { - routes.append(RouteData()); - record = true; - - if (list.size() >= 3) - routes.last().setName(list.at(2).trimmed() - .replace('\xD1', ',')); - if (list.size() >= 4) - routes.last().setDescription(list.at(3).trimmed() - .replace('\xD1', ',')); - } else if (list.at(0).trimmed() == "W") { - if (!record || list.size() < 7) { - _errorString = "Parse error"; - return false; - } - - qreal lat = list.at(5).trimmed().toDouble(&res); - if (!res || (lat < -90.0 || lat > 90.0)) { - _errorString = "Invalid latitude"; - return false; - } - qreal lon = list.at(6).trimmed().toDouble(&res); - if (!res || (lon < -180.0 || lon > 180.0)) { - _errorString = "Invalid longitude"; - return false; - } - - Waypoint wp(gcs->toWGS84(Coordinates(lon, lat))); - - QString name(list.at(4).trimmed().replace('\xD1', ',')); - if (!name.isEmpty()) - wp.setName(name); - if (list.size() >= 8) { - QByteArray field(list.at(7).trimmed()); - if (!field.isEmpty()) { - double date = field.toDouble(&res); - if (!res) { - _errorString = "Invalid date"; - return false; - } - wp.setTimestamp(QDateTime::fromMSecsSinceEpoch( - Date::delphi2unixMS(date))); - } - } - if (list.size() >= 14) { - QString desc(list.at(13).trimmed().replace('\xD1', ',')); - if (!desc.isEmpty()) - wp.setDescription(desc); - } - - routes.last().append(wp); - } else { - _errorString = "Parse error"; - return false; - } - } - - _errorLine++; - } - - return true; -} diff --git a/src/data/rteparser.h b/src/data/rteparser.h deleted file mode 100644 index 122d3d99..00000000 --- a/src/data/rteparser.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef RTEPARSER_H -#define RTEPARSER_H - -#include "parser.h" - -class RTEParser : public Parser -{ -public: - RTEParser() : _errorLine(0) {} - - bool parse(QFile *file, QList &tracks, QList &routes, - QList &waypoints); - QString errorString() const {return _errorString;} - int errorLine() const {return _errorLine;} - -private: - QString _errorString; - int _errorLine; -}; - -#endif // RTEPARSER_H diff --git a/src/data/wptparser.cpp b/src/data/wptparser.cpp deleted file mode 100644 index 8697c521..00000000 --- a/src/data/wptparser.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "map/gcs.h" -#include "date.h" -#include "wptparser.h" - - -bool WPTParser::parse(QFile *file, QList &tracks, - QList &routes, QList &waypoints) -{ - Q_UNUSED(tracks); - Q_UNUSED(routes); - bool res; - const GCS *gcs; - - _errorLine = 1; - _errorString.clear(); - - while (!file->atEnd()) { - QByteArray line = file->readLine(); - - if (_errorLine == 1) { - if (!line.trimmed().startsWith("OziExplorer Waypoint File")) { - _errorString = "Not a WPT file"; - return false; - } - } else if (_errorLine == 2) { - if (!(gcs = GCS::gcs(QString(line.trimmed())))) { - _errorString = "Invalid/unknown datum"; - return false; - } - } else if (_errorLine > 4) { - QList list = line.split(','); - if (list.size() < 4) { - _errorString = "Parse error"; - return false; - } - - qreal lat = list.at(2).trimmed().toDouble(&res); - if (!res || (lat < -90.0 || lat > 90.0)) { - _errorString = "Invalid latitude"; - return false; - } - qreal lon = list.at(3).trimmed().toDouble(&res); - if (!res || (lon < -180.0 || lon > 180.0)) { - _errorString = "Invalid longitude"; - return false; - } - - Waypoint wp(gcs->toWGS84(Coordinates(lon, lat))); - - QString name(list.at(1).trimmed().replace('\xD1', ',')); - if (!name.isEmpty()) - wp.setName(name); - if (list.size() >= 5) { - QByteArray field(list.at(4).trimmed()); - if (!field.isEmpty()) { - double date = field.toDouble(&res); - if (!res) { - _errorString = "Invalid date"; - return false; - } - wp.setTimestamp(QDateTime::fromMSecsSinceEpoch( - Date::delphi2unixMS(date))); - } - } - if (list.size() >= 11) { - QString desc(list.at(10).trimmed().replace('\xD1', ',')); - if (!desc.isEmpty()) - wp.setDescription(desc); - } - if (list.size() >= 15) { - QByteArray field(list.at(14).trimmed()); - if (!field.isEmpty()) { - double elevation = list.at(14).trimmed().toDouble(&res); - if (!res) { - _errorString = "Invalid elevation"; - return false; - } - if (elevation != -777) - wp.setElevation(elevation * 0.3048); - } - } - - waypoints.append(wp); - } - - _errorLine++; - } - - return true; -} diff --git a/src/data/wptparser.h b/src/data/wptparser.h deleted file mode 100644 index b7d599f7..00000000 --- a/src/data/wptparser.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef WPTPARSER_H -#define WPTPARSER_H - -#include "parser.h" - -class WPTParser : public Parser -{ -public: - WPTParser() : _errorLine(0) {} - - bool parse(QFile *file, QList &tracks, QList &routes, - QList &waypoints); - QString errorString() const {return _errorString;} - int errorLine() const {return _errorLine;} - -private: - QString _errorString; - int _errorLine; -}; - -#endif // WPTPARSER_H