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 visible: _currentItem && !_vertexDrag
140 opacity: _root.opacity
141 }
142 }
143
144 Component {
145 id: entryArrow2Component
146
147 MapLineArrow {
148 fromCoord: _transectPoints[nextTrueTransectIndex]
149 toCoord: _transectPoints[nextTrueTransectIndex + 1]
150 arrowPosition: 1
151 visible: _currentItem && _transectCount > 3 && !_vertexDrag
152 opacity: _root.opacity
153
154 property int nextTrueTransectIndex: _firstTrueTransectIndex + (_hasTurnaround ? 4 : 2)
155 }
156 }
157
158 Component {
159 id: exitArrow1Component
160
161 MapLineArrow {
162 fromCoord: _transectPoints[_lastTrueTransectIndex - 1]
163 toCoord: _transectPoints[_lastTrueTransectIndex]
164 arrowPosition: 3
165 visible: _currentItem && !_vertexDrag
166 opacity: _root.opacity
167 }
168 }
169
170 Component {
171 id: exitArrow2Component
172
173 MapLineArrow {
174 fromCoord: _transectPoints[prevTrueTransectIndex - 1]
175 toCoord: _transectPoints[prevTrueTransectIndex]
176 arrowPosition: 13
177 visible: _currentItem && _transectCount > 3 && !_vertexDrag
178 opacity: _root.opacity
179
180 property int prevTrueTransectIndex: _lastTrueTransectIndex - (_hasTurnaround ? 4 : 2)
181 }
182 }
183
184 // Exit point
185 Component {
186 id: exitPointComponent
187
188 MapQuickItem {
189 anchorPoint.x: sourceItem.anchorPointX
190 anchorPoint.y: sourceItem.anchorPointY
191 z: QGroundControl.zOrderMapItems
192 coordinate: _missionItem.exitCoordinate
193 visible: _missionItem.exitCoordinate.isValid && !_vertexDrag
194 opacity: _root.opacity
195
196 sourceItem: MissionItemIndexLabel {
197 index: _missionItem.lastSequenceNumber
198 checked: _missionItem.isCurrentItem
199 onClicked: if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)
200 }
201 }
202 }
203}