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