7import QGroundControl.Controls
8import QGroundControl.FlightMap
10/// Base control for both Survey and Corridor Scan map visuals
14 property var map ///< Map control to place item in
15 property bool polygonInteractive: true
16 property bool interactive: true
18 property bool hideMapPolygon: false
19 property real polygonBorderWidth: 1
21 property var _missionItem: object
22 property var _mapPolygon: object.surveyAreaPolygon
23 property bool _currentItem: object.isCurrentItem
24 property bool _vertexDrag: _mapPolygon.vertexDrag || hideMapPolygon
25 property var _transectPoints: _missionItem.visualTransectPoints
26 property var _entryIndices: _missionItem.visualTransectEntryIndices
27 property var _exitIndices: _missionItem.visualTransectExitIndices
28 // Items loaded from a plan file have no transect structure until rebuilt, so fall back to a fixed point stride
29 property bool _hasTransectIndices: _entryIndices.length > 0 && _entryIndices.length === _exitIndices.length
30 property int _transectStride: _hasTurnaround ? 4 : 2
31 property int _transectCount: _hasTransectIndices ? _entryIndices.length : _transectPoints.length / _transectStride
32 property bool _hasTurnaround: _missionItem.turnAroundDistance.rawValue !== 0
33 property int _firstTrueTransectIndex: _hasTransectIndices ? _entryIndices[0] : (_hasTurnaround ? 1 : 0)
34 property int _lastTrueTransectIndex: _hasTransectIndices ? _exitIndices[_exitIndices.length - 1] : _transectPoints.length - (_hasTurnaround ? 2 : 1)
35 property int _lastPointIndex: _transectPoints.length - 1
36 property bool _showPartialEntryExit: !_currentItem && _hasTurnaround &&_transectPoints.length >= 2
37 property var _fullTransectsComponent: null
38 property var _entryTransectsComponent: null
39 property var _exitTransectsComponent: null
40 property var _entryCoordinate
41 property var _exitCoordinate
43 signal clicked(int sequenceNumber)
45 function _addVisualElements() {
46 var toAdd = [ fullTransectsComponent, entryTransectComponent, exitTransectComponent, entryPointComponent, exitPointComponent,
47 entryArrow1Component, entryArrow2Component, exitArrow1Component, exitArrow2Component ]
48 objMgr.createObjects(toAdd, map, true /* parentObjectIsMap */)
51 function _destroyVisualElements() {
52 objMgr.destroyObjects()
55 Component.onCompleted: {
59 Component.onDestruction: {
60 _destroyVisualElements()
63 QGCDynamicObjectManager {
68 QGCMapPolygonVisuals {
71 mapPolygon: _mapPolygon
72 interactive: polygonInteractive && _missionItem.isCurrentItem && _root.interactive
73 borderWidth: polygonBorderWidth
75 interiorColor: QGroundControl.globalPalette.surveyPolygonInterior
76 altColor: QGroundControl.globalPalette.surveyPolygonTerrainCollision
77 interiorOpacity: 0.5 * _root.opacity
78 visible: !hideMapPolygon
81 // Full set of transects lines. Shown when item is selected.
83 id: fullTransectsComponent
89 visible: _currentItem && !_vertexDrag
90 opacity: _root.opacity
94 // Entry and exit transect lines only. Used when item is not selected.
96 id: entryTransectComponent
101 path: _showPartialEntryExit ? [ _transectPoints[0], _transectPoints[1] ] : []
102 visible: _showPartialEntryExit && !_vertexDrag
103 opacity: _root.opacity
107 id: exitTransectComponent
112 path: _showPartialEntryExit ? [ _transectPoints[_lastPointIndex - 1], _transectPoints[_lastPointIndex] ] : []
113 visible: _showPartialEntryExit && !_vertexDrag
114 opacity: _root.opacity
120 id: entryPointComponent
123 anchorPoint.x: sourceItem.anchorPointX
124 anchorPoint.y: sourceItem.anchorPointY
125 z: QGroundControl.zOrderMapItems
126 coordinate: _missionItem.coordinate
127 visible: _missionItem.exitCoordinate.isValid && !_vertexDrag
128 opacity: _root.opacity
130 sourceItem: MissionItemIndexLabel {
131 index: _missionItem.sequenceNumber
132 checked: _missionItem.isCurrentItem
133 onClicked: if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)
139 id: entryArrow1Component
142 fromCoord: _transectPoints[_firstTrueTransectIndex]
143 toCoord: _transectPoints[_firstTrueTransectIndex + 1]
145 mapControl: _root.map
146 visible: _currentItem && !_vertexDrag
147 opacity: _root.opacity
152 id: entryArrow2Component
155 fromCoord: _transectPoints[nextTrueTransectIndex]
156 toCoord: _transectPoints[nextTrueTransectIndex + 1]
158 mapControl: _root.map
159 visible: _currentItem && _transectCount > 3 && !_vertexDrag
160 opacity: _root.opacity
162 property int nextTrueTransectIndex: _hasTransectIndices ? _entryIndices[Math.min(1, _entryIndices.length - 1)] : _firstTrueTransectIndex + _transectStride
167 id: exitArrow1Component
170 fromCoord: _transectPoints[_lastTrueTransectIndex - 1]
171 toCoord: _transectPoints[_lastTrueTransectIndex]
173 mapControl: _root.map
174 visible: _currentItem && !_vertexDrag
175 opacity: _root.opacity
180 id: exitArrow2Component
183 fromCoord: _transectPoints[prevTrueTransectIndex - 1]
184 toCoord: _transectPoints[prevTrueTransectIndex]
186 mapControl: _root.map
187 visible: _currentItem && _transectCount > 3 && !_vertexDrag
188 opacity: _root.opacity
190 property int prevTrueTransectIndex: _hasTransectIndices ? _exitIndices[Math.max(0, _exitIndices.length - 2)] : _lastTrueTransectIndex - _transectStride
196 id: exitPointComponent
199 anchorPoint.x: sourceItem.anchorPointX
200 anchorPoint.y: sourceItem.anchorPointY
201 z: QGroundControl.zOrderMapItems
202 coordinate: _missionItem.exitCoordinate
203 visible: _missionItem.exitCoordinate.isValid && !_vertexDrag
204 opacity: _root.opacity
206 sourceItem: MissionItemIndexLabel {
207 index: _missionItem.lastSequenceNumber
208 checked: _missionItem.isCurrentItem
209 onClicked: if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)