QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TransectStyleMapVisuals.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtLocation
4import QtPositioning
5
6import QGroundControl
7import QGroundControl.Controls
8import QGroundControl.FlightMap
9
10/// Base control for both Survey and Corridor Scan map visuals
11Item {
12 id: _root
13
14 property var map ///< Map control to place item in
15 property bool polygonInteractive: true
16 property bool interactive: true
17 property var vehicle
18 property bool hideMapPolygon: false
19 property real polygonBorderWidth: 1
20
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
42
43 signal clicked(int sequenceNumber)
44
45 function _addVisualElements() {
46 var toAdd = [ fullTransectsComponent, entryTransectComponent, exitTransectComponent, entryPointComponent, exitPointComponent,
47 entryArrow1Component, entryArrow2Component, exitArrow1Component, exitArrow2Component ]
48 objMgr.createObjects(toAdd, map, true /* parentObjectIsMap */)
49 }
50
51 function _destroyVisualElements() {
52 objMgr.destroyObjects()
53 }
54
55 Component.onCompleted: {
56 _addVisualElements()
57 }
58
59 Component.onDestruction: {
60 _destroyVisualElements()
61 }
62
63 QGCDynamicObjectManager {
64 id: objMgr
65 }
66
67 // Area polygon
68 QGCMapPolygonVisuals {
69 id: mapPolygonVisuals
70 mapControl: map
71 mapPolygon: _mapPolygon
72 interactive: polygonInteractive && _missionItem.isCurrentItem && _root.interactive
73 borderWidth: polygonBorderWidth
74 borderColor: "black"
75 interiorColor: QGroundControl.globalPalette.surveyPolygonInterior
76 altColor: QGroundControl.globalPalette.surveyPolygonTerrainCollision
77 interiorOpacity: 0.5 * _root.opacity
78 visible: !hideMapPolygon
79 }
80
81 // Full set of transects lines. Shown when item is selected.
82 Component {
83 id: fullTransectsComponent
84
85 MapPolyline {
86 line.color: "white"
87 line.width: 2
88 path: _transectPoints
89 visible: _currentItem && !_vertexDrag
90 opacity: _root.opacity
91 }
92 }
93
94 // Entry and exit transect lines only. Used when item is not selected.
95 Component {
96 id: entryTransectComponent
97
98 MapPolyline {
99 line.color: "white"
100 line.width: 2
101 path: _showPartialEntryExit ? [ _transectPoints[0], _transectPoints[1] ] : []
102 visible: _showPartialEntryExit && !_vertexDrag
103 opacity: _root.opacity
104 }
105 }
106 Component {
107 id: exitTransectComponent
108
109 MapPolyline {
110 line.color: "white"
111 line.width: 2
112 path: _showPartialEntryExit ? [ _transectPoints[_lastPointIndex - 1], _transectPoints[_lastPointIndex] ] : []
113 visible: _showPartialEntryExit && !_vertexDrag
114 opacity: _root.opacity
115 }
116 }
117
118 // Entry point
119 Component {
120 id: entryPointComponent
121
122 MapQuickItem {
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
129
130 sourceItem: MissionItemIndexLabel {
131 index: _missionItem.sequenceNumber
132 checked: _missionItem.isCurrentItem
133 onClicked: if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)
134 }
135 }
136 }
137
138 Component {
139 id: entryArrow1Component
140
141 MapLineArrow {
142 fromCoord: _transectPoints[_firstTrueTransectIndex]
143 toCoord: _transectPoints[_firstTrueTransectIndex + 1]
144 arrowPosition: 1
145 mapControl: _root.map
146 visible: _currentItem && !_vertexDrag
147 opacity: _root.opacity
148 }
149 }
150
151 Component {
152 id: entryArrow2Component
153
154 MapLineArrow {
155 fromCoord: _transectPoints[nextTrueTransectIndex]
156 toCoord: _transectPoints[nextTrueTransectIndex + 1]
157 arrowPosition: 1
158 mapControl: _root.map
159 visible: _currentItem && _transectCount > 3 && !_vertexDrag
160 opacity: _root.opacity
161
162 property int nextTrueTransectIndex: _hasTransectIndices ? _entryIndices[Math.min(1, _entryIndices.length - 1)] : _firstTrueTransectIndex + _transectStride
163 }
164 }
165
166 Component {
167 id: exitArrow1Component
168
169 MapLineArrow {
170 fromCoord: _transectPoints[_lastTrueTransectIndex - 1]
171 toCoord: _transectPoints[_lastTrueTransectIndex]
172 arrowPosition: 3
173 mapControl: _root.map
174 visible: _currentItem && !_vertexDrag
175 opacity: _root.opacity
176 }
177 }
178
179 Component {
180 id: exitArrow2Component
181
182 MapLineArrow {
183 fromCoord: _transectPoints[prevTrueTransectIndex - 1]
184 toCoord: _transectPoints[prevTrueTransectIndex]
185 arrowPosition: 13
186 mapControl: _root.map
187 visible: _currentItem && _transectCount > 3 && !_vertexDrag
188 opacity: _root.opacity
189
190 property int prevTrueTransectIndex: _hasTransectIndices ? _exitIndices[Math.max(0, _exitIndices.length - 2)] : _lastTrueTransectIndex - _transectStride
191 }
192 }
193
194 // Exit point
195 Component {
196 id: exitPointComponent
197
198 MapQuickItem {
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
205
206 sourceItem: MissionItemIndexLabel {
207 index: _missionItem.lastSequenceNumber
208 checked: _missionItem.isCurrentItem
209 onClicked: if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)
210 }
211 }
212 }
213}