From 9f6ade3f32df4e3f351cfafa982f3d76510122fc Mon Sep 17 00:00:00 2001 From: Valentin Platzgummer Date: Tue, 17 Sep 2019 13:50:27 +0200 Subject: [PATCH] border polygon works now --- qgroundcontrol.qrc | 1 + src/Wima/WimaArea.cc | 31 ++++ src/Wima/WimaArea.h | 26 ++- src/Wima/WimaPlaner.cc | 4 +- src/WimaView/WimaCorridorEditor.qml | 173 ++++++++++++++++++ src/WimaView/WimaCorridorMapVisual.qml | 90 +++++---- src/WimaView/WimaItemEditor.qml | 2 +- src/WimaView/WimaMeasurementAreaEditor.qml | 13 +- src/WimaView/WimaMeasurementAreaMapVisual.qml | 76 ++++---- src/WimaView/WimaServiceAreaEditor.qml | 18 +- src/WimaView/WimaServiceAreaMapVisual.qml | 91 +++++---- 11 files changed, 389 insertions(+), 136 deletions(-) create mode 100644 src/WimaView/WimaCorridorEditor.qml diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index b125c4a86..914551028 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -226,6 +226,7 @@ src/WimaView/CoordinateIndicatorDrag.qml src/WimaView/CoordinateIndicator.qml src/WimaView/WimaJoinedAreaMapVisual.qml + src/WimaView/WimaCorridorEditor.qml src/Settings/APMMavlinkStreamRate.SettingsGroup.json diff --git a/src/Wima/WimaArea.cc b/src/Wima/WimaArea.cc index 11e848627..8f33701e2 100644 --- a/src/Wima/WimaArea.cc +++ b/src/Wima/WimaArea.cc @@ -34,6 +34,7 @@ WimaArea::WimaArea(QObject *parent) , _borderPolygonOffset (SettingsFact(settingsGroup, _metaDataMap[borderPolygonOffsetName], this /* QObject parent */)) , _showBorderPolygon (SettingsFact(settingsGroup, _metaDataMap[showBorderPolygonName], this /* QObject parent */)) , _borderPolygon (QGCMapPolygon(this)) + , _wimaAreaInteractive (false) { init(); _maxAltitude = 30; @@ -45,6 +46,7 @@ WimaArea::WimaArea(const WimaArea &other, QObject *parent) , _borderPolygonOffset (SettingsFact(settingsGroup, _metaDataMap[borderPolygonOffsetName], this /* QObject parent */)) , _showBorderPolygon (SettingsFact(settingsGroup, _metaDataMap[showBorderPolygonName], this /* QObject parent */)) , _borderPolygon (QGCMapPolygon(this)) + , _wimaAreaInteractive (false) { init(); *this = other; @@ -66,6 +68,15 @@ WimaArea &WimaArea::operator=(const WimaArea &other) return *this; } +void WimaArea::setWimaAreaInteractive(bool interactive) +{ + if (WimaArea::_wimaAreaInteractive != interactive) { + WimaArea::_wimaAreaInteractive = interactive; + + emit WimaArea::wimaAreaInteractiveChanged(); + } +} + /*! \fn void WimaArea::setMaxAltitude(double altitude) @@ -101,12 +112,14 @@ void WimaArea::recalcPolygons() if (_showBorderPolygon.rawValue().toBool() == true) { if ( _borderPolygon.count() >= 3 ) { + //_borderPolygon.verifyClockwiseWinding(); // causes seg. fault this->setPath(_borderPolygon.coordinateList()); this->offset(-_borderPolygonOffset.rawValue().toDouble()); } } else { if (this->count() >= 3){ + //this->verifyClockwiseWinding(); // causes seg. fault _borderPolygon.setPath(this->coordinateList()); _borderPolygon.offset(_borderPolygonOffset.rawValue().toDouble()); } @@ -128,6 +141,22 @@ void WimaArea::updatePolygonConnections(QVariant showBorderPolygon) } } +void WimaArea::recalcInteractivity() +{ + if ( _wimaAreaInteractive == false) { + this->setWimaAreaInteractive(false); + _borderPolygon.setInteractive(false); + } else { + if (_showBorderPolygon.rawValue().toBool() == true) { + _borderPolygon.setInteractive(true); + this->setInteractive(false); + } else { + _borderPolygon.setInteractive(false); + this->setInteractive(true); + } + } +} + /*! * \fn int WimaArea::getClosestVertexIndex(const QGeoCoordinate &coordinate) const * Returns the index of the vertex (element of the polygon path) @@ -434,6 +463,8 @@ void WimaArea::init() connect(&_borderPolygonOffset, &SettingsFact::rawValueChanged, this, &WimaArea::recalcPolygons); connect(&_showBorderPolygon, &SettingsFact::rawValueChanged, this, &WimaArea::updatePolygonConnections); + connect(&_showBorderPolygon, &SettingsFact::rawValueChanged, this, &WimaArea::recalcInteractivity); + connect(this, &WimaArea::wimaAreaInteractiveChanged, this, &WimaArea::recalcInteractivity); } /*! diff --git a/src/Wima/WimaArea.h b/src/Wima/WimaArea.h index dbf2d1b27..dfff87588 100644 --- a/src/Wima/WimaArea.h +++ b/src/Wima/WimaArea.h @@ -23,12 +23,13 @@ public: WimaArea &operator=(const WimaArea &other); - Q_PROPERTY(double maxAltitude READ maxAltitude WRITE setMaxAltitude NOTIFY maxAltitudeChanged) - Q_PROPERTY(QString mapVisualQML READ mapVisualQML CONSTANT) - Q_PROPERTY(QString editorQML READ editorQML CONSTANT) - Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffsetFact CONSTANT) - Q_PROPERTY(QGCMapPolygon* borderPolygon READ borderPolygon NOTIFY borderPolygonChanged) - Q_PROPERTY(Fact* showBorderPolygon READ showBorderPolygon CONSTANT) + Q_PROPERTY(double maxAltitude READ maxAltitude WRITE setMaxAltitude NOTIFY maxAltitudeChanged) + Q_PROPERTY(QString mapVisualQML READ mapVisualQML CONSTANT) + Q_PROPERTY(QString editorQML READ editorQML CONSTANT) + Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffsetFact CONSTANT) + Q_PROPERTY(QGCMapPolygon* borderPolygon READ borderPolygon NOTIFY borderPolygonChanged) + Q_PROPERTY(Fact* showBorderPolygon READ showBorderPolygon CONSTANT) + Q_PROPERTY(bool wimaAreaInteractive READ wimaAreaInteractive WRITE setWimaAreaInteractive NOTIFY wimaAreaInteractiveChanged) //Property accessors @@ -37,6 +38,9 @@ public: Fact* showBorderPolygon (void) { return &_showBorderPolygon;} double borderPolygonOffset (void) const { return _borderPolygonOffset.rawValue().toDouble();} QGCMapPolygon* borderPolygon (void) { return &_borderPolygon;} + bool wimaAreaInteractive (void) const { return _wimaAreaInteractive;} + + void setWimaAreaInteractive (bool interactive); // overrides from WimaArea virtual QString mapVisualQML (void) const { return ""; } @@ -76,9 +80,10 @@ public: static const char* settingsGroup; signals: - void maxAltitudeChanged (void); + void maxAltitudeChanged (void); void borderPolygonChanged (void); void borderPolygonOffsetChanged (void); + void wimaAreaInteractiveChanged (void); public slots: void setMaxAltitude (double altitude); @@ -86,8 +91,9 @@ public slots: void setBorderPolygonOffset (double offset); private slots: - void recalcPolygons (void); - void updatePolygonConnections(QVariant value); + void recalcPolygons (void); + void updatePolygonConnections (QVariant value); + void recalcInteractivity (void); private: @@ -100,6 +106,8 @@ private: SettingsFact _showBorderPolygon; QGCMapPolygon _borderPolygon; + + bool _wimaAreaInteractive; }; diff --git a/src/Wima/WimaPlaner.cc b/src/Wima/WimaPlaner.cc index 3abe9f84c..2db04c0b1 100644 --- a/src/Wima/WimaPlaner.cc +++ b/src/Wima/WimaPlaner.cc @@ -557,7 +557,7 @@ void WimaPlaner::recalcPolygonInteractivity(int index) if (index >= 0 && index < _visualItems.count()) { resetAllInteractive(); WimaArea* interactivePoly = qobject_cast(_visualItems.get(index)); - interactivePoly->setInteractive(true); + interactivePoly->setWimaAreaInteractive(true); } } @@ -649,7 +649,7 @@ void WimaPlaner::resetAllInteractive() if (itemCount > 0){ for (int i = 0; i < itemCount; i++) { WimaArea* iteratorPoly = qobject_cast(_visualItems.get(i)); - iteratorPoly->setInteractive(false); + iteratorPoly->setWimaAreaInteractive(false); } } } diff --git a/src/WimaView/WimaCorridorEditor.qml b/src/WimaView/WimaCorridorEditor.qml new file mode 100644 index 000000000..a27396438 --- /dev/null +++ b/src/WimaView/WimaCorridorEditor.qml @@ -0,0 +1,173 @@ +import QtQuick 2.3 +import QtQuick.Controls 1.2 +import QtQuick.Controls.Styles 1.4 +import QtQuick.Dialogs 1.2 +import QtQuick.Extras 1.4 +import QtQuick.Layouts 1.2 + +import QGroundControl 1.0 +import QGroundControl.ScreenTools 1.0 +import QGroundControl.Vehicle 1.0 +import QGroundControl.Controls 1.0 +import QGroundControl.FactControls 1.0 +import QGroundControl.Palette 1.0 +import QGroundControl.FlightMap 1.0 + +// Editor for Operating Area items +Rectangle { + id: _root + height: visible ? (editorColumn.height + (_margin * 2)) : 0 + width: availableWidth + color: qgcPal.windowShadeDark + radius: _radius + + // The following properties must be available up the hierarchy chain + //property real availableWidth ///< Width for control + //property var areaItem ///< Mission Item for editor + + property real _margin: ScreenTools.defaultFontPixelWidth / 2 + property real _fieldWidth: ScreenTools.defaultFontPixelWidth * 10.5 + //property var polyline: areaItem.polyline + //property bool polylineInteractive: polyline.interactive + property bool polygonInteractive: areaItem.interactive + property var polygon: areaItem + property bool initNecesarry: true + + /*onPolylineInteractiveChanged: { + polyline.interactive = polylineInteractive; + }*/ + + onPolygonInteractiveChanged: { + polygon.interactive = polygonInteractive; + } + + /*function editPolyline(){ + if (polylineInteractive){ + //polyline.interactive = false; + polylineInteractive = false; + //polygonInteractive = true; + }else{ + //polyline.interactive = true; + polylineInteractive = true; + //polygonInteractive = false; + } + }*/ + + + + + QGCPalette { id: qgcPal; colorGroupEnabled: true } + + Column { + id: editorColumn + anchors.margins: _margin + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + spacing: _margin + + SectionHeader { + id: scanHeader + text: qsTr("Settings") + } + + Column { + anchors.left: parent.left + anchors.right: parent.right + spacing: _margin + visible: scanHeader.checked + + GridLayout { + anchors.left: parent.left + anchors.right: parent.right + columnSpacing: _margin + rowSpacing: _margin + columns: 2 + + + QGCLabel { text: qsTr("Offset") } + + FactTextField { + fact: areaItem.borderPolygonOffset + Layout.fillWidth: true + } + + + + /*QGCLabel { + text: qsTr("Bottom Layer Altitude") + } + FactTextField { + fact: areaItem.bottomLayerAltitude + Layout.fillWidth: true + } + + QGCLabel { text: qsTr("Number of Layers") } + FactTextField { + fact: areaItem.numberOfLayers + Layout.fillWidth: true + } + + QGCLabel { text: qsTr("Layer Distance") } + FactTextField { + fact: areaItem.layerDistance + Layout.fillWidth: true + }*/ + + + } + + Item { + height: ScreenTools.defaultFontPixelHeight / 2 + width: 1 + } + } + + FactCheckBox { + text: qsTr("Border Polygon") + fact: areaItem.showBorderPolygon + //enabled: !missionItem.followTerrain + } + + // Column - Scan + /*SectionHeader { + id: polylineHeader + text: qsTr("Gateway Poly Line") + } + + QGCButton { + id: polylineEditor + anchors.topMargin: _margin / 2 + anchors.leftMargin: ScreenTools.defaultFontPixelWidth * 2 + anchors.rightMargin: ScreenTools.defaultFontPixelWidth + text: polylineInteractive ? "Done" : "Edit" + + onClicked: editPolyline() + } + + QGCButton { + id: swapEndpoints + anchors.topMargin: _margin / 2 + anchors.leftMargin: ScreenTools.defaultFontPixelWidth * 2 + anchors.rightMargin: ScreenTools.defaultFontPixelWidth + text: "Swap End-Points" + + onClicked: polyline.swapEndPoints() + }*/ + + SectionHeader { + id: statsHeader + text: qsTr("Statistics") + } + + Grid { + columns: 2 + columnSpacing: ScreenTools.defaultFontPixelWidth + visible: statsHeader.checked + + /*QGCLabel { text: qsTr("Layers") } + QGCLabel { text: areaItem.layers.valueString }*/ + + } + } // Column +} // Rectangle diff --git a/src/WimaView/WimaCorridorMapVisual.qml b/src/WimaView/WimaCorridorMapVisual.qml index bdc411ca3..a34b88372 100644 --- a/src/WimaView/WimaCorridorMapVisual.qml +++ b/src/WimaView/WimaCorridorMapVisual.qml @@ -33,40 +33,50 @@ Item { /// Add an initial 4 sided polygon if there is none function _addInitialPolygon() { - if (_polygon.count < 3) { - // Initial polygon is inset to take 2/3rds space - var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height) - rect.x += (rect.width * 0.25) / 2 - rect.y += (rect.height * 0.25) / 2 - rect.width *= 0.25 - rect.height *= 0.25 - - var centerCoord = map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)), false /* clipToViewPort */) - var topLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */) - var topRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y), false /* clipToViewPort */) - var bottomLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y + rect.height), false /* clipToViewPort */) - var bottomRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */) - - // Adjust polygon to max size - var maxSize = 100 - var halfWidthMeters = Math.min(topLeftCoord.distanceTo(topRightCoord), maxSize) / 2 - var halfHeightMeters = Math.min(topLeftCoord.distanceTo(bottomLeftCoord), maxSize) / 2 - topLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 0) - topRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0) - bottomLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180) - bottomRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 180) - - _polygon.appendVertex(topLeftCoord) - _polygon.appendVertex(topRightCoord) - _polygon.appendVertex(bottomRightCoord) - _polygon.appendVertex(bottomLeftCoord) + + // Initial polygon is inset to take 2/3rds space + var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height) + rect.x += (rect.width * 0.25) / 2 + rect.y += (rect.height * 0.25) / 2 + rect.width *= 0.75 + rect.height *= 0.75 + + var centerCoord = map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)), false /* clipToViewPort */) + var topLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */) + var topRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y), false /* clipToViewPort */) + var bottomLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y + rect.height), false /* clipToViewPort */) + var bottomRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */) + + // Adjust polygon to max size + var maxSize = 100 + var halfWidthMeters = Math.min(topLeftCoord.distanceTo(topRightCoord), maxSize) / 2 + var halfHeightMeters = Math.min(topLeftCoord.distanceTo(bottomLeftCoord), maxSize) / 2 + topLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 0) + topRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0) + bottomLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180) + bottomRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 180) + + if (areaItem.showBorderPolygon.rawValue === true) { + + if (areaItem.borderPolygon.count < 3) { + + areaItem.borderPolygon.appendVertex(topLeftCoord) + areaItem.borderPolygon.appendVertex(topRightCoord) + areaItem.borderPolygon.appendVertex(bottomRightCoord) + areaItem.borderPolygon.appendVertex(bottomLeftCoord) + } + } else { + if (_polygon.count < 3) { + + _polygon.appendVertex(topLeftCoord) + _polygon.appendVertex(topRightCoord) + _polygon.appendVertex(bottomRightCoord) + _polygon.appendVertex(bottomLeftCoord) + } } - } - /*function _addInitialPolyline(){ - _polyline.setStartVertexIndex(0); - _polyline.setEndVertexIndex(1); - }*/ + + } @@ -88,14 +98,14 @@ Item { interiorOpacity: 0.2 } - /*WimaMapPolylineVisuals { + WimaMapPolygonVisuals { qgcView: _root.qgcView mapControl: map - mapPolyline: _polyline - lineWidth: 4 - lineColor: interactive ? "white" : "yellow" - enableSplitHandels: false - enableDragHandels: true - edgeHandelsOnly: true - }*/ + mapPolygon: areaItem.borderPolygon + borderWidth: 1 + borderColor: areaItem.borderPolygon.interactive ? "white" : "transparent" + interiorColor: "transparent" + interiorOpacity: 1 + } + } diff --git a/src/WimaView/WimaItemEditor.qml b/src/WimaView/WimaItemEditor.qml index 9b2df5b62..234d42750 100644 --- a/src/WimaView/WimaItemEditor.qml +++ b/src/WimaView/WimaItemEditor.qml @@ -32,7 +32,7 @@ Rectangle { property var _masterController: masterController property var _missionController: _masterController.missionController - property bool interactive: areaItem.interactive + property bool interactive: areaItem.wimaAreaInteractive property color _outerTextColor: interactive ? qgcPal.primaryButtonText : qgcPal.text property real _sectionSpacer: ScreenTools.defaultFontPixelWidth / 2 // spacing between section headings diff --git a/src/WimaView/WimaMeasurementAreaEditor.qml b/src/WimaView/WimaMeasurementAreaEditor.qml index b2fc42416..a942b900b 100644 --- a/src/WimaView/WimaMeasurementAreaEditor.qml +++ b/src/WimaView/WimaMeasurementAreaEditor.qml @@ -95,15 +95,12 @@ Rectangle { fact: areaItem.borderPolygonOffset Layout.fillWidth: true } + } - QGCLabel { text: qsTr("Border Poly.") } - - FactTextField { - fact: areaItem.showBorderPolygon - Layout.fillWidth: true - } - - + FactCheckBox { + text: qsTr("Border Polygon") + fact: areaItem.showBorderPolygon + //enabled: !missionItem.followTerrain } Item { diff --git a/src/WimaView/WimaMeasurementAreaMapVisual.qml b/src/WimaView/WimaMeasurementAreaMapVisual.qml index ac192a86c..da2cb6529 100644 --- a/src/WimaView/WimaMeasurementAreaMapVisual.qml +++ b/src/WimaView/WimaMeasurementAreaMapVisual.qml @@ -32,42 +32,50 @@ Item { /// Add an initial 4 sided polygon if there is none function _addInitialPolygon() { - if (areaItem.borderPolygon.count < 3) { - // Initial polygon is inset to take 2/3rds space - var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height) - rect.x += (rect.width * 0.25) / 2 - rect.y += (rect.height * 0.25) / 2 - rect.width *= 0.75 - rect.height *= 0.75 - - var centerCoord = map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)), false /* clipToViewPort */) - var topLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */) - var topRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y), false /* clipToViewPort */) - var bottomLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y + rect.height), false /* clipToViewPort */) - var bottomRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */) - - // Adjust polygon to max size - var maxSize = 100 - var halfWidthMeters = Math.min(topLeftCoord.distanceTo(topRightCoord), maxSize) / 2 - var halfHeightMeters = Math.min(topLeftCoord.distanceTo(bottomLeftCoord), maxSize) / 2 - topLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 0) - topRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0) - bottomLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180) - bottomRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 180) - - areaItem.borderPolygon.appendVertex(topLeftCoord) - areaItem.borderPolygon.appendVertex(topRightCoord) - areaItem.borderPolygon.appendVertex(bottomRightCoord) - areaItem.borderPolygon.appendVertex(bottomLeftCoord) - } - } - /*function _addInitialPolyline(){ - _polyline.setStartVertexIndex(0); - _polyline.setEndVertexIndex(1); - }*/ + // Initial polygon is inset to take 2/3rds space + var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height) + rect.x += (rect.width * 0.25) / 2 + rect.y += (rect.height * 0.25) / 2 + rect.width *= 0.75 + rect.height *= 0.75 + + var centerCoord = map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)), false /* clipToViewPort */) + var topLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */) + var topRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y), false /* clipToViewPort */) + var bottomLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y + rect.height), false /* clipToViewPort */) + var bottomRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */) + + // Adjust polygon to max size + var maxSize = 100 + var halfWidthMeters = Math.min(topLeftCoord.distanceTo(topRightCoord), maxSize) / 2 + var halfHeightMeters = Math.min(topLeftCoord.distanceTo(bottomLeftCoord), maxSize) / 2 + topLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 0) + topRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0) + bottomLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180) + bottomRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 180) + + if (areaItem.showBorderPolygon.rawValue === true) { + + if (areaItem.borderPolygon.count < 3) { + + areaItem.borderPolygon.appendVertex(topLeftCoord) + areaItem.borderPolygon.appendVertex(topRightCoord) + areaItem.borderPolygon.appendVertex(bottomRightCoord) + areaItem.borderPolygon.appendVertex(bottomLeftCoord) + } + } else { + if (_polygon.count < 3) { + + _polygon.appendVertex(topLeftCoord) + _polygon.appendVertex(topRightCoord) + _polygon.appendVertex(bottomRightCoord) + _polygon.appendVertex(bottomLeftCoord) + } + } + } Component.onCompleted: { _addInitialPolygon() @@ -93,7 +101,7 @@ Item { mapControl: map mapPolygon: areaItem.borderPolygon borderWidth: 1 - borderColor: "white" + borderColor: areaItem.borderPolygon.interactive ? "white" : "transparent" interiorColor: "transparent" interiorOpacity: 1 } diff --git a/src/WimaView/WimaServiceAreaEditor.qml b/src/WimaView/WimaServiceAreaEditor.qml index 1ee565ceb..96a3679c9 100644 --- a/src/WimaView/WimaServiceAreaEditor.qml +++ b/src/WimaView/WimaServiceAreaEditor.qml @@ -73,7 +73,7 @@ Rectangle { Column { anchors.left: parent.left - anchors.right: parent.rightsetI + anchors.right: parent.right spacing: _margin visible: scanHeader.checked @@ -84,6 +84,13 @@ Rectangle { rowSpacing: _margin columns: 2 + QGCLabel { text: qsTr("Offset") } + + FactTextField { + fact: areaItem.borderPolygonOffset + Layout.fillWidth: true + } + /*QGCLabel { text: qsTr("Bottom Layer Altitude") } @@ -111,7 +118,14 @@ Rectangle { height: ScreenTools.defaultFontPixelHeight / 2 width: 1 } - } // Column - Scan + } + + FactCheckBox { + text: qsTr("Border Polygon") + fact: areaItem.showBorderPolygon + //enabled: !missionItem.followTerrain + } + // Column - Scan /*SectionHeader { id: polylineHeader text: qsTr("Gateway Poly Line") diff --git a/src/WimaView/WimaServiceAreaMapVisual.qml b/src/WimaView/WimaServiceAreaMapVisual.qml index a73da6b9d..fe8b990f2 100644 --- a/src/WimaView/WimaServiceAreaMapVisual.qml +++ b/src/WimaView/WimaServiceAreaMapVisual.qml @@ -31,42 +31,53 @@ Item { signal clicked(int sequenceNumber) + /// Add an initial 4 sided polygon if there is none /// Add an initial 4 sided polygon if there is none function _addInitialPolygon() { - if (_polygon.count < 3) { - // Initial polygon is inset to take 2/3rds space - var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height) - rect.x += (rect.width * 0.25) / 2 - rect.y += (rect.height * 0.25) / 2 - rect.width *= 0.25 - rect.height *= 0.25 - - var centerCoord = map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)), false /* clipToViewPort */) - var topLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */) - var topRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y), false /* clipToViewPort */) - var bottomLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y + rect.height), false /* clipToViewPort */) - var bottomRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */) - - // Adjust polygon to max size - var maxSize = 100 - var halfWidthMeters = Math.min(topLeftCoord.distanceTo(topRightCoord), maxSize) / 2 - var halfHeightMeters = Math.min(topLeftCoord.distanceTo(bottomLeftCoord), maxSize) / 2 - topLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 0) - topRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0) - bottomLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180) - bottomRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 180) - - _polygon.appendVertex(topLeftCoord) - _polygon.appendVertex(topRightCoord) - _polygon.appendVertex(bottomRightCoord) - _polygon.appendVertex(bottomLeftCoord) + + // Initial polygon is inset to take 2/3rds space + var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height) + rect.x += (rect.width * 0.25) / 2 + rect.y += (rect.height * 0.25) / 2 + rect.width *= 0.75 + rect.height *= 0.75 + + var centerCoord = map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)), false /* clipToViewPort */) + var topLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */) + var topRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y), false /* clipToViewPort */) + var bottomLeftCoord = map.toCoordinate(Qt.point(rect.x, rect.y + rect.height), false /* clipToViewPort */) + var bottomRightCoord = map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */) + + // Adjust polygon to max size + var maxSize = 100 + var halfWidthMeters = Math.min(topLeftCoord.distanceTo(topRightCoord), maxSize) / 2 + var halfHeightMeters = Math.min(topLeftCoord.distanceTo(bottomLeftCoord), maxSize) / 2 + topLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 0) + topRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0) + bottomLeftCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180) + bottomRightCoord = centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 180) + + if (areaItem.showBorderPolygon.rawValue === true) { + + if (areaItem.borderPolygon.count < 3) { + + areaItem.borderPolygon.appendVertex(topLeftCoord) + areaItem.borderPolygon.appendVertex(topRightCoord) + areaItem.borderPolygon.appendVertex(bottomRightCoord) + areaItem.borderPolygon.appendVertex(bottomLeftCoord) + } + } else { + if (_polygon.count < 3) { + + _polygon.appendVertex(topLeftCoord) + _polygon.appendVertex(topRightCoord) + _polygon.appendVertex(bottomRightCoord) + _polygon.appendVertex(bottomLeftCoord) + } } - } - /*function _addInitialPolyline(){ - _polyline.setStartVertexIndex(0); - _polyline.setEndVertexIndex(1); - }*/ + + } @@ -88,14 +99,14 @@ Item { interiorOpacity: 0.25 } - /*WimaMapPolylineVisuals { + WimaMapPolygonVisuals { qgcView: _root.qgcView mapControl: map - mapPolyline: _polyline - lineWidth: 4 - lineColor: interactive ? "white" : "yellow" - enableSplitHandels: false - enableDragHandels: true - edgeHandelsOnly: true - }*/ + mapPolygon: areaItem.borderPolygon + borderWidth: 1 + borderColor: areaItem.borderPolygon.interactive ? "white" : "transparent" + interiorColor: "transparent" + interiorOpacity: 1 + } + } -- 2.22.0