Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
fb486d9c
Commit
fb486d9c
authored
Mar 02, 2017
by
Don Gagne
Browse files
Convert polygon editing to dynamic objects
parent
1991d269
Changes
9
Hide whitespace changes
Inline
Side-by-side
qgroundcontrol.qrc
View file @
fb486d9c
...
...
@@ -133,8 +133,10 @@
<file alias="QGroundControl/FlightMap/InstrumentSwipeView.qml">src/FlightMap/Widgets/InstrumentSwipeView.qml</file>
<file alias="QGroundControl/FlightMap/MapScale.qml">src/FlightMap/MapScale.qml</file>
<file alias="QGroundControl/FlightMap/MissionItemIndicator.qml">src/FlightMap/MapItems/MissionItemIndicator.qml</file>
<file alias="QGroundControl/FlightMap/MissionItemIndicatorDrag.qml">src/FlightMap/MapItems/MissionItemIndicatorDrag.qml</file>
<file alias="QGroundControl/FlightMap/MissionItemView.qml">src/FlightMap/MapItems/MissionItemView.qml</file>
<file alias="QGroundControl/FlightMap/MissionLineView.qml">src/FlightMap/MapItems/MissionLineView.qml</file>
<file alias="QGroundControl/FlightMap/PolygonEditor.qml">src/FlightMap/MapItems/PolygonEditor.qml</file>
<file alias="QGroundControl/FlightMap/QGCArtificialHorizon.qml">src/FlightMap/Widgets/QGCArtificialHorizon.qml</file>
<file alias="QGroundControl/FlightMap/QGCAttitudeHUD.qml">src/FlightMap/Widgets/QGCAttitudeHUD.qml</file>
<file alias="QGroundControl/FlightMap/QGCAttitudeWidget.qml">src/FlightMap/Widgets/QGCAttitudeWidget.qml</file>
...
...
src/FlightMap/FlightMap.qml
View file @
fb486d9c
...
...
@@ -137,292 +137,4 @@ Map {
label
:
"
Q
"
}
}
//---- Polygon drawing code
//
// Usage:
//
// Connections {
// target: map.polygonDraw
//
// onPolygonCaptureStarted: {
// // Polygon creation has started
// }
//
// onPolygonCaptureFinished: {
// // Polygon capture complete, coordinates signal variable contains the polygon points
// }
// }
//
// map.polygonDraqw.startPolgyon() - begin capturing a new polygon
// map.polygonDraqw.endPolygon() - end capture (right-click will also end capture)
// Not sure why this is needed, but trying to reference polygonDrawer directly from other code doesn't work
property
alias
polygonDraw
:
polygonDrawer
QGCMapLabel
{
id
:
polygonHelp
anchors.topMargin
:
parent
.
height
-
ScreenTools
.
availableHeight
anchors.top
:
parent
.
top
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
horizontalAlignment
:
Text
.
AlignHCenter
map
:
_map
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
{
id
:
polygonDrawer
anchors.fill
:
parent
acceptedButtons
:
Qt
.
LeftButton
|
Qt
.
RightButton
visible
:
drawingPolygon
z
:
1000
// Hack to fix MouseArea layering for now
property
alias
drawingPolygon
:
polygonDrawer
.
hoverEnabled
property
bool
adjustingPolygon
:
false
property
bool
polygonReady
:
polygonDrawerPolygonSet
.
path
.
length
>
2
///< true: enough points have been captured to create a closed polygon
property
bool
justClicked
:
false
property
var
_callbackObject
property
var
_vertexDragList
:
[]
/// Begin capturing a new polygon
/// polygonCaptureStarted will be signalled
function
startCapturePolygon
(
callback
)
{
polygonDrawer
.
_callbackObject
=
callback
polygonDrawer
.
drawingPolygon
=
true
polygonDrawer
.
_clearPolygon
()
polygonDrawer
.
_callbackObject
.
polygonCaptureStarted
()
}
/// Finish capturing the polygon
/// polygonCaptureFinished will be signalled
/// @return true: polygon completed, false: not enough points to complete polygon
function
finishCapturePolygon
()
{
if
(
!
polygonDrawer
.
polygonReady
)
{
return
false
}
var
polygonPath
=
polygonDrawerPolygonSet
.
path
_cancelCapturePolygon
()
polygonDrawer
.
_callbackObject
.
polygonCaptureFinished
(
polygonPath
)
return
true
}
function
startAdjustPolygon
(
callback
,
vertexCoordinates
)
{
polygonDraw
.
_callbackObject
=
callback
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 + _expandMargin;
"
+
"
height: _sideLength + _expandMargin;
"
+
"
color: 'red';
"
+
""
+
"
property var coordinate;
"
+
"
property int index;
"
+
""
+
"
readonly property real _sideLength: ScreenTools.defaultFontPixelWidth * 2;
"
+
"
readonly property real _halfSideLength: _sideLength / 2;
"
+
""
+
"
property real _expandMargin: ScreenTools.isMobile ? ScreenTools.defaultFontPixelWidth : 0;
"
+
""
+
"
Drag.active: dragMouseArea.drag.active;
"
+
""
+
"
onXChanged: updateCoordinate();
"
+
"
onYChanged: updateCoordinate();
"
+
""
+
"
function updateCoordinate() {
"
+
"
vertexDrag.coordinate = _map.toCoordinate(Qt.point(vertexDrag.x + _expandMargin + _halfSideLength, vertexDrag.y + _expandMargin + _halfSideLength), false);
"
+
"
polygonDrawer._callbackObject.polygonAdjustVertex(vertexDrag.index, vertexDrag.coordinate);
"
+
"
}
"
+
""
+
"
function updatePosition() {
"
+
"
var vertexPoint = _map.fromCoordinate(coordinate, false);
"
+
"
vertexDrag.x = vertexPoint.x - _expandMargin - _halfSideLength;
"
+
"
vertexDrag.y = vertexPoint.y - _expandMargin - _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
.
_callbackObject
.
polygonAdjustStarted
()
}
}
function
finishAdjustPolygon
()
{
_cancelAdjustPolygon
()
polygonDrawer
.
_callbackObject
.
polygonAdjustFinished
()
}
/// Cancels an in progress draw or adjust
function
cancelPolygonEdit
()
{
_cancelAdjustPolygon
()
_cancelCapturePolygon
()
}
function
_cancelAdjustPolygon
()
{
polygonDrawer
.
adjustingPolygon
=
false
for
(
var
i
=
0
;
i
<
polygonDrawer
.
_vertexDragList
.
length
;
i
++
)
{
polygonDrawer
.
_vertexDragList
[
i
].
destroy
()
}
polygonDrawer
.
_vertexDragList
=
[]
}
function
_cancelCapturePolygon
()
{
polygonDrawer
.
_clearPolygon
()
polygonDrawer
.
drawingPolygon
=
false
}
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
))
polygonDrawerPolygon
.
path
=
[
bogusCoord
,
bogusCoord
]
polygonDrawerNextPoint
.
path
=
[
bogusCoord
,
bogusCoord
]
polygonDrawerPolygon
.
path
=
[
]
polygonDrawerNextPoint
.
path
=
[
]
polygonDrawerPolygonSet
.
path
=
[
bogusCoord
,
bogusCoord
]
polygonDrawerPolygonSet
.
path
=
[
]
}
onClicked
:
{
if
(
mouse
.
button
==
Qt
.
LeftButton
)
{
polygonDrawer
.
justClicked
=
true
if
(
polygonDrawerPolygon
.
path
.
length
>
2
)
{
// Make sure the new line doesn't intersect the existing polygon
var
lastSegment
=
polygonDrawerPolygon
.
path
.
length
-
2
var
newLineA
=
_map
.
fromCoordinate
(
polygonDrawerPolygon
.
path
[
lastSegment
],
false
/* clipToViewPort */
)
var
newLineB
=
_map
.
fromCoordinate
(
polygonDrawerPolygon
.
path
[
lastSegment
+
1
],
false
/* clipToViewPort */
)
for
(
var
i
=
0
;
i
<
lastSegment
;
i
++
)
{
var
oldLineA
=
_map
.
fromCoordinate
(
polygonDrawerPolygon
.
path
[
i
],
false
/* clipToViewPort */
)
var
oldLineB
=
_map
.
fromCoordinate
(
polygonDrawerPolygon
.
path
[
i
+
1
],
false
/* clipToViewPort */
)
if
(
QGroundControl
.
linesIntersect
(
newLineA
,
newLineB
,
oldLineA
,
oldLineB
))
{
return
;
}
}
}
var
clickCoordinate
=
_map
.
toCoordinate
(
Qt
.
point
(
mouse
.
x
,
mouse
.
y
))
var
polygonPath
=
polygonDrawerPolygon
.
path
if
(
polygonPath
.
length
==
0
)
{
// Add first coordinate
polygonPath
.
push
(
clickCoordinate
)
}
else
{
// Add subsequent coordinate
if
(
ScreenTools
.
isMobile
)
{
// Since mobile has no mouse, the onPositionChangedHandler will not fire. We have to add the coordinate
// here instead.
polygonDrawer
.
justClicked
=
false
polygonPath
.
push
(
clickCoordinate
)
}
else
{
// The onPositionChanged handler for mouse movement will have already added the coordinate to the array.
// Just update it to the final position
polygonPath
[
polygonDrawerPolygon
.
path
.
length
-
1
]
=
clickCoordinate
}
}
polygonDrawerPolygonSet
.
path
=
polygonPath
polygonDrawerPolygon
.
path
=
polygonPath
}
else
if
(
polygonDrawer
.
polygonReady
)
{
finishCapturePolygon
()
}
}
onPositionChanged
:
{
if
(
ScreenTools
.
isMobile
)
{
// We don't track mouse drag on mobile
return
}
if
(
polygonDrawerPolygon
.
path
.
length
)
{
var
dragCoordinate
=
_map
.
toCoordinate
(
Qt
.
point
(
mouse
.
x
,
mouse
.
y
))
var
polygonPath
=
polygonDrawerPolygon
.
path
if
(
polygonDrawer
.
justClicked
){
// Add new drag coordinate
polygonPath
.
push
(
dragCoordinate
)
polygonDrawer
.
justClicked
=
false
}
// Update drag line
polygonDrawerNextPoint
.
path
=
[
polygonDrawerPolygon
.
path
[
polygonDrawerPolygon
.
path
.
length
-
2
],
dragCoordinate
]
polygonPath
[
polygonDrawerPolygon
.
path
.
length
-
1
]
=
dragCoordinate
polygonDrawerPolygon
.
path
=
polygonPath
}
}
}
/// Polygon being drawn
MapPolygon
{
id
:
polygonDrawerPolygon
color
:
"
blue
"
opacity
:
0.5
visible
:
polygonDrawerPolygon
.
path
.
length
>
2
}
MapPolygon
{
id
:
polygonDrawerPolygonSet
color
:
'
green
'
opacity
:
0.5
visible
:
polygonDrawer
.
polygonReady
}
/// Next line for polygon
MapPolyline
{
id
:
polygonDrawerNextPoint
line.color
:
"
green
"
line.width
:
3
visible
:
polygonDrawer
.
drawingPolygon
}
//---- End Polygon Drawing code
}
// Map
src/FlightMap/MapItems/MissionItemIndicatorDrag.qml
0 → 100644
View file @
fb486d9c
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import
QtQuick
2.4
import
QtLocation
5.3
import
QGroundControl
1.0
import
QGroundControl
.
ScreenTools
1.0
import
QGroundControl
.
Controls
1.0
/// Use the drag a MissionItemIndicator
Rectangle
{
id
:
itemDragger
x
:
itemIndicator
.
x
-
_expandMargin
y
:
itemIndicator
.
y
-
_expandMargin
width
:
itemIndicator
.
width
+
(
_expandMargin
*
2
)
height
:
itemIndicator
.
height
+
(
_expandMargin
*
2
)
color
:
"
transparent
"
z
:
QGroundControl
.
zOrderMapItems
+
1
// Above item icons
// These are handy for debugging so left in for now
//border.width: 1
//border.color: "white"
// Properties which must be specific by consumer
property
var
itemIndicator
///< The mission item indicator to drag around
property
var
itemCoordinate
///< Coordinate we are updating during drag
property
bool
_preventCoordinateBindingLoop
:
false
property
real
_expandMargin
:
ScreenTools
.
isMobile
?
ScreenTools
.
defaultFontPixelWidth
:
0
onXChanged
:
liveDrag
()
onYChanged
:
liveDrag
()
function
liveDrag
()
{
if
(
!
itemDragger
.
_preventCoordinateBindingLoop
&&
Drag
.
active
)
{
var
point
=
Qt
.
point
(
itemDragger
.
x
+
_expandMargin
+
itemIndicator
.
anchorPoint
.
x
,
itemDragger
.
y
+
_expandMargin
+
itemIndicator
.
anchorPoint
.
y
)
var
coordinate
=
map
.
toCoordinate
(
point
)
itemDragger
.
_preventCoordinateBindingLoop
=
true
coordinate
.
altitude
=
itemCoordinate
.
altitude
itemCoordinate
=
coordinate
itemDragger
.
_preventCoordinateBindingLoop
=
false
}
}
Drag.active
:
itemDrag
.
drag
.
active
MouseArea
{
id
:
itemDrag
anchors.fill
:
parent
drag.target
:
parent
drag.minimumX
:
0
drag.minimumY
:
0
drag.maximumX
:
itemDragger
.
parent
.
width
-
parent
.
width
drag.maximumY
:
itemDragger
.
parent
.
height
-
parent
.
height
}
}
src/FlightMap/MapItems/PolygonEditor.qml
0 → 100644
View file @
fb486d9c
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import
QtQuick
2.4
import
QtLocation
5.3
import
QGroundControl
1.0
import
QGroundControl
.
ScreenTools
1.0
import
QGroundControl
.
Controls
1.0
/// Polygon drawing item. Add to your control and call methods to get support for polygon drawing and adjustment.
Item
{
id
:
_root
// These properties must be provided by the consumer
property
var
map
///< Map control
property
var
callbackObject
///< Callback item
// These properties can be queried by the consumer
property
bool
drawingPolygon
:
false
property
bool
adjustingPolygon
:
false
property
bool
polygonReady
:
_currentPolygon
?
_currentPolygon
.
path
.
length
>
2
:
false
///< true: enough points have been captured to create a closed polygon
property
var
_helpLabel
///< Dynamically added help label component
property
var
_newPolygon
///< Dynamically added polygon which represents all polygon points including the one currently being drawn
property
var
_currentPolygon
///< Dynamically added polygon which represents the currently completed polygon
property
var
_nextPointLine
///< Dynamically added line which goes from last polygon point to the new one being drawn
property
var
_mouseArea
///< Dynamically added MouseArea which handles all clicking and mouse movement
property
var
_vertexDragList
:
[
]
///< Dynamically added vertex drag points
/// Begin capturing a new polygon
/// polygonCaptureStarted will be signalled through callbackObject
function
startCapturePolygon
()
{
_helpLabel
=
helpLabelComponent
.
createObject
(
map
)
_newPolygon
=
newPolygonComponent
.
createObject
(
map
)
_currentPolygon
=
currentPolygonComponent
.
createObject
(
map
)
_nextPointLine
=
nextPointComponent
.
createObject
(
map
)
_mouseArea
=
mouseAreaComponent
.
createObject
(
map
)
map
.
addMapItem
(
_newPolygon
)
map
.
addMapItem
(
_currentPolygon
)
map
.
addMapItem
(
_nextPointLine
)
drawingPolygon
=
true
callbackObject
.
polygonCaptureStarted
()
}
/// Finish capturing the polygon
/// polygonCaptureFinished will be signalled through callbackObject
/// @return true: polygon completed, false: not enough points to complete polygon
function
finishCapturePolygon
()
{
if
(
!
polygonReady
)
{
return
false
}
var
polygonPath
=
_currentPolygon
.
path
_cancelCapturePolygon
()
callbackObject
.
polygonCaptureFinished
(
polygonPath
)
return
true
}
function
startAdjustPolygon
(
vertexCoordinates
)
{
adjustingPolygon
=
true
for
(
var
i
=
0
;
i
<
vertexCoordinates
.
length
;
i
++
)
{
var
dragItem
=
Qt
.
createQmlObject
(
"
import QtQuick 2.5;
"
+
"
import QtLocation 5.3;
"
+
"
import QGroundControl.ScreenTools 1.0;
"
+
""
+
"
Rectangle {
"
+
"
id: vertexDrag;
"
+
"
width: _sideLength + _expandMargin;
"
+
"
height: _sideLength + _expandMargin;
"
+
"
color: 'red';
"
+
""
+
"
property var coordinate;
"
+
"
property int index;
"
+
""
+
"
readonly property real _sideLength: ScreenTools.defaultFontPixelWidth * 2;
"
+
"
readonly property real _halfSideLength: _sideLength / 2;
"
+
""
+
"
property real _expandMargin: ScreenTools.isMobile ? ScreenTools.defaultFontPixelWidth : 0;
"
+
""
+
"
Drag.active: dragMouseArea.drag.active;
"
+
""
+
"
onXChanged: updateCoordinate();
"
+
"
onYChanged: updateCoordinate();
"
+
""
+
"
function updateCoordinate() {
"
+
"
vertexDrag.coordinate = map.toCoordinate(Qt.point(vertexDrag.x + _expandMargin + _halfSideLength, vertexDrag.y + _expandMargin + _halfSideLength), false);
"
+
"
callbackObject.polygonAdjustVertex(vertexDrag.index, vertexDrag.coordinate);
"
+
"
}
"
+
""
+
"
function updatePosition() {
"
+
"
var vertexPoint = map.fromCoordinate(coordinate, false);
"
+
"
vertexDrag.x = vertexPoint.x - _expandMargin - _halfSideLength;
"
+
"
vertexDrag.y = vertexPoint.y - _expandMargin - _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
)
dragItem
.
z
=
QGroundControl
.
zOrderMapItems
+
1
dragItem
.
coordinate
=
vertexCoordinates
[
i
]
dragItem
.
index
=
i
dragItem
.
updatePosition
()
_vertexDragList
.
push
(
dragItem
)
callbackObject
.
polygonAdjustStarted
()
}
}
function
finishAdjustPolygon
()
{
_cancelAdjustPolygon
()
callbackObject
.
polygonAdjustFinished
()
}
/// Cancels an in progress draw or adjust
function
cancelPolygonEdit
()
{
_cancelAdjustPolygon
()
_cancelCapturePolygon
()
}
function
_cancelAdjustPolygon
()
{
adjustingPolygon
=
false
for
(
var
i
=
0
;
i
<
_vertexDragList
.
length
;
i
++
)
{
_vertexDragList
[
i
].
destroy
()
}
_vertexDragList
=
[]
}
function
_cancelCapturePolygon
()
{
_helpLabel
.
destroy
()
_newPolygon
.
destroy
()
_currentPolygon
.
destroy
()
_nextPointLine
.
destroy
()
_mouseArea
.
destroy
()
drawingPolygon
=
false
}
Component
{
id
:
helpLabelComponent
QGCMapLabel
{
id
:
polygonHelp
anchors.topMargin
:
parent
.
height
-
ScreenTools
.
availableHeight
anchors.top
:
parent
.
top
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
horizontalAlignment
:
Text
.
AlignHCenter
map
:
_root
.
map
text
:
qsTr
(
"
Click to add point %1
"
).
arg
(
ScreenTools
.
isMobile
||
!
polygonReady
?
""
:
qsTr
(
"
- Right Click to end polygon
"
))
Connections
{
target
:
_root
onDrawingPolygonChanged
:
{
if
(
drawingPolygon
)
{
polygonHelp
.
text
=
qsTr
(
"
Click to add point
"
)
}
polygonHelp
.
visible
=
drawingPolygon
}
onPolygonReadyChanged
:
{
if
(
polygonReady
&&
!
ScreenTools
.
isMobile
)
{
polygonHelp
.
text
=
qsTr
(
"
Click to add point - Right Click to end polygon
"
)
}
}
onAdjustingPolygonChanged
:
{
if
(
adjustingPolygon
)
{
polygonHelp
.
text
=
qsTr
(
"
Adjust polygon by dragging corners
"
)
}
polygonHelp
.
visible
=
adjustingPolygon
}
}
}
}
Component
{
id
:
mouseAreaComponent
MouseArea
{
anchors.fill
:
map
acceptedButtons
:
Qt
.
LeftButton
|
Qt
.
RightButton
hoverEnabled
:
true
z
:
QGroundControl
.
zOrderMapItems
+
1
property
bool
justClicked
:
false
onClicked
:
{
if
(
mouse
.
button
==
Qt
.
LeftButton
)
{
justClicked
=
true
if
(
_newPolygon
.
path
.
length
>
2
)
{
// Make sure the new line doesn't intersect the existing polygon
var
lastSegment
=
_newPolygon
.
path
.
length
-
2
var
newLineA
=
map
.
fromCoordinate
(
_newPolygon
.
path
[
lastSegment
],
false
/* clipToViewPort */
)
var
newLineB
=
map
.
fromCoordinate
(
_newPolygon
.
path
[
lastSegment
+
1
],
false
/* clipToViewPort */
)
for
(
var
i
=
0
;
i
<
lastSegment
;
i
++
)
{
var
oldLineA
=
map
.
fromCoordinate
(
_newPolygon
.
path
[
i
],
false
/* clipToViewPort */
)
var
oldLineB
=
map
.
fromCoordinate
(
_newPolygon
.
path
[
i
+
1
],
false
/* clipToViewPort */
)
if
(
QGroundControl
.
linesIntersect
(
newLineA
,
newLineB
,
oldLineA
,
oldLineB
))
{
return
;
}
}
}
var
clickCoordinate
=
map
.
toCoordinate
(
Qt
.
point
(
mouse
.
x
,
mouse
.
y
))
var
polygonPath
=
_newPolygon
.
path
if
(
polygonPath
.
length
==
0
)
{
// Add first coordinate
polygonPath
.
push
(
clickCoordinate
)
}
else
{
// Add subsequent coordinate
if
(
ScreenTools
.
isMobile
)
{
// Since mobile has no mouse, the onPositionChangedHandler will not fire. We have to add the coordinate
// here instead.
justClicked
=
false
polygonPath
.
push
(
clickCoordinate
)
}
else
{
// The onPositionChanged handler for mouse movement will have already added the coordinate to the array.
// Just update it to the final position
polygonPath
[
_newPolygon
.
path
.
length
-
1
]
=
clickCoordinate
}
}
_currentPolygon
.
path
=
polygonPath
_newPolygon
.
path
=
polygonPath
}
else
if
(
polygonReady
)
{
finishCapturePolygon
()
}
}
onPositionChanged
:
{
if
(
ScreenTools
.
isMobile
)
{
// We don't track mouse drag on mobile
return
}
if
(
_newPolygon
.
path
.
length
)
{
var
dragCoordinate
=
map
.
toCoordinate
(
Qt
.
point
(
mouse
.
x
,
mouse
.
y
))
var
polygonPath
=
_newPolygon
.
path
if
(
justClicked
){
// Add new drag coordinate
polygonPath
.
push
(
dragCoordinate
)
justClicked
=
false
}
// Update drag line
_nextPointLine
.
path
=
[
_newPolygon
.
path
[
_newPolygon
.
path
.
length
-
2
],
dragCoordinate
]
polygonPath
[
_newPolygon
.
path
.
length
-
1
]
=
dragCoordinate
_newPolygon
.
path
=
polygonPath
}
}
}
}
/// Polygon being drawn, including new point
Component
{
id
:
newPolygonComponent
MapPolygon
{
color
:
"
blue
"
opacity
:
0.5
visible
:
path
.
length
>
2
}
}
/// Current complete polygon
Component
{
id
:
currentPolygonComponent
MapPolygon
{
color
:
'
green
'
opacity
:
0.5
visible
:
polygonReady
}
}
/// Next line for polygon
Component
{
id
:
nextPointComponent
MapPolyline
{
line.color
:
"
green
"
line.width
:
3
}
}
}
src/FlightMap/qmldir
View file @
fb486d9c
...
...
@@ -22,10 +22,12 @@ VehicleHealthWidget 1.0 VehicleHealthWidget.qml
VibrationWidget 1.0 VibrationWidget.qml
# Map items
MissionItemIndicator 1.0 MissionItemIndicator.qml
MissionItemView 1.0 MissionItemView.qml
MissionLineView 1.0 MissionLineView.qml
VehicleMapItem 1.0 VehicleMapItem.qml
MissionItemIndicator 1.0 MissionItemIndicator.qml
MissionItemIndicatorDrag 1.0 MissionItemIndicatorDrag.qml
MissionItemView 1.0 MissionItemView.qml
MissionLineView 1.0 MissionLineView.qml
PolygonEditor 1.0 PolygonEditor.qml
VehicleMapItem 1.0 VehicleMapItem.qml
# Editor controls
QGCMapPolygonControls 1.0 QGCMapPolygonControls.qml
src/MissionEditor/FWLandingPatternMapVisual.qml
View file @
fb486d9c
...
...
@@ -16,6 +16,7 @@ import QGroundControl 1.0
import
QGroundControl
.
ScreenTools
1.0
import
QGroundControl
.
Palette
1.0
import
QGroundControl
.
Controls
1.0
import
QGroundControl
.
FlightMap
1.0
/// Fixed Wing Landing Pattern map visuals
Item
{
...
...
@@ -78,8 +79,8 @@ Item {
function
showDragAreas
()
{
if
(
_dragAreas
.
length
===
0
)
{
_dragAreas
.
push
(
d
ragAreaComponent
.
createObject
(
map
,
{
"
dragLoiter
"
:
true
}
))
_dragAreas
.
push
(
d
ragAreaComponent
.
createObject
(
map
,
{
"
dragLoiter
"
:
false
}
))
_dragAreas
.
push
(
loiterD
ragAreaComponent
.
createObject
(
map
))
_dragAreas
.
push
(
landD
ragAreaComponent
.
createObject
(
map
))
}
}
...
...
@@ -145,53 +146,27 @@ Item {
}
}
// Control which is used to drag
items
// Control which is used to drag
the loiter point
Component
{
id
:
dragAreaComponent
Rectangle
{
id
:
itemDragger
x
:
mapQuickItem
.
x
y
:
mapQuickItem
.
y
width
:
mapQuickItem
.
width
height
:
mapQuickItem
.
height
color
:
"
transparent
"
z
:
QGroundControl
.
zOrderMapItems
+
1
// Above item icons
property
bool
dragLoiter
property
var
mapQuickItem
:
dragLoiter
?
_itemVisuals
[
_loiterPointIndex
]
:
_itemVisuals
[
_landPointIndex
]
property
bool
_preventCoordinateBindingLoop
:
false
onXChanged
:
liveDrag
()
onYChanged
:
liveDrag
()
function
liveDrag
()
{
if
(
!
itemDragger
.
_preventCoordinateBindingLoop
&&
Drag
.
active
)
{
var
point
=
Qt
.
point
(
itemDragger
.
x
+
mapQuickItem
.
anchorPoint
.
x
,
itemDragger
.
y
+
mapQuickItem
.
anchorPoint
.
y
)
var
coordinate
=
map
.
toCoordinate
(
point
)
itemDragger
.
_preventCoordinateBindingLoop
=
true
if
(
dragLoiter
)
{
coordinate
.
altitude
=
_missionItem
.
loiterCoordinate
.
altitude
_missionItem
.
loiterCoordinate
=
coordinate
}
else
{
coordinate
.
altitude
=
_missionItem
.
landingCoordinate
.
altitude
_missionItem
.
landingCoordinate
=
coordinate
}
itemDragger
.
_preventCoordinateBindingLoop
=
false
}
}
id
:
loiterDragAreaComponent
Drag.active
:
itemDrag
.
drag
.
active
MissionItemIndicatorDrag
{
itemIndicator
:
_itemVisuals
[
_loiterPointIndex
]
itemCoordinate
:
_missionItem
.
loiterCoordinate
MouseArea
{
id
:
itemDrag
anchors.fill
:
parent
drag.target
:
parent
drag.minimumX
:
0
drag.minimumY
:
0
drag.maximumX
:
itemDragger
.
parent
.
width
-
parent
.
width
drag.maximumY
:
itemDragger
.
parent
.
height
-
parent
.
height
}
onItemCoordinateChanged
:
_missionItem
.
loiterCoordinate
=
itemCoordinate
}
}
// Control which is used to drag the loiter point
Component
{
id
:
landDragAreaComponent
MissionItemIndicatorDrag
{
itemIndicator
:
_itemVisuals
[
_landPointIndex
]
itemCoordinate
:
_missionItem
.
landingCoordinate
onItemCoordinateChanged
:
_missionItem
.
landingCoordinate
=
itemCoordinate
}
}
...
...
src/MissionEditor/MissionEditor.qml
View file @
fb486d9c
...
...
@@ -254,7 +254,7 @@ QGCView {
function
setCurrentItem
(
sequenceNumber
)
{
if
(
sequenceNumber
!==
_currentMissionIndex
)
{
editorMap
.
polygonDraw
.
cancelPolygonEdit
()
//
editorMap.polygonDraw.cancelPolygonEdit()
_currentMissionItem
=
undefined
_currentMissionIndex
=
-
1
for
(
var
i
=
0
;
i
<
_visualItems
.
count
;
i
++
)
{
...
...
src/MissionEditor/SimpleItemMapVisual.qml
View file @
fb486d9c
...
...
@@ -80,44 +80,11 @@ Item {
Component
{
id
:
dragAreaComponent
Rectangle
{
id
:
itemDragger
x
:
_itemVisual
.
x
-
_expandMargin
y
:
_itemVisual
.
y
-
_expandMargin
width
:
_itemVisual
.
width
+
(
_expandMargin
*
2
)
height
:
_itemVisual
.
height
+
(
_expandMargin
*
2
)
color
:
"
transparent
"
z
:
QGroundControl
.
zOrderMapItems
+
1
// Above item icons
property
bool
dragLoiter
property
bool
_preventCoordinateBindingLoop
:
false
property
real
_expandMargin
:
ScreenTools
.
isMobile
?
ScreenTools
.
defaultFontPixelWidth
:
0
onXChanged
:
liveDrag
()
onYChanged
:
liveDrag
()
function
liveDrag
()
{
if
(
!
itemDragger
.
_preventCoordinateBindingLoop
&&
Drag
.
active
)
{
var
point
=
Qt
.
point
(
itemDragger
.
x
+
_expandMargin
+
_itemVisual
.
anchorPoint
.
x
,
itemDragger
.
y
+
_expandMargin
+
_itemVisual
.
anchorPoint
.
y
)
var
coordinate
=
map
.
toCoordinate
(
point
)
itemDragger
.
_preventCoordinateBindingLoop
=
true
coordinate
.
altitude
=
_missionItem
.
coordinate
.
altitude
_missionItem
.
coordinate
=
coordinate
itemDragger
.
_preventCoordinateBindingLoop
=
false
}
}
MissionItemIndicatorDrag
{
itemIndicator
:
_itemVisual
itemCoordinate
:
_missionItem
.
coordinate
Drag.active
:
itemDrag
.
drag
.
active
MouseArea
{
id
:
itemDrag
anchors.fill
:
parent
drag.target
:
parent
drag.minimumX
:
0
drag.minimumY
:
0
drag.maximumX
:
itemDragger
.
parent
.
width
-
parent
.
width
drag.maximumY
:
itemDragger
.
parent
.
height
-
parent
.
height
}
onItemCoordinateChanged
:
_missionItem
.
coordinate
=
itemCoordinate
}
}
...
...
src/MissionEditor/SurveyItemEditor.qml
View file @
fb486d9c
...
...
@@ -9,6 +9,7 @@ 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 Survery mission items
Rectangle
{
...
...
@@ -593,29 +594,29 @@ Rectangle {
QGCButton
{
width
:
_root
.
width
*
0.45
text
:
editorMap
.
polygon
Draw
.
drawingPolygon
?
qsTr
(
"
Finish Draw
"
)
:
qsTr
(
"
Draw
"
)
visible
:
!
editorMap
.
polygonDraw
.
adjustingPolygon
enabled
:
((
editorMap
.
polygon
Draw
.
drawingPolygon
&&
editorMap
.
polygon
Draw
.
polygonReady
)
||
!
editorMap
.
polygon
Draw
.
drawingPolygon
)
text
:
polygon
Editor
.
drawingPolygon
?
qsTr
(
"
Finish Draw
"
)
:
qsTr
(
"
Draw
"
)
visible
:
!
polygonEditor
.
adjustingPolygon
enabled
:
((
polygon
Editor
.
drawingPolygon
&&
polygon
Editor
.
polygonReady
)
||
!
polygon
Editor
.
drawingPolygon
)
onClicked
:
{
if
(
editorMap
.
polygon
Draw
.
drawingPolygon
)
{
editorMap
.
polygon
Draw
.
finishCapturePolygon
()
if
(
polygon
Editor
.
drawingPolygon
)
{
polygon
Editor
.
finishCapturePolygon
()
}
else
{
editorMap
.
polygon
Draw
.
startCapturePolygon
(
_root
)
polygon
Editor
.
startCapturePolygon
()
}
}
}
QGCButton
{
width
:
_root
.
width
*
0.4
text
:
editorMap
.
polygon
Draw
.
adjustingPolygon
?
qsTr
(
"
Finish Adjust
"
)
:
qsTr
(
"
Adjust
"
)
visible
:
missionItem
.
polygonPath
.
length
>
0
&&
!
editorMap
.
polygon
Draw
.
drawingPolygon
text
:
polygon
Editor
.
adjustingPolygon
?
qsTr
(
"
Finish Adjust
"
)
:
qsTr
(
"
Adjust
"
)
visible
:
missionItem
.
polygonPath
.
length
>
0
&&
!
polygon
Editor
.
drawingPolygon
onClicked
:
{
if
(
editorMap
.
polygon
Draw
.
adjustingPolygon
)
{
editorMap
.
polygon
Draw
.
finishAdjustPolygon
()
if
(
polygon
Editor
.
adjustingPolygon
)
{
polygon
Editor
.
finishAdjustPolygon
()
}
else
{
editorMap
.
polygon
Draw
.
startAdjustPolygon
(
_root
,
missionItem
.
polygonPath
)
polygon
Editor
.
startAdjustPolygon
(
missionItem
.
polygonPath
)
}
}
}
...
...
@@ -652,4 +653,10 @@ Rectangle {
}
}
}
PolygonEditor
{
id
:
polygonEditor
map
:
editorMap
callbackObject
:
parent
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment