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

Support for adjusting existing survey polygon

parent 8ba8c2c1
......@@ -137,11 +137,11 @@ Map {
// Connections {
// target: map.polygonDraw
//
// onPolygonStarted: {
// onPolygonCaptureStarted: {
// // Polygon creation has started
// }
//
// onPolygonFinished: {
// onPolygonCaptureFinished: {
// // Polygon capture complete, coordinates signal variable contains the polygon points
// }
// }
......@@ -161,6 +161,30 @@ Map {
horizontalAlignment: Text.AlignHCenter
text: qsTr("Click to add point %1").arg(ScreenTools.isMobile || !polygonDrawer.polygonReady ? "" : qsTr("- Right Click to end polygon"))
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 {
......@@ -170,28 +194,40 @@ Map {
visible: drawingPolygon
z: 1000 // Hack to fix MouseArea layering for now
property alias drawingPolygon: polygonDrawer.hoverEnabled
property bool polygonReady: polygonDrawerPolygon.path.length > 3 ///< true: enough points have been captured to create a closed polygon
property alias drawingPolygon: polygonDrawer.hoverEnabled
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
signal polygonStarted
signal polygonCaptureStarted
/// Polygon capture is complete
/// @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
/// polygonStarted will be signalled
function startPolygon() {
/// polygonCaptureStarted will be signalled
function startCapturePolygon() {
polygonDrawer.drawingPolygon = true
polygonDrawer._clearPolygon()
polygonDrawer.polygonStarted()
polygonDrawer.polygonCaptureStarted()
}
/// Finish capturing the polygon
/// polygonFinished will be signalled
/// polygonCaptureFinished will be signalled
/// @return true: polygon completed, false: not enough points to complete polygon
function finishPolygon() {
function finishCapturePolygon() {
if (!polygonDrawer.polygonReady) {
return false
}
......@@ -200,10 +236,82 @@ Map {
polygonPath.pop() // get rid of drag coordinate
polygonDrawer._clearPolygon()
polygonDrawer.drawingPolygon = false
polygonDrawer.polygonFinished(polygonPath)
polygonDrawer.polygonCaptureFinished(polygonPath)
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() {
// 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))
......@@ -242,7 +350,7 @@ Map {
polygonPath.push(clickCoordinate)
polygonDrawerPolygon.path = polygonPath
} else if (polygonDrawer.polygonReady) {
finishPolygon()
finishCapturePolygon()
}
}
......@@ -261,6 +369,7 @@ Map {
}
}
/// Polygon being drawn
MapPolygon {
id: polygonDrawerPolygon
color: "blue"
......@@ -268,6 +377,7 @@ Map {
visible: polygonDrawer.drawingPolygon
}
/// Next line for polygon
MapPolyline {
id: polygonDrawerNextPoint
line.color: "green"
......
......@@ -101,26 +101,42 @@ Rectangle {
Connections {
target: editorMap.polygonDraw
onPolygonStarted: {
onPolygonCaptureStarted: {
missionItem.clearPolygon()
}
onPolygonFinished: {
onPolygonCaptureFinished: {
for (var i=0; i<coordinates.length; i++) {
missionItem.addPolygonCoordinate(coordinates[i])
}
}
onPolygonAdjustVertex: missionItem.adjustPolygonCoordinate(vertexIndex, vertexCoordinate)
}
QGCButton {
text: editorMap.polygonDraw.drawingPolygon ? qsTr("Finish Polygon") : qsTr("Draw Polygon")
enabled: (editorMap.polygonDraw.drawingPolygon && editorMap.polygonDraw.polygonReady) || !editorMap.polygonDraw.drawingPolygon
text: editorMap.polygonDraw.drawingPolygon ? qsTr("Finish Draw") : qsTr("Draw Polygon")
enabled: ((editorMap.polygonDraw.drawingPolygon && editorMap.polygonDraw.polygonReady) || !editorMap.polygonDraw.drawingPolygon) &&
!editorMap.polygonDraw.adjustingPolygon
onClicked: {
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 {
editorMap.polygonDraw.startPolygon()
editorMap.polygonDraw.startAdjustPolygon(missionItem.polygonPath)
}
}
}
......
......@@ -87,6 +87,14 @@ void ComplexMissionItem::addPolygonCoordinate(const QGeoCoordinate coordinate)
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 lastSeq = _sequenceNumber;
......
......@@ -37,6 +37,7 @@ public:
Q_INVOKABLE void clearPolygon(void);
Q_INVOKABLE void addPolygonCoordinate(const QGeoCoordinate coordinate);
Q_INVOKABLE void adjustPolygonCoordinate(int vertexIndex, const QGeoCoordinate coordinate);
QVariantList polygonPath(void) { return _polygonPath; }
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