mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-18 19:52:09 +01:00
Use the whole waypoint info in the route points
+ Optimize for waypoint reading
This commit is contained in:
parent
967e307be9
commit
e1bda86b35
@ -58,8 +58,7 @@ static double elevation(const QString &str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CUPParser::waypoint(const QStringList &entry, QVector<Waypoint> &waypoints,
|
bool CUPParser::waypoint(const QStringList &entry, QVector<Waypoint> &waypoints)
|
||||||
QMap<QString, Coordinates> &turnpoints)
|
|
||||||
{
|
{
|
||||||
if (entry.size() < 11) {
|
if (entry.size() < 11) {
|
||||||
_errorString = "Invalid number of fields";
|
_errorString = "Invalid number of fields";
|
||||||
@ -83,15 +82,13 @@ bool CUPParser::waypoint(const QStringList &entry, QVector<Waypoint> &waypoints,
|
|||||||
wp.setElevation(elevation(entry.at(5)));
|
wp.setElevation(elevation(entry.at(5)));
|
||||||
waypoints.append(wp);
|
waypoints.append(wp);
|
||||||
|
|
||||||
turnpoints.insert(wp.name(), wp.coordinates());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CUPParser::task(const QStringList &entry, QList<RouteData> &routes,
|
bool CUPParser::task(const QStringList &entry,
|
||||||
const QMap<QString, Coordinates> &turnpoints)
|
const QVector<Waypoint> &waypoints, QList<RouteData> &routes)
|
||||||
{
|
{
|
||||||
if (entry.size() < 2) {
|
if (entry.size() < 3) {
|
||||||
_errorString = "Invalid number of fields";
|
_errorString = "Invalid number of fields";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -99,13 +96,17 @@ bool CUPParser::task(const QStringList &entry, QList<RouteData> &routes,
|
|||||||
RouteData r;
|
RouteData r;
|
||||||
r.setName(entry.at(0));
|
r.setName(entry.at(0));
|
||||||
for (int i = 1; i < entry.size(); i++) {
|
for (int i = 1; i < entry.size(); i++) {
|
||||||
if (!turnpoints.contains(entry.at(i))) {
|
Waypoint w;
|
||||||
|
for (int j = 0; j < waypoints.size(); j++) {
|
||||||
|
if (waypoints.at(j).name() == entry.at(i)) {
|
||||||
|
w = waypoints.at(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (w.coordinates().isNull()) {
|
||||||
_errorString = entry.at(i) + ": unknown turnpoint";
|
_errorString = entry.at(i) + ": unknown turnpoint";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Waypoint w(turnpoints[entry.at(i)]);
|
|
||||||
w.setName(entry.at(i));
|
|
||||||
r.append(w);
|
r.append(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,9 +122,8 @@ bool CUPParser::parse(QFile *file, QList<TrackData> &tracks,
|
|||||||
Q_UNUSED(tracks);
|
Q_UNUSED(tracks);
|
||||||
Q_UNUSED(polygons);
|
Q_UNUSED(polygons);
|
||||||
CSV csv(file);
|
CSV csv(file);
|
||||||
SegmentType st = Header;
|
|
||||||
QStringList entry;
|
QStringList entry;
|
||||||
QMap<QString, Coordinates> turnpoints;
|
SegmentType segment = Header;
|
||||||
|
|
||||||
|
|
||||||
while (!csv.atEnd()) {
|
while (!csv.atEnd()) {
|
||||||
@ -133,26 +133,26 @@ bool CUPParser::parse(QFile *file, QList<TrackData> &tracks,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st == Header) {
|
if (segment == Header) {
|
||||||
st = Waypoints;
|
segment = Waypoints;
|
||||||
if (entry.size() >= 11 && entry.at(3) == "lat"
|
if (entry.size() >= 11 && entry.at(3) == "lat"
|
||||||
&& entry.at(4) == "lon") {
|
&& entry.at(4) == "lon") {
|
||||||
entry.clear();
|
entry.clear();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (st == Waypoints && entry.size() == 1
|
} else if (segment == Waypoints && entry.size() == 1
|
||||||
&& entry.at(0) == "-----Related Tasks-----") {
|
&& entry.at(0) == "-----Related Tasks-----") {
|
||||||
st = Tasks;
|
segment = Tasks;
|
||||||
entry.clear();
|
entry.clear();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st == Waypoints) {
|
if (segment == Waypoints) {
|
||||||
if (!waypoint(entry, waypoints, turnpoints))
|
if (!waypoint(entry, waypoints))
|
||||||
return false;
|
return false;
|
||||||
} else if (st == Tasks) {
|
} else if (segment == Tasks) {
|
||||||
if (entry.at(0) != "Options" && entry.at(0) != "ObsZone"
|
if (entry.at(0) != "Options" && entry.at(0) != "ObsZone"
|
||||||
&& !task(entry, routes, turnpoints))
|
&& !task(entry, waypoints, routes))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,10 +14,9 @@ public:
|
|||||||
int errorLine() const {return _errorLine;}
|
int errorLine() const {return _errorLine;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool waypoint(const QStringList &entry, QVector<Waypoint> &waypoints,
|
bool waypoint(const QStringList &entry, QVector<Waypoint> &waypoints);
|
||||||
QMap<QString, Coordinates> &turnpoints);
|
bool task(const QStringList &entry, const QVector<Waypoint> &waypoints,
|
||||||
bool task(const QStringList &entry, QList<RouteData> &routes,
|
QList<RouteData> &routes);
|
||||||
const QMap<QString, Coordinates> &turnpoints);
|
|
||||||
|
|
||||||
QString _errorString;
|
QString _errorString;
|
||||||
int _errorLine;
|
int _errorLine;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user