PlanView.qml 52.9 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9

10 11
import QtQuick          2.3
import QtQuick.Controls 1.2
Don Gagne's avatar
Don Gagne committed
12
import QtQuick.Dialogs  1.2
13 14 15
import QtLocation       5.3
import QtPositioning    5.3
import QtQuick.Layouts  1.2
16
import QtQuick.Window   2.2
Don Gagne's avatar
Don Gagne committed
17

18 19 20 21 22 23 24 25 26 27 28
import QGroundControl                   1.0
import QGroundControl.FlightMap         1.0
import QGroundControl.ScreenTools       1.0
import QGroundControl.Controls          1.0
import QGroundControl.FactSystem        1.0
import QGroundControl.FactControls      1.0
import QGroundControl.Palette           1.0
import QGroundControl.Controllers       1.0
import QGroundControl.ShapeFileHelper   1.0
import QGroundControl.Airspace          1.0
import QGroundControl.Airmap            1.0
Don Gagne's avatar
Don Gagne committed
29

30
Item {
31
    id: _root
32

Gus Grubba's avatar
Gus Grubba committed
33 34
    property bool planControlColapsed: false

35 36
    readonly property int   _decimalPlaces:             8
    readonly property real  _margin:                    ScreenTools.defaultFontPixelHeight * 0.5
37
    readonly property real  _toolsMargin:               ScreenTools.defaultFontPixelWidth * 0.75
Gus Grubba's avatar
Gus Grubba committed
38
    readonly property real  _radius:                    ScreenTools.defaultFontPixelWidth  * 0.5
39 40 41
    readonly property real  _rightPanelWidth:           Math.min(parent.width / 3, ScreenTools.defaultFontPixelWidth * 30)
    readonly property var   _defaultVehicleCoordinate:  QtPositioning.coordinate(37.803784, -122.462276)
    readonly property bool  _waypointsOnlyMode:         QGroundControl.corePlugin.options.missionWaypointsOnly
42

Gus Grubba's avatar
Gus Grubba committed
43
    property bool   _airspaceEnabled:                    QGroundControl.airmapSupported ? (QGroundControl.settingsManager.airMapSettings.enableAirMap.rawValue && QGroundControl.airspaceManager.connected): false
Gus Grubba's avatar
Gus Grubba committed
44 45 46 47 48 49 50 51
    property var    _missionController:                 _planMasterController.missionController
    property var    _geoFenceController:                _planMasterController.geoFenceController
    property var    _rallyPointController:              _planMasterController.rallyPointController
    property var    _visualItems:                       _missionController.visualItems
    property bool   _lightWidgetBorders:                editorMap.isSatelliteMap
    property bool   _addWaypointOnClick:                false
    property bool   _addROIOnClick:                     false
    property bool   _singleComplexItem:                 _missionController.complexMissionItemNames.length === 1
52
    property int    _editingLayer:                      layerTabBar.currentIndex ? _layers[layerTabBar.currentIndex] : _layerMission
Gus Grubba's avatar
Gus Grubba committed
53
    property int    _toolStripBottom:                   toolStrip.height + toolStrip.y
54
    property var    _appSettings:                       QGroundControl.settingsManager.appSettings
55
    property var    _planViewSettings:                  QGroundControl.settingsManager.planViewSettings
56

Gus Grubba's avatar
Gus Grubba committed
57 58
    readonly property var       _layers:                [_layerMission, _layerGeoFence, _layerRallyPoints]

59 60 61 62
    readonly property int       _layerMission:              1
    readonly property int       _layerGeoFence:             2
    readonly property int       _layerRallyPoints:          3
    readonly property string    _armedVehicleUploadPrompt:  qsTr("Vehicle is currently armed. Do you want to upload the mission to the vehicle?")
63

64
    function mapCenter() {
65
        var coordinate = editorMap.center
66
        coordinate.latitude  = coordinate.latitude.toFixed(_decimalPlaces)
67
        coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
68
        coordinate.altitude  = coordinate.altitude.toFixed(_decimalPlaces)
69 70 71
        return coordinate
    }

72
    function updateAirspace(reset) {
73 74 75 76
        if(_airspaceEnabled) {
            var coordinateNW = editorMap.toCoordinate(Qt.point(0,0), false /* clipToViewPort */)
            var coordinateSE = editorMap.toCoordinate(Qt.point(width,height), false /* clipToViewPort */)
            if(coordinateNW.isValid && coordinateSE.isValid) {
77
                QGroundControl.airspaceManager.setROI(coordinateNW, coordinateSE, true /*planView*/, reset)
78 79 80 81
            }
        }
    }

82 83 84 85 86
    property bool _firstMissionLoadComplete:    false
    property bool _firstFenceLoadComplete:      false
    property bool _firstRallyLoadComplete:      false
    property bool _firstLoadComplete:           false

87
    MapFitFunctions {
88
        id:                         mapFitFunctions  // The name for this id cannot be changed without breaking references outside of this code. Beware!
89 90
        map:                        editorMap
        usePlannedHomePosition:     true
91
        planMasterController:       _planMasterController
92 93
    }

94
    on_AirspaceEnabledChanged: {
95
        if(QGroundControl.airmapSupported) {
96 97
            if(_airspaceEnabled) {
                planControlColapsed = QGroundControl.airspaceManager.airspaceVisible
98
                updateAirspace(true)
99 100 101
            } else {
                planControlColapsed = false
            }
102
        } else {
Gus Grubba's avatar
Gus Grubba committed
103 104 105 106
            planControlColapsed = false
        }
    }

107
    onVisibleChanged: {
108 109 110 111 112 113
        if(visible) {
            editorMap.zoomLevel = QGroundControl.flightMapZoom
            editorMap.center    = QGroundControl.flightMapPosition
            if (!_planMasterController.containsItems) {
                toolStrip.simulateClick(toolStrip.fileButtonIndex)
            }
114 115 116
        }
    }

DonLakeFlyer's avatar
DonLakeFlyer committed
117
    Connections {
Gus Grubba's avatar
Gus Grubba committed
118
        target: _appSettings ? _appSettings.defaultMissionItemAltitude : null
DonLakeFlyer's avatar
DonLakeFlyer committed
119 120
        onRawValueChanged: {
            if (_visualItems.count > 1) {
121
                mainWindow.showComponentDialog(applyNewAltitude, qsTr("Apply new alititude"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
DonLakeFlyer's avatar
DonLakeFlyer committed
122 123 124 125 126 127 128 129 130 131
            }
        }
    }

    Component {
        id: applyNewAltitude
        QGCViewMessage {
            message:    qsTr("You have changed the default altitude for mission items. Would you like to apply that altitude to all the items in the current mission?")
            function accept() {
                hideDialog()
132
                _missionController.applyDefaultMissionAltitude()
DonLakeFlyer's avatar
DonLakeFlyer committed
133 134 135 136
            }
        }
    }

137
    Component {
138 139 140 141 142 143 144 145 146 147
        id: firmwareOrVehicleMismatchUploadDialogComponent
        QGCViewMessage {
            message: qsTr("This Plan was created for a different firmware or vehicle type than the firmware/vehicle type of vehicle you are uploading to. " +
                            "This can lead to errors or incorrect behavior. " +
                            "It is recommended to recreate the Plan for the correct firmware/vehicle type.\n\n" +
                            "Click 'Ok' to upload the Plan anyway.")

            function accept() {
                _planMasterController.sendToVehicle()
                hideDialog()
148 149 150 151
            }
        }
    }

Gus Grubba's avatar
Gus Grubba committed
152
    Connections {
153
        target: QGroundControl.airspaceManager
154
        onAirspaceVisibleChanged: {
155
            planControlColapsed = QGroundControl.airspaceManager.airspaceVisible
Gus Grubba's avatar
Gus Grubba committed
156 157 158
        }
    }

159 160 161 162 163 164 165
    Component {
        id: noItemForKML
        QGCViewMessage {
            message:    qsTr("You need at least one item to create a KML.")
        }
    }

166
    PlanMasterController {
167 168
        id:         _planMasterController
        flyView:    false
169

170
        Component.onCompleted: {
171
            _planMasterController.start()
172
            _missionController.setCurrentPlanViewSeqNum(0, true)
173
            mainWindow.planMasterControllerPlanView = _planMasterController
174 175
        }

176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        function waitingOnIncompleteDataMessage(save) {
            var saveOrUpload = save ? qsTr("Save") : qsTr("Upload")
            mainWindow.showMessageDialog(qsTr("Unable to %1").arg(saveOrUpload), qsTr("Plan has incomplete items. Complete all items and %1 again.").arg(saveOrUpload))
        }

        function waitingOnTerrainDataMessage(save) {
            var saveOrUpload = save ? qsTr("Save") : qsTr("Upload")
            mainWindow.showMessageDialog(qsTr("Unable to %1").arg(saveOrUpload), qsTr("Plan is waiting on terrain data from server for correct altitude values."))
        }

        function checkReadyForSaveUpload(save) {
            if (readyForSaveState() == VisualMissionItem.NotReadyForSaveData) {
                waitingOnIncompleteDataMessage(save)
                return false
            } else if (readyForSaveState() == VisualMissionItem.NotReadyForSaveTerrain) {
                waitingOnTerrainDataMessage(save)
                return false
            }
            return true
195 196
        }

197
        function upload() {
198
            if (!checkReadyForSaveUpload(false /* save */)) {
199 200
                return
            }
201 202 203 204 205 206 207 208 209 210
            switch (_missionController.sendToVehiclePreCheck()) {
                case MissionController.SendToVehiclePreCheckStateOk:
                    sendToVehicle()
                    break
                case MissionController.SendToVehiclePreCheckStateActiveMission:
                    mainWindow.showMessageDialog(qsTr("Send To Vehicle"), qsTr("Current mission must be paused prior to uploading a new Plan"))
                    break
                case MissionController.SendToVehiclePreCheckStateFirwmareVehicleMismatch:
                    mainWindow.showComponentDialog(firmwareOrVehicleMismatchUploadDialogComponent, qsTr("Plan Upload"), mainWindow.showDialogDefaultWidth, StandardButton.Ok | StandardButton.Cancel)
                    break
211
            }
DonLakeFlyer's avatar
DonLakeFlyer committed
212 213
        }

214
        function loadFromSelectedFile() {
215
            fileDialog.title =          qsTr("Select Plan File")
DonLakeFlyer's avatar
DonLakeFlyer committed
216
            fileDialog.planFiles =      true
217
            fileDialog.selectExisting = true
Gus Grubba's avatar
Gus Grubba committed
218
            fileDialog.nameFilters =    _planMasterController.loadNameFilters
219 220
            fileDialog.fileExtension =  _appSettings.planFileExtension
            fileDialog.fileExtension2 = _appSettings.missionFileExtension
221
            fileDialog.openForLoad()
222 223 224
        }

        function saveToSelectedFile() {
225
            if (!checkReadyForSaveUpload(true /* save */)) {
226 227
                return
            }
228
            fileDialog.title =          qsTr("Save Plan")
229
            fileDialog.planFiles =      true
230
            fileDialog.selectExisting = false
Gus Grubba's avatar
Gus Grubba committed
231
            fileDialog.nameFilters =    _planMasterController.saveNameFilters
232 233
            fileDialog.fileExtension =  _appSettings.planFileExtension
            fileDialog.fileExtension2 = _appSettings.missionFileExtension
234
            fileDialog.openForSave()
235 236
        }

237
        function fitViewportToItems() {
238
            mapFitFunctions.fitMapViewportToMissionItems()
239
        }
240 241

        function saveKmlToSelectedFile() {
242
            if (!checkReadyForSaveUpload(true /* save */)) {
243 244
                return
            }
245
            fileDialog.title =          qsTr("Save KML")
246
            fileDialog.planFiles =      false
247
            fileDialog.selectExisting = false
248 249
            fileDialog.nameFilters =    ShapeFileHelper.fileDialogKMLFilters
            fileDialog.fileExtension =  _appSettings.kmlFileExtension
250
            fileDialog.fileExtension2 = ""
251 252
            fileDialog.openForSave()
        }
253
    }
254

255 256
    Connections {
        target: _missionController
257

258
        onNewItemsFromVehicle: {
Gus Grubba's avatar
Gus Grubba committed
259
            if (_visualItems && _visualItems.count !== 1) {
260 261
                mapFitFunctions.fitMapViewportToMissionItems()
            }
262
            _missionController.setCurrentPlanViewSeqNum(0, true)
263 264
        }
    }
265

266 267 268 269 270 271 272 273
    function insertSimpleItemAfterCurrent(coordinate) {
        var nextIndex = _missionController.currentPlanViewVIIndex + 1
        _missionController.insertSimpleMissionItem(coordinate, nextIndex, true /* makeCurrentItem */)
    }

    function insertROIAfterCurrent(coordinate) {
        var nextIndex = _missionController.currentPlanViewVIIndex + 1
        _missionController.insertROIMissionItem(coordinate, nextIndex, true /* makeCurrentItem */)
274 275
    }

276 277 278
    function insertCancelROIAfterCurrent() {
        var nextIndex = _missionController.currentPlanViewVIIndex + 1
        _missionController.insertCancelROIMissionItem(nextIndex, true /* makeCurrentItem */)
279 280
    }

281 282 283 284 285
    function insertComplexItemAfterCurrent(complexItemName) {
        var nextIndex = _missionController.currentPlanViewVIIndex + 1
        _missionController.insertComplexMissionItem(complexItemName, mapCenter(), nextIndex, true /* makeCurrentItem */)
    }

286 287 288 289 290 291 292 293 294 295 296
    function insertTakeItemAfterCurrent() {
        var nextIndex = _missionController.currentPlanViewVIIndex + 1
        _missionController.insertTakeoffItem(mapCenter(), nextIndex, true /* makeCurrentItem */)
    }

    function insertLandItemAfterCurrent() {
        var nextIndex = _missionController.currentPlanViewVIIndex + 1
        _missionController.insertLandItem(mapCenter(), nextIndex, true /* makeCurrentItem */)
    }


297 298 299 300 301
    function selectNextNotReady() {
        var foundCurrent = false
        for (var i=0; i<_missionController.visualItems.count; i++) {
            var vmi = _missionController.visualItems.get(i)
            if (vmi.readyForSaveState === VisualMissionItem.NotReadyForSaveData) {
302
                _missionController.setCurrentPlanViewSeqNum(vmi.sequenceNumber, true)
303 304 305 306 307
                break
            }
        }
    }

308 309
    property int _moveDialogMissionItemIndex

310 311
    QGCFileDialog {
        id:             fileDialog
Gus Grubba's avatar
Gus Grubba committed
312
        folder:         _appSettings ? _appSettings.missionSavePath : ""
313

314 315
        property bool planFiles: true    ///< true: working with plan files, false: working with kml file

316
        onAcceptedForSave: {
317
            if (planFiles) {
Gus Grubba's avatar
Gus Grubba committed
318
                _planMasterController.saveToFile(file)
319
            } else {
Gus Grubba's avatar
Gus Grubba committed
320
                _planMasterController.saveToKml(file)
321
            }
322
            close()
323 324
        }

325
        onAcceptedForLoad: {
326 327 328
            _planMasterController.loadFromFile(file)
            _planMasterController.fitViewportToItems()
            _missionController.setCurrentPlanViewSeqNum(0, true)
329
            close()
330 331 332
        }
    }

333 334 335 336 337
    Component {
        id: moveDialog
        QGCViewDialog {
            function accept() {
                var toIndex = toCombo.currentIndex
Gus Grubba's avatar
Gus Grubba committed
338
                if (toIndex === 0) {
339 340
                    toIndex = 1
                }
341
                _missionController.moveMissionItem(_moveDialogMissionItemIndex, toIndex)
342 343 344 345 346 347 348 349 350 351 352
                hideDialog()
            }
            Column {
                anchors.left:   parent.left
                anchors.right:  parent.right
                spacing:        ScreenTools.defaultFontPixelHeight

                QGCLabel {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    wrapMode:       Text.WordWrap
353
                    text:           qsTr("Move the selected mission item to the be after following mission item:")
354 355 356 357
                }

                QGCComboBox {
                    id:             toCombo
358
                    model:          _visualItems.count
359 360 361 362 363 364
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

365
    Item {
Don Gagne's avatar
Don Gagne committed
366
        id:             panel
367
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
368

369
        FlightMap {
370 371 372 373 374
            id:                         editorMap
            anchors.fill:               parent
            mapName:                    "MissionEditor"
            allowGCSLocationCenter:     true
            allowVehicleLocationCenter: true
375
            planView:                   true
Don Gagne's avatar
Don Gagne committed
376

377 378 379
            zoomLevel:                  QGroundControl.flightMapZoom
            center:                     QGroundControl.flightMapPosition

380
            // This is the center rectangle of the map which is not obscured by tools
381
            property rect centerViewport:   Qt.rect(_leftToolWidth + _margin,  _margin, editorMap.width - _leftToolWidth - _rightToolWidth - (_margin * 2), (terrainStatus.visible ? terrainStatus.y : height - _margin) - _margin)
382

383 384
            property real _leftToolWidth:       toolStrip.x + toolStrip.width
            property real _rightToolWidth:      rightPanel.width + rightPanel.anchors.rightMargin
385
            property real _nonInteractiveOpacity:  0.5
386

387 388
            // Initial map position duplicates Fly view position
            Component.onCompleted: editorMap.center = QGroundControl.flightMapPosition
389

390 391
            QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

392 393 394 395 396 397 398 399
            onZoomLevelChanged: {
                QGroundControl.flightMapZoom = zoomLevel
                updateAirspace(false)
            }
            onCenterChanged: {
                QGroundControl.flightMapPosition = center
                updateAirspace(false)
            }
400

401 402 403
            MouseArea {
                anchors.fill: parent
                onClicked: {
404 405
                    // Take focus to close any previous editing
                    editorMap.focus = true
406 407 408 409
                    var coordinate = editorMap.toCoordinate(Qt.point(mouse.x, mouse.y), false /* clipToViewPort */)
                    coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
                    coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
                    coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
410

411 412 413
                    switch (_editingLayer) {
                    case _layerMission:
                        if (_addWaypointOnClick) {
414
                            insertSimpleItemAfterCurrent(coordinate)
415
                        } else if (_addROIOnClick) {
416
                            insertROIAfterCurrent(coordinate)
417
                            _addROIOnClick = false
418
                        }
419

420 421
                        break
                    case _layerRallyPoints:
Gus Grubba's avatar
Gus Grubba committed
422
                        if (_rallyPointController.supported && _addWaypointOnClick) {
423
                            _rallyPointController.addPoint(coordinate)
424
                        }
425
                        break
Don Gagne's avatar
Don Gagne committed
426
                    }
Don Gagne's avatar
Don Gagne committed
427
                }
428
            }
Don Gagne's avatar
Don Gagne committed
429

430 431
            // Add the mission item visuals to the map
            Repeater {
432
                model: _missionController.visualItems
433 434
                delegate: MissionItemMapVisual {
                    map:        editorMap
435
                    onClicked:  _missionController.setCurrentPlanViewSeqNum(sequenceNumber, false)
436 437
                    opacity:    _editingLayer == _layerMission ? 1 : editorMap._nonInteractiveOpacity
                    interactive: _editingLayer == _layerMission
438
                }
439
            }
440

441 442
            // Add lines between waypoints
            MissionLineView {
443
                showSpecialVisual:  _missionController.isROIBeginCurrentItem
444
                model:              _missionController.simpleFlightPathSegments
445
                opacity:            _editingLayer == _layerMission ? 1 : editorMap._nonInteractiveOpacity
446
            }
447

448
            // Direction arrows in waypoint lines
449 450 451 452 453 454
            MapItemView {
                model: _editingLayer == _layerMission ? _missionController.directionArrows : undefined

                delegate: MapLineArrow {
                    fromCoord:      object ? object.coordinate1 : undefined
                    toCoord:        object ? object.coordinate2 : undefined
455 456 457 458
                    arrowPosition:  3
                    z:              QGroundControl.zOrderWaypointLines + 1
                }
            }
459 460 461

            // Incomplete segment lines
            MapItemView {
462
                model: _missionController.incompleteComplexItemLines
463 464 465 466 467 468

                delegate: MapPolyline {
                    path:       [ object.coordinate1, object.coordinate2 ]
                    line.width: 1
                    line.color: "red"
                    z:          QGroundControl.zOrderWaypointLines
469
                    opacity:    _editingLayer == _layerMission ? 1 : editorMap._nonInteractiveOpacity
470 471
                }
            }
472 473 474 475 476 477 478

            // UI for splitting the current segment
            MapQuickItem {
                id:             splitSegmentItem
                anchorPoint.x:  sourceItem.width / 2
                anchorPoint.y:  sourceItem.height / 2
                z:              QGroundControl.zOrderWaypointLines + 1
479
                visible:        _editingLayer == _layerMission
480 481

                sourceItem: SplitIndicator {
482 483 484
                    onClicked:  _missionController.insertSimpleMissionItem(splitSegmentItem.coordinate,
                                                                           _missionController.currentPlanViewVIIndex,
                                                                           true /* makeCurrentItem */)
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
                }

                function _updateSplitCoord() {
                    if (_missionController.splitSegment) {
                        var distance = _missionController.splitSegment.coordinate1.distanceTo(_missionController.splitSegment.coordinate2)
                        var azimuth = _missionController.splitSegment.coordinate1.azimuthTo(_missionController.splitSegment.coordinate2)
                        splitSegmentItem.coordinate = _missionController.splitSegment.coordinate1.atDistanceAndAzimuth(distance / 2, azimuth)
                    } else {
                        coordinate = QtPositioning.coordinate()
                    }
                }

                Connections {
                    target:                 _missionController
                    onSplitSegmentChanged:  splitSegmentItem._updateSplitCoord()
                }

                Connections {
                    target:                 _missionController.splitSegment
                    onCoordinate1Changed:   splitSegmentItem._updateSplitCoord()
                    onCoordinate2Changed:   splitSegmentItem._updateSplitCoord()
506 507 508
                }
            }

509 510 511
            // Add the vehicles to the map
            MapItemView {
                model: QGroundControl.multiVehicleManager.vehicles
512
                delegate: VehicleMapItem {
513 514
                    vehicle:        object
                    coordinate:     object.coordinate
515
                    map:            editorMap
516 517
                    size:           ScreenTools.defaultFontPixelHeight * 3
                    z:              QGroundControl.zOrderMapItems - 1
518
                }
519
            }
520

521 522
            GeoFenceMapVisuals {
                map:                    editorMap
523
                myGeoFenceController:   _geoFenceController
524
                interactive:            _editingLayer == _layerGeoFence
525
                homePosition:           _missionController.plannedHomePosition
526
                planView:               true
527
                opacity:                _editingLayer != _layerGeoFence ? editorMap._nonInteractiveOpacity : 1
528
            }
529

530 531
            RallyPointMapVisuals {
                map:                    editorMap
532
                myRallyPointController: _rallyPointController
533 534
                interactive:            _editingLayer == _layerRallyPoints
                planView:               true
535
                opacity:                _editingLayer != _layerRallyPoints ? editorMap._nonInteractiveOpacity : 1
536
            }
537

538 539
            // Airspace overlap support
            MapItemView {
540
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.circles : []
541 542 543
                delegate: MapCircle {
                    center:         object.center
                    radius:         object.radius
544
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
545 546
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
547 548 549 550
                }
            }

            MapItemView {
551
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : []
552 553
                delegate: MapPolygon {
                    path:           object.polygon
554
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
555 556
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
557 558
                }
            }
559
        }
560

561 562
        //-----------------------------------------------------------
        // Left tool strip
Gus Grubba's avatar
Gus Grubba committed
563
        ToolStrip {
564
            id:                 toolStrip
565
            anchors.margins:    _toolsMargin
566 567 568
            anchors.left:       parent.left
            anchors.top:        parent.top
            z:                  QGroundControl.zOrderWidgets
569
            maxHeight:          parent.height - toolStrip.y
570
            title:              qsTr("Plan")
571

572 573 574 575 576 577 578 579
            //readonly property int flyButtonIndex:       0
            readonly property int fileButtonIndex:      0
            readonly property int takeoffButtonIndex:   1
            readonly property int waypointButtonIndex:  2
            readonly property int roiButtonIndex:       3
            readonly property int patternButtonIndex:   4
            readonly property int landButtonIndex:      5
            readonly property int centerButtonIndex:    6
580

581 582
            property bool _isRallyLayer:    _editingLayer == _layerRallyPoints
            property bool _isMissionLayer:  _editingLayer == _layerMission
583

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
            ToolStripActionList {
                id: toolStripActionList
                model: [
                    ToolStripAction {
                        text:                   qsTr("File")
                        enabled:                !_planMasterController.syncInProgress
                        visible:                true
                        showAlternateIcon:      _planMasterController.dirty
                        iconSource:             "/qmlimages/MapSync.svg"
                        alternateIconSource:    "/qmlimages/MapSyncChanged.svg"
                        dropPanelComponent:     syncDropPanel
                    },
                    ToolStripAction {
                        text:       qsTr("Takeoff")
                        iconSource: "/res/takeoff.svg"
                        enabled:    _missionController.isInsertTakeoffValid
                        visible:    toolStrip._isMissionLayer
                        onTriggered: {
                            toolStrip.allAddClickBoolsOff()
                            insertTakeItemAfterCurrent()
                        }
                    },
                    ToolStripAction {
                        text:               _editingLayer == _layerRallyPoints ? qsTr("Rally Point") : qsTr("Waypoint")
                        iconSource:         "/qmlimages/MapAddMission.svg"
                        enabled:            toolStrip._isRallyLayer ? true : _missionController.flyThroughCommandsAllowed
                        visible:            toolStrip._isRallyLayer || toolStrip._isMissionLayer
                        checkable:          true
                        onCheckedChanged:   _addWaypointOnClick = checked
                        property bool myAddWaypointOnClick: _addWaypointOnClick
                        onMyAddWaypointOnClickChanged: checked = _addWaypointOnClick
                    },
                    ToolStripAction {
                        text:               _missionController.isROIActive ? qsTr("Cancel ROI") : qsTr("ROI")
                        iconSource:         "/qmlimages/MapAddMission.svg"
                        enabled:            !_missionController.onlyInsertTakeoffValid
                        visible:            toolStrip._isMissionLayer && _planMasterController.controllerVehicle.roiModeSupported
                        checkable:          !_missionController.isROIActive
                        onCheckedChanged:   _addROIOnClick = checked
                        onTriggered: {
                            if (_missionController.isROIActive) {
                                toolStrip.allAddClickBoolsOff()
                                insertCancelROIAfterCurrent()
                            }
                        }
                        property bool myAddROIOnClick: _addROIOnClick
                        onMyAddROIOnClickChanged: checked = _addROIOnClick
                    },
                    ToolStripAction {
                        text:               _singleComplexItem ? _missionController.complexMissionItemNames[0] : qsTr("Pattern")
                        iconSource:         "/qmlimages/MapDrawShape.svg"
                        enabled:            _missionController.flyThroughCommandsAllowed
                        visible:            toolStrip._isMissionLayer
                        dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel
                        onTriggered: {
                            toolStrip.allAddClickBoolsOff()
                            if (_singleComplexItem) {
                                insertComplexItemAfterCurrent(_missionController.complexMissionItemNames[0])
                            }
                        }
                    },
                    ToolStripAction {
                        text:       _planMasterController.controllerVehicle.multiRotor ? qsTr("Return") : qsTr("Land")
                        iconSource: "/res/rtl.svg"
                        enabled:    _missionController.isInsertLandValid
                        visible:    toolStrip._isMissionLayer
                        onTriggered: {
                            toolStrip.allAddClickBoolsOff()
                            insertLandItemAfterCurrent()
                        }
                    },
                    ToolStripAction {
                        text:               qsTr("Center")
                        iconSource:         "/qmlimages/MapCenter.svg"
                        enabled:            true
                        visible:            true
                        dropPanelComponent: centerMapDropPanel
                    }
                ]
            }

            model: toolStripActionList.model
666

667 668 669 670 671
            function allAddClickBoolsOff() {
                _addROIOnClick =        false
                _addWaypointOnClick =   false
            }

672
            onDropped: allAddClickBoolsOff()
Gus Grubba's avatar
Gus Grubba committed
673
        }
674

Gus Grubba's avatar
Gus Grubba committed
675
        //-----------------------------------------------------------
676 677 678
        // Right pane for mission editing controls
        Rectangle {
            id:                 rightPanel
679
            height:             parent.height
680 681
            width:              _rightPanelWidth
            color:              qgcPal.window
682
            opacity:            layerTabBar.visible ? 0.2 : 0
Gus Grubba's avatar
Gus Grubba committed
683 684
            anchors.bottom:     parent.bottom
            anchors.right:      parent.right
685
            anchors.rightMargin: _toolsMargin
686
        }
Gus Grubba's avatar
Gus Grubba committed
687 688
        //-------------------------------------------------------
        // Right Panel Controls
689
        Item {
Gus Grubba's avatar
Gus Grubba committed
690
            anchors.fill:           rightPanel
691
            anchors.topMargin:      _toolsMargin
Gus Grubba's avatar
Gus Grubba committed
692 693 694
            DeadMouseArea {
                anchors.fill:   parent
            }
Gus Grubba's avatar
Gus Grubba committed
695 696
            Column {
                id:                 rightControls
Gus Grubba's avatar
Gus Grubba committed
697
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
698 699
                anchors.left:       parent.left
                anchors.right:      parent.right
Gus Grubba's avatar
Gus Grubba committed
700 701 702 703
                anchors.top:        parent.top
                //-------------------------------------------------------
                // Airmap Airspace Control
                AirspaceControl {
Gus Grubba's avatar
Gus Grubba committed
704 705
                    id:             airspaceControl
                    width:          parent.width
706
                    visible:        _airspaceEnabled
707
                    planView:       true
708
                    showColapse:    true
709
                }
Gus Grubba's avatar
Gus Grubba committed
710 711 712 713
                //-------------------------------------------------------
                // Mission Controls (Colapsed)
                Rectangle {
                    width:      parent.width
Gus Grubba's avatar
Gus Grubba committed
714
                    height:     planControlColapsed ? colapsedRow.height + ScreenTools.defaultFontPixelHeight : 0
Gus Grubba's avatar
Gus Grubba committed
715 716
                    color:      qgcPal.missionItemEditor
                    radius:     _radius
717
                    visible:    planControlColapsed && _airspaceEnabled
Gus Grubba's avatar
Gus Grubba committed
718 719 720 721 722 723 724
                    Row {
                        id:                     colapsedRow
                        spacing:                ScreenTools.defaultFontPixelWidth
                        anchors.left:           parent.left
                        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
                        anchors.verticalCenter: parent.verticalCenter
                        QGCColoredImage {
725 726 727 728 729
                            width:              height
                            height:             ScreenTools.defaultFontPixelWidth * 2.5
                            sourceSize.height:  height
                            source:             "qrc:/res/waypoint.svg"
                            color:              qgcPal.text
Gus Grubba's avatar
Gus Grubba committed
730 731 732
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        QGCLabel {
733 734
                            text:               qsTr("Plan")
                            color:              qgcPal.text
Gus Grubba's avatar
Gus Grubba committed
735
                            anchors.verticalCenter: parent.verticalCenter
736 737
                        }
                    }
Gus Grubba's avatar
Gus Grubba committed
738 739 740 741
                    QGCColoredImage {
                        width:                  height
                        height:                 ScreenTools.defaultFontPixelWidth * 2.5
                        sourceSize.height:      height
742
                        source:                 QGroundControl.airmapSupported ? "qrc:/airmap/expand.svg" : ""
743
                        color:                  "white"
744
                        visible:                QGroundControl.airmapSupported
Gus Grubba's avatar
Gus Grubba committed
745 746 747 748 749 750
                        anchors.right:          parent.right
                        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                        anchors.verticalCenter: parent.verticalCenter
                    }
                    MouseArea {
                        anchors.fill:   parent
751
                        enabled:        QGroundControl.airmapSupported
Gus Grubba's avatar
Gus Grubba committed
752
                        onClicked: {
753
                            QGroundControl.airspaceManager.airspaceVisible = false
Gus Grubba's avatar
Gus Grubba committed
754 755
                        }
                    }
Gus Grubba's avatar
Gus Grubba committed
756
                }
Gus Grubba's avatar
Gus Grubba committed
757 758
                //-------------------------------------------------------
                // Mission Controls (Expanded)
759 760
                QGCTabBar {
                    id:         layerTabBar
Gus Grubba's avatar
Gus Grubba committed
761
                    width:      parent.width
Gus Grubba's avatar
Gus Grubba committed
762
                    visible:    (!planControlColapsed || !_airspaceEnabled) && QGroundControl.corePlugin.options.enablePlanViewSelector
763 764 765 766 767 768 769 770 771 772 773
                    Component.onCompleted: currentIndex = 0
                    QGCTabButton {
                        text:       qsTr("Mission")
                    }
                    QGCTabButton {
                        text:       qsTr("Fence")
                        enabled:    _geoFenceController.supported
                    }
                    QGCTabButton {
                        text:       qsTr("Rally")
                        enabled:    _rallyPointController.supported
Gus Grubba's avatar
Gus Grubba committed
774 775 776 777 778 779 780 781 782 783
                    }
                }
            }
            //-------------------------------------------------------
            // Mission Item Editor
            Item {
                id:                     missionItemEditor
                anchors.left:           parent.left
                anchors.right:          parent.right
                anchors.top:            rightControls.bottom
Gus Grubba's avatar
Gus Grubba committed
784
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
785 786 787 788
                anchors.bottom:         parent.bottom
                anchors.bottomMargin:   ScreenTools.defaultFontPixelHeight * 0.25
                visible:                _editingLayer == _layerMission && !planControlColapsed
                QGCListView {
Gus Grubba's avatar
Gus Grubba committed
789 790 791 792 793 794 795
                    id:                 missionItemEditorListView
                    anchors.fill:       parent
                    spacing:            ScreenTools.defaultFontPixelHeight / 4
                    orientation:        ListView.Vertical
                    model:              _missionController.visualItems
                    cacheBuffer:        Math.max(height * 2, 0)
                    clip:               true
796
                    currentIndex:       _missionController.currentPlanViewSeqNum
Gus Grubba's avatar
Gus Grubba committed
797
                    highlightMoveDuration: 250
Gus Grubba's avatar
Gus Grubba committed
798
                    visible:            _editingLayer == _layerMission && !planControlColapsed
Gus Grubba's avatar
Gus Grubba committed
799 800
                    //-- List Elements
                    delegate: MissionItemEditor {
Gus Grubba's avatar
Gus Grubba committed
801
                        map:            editorMap
Gus Grubba's avatar
Gus Grubba committed
802
                        masterController:  _planMasterController
Gus Grubba's avatar
Gus Grubba committed
803 804 805
                        missionItem:    object
                        width:          parent.width
                        readOnly:       false
806
                        onClicked:      _missionController.setCurrentPlanViewSeqNum(object.sequenceNumber, false)
Gus Grubba's avatar
Gus Grubba committed
807
                        onRemove: {
808
                            var removeVIIndex = index
809
                            _missionController.removeVisualItem(removeVIIndex)
810 811
                            if (removeVIIndex >= _missionController.visualItems.count) {
                                removeVIIndex--
Gus Grubba's avatar
Gus Grubba committed
812 813
                            }
                        }
814
                        onSelectNextNotReadyItem:   selectNextNotReady()
Gus Grubba's avatar
Gus Grubba committed
815 816 817 818 819 820
                    }
                }
            }
            // GeoFence Editor
            GeoFenceEditor {
                anchors.top:            rightControls.bottom
Gus Grubba's avatar
Gus Grubba committed
821
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Don Gagne's avatar
Don Gagne committed
822
                anchors.bottom:         parent.bottom
Gus Grubba's avatar
Gus Grubba committed
823 824 825 826 827 828
                anchors.left:           parent.left
                anchors.right:          parent.right
                myGeoFenceController:   _geoFenceController
                flightMap:              editorMap
                visible:                _editingLayer == _layerGeoFence
            }
829

Gus Grubba's avatar
Gus Grubba committed
830 831 832 833
            // Rally Point Editor
            RallyPointEditorHeader {
                id:                     rallyPointHeader
                anchors.top:            rightControls.bottom
Gus Grubba's avatar
Gus Grubba committed
834
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
835 836 837 838 839 840 841 842
                anchors.left:           parent.left
                anchors.right:          parent.right
                visible:                _editingLayer == _layerRallyPoints
                controller:             _rallyPointController
            }
            RallyPointItemEditor {
                id:                     rallyPointEditor
                anchors.top:            rallyPointHeader.bottom
Gus Grubba's avatar
Gus Grubba committed
843
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
844 845 846 847 848
                anchors.left:           parent.left
                anchors.right:          parent.right
                visible:                _editingLayer == _layerRallyPoints && _rallyPointController.points.count
                rallyPoint:             _rallyPointController.currentRallyPoint
                controller:             _rallyPointController
849
            }
Gus Grubba's avatar
Gus Grubba committed
850
        }
851

852 853 854 855 856 857 858 859 860 861 862 863
        TerrainStatus {
            id:                 terrainStatus
            anchors.margins:    _toolsMargin
            anchors.leftMargin: 0
            anchors.left:       mapScale.left
            anchors.right:      rightPanel.left
            anchors.bottom:     parent.bottom
            height:             ScreenTools.defaultFontPixelHeight * 7
            missionController:  _missionController
            visible:            _internalVisible && _editingLayer === _layerMission && QGroundControl.corePlugin.options.showMissionStatus

            onSetCurrentSeqNum: _missionController.setCurrentPlanViewSeqNum(seqNum, true)
864

865 866 867 868 869 870 871
            property bool _internalVisible: _planViewSettings.showMissionItemStatus.rawValue

            function toggleVisible() {
                _internalVisible = !_internalVisible
                _planViewSettings.showMissionItemStatus.rawValue = _internalVisible
            }
        }
872 873 874 875

        MapScale {
            id:                     mapScale
            anchors.margins:        _toolsMargin
876 877
            anchors.bottom:         terrainStatus.visible ? terrainStatus.top : parent.bottom
            anchors.left:           toolStrip.y + toolStrip.height + _toolsMargin > mapScale.y ? toolStrip.right: parent.left
878 879 880
            mapControl:             editorMap
            buttonsOnLeft:          true
            terrainButtonVisible:   _editingLayer === _layerMission
881 882
            terrainButtonChecked:   terrainStatus.visible
            onTerrainButtonClicked: terrainStatus.toggleVisible()
883
        }
Gus Grubba's avatar
Gus Grubba committed
884
    }
885

886 887 888 889
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
890
            message:   qsTr("You have unsaved/unsent changes. Loading from the Vehicle will lose these changes. Are you sure you want to load from the Vehicle?")
891 892
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
893
                _planMasterController.loadFromVehicle()
894 895 896 897 898 899 900 901
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
DonLakeFlyer's avatar
DonLakeFlyer committed
902
            message:   qsTr("You have unsaved/unsent changes. Loading from a file will lose these changes. Are you sure you want to load from a file?")
903 904
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
905
                _planMasterController.loadFromSelectedFile()
906 907 908 909
            }
        }
    }

910 911
    property var createPlanRemoveAllPromptDialogMapCenter
    property var createPlanRemoveAllPromptDialogPlanCreator
912
    Component {
913
        id: createPlanRemoveAllPromptDialog
914
        QGCViewMessage {
915
            message: qsTr("Are you sure you want to remove current plan and create a new plan? ")
916
            function accept() {
917
                createPlanRemoveAllPromptDialogPlanCreator.createPlan(createPlanRemoveAllPromptDialogMapCenter)
918 919 920 921 922
                hideDialog()
            }
        }
    }

923 924 925 926 927
    Component {
        id: clearVehicleMissionDialog
        QGCViewMessage {
            message: qsTr("Are you sure you want to remove all mission items and clear the mission from the vehicle?")
            function accept() {
Gus Grubba's avatar
Gus Grubba committed
928
                _planMasterController.removeAllFromVehicle()
929
                _missionController.setCurrentPlanViewSeqNum(0, true)
930 931 932 933 934
                hideDialog()
            }
        }
    }

935 936 937 938 939 940 941 942 943 944 945
    //- ToolStrip DropPanel Components

    Component {
        id: centerMapDropPanel

        CenterMapDropPanel {
            map:            editorMap
            fitFunctions:   mapFitFunctions
        }
    }

946 947 948 949 950 951 952 953 954
    Component {
        id: patternDropPanel

        ColumnLayout {
            spacing:    ScreenTools.defaultFontPixelWidth * 0.5

            QGCLabel { text: qsTr("Create complex pattern:") }

            Repeater {
955
                model: _missionController.complexMissionItemNames
956 957 958 959 960 961

                QGCButton {
                    text:               modelData
                    Layout.fillWidth:   true

                    onClicked: {
962
                        insertComplexItemAfterCurrent(modelData)
963 964 965 966 967 968
                        dropPanel.hide()
                    }
                }
            }
        } // Column
    }
969 970

    Component {
971
        id: syncDropPanel
972

973
        ColumnLayout {
974 975
            id:         columnHolder
            spacing:    _margin
976

977
            property string _overwriteText: (_editingLayer == _layerMission) ? qsTr("Mission overwrite") : ((_editingLayer == _layerGeoFence) ? qsTr("GeoFence overwrite") : qsTr("Rally Points overwrite"))
978

979
            QGCLabel {
980
                id:                 unsavedChangedLabel
981 982 983 984 985 986 987 988 989 990 991 992
                Layout.fillWidth:   true
                wrapMode:           Text.WordWrap
                text:               activeVehicle ?
                                        qsTr("You have unsaved changes. You should upload to your vehicle, or save to a file.") :
                                        qsTr("You have unsaved changes.")
                visible:            _planMasterController.dirty
            }

            SectionHeader {
                id:                 createSection
                Layout.fillWidth:   true
                text:               qsTr("Create Plan")
993
                showSpacer:         false
994 995
            }

996 997
            GridLayout {
                columns:            2
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
                columnSpacing:      _margin
                rowSpacing:         _margin
                Layout.fillWidth:   true
                visible:            createSection.visible

                Repeater {
                    model: _planMasterController.planCreators

                    Rectangle {
                        id:     button
                        width:  ScreenTools.defaultFontPixelHeight * 7
                        height: planCreatorNameLabel.y + planCreatorNameLabel.height
                        color:  button.pressed || button.highlighted ? qgcPal.buttonHighlight : qgcPal.button

                        property bool highlighted: mouseArea.containsMouse
                        property bool pressed:     mouseArea.pressed

                        Image {
                            id:                 planCreatorImage
                            anchors.left:       parent.left
                            anchors.right:      parent.right
                            source:             object.imageResource
                            sourceSize.width:   width
                            fillMode:           Image.PreserveAspectFit
                            mipmap:             true
                        }

                        QGCLabel {
                            id:                     planCreatorNameLabel
                            anchors.top:            planCreatorImage.bottom
                            anchors.left:           parent.left
                            anchors.right:          parent.right
                            horizontalAlignment:    Text.AlignHCenter
                            text:                   object.name
                            color:                  button.pressed || button.highlighted ? qgcPal.buttonHighlightText : qgcPal.buttonText
                        }

                        QGCMouseArea {
                            id:                 mouseArea
                            anchors.fill:       parent
                            hoverEnabled:       true
                            preventStealing:    true
                            onClicked:          {
                                if (_planMasterController.containsItems) {
                                    createPlanRemoveAllPromptDialogMapCenter = _mapCenter()
                                    createPlanRemoveAllPromptDialogPlanCreator = object
                                    mainWindow.showComponentDialog(createPlanRemoveAllPromptDialog, qsTr("Create Plan"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
                                } else {
                                    object.createPlan(_mapCenter())
                                }
                                dropPanel.hide()
                            }

                            function _mapCenter() {
                                var centerPoint = Qt.point(editorMap.centerViewport.left + (editorMap.centerViewport.width / 2), editorMap.centerViewport.top + (editorMap.centerViewport.height / 2))
                                return editorMap.toCoordinate(centerPoint, false /* clipToViewPort */)
                            }
                        }
                    }
                }
            }

            SectionHeader {
                id:                 storageSection
                Layout.fillWidth:   true
                text:               qsTr("Storage")
            }

            GridLayout {
                columns:            3
1068 1069
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
1070
                visible:            storageSection.visible
1071

1072
                /*QGCButton {
1073
                    text:               qsTr("New...")
1074
                    Layout.fillWidth:   true
1075
                    onClicked:  {
1076
                        dropPanel.hide()
1077 1078 1079
                        if (_planMasterController.containsItems) {
                            mainWindow.showComponentDialog(removeAllPromptDialog, qsTr("New Plan"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
                        }
1080
                    }
1081
                }*/
1082

1083
                QGCButton {
1084
                    text:               qsTr("Open...")
1085
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1086
                    enabled:            !_planMasterController.syncInProgress
1087 1088
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1089
                        if (_planMasterController.dirty) {
1090
                            mainWindow.showComponentDialog(syncLoadFromFileOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1091
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1092
                            _planMasterController.loadFromSelectedFile()
1093 1094 1095
                        }
                    }
                }
1096

1097
                QGCButton {
1098
                    text:               qsTr("Save")
1099
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1100
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.currentPlanFile !== ""
1101 1102
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1103 1104
                        if(_planMasterController.currentPlanFile !== "") {
                            _planMasterController.saveToCurrent()
1105
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1106
                            _planMasterController.saveToSelectedFile()
1107
                        }
1108 1109 1110 1111
                    }
                }

                QGCButton {
1112
                    text:               qsTr("Save As...")
1113
                    Layout.fillWidth:   true
1114
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.containsItems
1115 1116
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1117
                        _planMasterController.saveToSelectedFile()
1118 1119 1120 1121
                    }
                }

                QGCButton {
1122 1123
                    Layout.columnSpan:  3
                    Layout.fillWidth:   true
1124
                    text:               qsTr("Save Mission Waypoints As KML...")
Gus Grubba's avatar
Gus Grubba committed
1125
                    enabled:            !_planMasterController.syncInProgress && _visualItems.count > 1
1126
                    onClicked: {
1127
                        // First point does not count
1128
                        if (_visualItems.count < 2) {
1129
                            mainWindow.showComponentDialog(noItemForKML, qsTr("KML"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
1130 1131
                            return
                        }
1132
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1133
                        _planMasterController.saveKmlToSelectedFile()
1134 1135
                    }
                }
1136
            }
1137

1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
            SectionHeader {
                id:                 vehicleSection
                Layout.fillWidth:   true
                text:               qsTr("Vehicle")
            }

            RowLayout {
                Layout.fillWidth:   true
                spacing:            _margin
                visible:            vehicleSection.visible
1148

1149
                QGCButton {
1150
                    text:               qsTr("Upload")
1151
                    Layout.fillWidth:   true
1152
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress && _planMasterController.containsItems
1153 1154
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
1155
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1156
                        _planMasterController.upload()
1157 1158
                    }
                }
1159 1160 1161 1162

                QGCButton {
                    text:               qsTr("Download")
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1163
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1164 1165 1166
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1167
                        if (_planMasterController.dirty) {
1168
                            mainWindow.showComponentDialog(syncLoadFromVehicleOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1169
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1170
                            _planMasterController.loadFromVehicle()
1171 1172 1173 1174 1175
                        }
                    }
                }

                QGCButton {
1176
                    text:               qsTr("Clear")
1177 1178
                    Layout.fillWidth:   true
                    Layout.columnSpan:  2
Gus Grubba's avatar
Gus Grubba committed
1179
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1180 1181 1182
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
1183
                        mainWindow.showComponentDialog(clearVehicleMissionDialog, text, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1184 1185
                    }
                }
1186
            }
1187 1188
        }
    }
Gus Grubba's avatar
Gus Grubba committed
1189
}