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
20 property var _missionItem: object
21 property var _mapPolygon: object.surveyAreaPolygon
22 property bool _currentItem: object.isCurrentItem
23 property bool _vertexDrag: _mapPolygon.vertexDrag || hideMapPolygon
24 property var _transectPoints: _missionItem.visualTransectPoints
25 property int _transectCount: _transectPoints.length / (_hasTurnaround ? 4 : 2)
26 property bool _hasTurnaround: _missionItem.turnAroundDistance.rawValue !== 0
27 property int _firstTrueTransectIndex: _hasTurnaround ? 1 : 0
28 property int _lastTrueTransectIndex: _transectPoints.length - (_hasTurnaround ? 2 : 1)
29 property int _lastPointIndex: _transectPoints.length - 1
30 property bool _showPartialEntryExit: !_currentItem && _hasTurnaround &&_transectPoints.length >= 2
31 property var _fullTransectsComponent: null
32 property var _entryTransectsComponent: null
33 property var _exitTransectsComponent: null
34 property var _entryCoordinate
35 property var _exitCoordinate
36
37 signal clicked(int sequenceNumber)
38
39 function _addVisualElements() {
40 var toAdd = [ fullTransectsComponent, entryTransectComponent, exitTransectComponent, entryPointComponent, exitPointComponent,
41 entryArrow1Component, entryArrow2Component, exitArrow1Component, exitArrow2Component ]
42 objMgr.createObjects(toAdd, map, true /* parentObjectIsMap */)
43 }
44
45 function _destroyVisualElements() {
46 objMgr.destroyObjects()
47 }
48
49 Component.onCompleted: {
50 _addVisualElements()
51 }
52
53 Component.onDestruction: {
54 _destroyVisualElements()
55 }
56
57 QGCDynamicObjectManager {
58 id: objMgr
59 }
60
61 // Area polygon
62 QGCMapPolygonVisuals {
63 id: mapPolygonVisuals
64 mapControl: map
65 mapPolygon: _mapPolygon
66 interactive: polygonInteractive && _missionItem.isCurrentItem && _root.interactive
67 borderWidth: 1
68 borderColor: "black"
69 interiorColor: QGroundControl.globalPalette.surveyPolygonInterior
70 altColor: QGroundControl.globalPalette.surveyPolygonTerrainCollision
71 interiorOpacity: 0.5 * _root.opacity
72 visible: !hideMapPolygon
73 }
74
75 // Full set of transects lines. Shown when item is selected.
76 Component {
77 id: fullTransectsComponent
78
79 MapPolyline {
80 line.color: "white"
81 line.width: 2
82 path: _transectPoints
83 visible: _currentItem && !_vertexDrag
84 opacity: _root.opacity
85 }
86 }
87
88 // Entry and exit transect lines only. Used when item is not selected.
89 Component {
90 id: entryTransectComponent
91
92 MapPolyline {
93 line.color: "white"
94 line.width: 2
95 path: _showPartialEntryExit ? [ _transectPoints[0], _transectPoints[1] ] : []
96 visible: _showPartialEntryExit && !_vertexDrag
97 opacity: _root.opacity
98 }
99 }
100 Component {
101 id: exitTransectComponent
102
103 MapPolyline {
104 line.color: "white"
105 line.width: 2
106 path: _showPartialEntryExit ? [ _transectPoints[_lastPointIndex - 1], _transectPoints[_lastPointIndex] ] : []
107 visible: _showPartialEntryExit && !_vertexDrag
108 opacity: _root.opacity
109 }
110 }
111
112 // Entry point
113 Component {
114 id: entryPointComponent
115
116 MapQuickItem {
117 anchorPoint.x: sourceItem.anchorPointX
118 anchorPoint.y: sourceItem.anchorPointY
119 z: QGroundControl.zOrderMapItems
120 coordinate: _missionItem.coordinate
121 visible: _missionItem.exitCoordinate.isValid && !_vertexDrag
122 opacity: _root.opacity
123
124 sourceItem: MissionItemIndexLabel {
125 index: _missionItem.sequenceNumber
126 checked: _missionItem.isCurrentItem
127 onClicked: if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)
128 }
129 }
130 }
131
132 Component {
133 id: entryArrow1Component
134
135 MapLineArrow {
136 fromCoord: _transectPoints[_firstTrueTransectIndex]
137 toCoord: _transectPoints[_firstTrueTransectIndex + 1]
138 arrowPosition: 1
139 mapControl: _root.map
140 visible: _currentItem && !_vertexDrag
141 opacity: _root.opacity
142 }
143 }
144
145 Component {
146 id: entryArrow2Component
147
148 MapLineArrow {
149 fromCoord: _transectPoints[nextTrueTransectIndex]
150 toCoord: _transectPoints[nextTrueTransectIndex + 1]
151 arrowPosition: 1
152 mapControl: _root.map
153 visible: _currentItem && _transectCount > 3 && !_vertexDrag
154 opacity: _root.opacity
155
156 property int nextTrueTransectIndex: _firstTrueTransectIndex + (_hasTurnaround ? 4 : 2)
157 }
158 }
159
160 Component {
161 id: exitArrow1Component
162
163 MapLineArrow {
164 fromCoord: _transectPoints[_lastTrueTransectIndex - 1]
165 toCoord: _transectPoints[_lastTrueTransectIndex]
166 arrowPosition: 3
167 mapControl: _root.map
168 visible: _currentItem && !_vertexDrag
169 opacity: _root.opacity
170 }
171 }
172
173 Component {
174 id: exitArrow2Component
175
176 MapLineArrow {
177 fromCoord: _transectPoints[prevTrueTransectIndex - 1]
178 toCoord: _transectPoints[prevTrueTransectIndex]
179 arrowPosition: 13
180 mapControl: _root.map
181 visible: _currentItem && _transectCount > 3 && !_vertexDrag
182 opacity: _root.opacity
183
184 property int prevTrueTransectIndex: _lastTrueTransectIndex - (_hasTurnaround ? 4 : 2)
185 }
186 }
187
188 // Exit point
189 Component {
190 id: exitPointComponent
191
192 MapQuickItem {
193 anchorPoint.x: sourceItem.anchorPointX
194 anchorPoint.y: sourceItem.anchorPointY
195 z: QGroundControl.zOrderMapItems
196 coordinate: _missionItem.exitCoordinate
197 visible: _missionItem.exitCoordinate.isValid && !_vertexDrag
198 opacity: _root.opacity
199
200 sourceItem: MissionItemIndexLabel {
201 index: _missionItem.lastSequenceNumber
202 checked: _missionItem.isCurrentItem
203 onClicked: if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)
204 }
205 }
206 }
207}