Commit 20b7fce7 authored by Don Gagne's avatar Don Gagne

Support for adjusting existing survey polygon

parent 8ba8c2c1
...@@ -137,11 +137,11 @@ Map { ...@@ -137,11 +137,11 @@ Map {
// Connections { // Connections {
// target: map.polygonDraw // target: map.polygonDraw
// //
// onPolygonStarted: { // onPolygonCaptureStarted: {
// // Polygon creation has started // // Polygon creation has started
// } // }
// //
// onPolygonFinished: { // onPolygonCaptureFinished: {
// // Polygon capture complete, coordinates signal variable contains the polygon points // // Polygon capture complete, coordinates signal variable contains the polygon points
// } // }
// } // }
...@@ -161,6 +161,30 @@ Map { ...@@ -161,6 +161,30 @@ Map {
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
text: qsTr("Click to add point %1").arg(ScreenTools.isMobile || !polygonDrawer.polygonReady ? "" : qsTr("- Right Click to end polygon")) text: qsTr("Click to add point %1").arg(ScreenTools.isMobile || !polygonDrawer.polygonReady ? "" : qsTr("- Right Click to end polygon"))
visible: polygonDrawer.drawingPolygon visible: polygonDrawer.drawingPolygon
Connections {
target: polygonDrawer
onDrawingPolygonChanged: {
if (polygonDrawer.drawingPolygon) {
polygonHelp.text = qsTr("Click to add point")
}
polygonHelp.visible = polygonDrawer.drawingPolygon
}
onPolygonReadyChanged: {
if (polygonDrawer.polygonReady && !ScreenTools.isMobile) {
polygonHelp.text = qsTr("Click to add point - Right Click to end polygon")
}
}
onAdjustingPolygonChanged: {
if (polygonDrawer.adjustingPolygon) {
polygonHelp.text = qsTr("Adjust polygon by dragging corners")
}
polygonHelp.visible = polygonDrawer.adjustingPolygon
}
}
} }
MouseArea { MouseArea {
...@@ -170,28 +194,40 @@ Map { ...@@ -170,28 +194,40 @@ Map {
visible: drawingPolygon visible: drawingPolygon
z: 1000 // Hack to fix MouseArea layering for now z: 1000 // Hack to fix MouseArea layering for now
property alias drawingPolygon: polygonDrawer.hoverEnabled property alias drawingPolygon: polygonDrawer.hoverEnabled
property bool polygonReady: polygonDrawerPolygon.path.length > 3 ///< true: enough points have been captured to create a closed polygon property bool adjustingPolygon: false
property bool polygonReady: polygonDrawerPolygon.path.length > 3 ///< true: enough points have been captured to create a closed polygon
/// New polygon capture has started /// New polygon capture has started
signal polygonStarted signal polygonCaptureStarted
/// Polygon capture is complete /// Polygon capture is complete
/// @param coordinates Map coordinates for the polygon points /// @param coordinates Map coordinates for the polygon points
signal polygonFinished(var coordinates) signal polygonCaptureFinished(var coordinates)
/// Polygon adjustment has begun
signal polygonAdjustStarted
/// Polygon Vertex coordinate has been adjusted
signal polygonAdjustVertex(int vertexIndex, var vertexCoordinate)
/// Polygon adjustment finished
signal polygonAdjustFinished
property var _vertexDragList: []
/// Begin capturing a new polygon /// Begin capturing a new polygon
/// polygonStarted will be signalled /// polygonCaptureStarted will be signalled
function startPolygon() { function startCapturePolygon() {
polygonDrawer.drawingPolygon = true polygonDrawer.drawingPolygon = true
polygonDrawer._clearPolygon() polygonDrawer._clearPolygon()
polygonDrawer.polygonStarted() polygonDrawer.polygonCaptureStarted()
} }
/// Finish capturing the polygon /// Finish capturing the polygon
/// polygonFinished will be signalled /// polygonCaptureFinished will be signalled
/// @return true: polygon completed, false: not enough points to complete polygon /// @return true: polygon completed, false: not enough points to complete polygon
function finishPolygon() { function finishCapturePolygon() {
if (!polygonDrawer.polygonReady) { if (!polygonDrawer.polygonReady) {
return false return false
} }
...@@ -200,10 +236,82 @@ Map { ...@@ -200,10 +236,82 @@ Map {
polygonPath.pop() // get rid of drag coordinate polygonPath.pop() // get rid of drag coordinate
polygonDrawer._clearPolygon() polygonDrawer._clearPolygon()
polygonDrawer.drawingPolygon = false polygonDrawer.drawingPolygon = false
polygonDrawer.polygonFinished(polygonPath) polygonDrawer.polygonCaptureFinished(polygonPath)
return true return true
} }
function startAdjustPolygon(vertexCoordinates) {
polygonDrawer.adjustingPolygon = true
for (var i=0; i<vertexCoordinates.length; i++) {
var mapItem = Qt.createQmlObject(
"import QtQuick 2.5; " +
"import QtLocation 5.3; " +
"import QGroundControl.ScreenTools 1.0; " +
"Rectangle {" +
" id: vertexDrag; " +
" width: _sideLength; " +
" height: _sideLength; " +
" color: 'red'; " +
"" +
" property var coordinate; " +
" property int index; " +
"" +
" readonly property real _sideLength: ScreenTools.defaultFontPixelWidth * 2; " +
" readonly property real _halfSideLength: _sideLength / 2; " +
"" +
" Drag.active: dragMouseArea.drag.active; " +
" Drag.hotSpot.x: _halfSideLength; " +
" Drag.hotSpot.y: _halfSideLength; " +
"" +
" onXChanged: updateCoordinate(); " +
" onYChanged: updateCoordinate(); " +
"" +
" function updateCoordinate() { " +
" vertexDrag.coordinate = _map.toCoordinate(Qt.point(vertexDrag.x + _halfSideLength, vertexDrag.y + _halfSideLength), false); " +
" polygonDrawer.polygonAdjustVertex(vertexDrag.index, vertexDrag.coordinate); " +
" } " +
"" +
" function updatePosition() { " +
" var vertexPoint = _map.fromCoordinate(coordinate, false); " +
" vertexDrag.x = vertexPoint.x - _halfSideLength; " +
" vertexDrag.y = vertexPoint.y - _halfSideLength; " +
" } " +
"" +
" Connections { " +
" target: _map; " +
" onCenterChanged: updatePosition(); " +
" onZoomLevelChanged: updatePosition(); " +
" } " +
"" +
" MouseArea { " +
" id: dragMouseArea; " +
" anchors.fill: parent; " +
" drag.target: parent; " +
" drag.minimumX: 0; " +
" drag.minimumY: 0; " +
" drag.maximumX: _map.width - parent.width; " +
" drag.maximumY: _map.height - parent.height; " +
" } " +
"} ",
_map)
mapItem.z = QGroundControl.zOrderMapItems + 1
mapItem.coordinate = vertexCoordinates[i]
mapItem.index = i
mapItem.updatePosition()
polygonDrawer._vertexDragList.push(mapItem)
polygonDrawer.polygonAdjustStarted()
}
}
function finishAdjustPolygon() {
polygonDrawer.adjustingPolygon = false
for (var i=0; i<polygonDrawer._vertexDragList.length; i++) {
polygonDrawer._vertexDragList[i].destroy()
}
polygonDrawer._vertexDragList = []
polygonDrawer.polygonAdjustFinished()
}
function _clearPolygon() { function _clearPolygon() {
// Simpler methods to clear the path simply don't work due to bugs. This craziness does. // Simpler methods to clear the path simply don't work due to bugs. This craziness does.
var bogusCoord = _map.toCoordinate(Qt.point(height/2, width/2)) var bogusCoord = _map.toCoordinate(Qt.point(height/2, width/2))
...@@ -242,7 +350,7 @@ Map { ...@@ -242,7 +350,7 @@ Map {
polygonPath.push(clickCoordinate) polygonPath.push(clickCoordinate)
polygonDrawerPolygon.path = polygonPath polygonDrawerPolygon.path = polygonPath
} else if (polygonDrawer.polygonReady) { } else if (polygonDrawer.polygonReady) {
finishPolygon() finishCapturePolygon()
} }
} }
...@@ -261,6 +369,7 @@ Map { ...@@ -261,6 +369,7 @@ Map {
} }
} }
/// Polygon being drawn
MapPolygon { MapPolygon {
id: polygonDrawerPolygon id: polygonDrawerPolygon
color: "blue" color: "blue"
...@@ -268,6 +377,7 @@ Map { ...@@ -268,6 +377,7 @@ Map {
visible: polygonDrawer.drawingPolygon visible: polygonDrawer.drawingPolygon
} }
/// Next line for polygon
MapPolyline { MapPolyline {
id: polygonDrawerNextPoint id: polygonDrawerNextPoint
line.color: "green" line.color: "green"
......
...@@ -101,26 +101,42 @@ Rectangle { ...@@ -101,26 +101,42 @@ Rectangle {
Connections { Connections {
target: editorMap.polygonDraw target: editorMap.polygonDraw
onPolygonStarted: { onPolygonCaptureStarted: {
missionItem.clearPolygon() missionItem.clearPolygon()
} }
onPolygonFinished: { onPolygonCaptureFinished: {
for (var i=0; i<coordinates.length; i++) { for (var i=0; i<coordinates.length; i++) {
missionItem.addPolygonCoordinate(coordinates[i]) missionItem.addPolygonCoordinate(coordinates[i])
} }
} }
onPolygonAdjustVertex: missionItem.adjustPolygonCoordinate(vertexIndex, vertexCoordinate)
} }
QGCButton { QGCButton {
text: editorMap.polygonDraw.drawingPolygon ? qsTr("Finish Polygon") : qsTr("Draw Polygon") text: editorMap.polygonDraw.drawingPolygon ? qsTr("Finish Draw") : qsTr("Draw Polygon")
enabled: (editorMap.polygonDraw.drawingPolygon && editorMap.polygonDraw.polygonReady) || !editorMap.polygonDraw.drawingPolygon enabled: ((editorMap.polygonDraw.drawingPolygon && editorMap.polygonDraw.polygonReady) || !editorMap.polygonDraw.drawingPolygon) &&
!editorMap.polygonDraw.adjustingPolygon
onClicked: { onClicked: {
if (editorMap.polygonDraw.drawingPolygon) { if (editorMap.polygonDraw.drawingPolygon) {
editorMap.polygonDraw.finishPolygon() editorMap.polygonDraw.finishCapturePolygon()
} else {
editorMap.polygonDraw.startCapturePolygon()
}
}
}
QGCButton {
text: editorMap.polygonDraw.adjustingPolygon ? qsTr("Finish Adjust") : qsTr("Adjust Polygon")
enabled: !editorMap.polygonDraw.drawingPolygon
onClicked: {
if (editorMap.polygonDraw.adjustingPolygon) {
editorMap.polygonDraw.finishAdjustPolygon()
} else { } else {
editorMap.polygonDraw.startPolygon() editorMap.polygonDraw.startAdjustPolygon(missionItem.polygonPath)
} }
} }
} }
......
...@@ -87,6 +87,14 @@ void ComplexMissionItem::addPolygonCoordinate(const QGeoCoordinate coordinate) ...@@ -87,6 +87,14 @@ void ComplexMissionItem::addPolygonCoordinate(const QGeoCoordinate coordinate)
setDirty(true); setDirty(true);
} }
void ComplexMissionItem::adjustPolygonCoordinate(int vertexIndex, const QGeoCoordinate coordinate)
{
_polygonPath[vertexIndex] = QVariant::fromValue(coordinate);
emit polygonPathChanged();
_generateGrid();
setDirty(true);
}
int ComplexMissionItem::lastSequenceNumber(void) const int ComplexMissionItem::lastSequenceNumber(void) const
{ {
int lastSeq = _sequenceNumber; int lastSeq = _sequenceNumber;
......
...@@ -37,6 +37,7 @@ public: ...@@ -37,6 +37,7 @@ public:
Q_INVOKABLE void clearPolygon(void); Q_INVOKABLE void clearPolygon(void);
Q_INVOKABLE void addPolygonCoordinate(const QGeoCoordinate coordinate); Q_INVOKABLE void addPolygonCoordinate(const QGeoCoordinate coordinate);
Q_INVOKABLE void adjustPolygonCoordinate(int vertexIndex, const QGeoCoordinate coordinate);
QVariantList polygonPath(void) { return _polygonPath; } QVariantList polygonPath(void) { return _polygonPath; }
QVariantList gridPoints (void) { return _gridPoints; } QVariantList gridPoints (void) { return _gridPoints; }
......
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