Unverified Commit dd1ea23a authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #6239 from DonLakeFlyer/PolyLineLoadKML

PolyLine load kml support
parents 5e705032 3f1b3bf2
...@@ -56,9 +56,11 @@ const QGCMapPolygon& QGCMapPolygon::operator=(const QGCMapPolygon& other) ...@@ -56,9 +56,11 @@ const QGCMapPolygon& QGCMapPolygon::operator=(const QGCMapPolygon& other)
clear(); clear();
QVariantList vertices = other.path(); QVariantList vertices = other.path();
for (int i=0; i<vertices.count(); i++) { QList<QGeoCoordinate> rgCoord;
appendVertex(vertices[i].value<QGeoCoordinate>()); foreach (const QVariant& vertexVar, vertices) {
rgCoord.append(vertexVar.value<QGeoCoordinate>());
} }
appendVertices(rgCoord);
setDirty(true); setDirty(true);
...@@ -270,7 +272,6 @@ void QGCMapPolygon::appendVertices(const QList<QGeoCoordinate>& coordinates) ...@@ -270,7 +272,6 @@ void QGCMapPolygon::appendVertices(const QList<QGeoCoordinate>& coordinates)
emit pathChanged(); emit pathChanged();
} }
void QGCMapPolygon::_polygonModelDirtyChanged(bool dirty) void QGCMapPolygon::_polygonModelDirtyChanged(bool dirty)
{ {
if (dirty) { if (dirty) {
...@@ -447,9 +448,7 @@ void QGCMapPolygon::offset(double distance) ...@@ -447,9 +448,7 @@ void QGCMapPolygon::offset(double distance)
// Update internals // Update internals
clear(); clear();
for (int i=0; i<rgNewPolygon.count(); i++) { appendVertices(rgNewPolygon);
appendVertex(rgNewPolygon[i]);
}
} }
bool QGCMapPolygon::loadKMLFile(const QString& kmlFile) bool QGCMapPolygon::loadKMLFile(const QString& kmlFile)
......
...@@ -358,13 +358,13 @@ bool QGCMapPolyline::loadKMLFile(const QString& kmlFile) ...@@ -358,13 +358,13 @@ bool QGCMapPolyline::loadKMLFile(const QString& kmlFile)
return false; return false;
} }
QDomNodeList rgNodes = doc.elementsByTagName("Polygon"); QDomNodeList rgNodes = doc.elementsByTagName("LineString");
if (rgNodes.count() == 0) { if (rgNodes.count() == 0) {
qgcApp()->showMessage(tr("Unable to find Polygon node in KML")); qgcApp()->showMessage(tr("Unable to find LineString node in KML"));
return false; return false;
} }
QDomNode coordinatesNode = rgNodes.item(0).namedItem("outerBoundaryIs").namedItem("LinearRing").namedItem("coordinates"); QDomNode coordinatesNode = rgNodes.item(0).namedItem("coordinates");
if (coordinatesNode.isNull()) { if (coordinatesNode.isNull()) {
qgcApp()->showMessage(tr("Internal error: Unable to find coordinates node in KML")); qgcApp()->showMessage(tr("Internal error: Unable to find coordinates node in KML"));
return false; return false;
...@@ -386,29 +386,8 @@ bool QGCMapPolyline::loadKMLFile(const QString& kmlFile) ...@@ -386,29 +386,8 @@ bool QGCMapPolyline::loadKMLFile(const QString& kmlFile)
rgCoords.append(coord); rgCoords.append(coord);
} }
// Determine winding, reverse if needed
double sum = 0;
for (int i=0; i<rgCoords.count(); i++) {
QGeoCoordinate coord1 = rgCoords[i];
QGeoCoordinate coord2 = (i == rgCoords.count() - 1) ? rgCoords[0] : rgCoords[i+1];
sum += (coord2.longitude() - coord1.longitude()) * (coord2.latitude() + coord1.latitude());
}
bool reverse = sum < 0.0;
if (reverse) {
QList<QGeoCoordinate> rgReversed;
for (int i=0; i<rgCoords.count(); i++) {
rgReversed.prepend(rgCoords[i]);
}
rgCoords = rgReversed;
}
clear(); clear();
for (int i=0; i<rgCoords.count(); i++) { appendVertices(rgCoords);
appendVertex(rgCoords[i]);
}
return true; return true;
} }
...@@ -438,3 +417,15 @@ double QGCMapPolyline::length(void) const ...@@ -438,3 +417,15 @@ double QGCMapPolyline::length(void) const
return length; return length;
} }
void QGCMapPolyline::appendVertices(const QList<QGeoCoordinate>& coordinates)
{
QList<QObject*> objects;
foreach (const QGeoCoordinate& coordinate, coordinates) {
objects.append(new QGCQGeoCoordinate(coordinate, this));
_polylinePath.append(QVariant::fromValue(coordinate));
}
_polylineModel.append(objects);
emit pathChanged();
}
...@@ -34,6 +34,7 @@ public: ...@@ -34,6 +34,7 @@ public:
Q_INVOKABLE void clear(void); Q_INVOKABLE void clear(void);
Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate); Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate);
Q_INVOKABLE void removeVertex(int vertexIndex); Q_INVOKABLE void removeVertex(int vertexIndex);
Q_INVOKABLE void appendVertices(const QList<QGeoCoordinate>& coordinates);
/// Adjust the value for the specified coordinate /// Adjust the value for the specified coordinate
/// @param vertexIndex Polygon point index to modify (0-based) /// @param vertexIndex Polygon point index to modify (0-based)
......
...@@ -120,13 +120,28 @@ Item { ...@@ -120,13 +120,28 @@ Item {
selectExisting: true selectExisting: true
nameFilters: [ qsTr("KML files (*.kml)") ] nameFilters: [ qsTr("KML files (*.kml)") ]
onAcceptedForLoad: { onAcceptedForLoad: {
mapPolyline.loadKMLFile(file) mapPolyline.loadKMLFile(file)
close() close()
} }
} }
Menu {
id: menu
property int removeVertex
MenuItem {
text: qsTr("Remove vertex" )
onTriggered: mapPolyline.removeVertex(parent.removeVertex)
}
MenuItem {
text: qsTr("Load KML...")
onTriggered: kmlLoadDialog.openForLoad()
}
}
Component { Component {
id: polylineComponent id: polylineComponent
...@@ -227,7 +242,15 @@ Item { ...@@ -227,7 +242,15 @@ Item {
} }
} }
onClicked: mapPolyline.removeVertex(polylineVertex) onClicked: {
if (polylineVertex == 0) {
menu.removeVertex = polylineVertex
menu.popup()
} else {
mapPolyline.removeVertex(polylineVertex)
}
}
} }
} }
...@@ -249,6 +272,14 @@ Item { ...@@ -249,6 +272,14 @@ Item {
radius: width / 2 radius: width / 2
color: "white" color: "white"
opacity: .90 opacity: .90
QGCLabel {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
text: "..."
color: "black"
visible: polylineVertex == 0
}
} }
} }
} }
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
}, },
{ {
"name": "TerrainAdjustTolerance", "name": "TerrainAdjustTolerance",
"shortDescription": "TerrainAdjustTolerance", "shortDescription": "If adjacent terrain waypoints are within this tolerence they will be removed.",
"type": "double", "type": "double",
"decimalPlaces": 2, "decimalPlaces": 2,
"min": 0, "min": 0,
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
}, },
{ {
"name": "TerrainAdjustMaxClimbRate", "name": "TerrainAdjustMaxClimbRate",
"shortDescription": "TerrainAdjustMaxClimbRate", "shortDescription": "The maximum climb rate from one waypoint to another when adjusting for terrain. Set to 0 for no max.",
"type": "double", "type": "double",
"decimalPlaces": 2, "decimalPlaces": 2,
"min": 0, "min": 0,
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
}, },
{ {
"name": "TerrainAdjustMaxDescentRate", "name": "TerrainAdjustMaxDescentRate",
"shortDescription": "TerrainAdjustMaxDescentRate", "shortDescription": "The maximum descent rate from one waypoint to another when adjusting for terrain. Set to 0 for no max.",
"type": "double", "type": "double",
"decimalPlaces": 2, "decimalPlaces": 2,
"min": 0, "min": 0,
......
...@@ -500,7 +500,7 @@ int TransectStyleComplexItem::_maxPathHeight(const TerrainPathQuery::PathHeightI ...@@ -500,7 +500,7 @@ int TransectStyleComplexItem::_maxPathHeight(const TerrainPathQuery::PathHeightI
void TransectStyleComplexItem::_adjustForMaxRates(QList<CoordInfo_t>& transect) void TransectStyleComplexItem::_adjustForMaxRates(QList<CoordInfo_t>& transect)
{ {
double maxClimbRate = _terrainAdjustMaxClimbRateFact.rawValue().toDouble(); double maxClimbRate = _terrainAdjustMaxClimbRateFact.rawValue().toDouble();
double maxDescentRate = -_terrainAdjustMaxDescentRateFact.rawValue().toDouble(); double maxDescentRate = _terrainAdjustMaxDescentRateFact.rawValue().toDouble();
double flightSpeed = _missionFlightStatus.vehicleSpeed; double flightSpeed = _missionFlightStatus.vehicleSpeed;
if (qIsNaN(flightSpeed) || (maxClimbRate == 0 && maxDescentRate == 0)) { if (qIsNaN(flightSpeed) || (maxClimbRate == 0 && maxDescentRate == 0)) {
...@@ -510,6 +510,7 @@ void TransectStyleComplexItem::_adjustForMaxRates(QList<CoordInfo_t>& transect) ...@@ -510,6 +510,7 @@ void TransectStyleComplexItem::_adjustForMaxRates(QList<CoordInfo_t>& transect)
return; return;
} }
if (maxClimbRate > 0) {
// Adjust climb rates // Adjust climb rates
bool climbRateAdjusted; bool climbRateAdjusted;
do { do {
...@@ -534,9 +535,12 @@ void TransectStyleComplexItem::_adjustForMaxRates(QList<CoordInfo_t>& transect) ...@@ -534,9 +535,12 @@ void TransectStyleComplexItem::_adjustForMaxRates(QList<CoordInfo_t>& transect)
} }
} }
} while (climbRateAdjusted); } while (climbRateAdjusted);
}
if (maxDescentRate > 0) {
// Adjust descent rates // Adjust descent rates
bool descentRateAdjusted; bool descentRateAdjusted;
maxDescentRate = -maxDescentRate;
do { do {
//qDebug() << "descent rate pass"; //qDebug() << "descent rate pass";
descentRateAdjusted = false; descentRateAdjusted = false;
...@@ -559,6 +563,7 @@ void TransectStyleComplexItem::_adjustForMaxRates(QList<CoordInfo_t>& transect) ...@@ -559,6 +563,7 @@ void TransectStyleComplexItem::_adjustForMaxRates(QList<CoordInfo_t>& transect)
} }
} }
} while (descentRateAdjusted); } while (descentRateAdjusted);
}
} }
void TransectStyleComplexItem::_adjustForTolerance(QList<CoordInfo_t>& transect) void TransectStyleComplexItem::_adjustForTolerance(QList<CoordInfo_t>& transect)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment