QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PlanView.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Dialogs
4import QtLocation
5import QtPositioning
6import QtQuick.Layouts
7import QtQuick.Window
8
9import QGroundControl
10import QGroundControl.FlightMap
11import QGroundControl.Controls
12import QGroundControl.FactControls
13import QGroundControl.FlyView
14import QGroundControl.Geo
15import QGroundControl.Toolbar
16
17Item {
18 id: _root
19
20 readonly property int _decimalPlaces: 8
21 readonly property real _margin: ScreenTools.defaultFontPixelHeight * 0.5
22 readonly property real _toolsMargin: ScreenTools.defaultFontPixelWidth * 0.75
23 readonly property real _rightPanelWidth: Math.min(width / 3, ScreenTools.defaultFontPixelWidth * 30)
24
25 property var _planMasterController: planMasterController
26 property var _missionController: _planMasterController.missionController
27 property var _geoFenceController: _planMasterController.geoFenceController
28 property var _rallyPointController: _planMasterController.rallyPointController
29 property var _visualItems: _missionController.visualItems
30 property bool _singleComplexItem: _missionController.complexMissionItems.length === 1
31 property int _editingLayer: _layerMission
32 property var _appSettings: QGroundControl.settingsManager.appSettings
33 property var _planViewSettings: QGroundControl.settingsManager.planViewSettings
34 readonly property bool _useNewPlanPanelSetting: _planViewSettings.useNewPlanPanel.rawValue
35 // The Plan map engine in use, decided once at startup (the setting is qgcRebootRequired). The GeoMap engine
36 // supports the tabbed panel only, so the panel follows it instead of the setting while it is loaded
37 property bool _useGeoMapEngine: false
38 readonly property bool _useNewPlanPanel: _useNewPlanPanelSetting || _useGeoMapEngine
39 property bool _promptForPlanUsageShowing: false
40 property bool _addROIOnClick: false
41 property bool _addWaypointOnClick: false
42
43 // The map is created by editorMapLoader: QtLocation FlightMap or, when enabled, the experimental GeoMap engine
44 readonly property var editorMap: editorMapLoader.item
45 readonly property real _nonInteractiveOpacity: 0.5
46 readonly property real _leftToolWidth: toolStrip.x + toolStrip.width
47 readonly property real _rightToolWidth: rightPanel.width + rightPanel.anchors.rightMargin
48 // This is the center rectangle of the map which is not obscured by tools
49 readonly property rect _centerViewport: Qt.rect(_leftToolWidth + _margin, _margin, mainPlanViewArea.width - _leftToolWidth - _rightToolWidth - (_margin * 2), (missionStatus.visible ? missionStatus.y : mainPlanViewArea.height - _margin) - _margin)
50
51 readonly property int _layerMission: PlanEditLayers.layerMission
52 readonly property int _layerPlan: PlanEditLayers.layerPlan
53 readonly property int _layerFence: PlanEditLayers.layerFence
54 readonly property int _layerRally: PlanEditLayers.layerRally
55
56 onVisibleChanged: {
57 if (visible && editorMap) {
58 editorMap.zoomLevel = QGroundControl.flightMapZoom
59 editorMap.center = QGroundControl.flightMapPosition
60 }
61 }
62
63 Connections {
64 target: planToolBar
65 function onToolbarButtonClicked() {
66 _addWaypointOnClick = false
67 _addROIOnClick = false
68 }
69 }
70
71 function mapCenter() {
72 var coordinate = editorMap.center
73 coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
74 coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
75 coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
76 return coordinate
77 }
78
79 function _onEditorMapClicked(mouse) {
80 // Take focus to close any previous editing
81 editorMap.focus = true
82
83 // Collapse layer switcher on any map click
84 layerSwitcher.expanded = false
85 collapseTimer.stop()
86
87 if (!mainWindow.allowViewSwitch()) {
88 return
89 }
90 var coordinate = editorMap.toCoordinate(Qt.point(mouse.x, mouse.y), false /* clipToViewPort */)
91 if (!coordinate.isValid) {
92 return
93 }
94 coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
95 coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
96 coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
97
98 switch (_editingLayer) {
99 case _layerPlan:
100 _missionController.setHomePosition(coordinate)
101 break
102 case _layerMission:
103 if (!_useNewPlanPanel && _planMasterController.showCreateFromTemplate) {
104 _missionController.setHomePosition(coordinate)
105 } else if (_addROIOnClick) {
106 _addROIOnClick = false
107 if (_missionController.isROIActive) {
108 var pos = Qt.point(mouse.x, mouse.y)
109 // For some strange reason using mainWindow in mapToItem doesn't work, so we use globals.parent instead which also gets us mainWindow
110 pos = editorMap.mapToItem(globals.parent, pos)
111 var dropPanel = insertOrCancelROIDropPanelComponent.createObject(mainWindow, { mapClickCoord: coordinate, clickRect: Qt.rect(pos.x, pos.y, 0, 0) })
112 dropPanel.open()
113 } else {
114 insertROIAfterCurrent(coordinate)
115 }
116 } else if (_addWaypointOnClick) {
117 insertSimpleItemAfterCurrent(coordinate)
118 }
119 break
120 case _layerRally:
121 if (_rallyPointController.supported) {
122 _rallyPointController.addPoint(coordinate)
123 }
124 break
125 }
126 }
127
128 function _onMapItemSelected(sequenceNumber) {
129 if (!mainWindow.allowViewSwitch()) {
130 return
131 }
132 _missionController.setCurrentPlanViewSeqNum(sequenceNumber, false)
133 rightPanel.showItemInspector()
134 }
135
136 MapFitFunctions {
137 id: mapFitFunctions // The name for this id cannot be changed without breaking references outside of this code. Beware!
138 map: editorMap
139 usePlannedHomePosition: true
140 planMasterController: _planMasterController
141 }
142
143 PlanMasterController {
144 id: planMasterController
145 flyView: false
146
147 Component.onCompleted: {
148 _planMasterController.start()
149 _missionController.setCurrentPlanViewSeqNum(0, true)
150 }
151
152 onPromptForPlanUsageOnVehicleChange: {
153 if (!_promptForPlanUsageShowing) {
154 _promptForPlanUsageShowing = true
155 promptForPlanUsageOnVehicleChangePopupFactory.open()
156 }
157 }
158
159 function waitingOnIncompleteDataMessage(save) {
160 var saveOrUpload = save ? qsTr("Save") : qsTr("Upload")
161 QGroundControl.showMessageDialog(_root, qsTr("Unable to %1").arg(saveOrUpload), qsTr("Plan has incomplete items. Complete all items and %1 again.").arg(saveOrUpload))
162 }
163
164 function waitingOnTerrainDataMessage(save) {
165 var saveOrUpload = save ? qsTr("Save") : qsTr("Upload")
166 QGroundControl.showMessageDialog(_root, qsTr("Unable to %1").arg(saveOrUpload), qsTr("Plan is waiting on terrain data from server for correct altitude values."))
167 }
168
169 function checkReadyForSaveUpload(save) {
170 if (readyForSaveState() == VisualMissionItem.NotReadyForSaveData) {
171 waitingOnIncompleteDataMessage(save)
172 return false
173 } else if (readyForSaveState() == VisualMissionItem.NotReadyForSaveTerrain) {
174 waitingOnTerrainDataMessage(save)
175 return false
176 }
177 return true
178 }
179
180 function upload() {
181 if (!checkReadyForSaveUpload(false /* save */)) {
182 return
183 }
184 switch (_missionController.sendToVehiclePreCheck()) {
185 case MissionController.SendToVehiclePreCheckStateOk: sendToVehicle()
186 break
187 case MissionController.SendToVehiclePreCheckStateActiveMission: QGroundControl.showMessageDialog(_root, qsTr("Send To Vehicle"), qsTr("Current mission must be paused prior to uploading a new Plan"))
188 break
189 case MissionController.SendToVehiclePreCheckStateFirwmareVehicleMismatch: QGroundControl.showMessageDialog(_root, qsTr("Plan Upload"),
190 qsTr("This Plan was created for a different firmware or vehicle type than the firmware/vehicle type of vehicle you are uploading to. " +
191 "This can lead to errors or incorrect behavior. " +
192 "It is recommended to recreate the Plan for the correct firmware/vehicle type.\n\n" +
193 "Click 'Ok' to upload the Plan anyway."),
194 Dialog.Ok | Dialog.Cancel,
195 function() { _planMasterController.sendToVehicle() })
196 break
197 }
198 }
199
200 function loadFromSelectedFile() {
201 fileDialog.title = qsTr("Select Plan File")
202 fileDialog.planFiles = true
203 fileDialog.nameFilters = _planMasterController.loadNameFilters
204 fileDialog.openForLoad()
205 }
206
207 function saveToSelectedFile() {
208 if (!checkReadyForSaveUpload(true /* save */)) {
209 return
210 }
211 fileDialog.title = qsTr("Save Plan")
212 fileDialog.planFiles = true
213 fileDialog.nameFilters = _planMasterController.saveNameFilters
214 fileDialog.openForSave()
215 }
216
217 function fitViewportToItems() {
218 mapFitFunctions.fitMapViewportToMissionItems()
219 }
220
221 function saveKmlToSelectedFile() {
222 if (!checkReadyForSaveUpload(true /* save */)) {
223 return
224 }
225 fileDialog.title = qsTr("Save KML")
226 fileDialog.planFiles = false
227 fileDialog.nameFilters = ShapeFileHelper.fileDialogKMLFilters
228 fileDialog.openForSave()
229 }
230 }
231
232 Connections {
233 target: _missionController
234
235 function onNewItemsFromVehicle() {
236 if (_visualItems && _visualItems.count !== 1) {
237 mapFitFunctions.fitMapViewportToMissionItems()
238 }
239 _missionController.setCurrentPlanViewSeqNum(0, true)
240 }
241 }
242
243 function insertSimpleItemAfterCurrent(coordinate) {
244 var nextIndex = _missionController.currentPlanViewVIIndex + 1
245 _missionController.insertSimpleMissionItem(coordinate, nextIndex, true /* makeCurrentItem */)
246 }
247
248 function insertROIAfterCurrent(coordinate) {
249 var nextIndex = _missionController.currentPlanViewVIIndex + 1
250 _missionController.insertROIMissionItem(coordinate, nextIndex, true /* makeCurrentItem */)
251 }
252
253 function insertCancelROIAfterCurrent() {
254 var nextIndex = _missionController.currentPlanViewVIIndex + 1
255 _missionController.insertCancelROIMissionItem(nextIndex, true /* makeCurrentItem */)
256 }
257
258 function insertComplexItemAfterCurrent(complexItemName) {
259 var nextIndex = _missionController.currentPlanViewVIIndex + 1
260 _missionController.insertComplexMissionItem(complexItemName, mapCenter(), nextIndex, true /* makeCurrentItem */)
261 }
262
263 function insertTakeoffItemAfterCurrent() {
264 var nextIndex = _missionController.currentPlanViewVIIndex + 1
265 _missionController.insertTakeoffItem(mapCenter(), nextIndex, true /* makeCurrentItem */)
266 }
267
268 function insertVTOLMulticopterTakeoffItemAfterCurrent() {
269 var nextIndex = _missionController.currentPlanViewVIIndex + 1
270 _missionController.insertVTOLMulticopterTakeoffItem(mapCenter(), nextIndex, true /* makeCurrentItem */)
271 }
272
273 function insertLandItemAfterCurrent() {
274 var nextIndex = _missionController.currentPlanViewVIIndex + 1
275 _missionController.insertLandItem(mapCenter(), nextIndex, true /* makeCurrentItem */)
276 }
277
278 function _landButtonText() {
279 // Must mirror MissionController::insertLandItem: only fixed-wing/VTOL get landing patterns
280 if (!_planMasterController.controllerVehicle.fixedWing && !_planMasterController.controllerVehicle.vtol) {
281 return qsTr("Return")
282 }
283 if (_missionController.isInsertLandValid && _missionController.hasLandItem) {
284 return qsTr("Alt Land")
285 }
286 return qsTr("Land")
287 }
288
289 QGCFileDialog {
290 id: fileDialog
291 folder: _appSettings ? _appSettings.missionSavePath : ""
292
293 property bool planFiles: true ///< true: working with plan files, false: working with kml file
294
295 onAcceptedForSave: (file) => {
296 if (planFiles) {
297 if (_planMasterController.saveToFile(file)) {
298 close()
299 }
300 } else {
301 _planMasterController.saveToKml(file)
302 close()
303 }
304 }
305
306 onAcceptedForLoad: (file) => {
307 _planMasterController.loadFromFile(file)
308 _planMasterController.fitViewportToItems()
309 _missionController.setCurrentPlanViewSeqNum(0, true)
310 close()
311 }
312 }
313
314 PlanViewToolBar {
315 id: planToolBar
316 planMasterController: _planMasterController
317 statusHint: {
318 if (_editingLayer === _layerPlan) {
319 return _missionController.homePositionSet ? qsTr("Click in map to move Home") : qsTr("Click in map to set Home")
320 }
321 if (_editingLayer === _layerRally) {
322 return qsTr("Click in map to add rally points")
323 }
324 return ""
325 }
326 }
327
328 Item {
329 id: mainPlanViewArea
330 anchors.left: parent.left
331 anchors.right: parent.right
332 anchors.top: planToolBar.bottom
333 anchors.bottom: parent.bottom
334
335 Loader {
336 id: editorMapLoader
337 anchors.fill: parent
338
339 // Engine choice is snapshotted at startup (the setting is qgcRebootRequired)
340 Component.onCompleted: {
341 _root._useGeoMapEngine = _root._planViewSettings.useGeoMapEngine.rawValue && _root._useNewPlanPanelSetting
342 sourceComponent = _root._useGeoMapEngine ? geoMapEngineComponent : qtLocationEngineComponent
343 }
344 }
345
346 Component {
347 id: geoMapEngineComponent
348
349 PlanViewGeoMap {
350 objectName: "planView_map"
351 planMasterController: _root._planMasterController
352 centerViewport: _root._centerViewport
353 missionOpacity: _root._editingLayer == _root._layerMission ? 1 : _root._nonInteractiveOpacity
354 missionInteractive: _root._editingLayer == _root._layerMission
355 rallyOpacity: _root._editingLayer == _root._layerRally ? 1 : _root._nonInteractiveOpacity
356 rallyInteractive: _root._editingLayer == _root._layerRally
357 showControls: true
358 showScale: true
359 controlsLeftMargin: _root._leftToolWidth + _root._toolsMargin
360 controlsTopMargin: _root._toolsMargin
361 _nonInteractiveOpacity: _root._nonInteractiveOpacity
362
363 onMapClicked: (mouse) => _root._onEditorMapClicked(mouse)
364 onItemSelected: (sequenceNumber) => _root._onMapItemSelected(sequenceNumber)
365 }
366 }
367
368 Component {
369 id: qtLocationEngineComponent
370
371 FlightMap {
372 id: qtLocationMap
373 objectName: "planView_map"
374 mapName: "MissionEditor"
375 allowGCSLocationCenter: true
376 allowVehicleLocationCenter: true
377 planView: true
378
379 zoomLevel: QGroundControl.flightMapZoom
380 center: QGroundControl.flightMapPosition
381
382 property rect centerViewport: _root._centerViewport
383 property real _nonInteractiveOpacity: _root._nonInteractiveOpacity
384
385 // Initial map position duplicates Fly view position
386 Component.onCompleted: qtLocationMap.center = QGroundControl.flightMapPosition
387
388 onZoomLevelChanged: {
389 QGroundControl.flightMapZoom = qtLocationMap.zoomLevel
390 }
391 onCenterChanged: {
392 QGroundControl.flightMapPosition = qtLocationMap.center
393 }
394
395 onMapClicked: (mouse) => _root._onEditorMapClicked(mouse)
396
397 MissionItemIndicatorGroup {
398 id: _missionItemIndicatorGroup
399
400 objectName: "planView_missionItemIndicators"
401 map: qtLocationMap
402 missionItems: _root._missionController.visualItems
403 onItemSelected: (sequenceNumber) => _root._onMapItemSelected(sequenceNumber)
404 }
405
406 // Add the mission item visuals to the map
407 Repeater {
408 model: _missionController.visualItems
409 delegate: MissionItemMapVisual {
410 map: qtLocationMap
411 opacity: _editingLayer == _layerMission ? 1 : qtLocationMap._nonInteractiveOpacity
412 interactive: _editingLayer == _layerMission
413 vehicle: _planMasterController.controllerVehicle
414 indicatorGroup: _missionItemIndicatorGroup
415 onClicked: (sequenceNumber) => _root._onMapItemSelected(sequenceNumber)
416 }
417 }
418
419 // Add lines between waypoints
420 MissionLineView {
421 showSpecialVisual: _missionController.isROIBeginCurrentItem
422 model: _missionController.simpleFlightPathSegments
423 opacity: _editingLayer == _layerMission ? 1 : qtLocationMap._nonInteractiveOpacity
424 }
425
426 // Direction arrows in waypoint lines
427 MapItemView {
428 model: _editingLayer == _layerMission ? _missionController.directionArrows : undefined
429
430 delegate: MapLineArrow {
431 fromCoord: object ? object.coordinate1 : undefined
432 toCoord: object ? object.coordinate2 : undefined
433 arrowPosition: 3
434 mapControl: qtLocationMap
435 z: QGroundControl.zOrderWaypointLines + 1
436 }
437 }
438
439 // UI for splitting the current segment
440 MapQuickItem {
441 id: splitSegmentItem
442
443 property real _screenLegLength: 0
444
445 anchorPoint.x: sourceItem.width / 2
446 anchorPoint.y: sourceItem.height / 2
447 z: QGroundControl.zOrderWaypointLines + 1
448 visible: _editingLayer == _layerMission
449 && _screenLegLength > _missionItemIndicatorGroup.groupingDistance * 2
450
451 sourceItem: SplitIndicator {
452 onClicked: _missionController.insertSimpleMissionItem(splitSegmentItem.coordinate,
453 _missionController.currentPlanViewVIIndex,
454 true /* makeCurrentItem */)
455 }
456
457 function _updateScreenLegLength() {
458 const segment = _root._missionController.splitSegment
459 if (segment && segment.coordinate1.isValid && segment.coordinate2.isValid) {
460 const fromPoint = qtLocationMap.fromCoordinate(segment.coordinate1, false /* clipToViewPort */)
461 const toPoint = qtLocationMap.fromCoordinate(segment.coordinate2, false /* clipToViewPort */)
462 _screenLegLength = Math.hypot(toPoint.x - fromPoint.x, toPoint.y - fromPoint.y)
463 } else {
464 _screenLegLength = 0
465 }
466 }
467
468 function _updateSplitCoord() {
469 if (_missionController.splitSegment) {
470 var distance = _missionController.splitSegment.coordinate1.distanceTo(_missionController.splitSegment.coordinate2)
471 var azimuth = _missionController.splitSegment.coordinate1.azimuthTo(_missionController.splitSegment.coordinate2)
472 splitSegmentItem.coordinate = _missionController.splitSegment.coordinate1.atDistanceAndAzimuth(distance / 2, azimuth)
473 } else {
474 coordinate = QtPositioning.coordinate()
475 }
476 _updateScreenLegLength()
477 }
478
479 Connections {
480 target: _missionController
481 function onSplitSegmentChanged() { splitSegmentItem._updateSplitCoord() }
482 }
483
484 Connections {
485 target: _missionController.splitSegment
486 function onCoordinate1Changed() { splitSegmentItem._updateSplitCoord() }
487 function onCoordinate2Changed() { splitSegmentItem._updateSplitCoord() }
488 }
489
490 Connections {
491 target: qtLocationMap
492 function onCenterChanged() { splitSegmentItem._updateScreenLegLength() }
493 function onZoomLevelChanged() { splitSegmentItem._updateScreenLegLength() }
494 }
495 }
496
497 // Add the vehicles to the map
498 MapItemView {
499 model: QGroundControl.multiVehicleManager.vehicles
500 delegate: VehicleMapItem {
501 vehicle: object
502 coordinate: object.coordinate
503 map: qtLocationMap
504 size: ScreenTools.defaultFontPixelHeight * 3
505 z: QGroundControl.zOrderMapItems - 1
506 }
507 }
508
509 GeoFenceMapVisuals {
510 objectName: "planView_geoFenceMapVisuals"
511 map: qtLocationMap
512 myGeoFenceController: _geoFenceController
513 interactive: _editingLayer == _layerFence
514 homePosition: _missionController.plannedHomePosition
515 planView: true
516 opacity: _editingLayer != _layerFence ? qtLocationMap._nonInteractiveOpacity : 1
517 }
518
519 RallyPointMapVisuals {
520 objectName: "planView_rallyPointMapVisuals"
521 map: qtLocationMap
522 myRallyPointController: _rallyPointController
523 interactive: _editingLayer == _layerRally
524 planView: true
525 opacity: _editingLayer != _layerRally ? qtLocationMap._nonInteractiveOpacity : 1
526 }
527 }
528 }
529
530 //-----------------------------------------------------------
531 // Left tool strip
532 ToolStrip {
533 id: toolStrip
534 anchors.margins: _toolsMargin
535 anchors.left: parent.left
536 anchors.top: parent.top
537 z: QGroundControl.zOrderWidgets
538 maxHeight: parent.height - toolStrip.y
539 visible: _editingLayer == _layerMission
540
541 property bool _isMissionLayer: _editingLayer == _layerMission
542
543 Binding {
544 target: waypointButton
545 property: "checked"
546 value: _addWaypointOnClick
547 }
548
549 Binding {
550 target: roiButton
551 property: "checked"
552 value: _addROIOnClick
553 }
554
555 ToolStripActionList {
556 id: toolStripActionList
557 model: [
558 ToolStripAction {
559 objectName: "planToolStrip_takeoffButton"
560 text: qsTr("Takeoff")
561 iconSource: "/res/takeoff.svg"
562 enabled: _missionController.isInsertTakeoffValid
563 visible: toolStrip._isMissionLayer && !_planMasterController.controllerVehicle.rover
564 dropPanelComponent: _planMasterController.controllerVehicle.supports.vtolMulticopterTakeoff
565 ? vtolTakeoffDropPanel
566 : null
567 onTriggered: {
568 insertTakeoffItemAfterCurrent()
569 }
570 },
571 ToolStripAction {
572 objectName: "planToolStrip_patternButton"
573 text: _singleComplexItem ? _missionController.complexMissionItems[0].translatedName : qsTr("Pattern")
574 iconSource: "/qmlimages/MapDrawShape.svg"
575 enabled: _missionController.flyThroughCommandsAllowed
576 visible: toolStrip._isMissionLayer
577 dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel
578 onTriggered: {
579 if (_singleComplexItem) {
580 insertComplexItemAfterCurrent(_missionController.complexMissionItems[0].canonicalName)
581 }
582 }
583 },
584 ToolStripAction {
585 id: waypointButton
586 objectName: "planToolStrip_waypointButton"
587 text: qsTr("Waypoint")
588 iconSource: "/res/waypoint.svg"
589 enabled: _missionController.flyThroughCommandsAllowed
590 visible: toolStrip._isMissionLayer
591 checkable: true
592 onTriggered: {
593 _addWaypointOnClick = !_addWaypointOnClick
594 if (_addWaypointOnClick) {
595 _addROIOnClick = false
596 // Arming an insert tool leaves template-creation mode, otherwise
597 // map clicks keep moving the home position instead of inserting
598 _planMasterController.userSelectedManualCreation = true
599 }
600 }
601 },
602 ToolStripAction {
603 id: roiButton
604 objectName: "planToolStrip_roiButton"
605 text: _missionController.isROIActive ? qsTr("Cancel ROI") : qsTr("ROI")
606 iconSource: "/qmlimages/roi.svg"
607 enabled: _missionController.isInsertROIValid
608 visible: toolStrip._isMissionLayer && _planMasterController.controllerVehicle.supports.roiMode
609 checkable: true
610 onTriggered: {
611 _addROIOnClick = !_addROIOnClick
612 if (_addROIOnClick) {
613 _addWaypointOnClick = false
614 _planMasterController.userSelectedManualCreation = true
615 }
616 }
617 },
618 ToolStripAction {
619 objectName: "planToolStrip_landButton"
620 text: _landButtonText()
621 iconSource: "/res/rtl.svg"
622 enabled: _missionController.isInsertLandValid
623 visible: toolStrip._isMissionLayer
624 onTriggered: {
625 insertLandItemAfterCurrent()
626 }
627 },
628 ToolStripAction {
629 text: qsTr("Stats")
630 iconSource: "/res/chevron-double-right.svg"
631 visible: missionStatus.hidden && QGroundControl.corePlugin.options.showMissionStatus
632 onTriggered: missionStatus.showMissionStatus()
633 }
634 ]
635 }
636
637 model: toolStripActionList.model
638 }
639
640 // The GeoMap engine shows its own scale next to its camera controls
641 MapScale {
642 anchors.margins: _toolsMargin
643 anchors.left: toolStrip.right
644 anchors.top: parent.top
645 mapControl: _root.editorMap
646 autoHide: true
647 visible: !_root._useGeoMapEngine
648 }
649
650 PlanViewRightPanel {
651 id: rightPanel
652 anchors.top: parent.top
653 anchors.bottom: parent.bottom
654 anchors.right: parent.right
655 width: _rightPanelWidth
656 planMasterController: _planMasterController
657 editorMap: _root.editorMap
658 useNewPlanPanel: _root._useNewPlanPanel
659 onEditingLayerChangeRequested: (layer) => _editingLayer = layer
660 }
661
662 // Layer switching icons — only active icon visible; click to expand choices leftward
663 Item {
664 id: layerSwitcher
665 objectName: "planView_layerSwitcher"
666 anchors.right: rightPanel.left
667 anchors.rightMargin: _toolsMargin
668 anchors.top: parent.top
669 anchors.topMargin: _toolsMargin
670 width: layerRow.width
671 height: _layerButtonSize
672 z: QGroundControl.zOrderWidgets
673 visible: !_planMasterController.showCreateFromTemplate && !_useNewPlanPanel
674
675 property bool expanded: false
676 property real _layerButtonSize: ScreenTools.defaultFontPixelHeight * 2.0
677 property real _spacing: ScreenTools.defaultFontPixelHeight * 0.25
678
679 Timer {
680 id: collapseTimer
681 interval: 5000
682 onTriggered: layerSwitcher.expanded = false
683 }
684
685 function toggle() {
686 expanded = !expanded
687 if (expanded) {
688 collapseTimer.restart()
689 } else {
690 collapseTimer.stop()
691 }
692 }
693
694 function choose(nodeType) {
695 expanded = false
696 collapseTimer.stop()
697 rightPanel.selectLayer(nodeType)
698 }
699
700 // Row laid out right-to-left: active icon on the right, choices expand left
701 Row {
702 id: layerRow
703 anchors.right: parent.right
704 spacing: layerSwitcher._spacing
705 layoutDirection: Qt.RightToLeft
706
707 // Active layer button (always visible)
708 Rectangle {
709 objectName: "layerSwitcher_activeButton"
710 width: layerSwitcher._layerButtonSize
711 height: width
712 radius: ScreenTools.defaultBorderRadius
713 color: QGroundControl.globalPalette.accent
714
715 QGCColoredImage {
716 anchors.centerIn: parent
717 width: parent.width * 0.6
718 height: width
719 source: PlanEditLayers.layerInfos.find(l => l.layer === _editingLayer)?.icon ?? "/res/waypoint.svg"
720 color: QGroundControl.globalPalette.accentText
721 }
722
723 QGCMouseArea {
724 anchors.fill: parent
725 onClicked: layerSwitcher.toggle()
726 }
727 }
728
729 // Choice buttons (only layers that are NOT the current one)
730 Repeater {
731 model: PlanEditLayers.layerInfos.filter(l => l.layer !== _editingLayer)
732
733 Rectangle {
734 required property var modelData
735 objectName: "layerSwitcher_choice_" + modelData.nodeType
736 width: choiceRow.implicitWidth + layerSwitcher._spacing * 2
737 height: layerSwitcher._layerButtonSize
738 radius: ScreenTools.defaultBorderRadius
739 color: QGroundControl.globalPalette.windowCard
740 visible: opacity > 0
741 opacity: layerSwitcher.expanded ? 1 : 0
742
743 Behavior on opacity { NumberAnimation { duration: 150 } }
744
745 Row {
746 id: choiceRow
747 anchors.centerIn: parent
748 spacing: layerSwitcher._spacing
749
750 QGCColoredImage {
751 anchors.verticalCenter: parent.verticalCenter
752 width: layerSwitcher._layerButtonSize * 0.6
753 height: width
754 source: modelData.icon
755 color: QGroundControl.globalPalette.textPrimary
756 }
757
758 QGCLabel {
759 anchors.verticalCenter: parent.verticalCenter
760 text: modelData.name
761 color: QGroundControl.globalPalette.textPrimary
762 }
763 }
764
765 QGCMouseArea {
766 anchors.fill: parent
767 onClicked: layerSwitcher.choose(modelData.nodeType)
768 }
769 }
770 }
771 }
772 }
773
774 RowLayout {
775 id: missionStatus
776 anchors.margins: _toolsMargin
777 anchors.left: _calcLeftAnchor()
778 anchors.right: rightPanel.left
779 anchors.bottom: parent.bottom
780 spacing: 0
781 visible: !hidden && _editingLayer == _layerMission && QGroundControl.corePlugin.options.showMissionStatus
782
783 readonly property bool hidden: _planViewSettings.showMissionItemStatus.rawValue ? false : true
784
785 function showMissionStatus() {
786 _planViewSettings.showMissionItemStatus.rawValue = true
787 }
788
789 function _calcLeftAnchor() {
790 let bottomOfToolStrip = toolStrip.y + toolStrip.height
791 let largestStatsHeight = Math.max(terrainStatus.height, missionStats.height)
792 if (bottomOfToolStrip + largestStatsHeight > parent.height - missionStatus.anchors.margins) {
793 return toolStrip.right
794 }
795 return parent.left
796 }
797
798 function _toggleMissionStatusVisibility() {
799 _planViewSettings.showMissionItemStatus.rawValue = _planViewSettings.showMissionItemStatus.rawValue ? false : true
800 }
801
802 ColumnLayout {
803 id: missionStatsButtonLayout
804 Layout.alignment: Qt.AlignBottom
805 spacing: 0
806
807 property real _buttonImplicitWidth: ScreenTools.defaultFontPixelHeight * 1.5
808 property real _buttonImageMargins: _buttonImplicitWidth * 0.15
809
810 Rectangle {
811 id: terrainButton
812 implicitWidth: missionStatsButtonLayout._buttonImplicitWidth
813 implicitHeight: implicitWidth
814 color: checked ? QGroundControl.globalPalette.accent : QGroundControl.globalPalette.windowCard
815
816 property bool checked: true
817
818 QGCColoredImage {
819 anchors.margins: missionStatsButtonLayout._buttonImageMargins
820 anchors.fill: parent
821 source: "/res/terrain.svg"
822 color: parent.checked ? QGroundControl.globalPalette.accentText : QGroundControl.globalPalette.textPrimary
823 }
824
825 QGCMouseArea {
826 anchors.fill: parent
827 onClicked: {
828 terrainButton.checked = true
829 missionStatsButton.checked = false
830 }
831 }
832 }
833
834 Rectangle {
835 id: missionStatsButton
836 implicitWidth: missionStatsButtonLayout._buttonImplicitWidth
837 implicitHeight: implicitWidth
838 color: checked ? QGroundControl.globalPalette.accent : QGroundControl.globalPalette.windowCard
839
840 property bool checked: false
841
842 QGCColoredImage {
843 anchors.margins: missionStatsButtonLayout._buttonImageMargins
844 anchors.fill: parent
845 source: "/res/sliders.svg"
846 color: parent.checked ? QGroundControl.globalPalette.accentText : QGroundControl.globalPalette.textPrimary
847 }
848
849 QGCMouseArea {
850 anchors.fill: parent
851 onClicked: {
852 missionStatsButton.checked = true
853 terrainButton.checked = false
854 }
855 }
856 }
857
858 Rectangle {
859 id: bottomStatusOpenCloseButton
860 implicitWidth: missionStatsButtonLayout._buttonImplicitWidth
861 implicitHeight: implicitWidth
862 color: QGroundControl.globalPalette.windowCard
863
864 QGCColoredImage {
865 anchors.margins: missionStatsButtonLayout._buttonImageMargins
866 anchors.fill: parent
867 source: "/res/chevron-double-left.svg"
868 color: QGroundControl.globalPalette.textPrimary
869 }
870
871 QGCMouseArea {
872 anchors.fill: parent
873 onClicked: missionStatus._toggleMissionStatusVisibility()
874 }
875 }
876 }
877
878 TerrainStatus {
879 id: terrainStatus
880 Layout.alignment: Qt.AlignBottom
881 Layout.fillWidth: true
882 height: ScreenTools.defaultFontPixelHeight * 7
883 missionController: _missionController
884 visible: terrainButton.checked
885 onSetCurrentSeqNum: _missionController.setCurrentPlanViewSeqNum(seqNum, true)
886 }
887
888 MissionStats {
889 id: missionStats
890 Layout.alignment: Qt.AlignBottom
891 Layout.fillWidth: true
892 visible: missionStatsButton.checked
893 planMasterController: _root._planMasterController
894 }
895 }
896 }
897
898 //- ToolStrip ToolStripDropPanel Components
899
900 Component {
901 id: patternDropPanel
902
903 ColumnLayout {
904 spacing: ScreenTools.defaultFontPixelWidth * 0.5
905
906 QGCLabel { text: qsTr("Create complex pattern:") }
907
908 Repeater {
909 model: _missionController.complexMissionItems
910
911 QGCButton {
912 text: modelData.translatedName
913 Layout.fillWidth: true
914
915 onClicked: {
916 insertComplexItemAfterCurrent(modelData.canonicalName)
917 dropPanel.hide()
918 }
919 }
920 }
921 } // Column
922 }
923
924 Component {
925 id: vtolTakeoffDropPanel
926
927 ColumnLayout {
928 spacing: ScreenTools.defaultFontPixelWidth * 0.5
929
930 QGCLabel { text: qsTr("Choose takeoff mode:") }
931
932 QGCButton {
933 objectName: "planTakeoff_vtolButton"
934 text: qsTr("VTOL takeoff")
935 Layout.fillWidth: true
936 primary: true
937
938 onClicked: {
939 insertTakeoffItemAfterCurrent()
940 dropPanel.hide()
941 }
942 }
943
944 QGCButton {
945 objectName: "planTakeoff_mcButton"
946 text: qsTr("Multicopter takeoff")
947 Layout.fillWidth: true
948
949 onClicked: {
950 insertVTOLMulticopterTakeoffItemAfterCurrent()
951 dropPanel.hide()
952 }
953 }
954 }
955 }
956
957 QGCPopupDialogFactory {
958 id: promptForPlanUsageOnVehicleChangePopupFactory
959
960 dialogComponent: promptForPlanUsageOnVehicleChangePopupComponent
961 }
962
963 Component {
964 id: promptForPlanUsageOnVehicleChangePopupComponent
965 QGCPopupDialog {
966 title: _planMasterController.managerVehicle.isOfflineEditingVehicle ? qsTr("Plan View - Vehicle Disconnected") : qsTr("Plan View - Vehicle Changed")
967 buttons: Dialog.NoButton
968
969 ColumnLayout {
970 QGCLabel {
971 Layout.maximumWidth: parent.width
972 wrapMode: QGCLabel.WordWrap
973 text: _planMasterController.managerVehicle.isOfflineEditingVehicle ?
974 qsTr("The vehicle associated with the plan in the Plan View is no longer available. What would you like to do with that plan?") : qsTr("The plan being worked on in the Plan View is not from the current vehicle. What would you like to do with that plan?")
975 }
976
977 QGCButton {
978 Layout.fillWidth: true
979 text: (_planMasterController.dirtyForSave) ?
980 (_planMasterController.managerVehicle.isOfflineEditingVehicle ?
981 qsTr("Discard Unsaved Changes") : qsTr("Discard Unsaved Changes, Load New Plan From Vehicle")) : qsTr("Load New Plan From Vehicle")
982 onClicked: {
983 _planMasterController.showPlanFromManagerVehicle()
984 _promptForPlanUsageShowing = false
985 close();
986 }
987 }
988
989 QGCButton {
990 Layout.fillWidth: true
991 text: _planMasterController.managerVehicle.isOfflineEditingVehicle ?
992 qsTr("Keep Current Plan") : qsTr("Keep Current Plan, Don't Update From Vehicle")
993 onClicked: {
994 _promptForPlanUsageShowing = false
995 close()
996 }
997 }
998 }
999 }
1000 }
1001
1002 Component {
1003 id: insertOrCancelROIDropPanelComponent
1004
1005 DropPanel {
1006 id: insertOrCancelROIDropPanel
1007 onClosed: destroy()
1008
1009 property var mapClickCoord
1010
1011 sourceComponent: Component {
1012 ColumnLayout {
1013 spacing: ScreenTools.defaultFontPixelWidth / 2
1014
1015 QGCButton {
1016 Layout.fillWidth: true
1017 text: qsTr("Insert ROI")
1018
1019 onClicked: {
1020 insertOrCancelROIDropPanel.close()
1021 insertROIAfterCurrent(mapClickCoord)
1022 }
1023 }
1024
1025 QGCButton {
1026 Layout.fillWidth: true
1027 text: qsTr("Insert Cancel ROI")
1028
1029 onClicked: {
1030 insertOrCancelROIDropPanel.close()
1031 insertCancelROIAfterCurrent()
1032 }
1033 }
1034 }
1035 }
1036 }
1037 }
1038}