PlanView.qml 52.7 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * 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
Gus Grubba's avatar
Gus Grubba committed
52
    property int    _editingLayer:                      bar.currentIndex ? _layers[bar.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

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

58 59 60 61
    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?")
62

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

71
    function updateAirspace(reset) {
72 73 74 75
        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) {
76
                QGroundControl.airspaceManager.setROI(coordinateNW, coordinateSE, true /*planView*/, reset)
77 78 79 80
            }
        }
    }

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

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

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

106 107 108 109 110 111
    onVisibleChanged: {
        if (visible && !_planMasterController.containsItems) {
            toolStrip.simulateClick(toolStrip.fileButtonIndex)
        }
    }

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

    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()
127
                _missionController.applyDefaultMissionAltitude()
DonLakeFlyer's avatar
DonLakeFlyer committed
128 129 130 131
            }
        }
    }

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    Component {
        id: activeMissionUploadDialogComponent
        QGCViewDialog {
            Column {
                anchors.fill:   parent
                spacing:        ScreenTools.defaultFontPixelHeight
                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       qsTr("Your vehicle is currently flying a mission. In order to upload a new or modified mission the current mission will be paused.")
                }
                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       qsTr("After the mission is uploaded you can adjust the current waypoint and start the mission.")
                }
                QGCButton {
                    text:       qsTr("Pause and Upload")
                    onClicked: {
Gus Grubba's avatar
Gus Grubba committed
151
                        activeVehicle.flightMode = activeVehicle.pauseFlightMode
152
                        _planMasterController.sendToVehicle()
153
                        hideDialog()
154 155 156 157 158 159
                    }
                }
            }
        }
    }

Gus Grubba's avatar
Gus Grubba committed
160
    Connections {
161
        target: QGroundControl.airspaceManager
162
        onAirspaceVisibleChanged: {
163
            planControlColapsed = QGroundControl.airspaceManager.airspaceVisible
Gus Grubba's avatar
Gus Grubba committed
164 165 166
        }
    }

167 168 169 170 171 172 173
    Component {
        id: noItemForKML
        QGCViewMessage {
            message:    qsTr("You need at least one item to create a KML.")
        }
    }

174
    PlanMasterController {
Gus Grubba's avatar
Gus Grubba committed
175
        id: _planMasterController
176

177
        Component.onCompleted: {
178
            _planMasterController.start(false /* flyView */)
179
            _missionController.setCurrentPlanViewSeqNum(0, true)
Gus Grubba's avatar
Gus Grubba committed
180
            mainWindow.planMasterControllerPlan = _planMasterController
181 182
        }

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
        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
202 203
        }

204
        function upload() {
205
            if (!checkReadyForSaveUpload(false /* save */)) {
206 207
                return
            }
Gus Grubba's avatar
Gus Grubba committed
208
            if (activeVehicle && activeVehicle.armed && activeVehicle.flightMode === activeVehicle.missionFlightMode) {
209
                mainWindow.showComponentDialog(activeMissionUploadDialogComponent, qsTr("Plan Upload"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
210
            } else {
211 212
                sendToVehicle()
            }
DonLakeFlyer's avatar
DonLakeFlyer committed
213 214
        }

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

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

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

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

256 257
    Connections {
        target: _missionController
258

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

267 268 269 270 271 272 273 274 275
    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 */)
        _addROIOnClick = false
276 277
    }

278 279 280
    function insertCancelROIAfterCurrent() {
        var nextIndex = _missionController.currentPlanViewVIIndex + 1
        _missionController.insertCancelROIMissionItem(nextIndex, true /* makeCurrentItem */)
281 282 283
        _addROIOnClick = false
    }

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

289 290 291 292 293
    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) {
294
                _missionController.setCurrentPlanViewSeqNum(vmi.sequenceNumber, true)
295 296 297 298 299
                break
            }
        }
    }

300 301
    property int _moveDialogMissionItemIndex

302 303
    QGCFileDialog {
        id:             fileDialog
Gus Grubba's avatar
Gus Grubba committed
304
        folder:         _appSettings ? _appSettings.missionSavePath : ""
305

306 307
        property bool planFiles: true    ///< true: working with plan files, false: working with kml file

308
        onAcceptedForSave: {
309
            if (planFiles) {
Gus Grubba's avatar
Gus Grubba committed
310
                _planMasterController.saveToFile(file)
311
            } else {
Gus Grubba's avatar
Gus Grubba committed
312
                _planMasterController.saveToKml(file)
313
            }
314
            close()
315 316
        }

317
        onAcceptedForLoad: {
318 319 320
            _planMasterController.loadFromFile(file)
            _planMasterController.fitViewportToItems()
            _missionController.setCurrentPlanViewSeqNum(0, true)
321
            close()
322 323 324
        }
    }

325 326 327 328 329
    Component {
        id: moveDialog
        QGCViewDialog {
            function accept() {
                var toIndex = toCombo.currentIndex
Gus Grubba's avatar
Gus Grubba committed
330
                if (toIndex === 0) {
331 332
                    toIndex = 1
                }
333
                _missionController.moveMissionItem(_moveDialogMissionItemIndex, toIndex)
334 335 336 337 338 339 340 341 342 343 344
                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
345
                    text:           qsTr("Move the selected mission item to the be after following mission item:")
346 347 348 349
                }

                QGCComboBox {
                    id:             toCombo
350
                    model:          _visualItems.count
351 352 353 354 355 356
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

357
    Item {
Don Gagne's avatar
Don Gagne committed
358
        id:             panel
359
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
360

361
        FlightMap {
362 363 364 365 366
            id:                         editorMap
            anchors.fill:               parent
            mapName:                    "MissionEditor"
            allowGCSLocationCenter:     true
            allowVehicleLocationCenter: true
367
            planView:                   true
Don Gagne's avatar
Don Gagne committed
368

369
            // This is the center rectangle of the map which is not obscured by tools
370
            property rect centerViewport:   Qt.rect(_leftToolWidth + _margin, _toolsMargin, editorMap.width - _leftToolWidth - _rightToolWidth - (_margin * 2), mapScale.y - _margin - _toolsMargin)
371

372 373
            property real _leftToolWidth:       toolStrip.x + toolStrip.width
            property real _rightToolWidth:      rightPanel.width + rightPanel.anchors.rightMargin
374

375
            readonly property real animationDuration: 500
376

377 378
            // Initial map position duplicates Fly view position
            Component.onCompleted: editorMap.center = QGroundControl.flightMapPosition
379

380 381 382 383 384 385
            Behavior on zoomLevel {
                NumberAnimation {
                    duration:       editorMap.animationDuration
                    easing.type:    Easing.InOutQuad
                }
            }
386

387 388
            QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

389 390
            onZoomLevelChanged: updateAirspace(false)
            onCenterChanged:    updateAirspace(false)
391

392 393 394
            MouseArea {
                anchors.fill: parent
                onClicked: {
395 396
                    // Take focus to close any previous editing
                    editorMap.focus = true
397 398 399 400
                    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)
401

402 403 404
                    switch (_editingLayer) {
                    case _layerMission:
                        if (_addWaypointOnClick) {
405
                            insertSimpleItemAfterCurrent(coordinate)
406 407
                        } else if (_addROIOnClick) {
                            _addROIOnClick = false
408
                            insertROIAfterCurrent(coordinate)
409
                        }
410

411 412
                        break
                    case _layerRallyPoints:
Gus Grubba's avatar
Gus Grubba committed
413
                        if (_rallyPointController.supported && _addWaypointOnClick) {
414
                            _rallyPointController.addPoint(coordinate)
415
                        }
416
                        break
Don Gagne's avatar
Don Gagne committed
417
                    }
Don Gagne's avatar
Don Gagne committed
418
                }
419
            }
Don Gagne's avatar
Don Gagne committed
420

421 422
            // Add the mission item visuals to the map
            Repeater {
423
                model: _editingLayer == _layerMission ? _missionController.visualItems : undefined
424 425
                delegate: MissionItemMapVisual {
                    map:        editorMap
426
                    onClicked:  _missionController.setCurrentPlanViewSeqNum(sequenceNumber, false)
427
                    visible:    _editingLayer == _layerMission
428
                }
429
            }
430

431 432
            // Add lines between waypoints
            MissionLineView {
433 434
                showSpecialVisual:  _missionController.isROIBeginCurrentItem
                model:              _editingLayer == _layerMission ? _missionController.waypointLines : undefined
435
            }
436

437
            // Direction arrows in waypoint lines
438 439 440 441 442 443
            MapItemView {
                model: _editingLayer == _layerMission ? _missionController.directionArrows : undefined

                delegate: MapLineArrow {
                    fromCoord:      object ? object.coordinate1 : undefined
                    toCoord:        object ? object.coordinate2 : undefined
444 445 446 447
                    arrowPosition:  3
                    z:              QGroundControl.zOrderWaypointLines + 1
                }
            }
448 449 450 451 452 453 454 455 456 457 458 459

            // Incomplete segment lines
            MapItemView {
                model: _editingLayer == _layerMission ? _missionController.incompleteComplexItemLines : undefined

                delegate: MapPolyline {
                    path:       [ object.coordinate1, object.coordinate2 ]
                    line.width: 1
                    line.color: "red"
                    z:          QGroundControl.zOrderWaypointLines
                }
            }
460 461 462 463 464 465 466

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

                sourceItem: SplitIndicator {
470 471 472
                    onClicked:  _missionController.insertSimpleMissionItem(splitSegmentItem.coordinate,
                                                                           _missionController.currentPlanViewVIIndex,
                                                                           true /* makeCurrentItem */)
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
                }

                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()
494 495 496
                }
            }

497 498 499 500 501 502 503
            // Add the vehicles to the map
            MapItemView {
                model: QGroundControl.multiVehicleManager.vehicles
                delegate:
                    VehicleMapItem {
                    vehicle:        object
                    coordinate:     object.coordinate
504
                    map:            editorMap
505 506
                    size:           ScreenTools.defaultFontPixelHeight * 3
                    z:              QGroundControl.zOrderMapItems - 1
507
                }
508
            }
509

510 511
            GeoFenceMapVisuals {
                map:                    editorMap
512
                myGeoFenceController:   _geoFenceController
513
                interactive:            _editingLayer == _layerGeoFence
514
                homePosition:           _missionController.plannedHomePosition
515 516
                planView:               true
            }
517

518 519
            RallyPointMapVisuals {
                map:                    editorMap
520
                myRallyPointController: _rallyPointController
521 522
                interactive:            _editingLayer == _layerRallyPoints
                planView:               true
523
            }
524

525 526
            // Airspace overlap support
            MapItemView {
527
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.circles : []
528 529 530
                delegate: MapCircle {
                    center:         object.center
                    radius:         object.radius
531
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
532 533
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
534 535 536 537
                }
            }

            MapItemView {
538
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : []
539 540
                delegate: MapPolygon {
                    path:           object.polygon
541
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
542 543
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
544 545
                }
            }
546
        }
547

548 549
        //-----------------------------------------------------------
        // Left tool strip
Gus Grubba's avatar
Gus Grubba committed
550
        ToolStrip {
551
            id:                 toolStrip
552
            anchors.margins:    _toolsMargin
553 554 555
            anchors.left:       parent.left
            anchors.top:        parent.top
            z:                  QGroundControl.zOrderWidgets
556
            maxHeight:          parent.height - toolStrip.y
557

558 559 560 561 562 563 564 565
            //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
566

567 568
            property bool _isRallyLayer:    _editingLayer == _layerRallyPoints
            property bool _isMissionLayer:  _editingLayer == _layerMission
569

Gus Grubba's avatar
Gus Grubba committed
570
            model: [
571
                /*{
Gus Grubba's avatar
Gus Grubba committed
572 573 574 575
                    name:               qsTr("Fly"),
                    iconSource:         "/qmlimages/PaperPlane.svg",
                    buttonEnabled:      true,
                    buttonVisible:      true,
576
                },*/
577
                {
Gus Grubba's avatar
Gus Grubba committed
578 579 580 581 582 583 584 585
                    name:               qsTr("File"),
                    iconSource:         "/qmlimages/MapSync.svg",
                    buttonEnabled:      !_planMasterController.syncInProgress,
                    buttonVisible:      true,
                    showAlternateIcon:  _planMasterController.dirty,
                    alternateIconSource:"/qmlimages/MapSyncChanged.svg",
                    dropPanelComponent: syncDropPanel
                },
586 587 588 589
                {
                    name:               qsTr("Takeoff"),
                    iconSource:         "/res/takeoff.svg",
                    buttonEnabled:      _missionController.isInsertTakeoffValid,
590
                    buttonVisible:      _isMissionLayer
591
                },
Gus Grubba's avatar
Gus Grubba committed
592 593 594
                {
                    name:               _editingLayer == _layerRallyPoints ? qsTr("Rally Point") : qsTr("Waypoint"),
                    iconSource:         "/qmlimages/MapAddMission.svg",
595 596
                    buttonEnabled:      _isRallyLayer ? true : _missionController.flyThroughCommandsAllowed,
                    buttonVisible:      _isRallyLayer || _isMissionLayer,
Gus Grubba's avatar
Gus Grubba committed
597 598 599 600
                    toggle:             true,
                    checked:            _addWaypointOnClick
                },
                {
601
                    name:               _missionController.isROIActive ? qsTr("Cancel ROI") : qsTr("ROI"),
Gus Grubba's avatar
Gus Grubba committed
602 603
                    iconSource:         "/qmlimages/MapAddMission.svg",
                    buttonEnabled:      true,
604
                    buttonVisible:      _isMissionLayer,
605
                    toggle:             !_missionController.isROIActive
Gus Grubba's avatar
Gus Grubba committed
606 607 608 609
                },
                {
                    name:               _singleComplexItem ? _missionController.complexMissionItemNames[0] : qsTr("Pattern"),
                    iconSource:         "/qmlimages/MapDrawShape.svg",
610 611
                    buttonEnabled:      _missionController.flyThroughCommandsAllowed,
                    buttonVisible:      _isMissionLayer,
Gus Grubba's avatar
Gus Grubba committed
612 613
                    dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel
                },
614 615 616 617
                {
                    name:               _planMasterController.controllerVehicle.fixedWing ? qsTr("Land") : qsTr("Return"),
                    iconSource:         "/res/rtl.svg",
                    buttonEnabled:      _missionController.isInsertLandValid,
618
                    buttonVisible:      _isMissionLayer
619
                },
Gus Grubba's avatar
Gus Grubba committed
620 621 622 623 624 625 626 627
                {
                    name:               qsTr("Center"),
                    iconSource:         "/qmlimages/MapCenter.svg",
                    buttonEnabled:      true,
                    buttonVisible:      true,
                    dropPanelComponent: centerMapDropPanel
                }
            ]
628

629 630 631 632 633
            function allAddClickBoolsOff() {
                _addROIOnClick =        false
                _addWaypointOnClick =   false
            }

Gus Grubba's avatar
Gus Grubba committed
634 635
            onClicked: {
                switch (index) {
636
                /*case flyButtonIndex:
637
                    mainWindow.showFlyView()
638
                    break*/
639
                case takeoffButtonIndex:
640
                    allAddClickBoolsOff()
641 642 643
                    _missionController.insertTakeoffItem(mapCenter(), _missionController.currentMissionIndex, true /* makeCurrentItem */)
                    break
                case waypointButtonIndex:
644 645
                    if (_addWaypointOnClick) {
                        allAddClickBoolsOff()
Gus Grubba's avatar
Gus Grubba committed
646 647
                        setChecked(index, false)
                    } else {
648
                        allAddClickBoolsOff()
649
                        _addWaypointOnClick = checked
Gus Grubba's avatar
Gus Grubba committed
650 651
                    }
                    break
652
                case roiButtonIndex:
653 654 655
                    if (_addROIOnClick) {
                        allAddClickBoolsOff()
                        setChecked(index, false)
656
                    } else {
657 658 659 660 661 662
                        allAddClickBoolsOff()
                        if (_missionController.isROIActive) {
                            insertCancelROIAfterCurrent()
                        } else {
                            _addROIOnClick = checked
                        }
663
                    }
Gus Grubba's avatar
Gus Grubba committed
664
                    break
665
                case patternButtonIndex:
666
                    allAddClickBoolsOff()
Gus Grubba's avatar
Gus Grubba committed
667
                    if (_singleComplexItem) {
668
                        insertComplexItemAfterCurrent(_missionController.complexMissionItemNames[0])
Gus Grubba's avatar
Gus Grubba committed
669 670
                    }
                    break
671
                case landButtonIndex:
672
                    allAddClickBoolsOff()
673 674
                    _missionController.insertLandItem(mapCenter(), _missionController.currentMissionIndex, true /* makeCurrentItem */)
                    break
675 676
                }
            }
677 678 679 680

            onDropped: {
                allAddClickBoolsOff()
            }
Gus Grubba's avatar
Gus Grubba committed
681
        }
682

Gus Grubba's avatar
Gus Grubba committed
683
        //-----------------------------------------------------------
684 685 686
        // Right pane for mission editing controls
        Rectangle {
            id:                 rightPanel
687
            height:             parent.height
688 689
            width:              _rightPanelWidth
            color:              qgcPal.window
690
            opacity:            planExpanded.visible ? 0.2 : 0
Gus Grubba's avatar
Gus Grubba committed
691 692
            anchors.bottom:     parent.bottom
            anchors.right:      parent.right
693
            anchors.rightMargin: _toolsMargin
694
        }
Gus Grubba's avatar
Gus Grubba committed
695 696
        //-------------------------------------------------------
        // Right Panel Controls
697
        Item {
Gus Grubba's avatar
Gus Grubba committed
698
            anchors.fill:           rightPanel
699
            anchors.topMargin:      _toolsMargin
Gus Grubba's avatar
Gus Grubba committed
700 701 702
            DeadMouseArea {
                anchors.fill:   parent
            }
Gus Grubba's avatar
Gus Grubba committed
703 704
            Column {
                id:                 rightControls
Gus Grubba's avatar
Gus Grubba committed
705
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
706 707
                anchors.left:       parent.left
                anchors.right:      parent.right
Gus Grubba's avatar
Gus Grubba committed
708 709 710 711
                anchors.top:        parent.top
                //-------------------------------------------------------
                // Airmap Airspace Control
                AirspaceControl {
Gus Grubba's avatar
Gus Grubba committed
712 713
                    id:             airspaceControl
                    width:          parent.width
714
                    visible:        _airspaceEnabled
715
                    planView:       true
716
                    showColapse:    true
717
                }
Gus Grubba's avatar
Gus Grubba committed
718 719 720 721
                //-------------------------------------------------------
                // Mission Controls (Colapsed)
                Rectangle {
                    width:      parent.width
Gus Grubba's avatar
Gus Grubba committed
722
                    height:     planControlColapsed ? colapsedRow.height + ScreenTools.defaultFontPixelHeight : 0
Gus Grubba's avatar
Gus Grubba committed
723 724
                    color:      qgcPal.missionItemEditor
                    radius:     _radius
725
                    visible:    planControlColapsed && _airspaceEnabled
Gus Grubba's avatar
Gus Grubba committed
726 727 728 729 730 731 732
                    Row {
                        id:                     colapsedRow
                        spacing:                ScreenTools.defaultFontPixelWidth
                        anchors.left:           parent.left
                        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
                        anchors.verticalCenter: parent.verticalCenter
                        QGCColoredImage {
733 734 735 736 737
                            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
738 739 740
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        QGCLabel {
741 742
                            text:               qsTr("Plan")
                            color:              qgcPal.text
Gus Grubba's avatar
Gus Grubba committed
743
                            anchors.verticalCenter: parent.verticalCenter
744 745
                        }
                    }
Gus Grubba's avatar
Gus Grubba committed
746 747 748 749
                    QGCColoredImage {
                        width:                  height
                        height:                 ScreenTools.defaultFontPixelWidth * 2.5
                        sourceSize.height:      height
750
                        source:                 QGroundControl.airmapSupported ? "qrc:/airmap/expand.svg" : ""
751
                        color:                  "white"
752
                        visible:                QGroundControl.airmapSupported
Gus Grubba's avatar
Gus Grubba committed
753 754 755 756 757 758
                        anchors.right:          parent.right
                        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                        anchors.verticalCenter: parent.verticalCenter
                    }
                    MouseArea {
                        anchors.fill:   parent
759
                        enabled:        QGroundControl.airmapSupported
Gus Grubba's avatar
Gus Grubba committed
760
                        onClicked: {
761
                            QGroundControl.airspaceManager.airspaceVisible = false
Gus Grubba's avatar
Gus Grubba committed
762 763
                        }
                    }
Gus Grubba's avatar
Gus Grubba committed
764
                }
Gus Grubba's avatar
Gus Grubba committed
765 766 767 768 769
                //-------------------------------------------------------
                // Mission Controls (Expanded)
                Rectangle {
                    id:         planExpanded
                    width:      parent.width
Gus Grubba's avatar
Gus Grubba committed
770
                    height:     (!planControlColapsed || !_airspaceEnabled) ? bar.height + ScreenTools.defaultFontPixelHeight : 0
Gus Grubba's avatar
Gus Grubba committed
771 772
                    color:      qgcPal.missionItemEditor
                    radius:     _radius
Gus Grubba's avatar
Gus Grubba committed
773
                    visible:    (!planControlColapsed || !_airspaceEnabled) && QGroundControl.corePlugin.options.enablePlanViewSelector
Gus Grubba's avatar
Gus Grubba committed
774
                    Item {
Gus Grubba's avatar
Gus Grubba committed
775
                        height:             bar.height
Gus Grubba's avatar
Gus Grubba committed
776 777
                        anchors.left:       parent.left
                        anchors.right:      parent.right
Gus Grubba's avatar
Gus Grubba committed
778
                        anchors.margins:    ScreenTools.defaultFontPixelWidth
Gus Grubba's avatar
Gus Grubba committed
779
                        anchors.verticalCenter: parent.verticalCenter
Gus Grubba's avatar
Gus Grubba committed
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
                        QGCTabBar {
                            id:             bar
                            width:          parent.width
                            anchors.centerIn: parent
                            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
797 798 799 800 801 802 803 804 805 806 807 808
                            }
                        }
                    }
                }
            }
            //-------------------------------------------------------
            // 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
809
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
810 811 812 813
                anchors.bottom:         parent.bottom
                anchors.bottomMargin:   ScreenTools.defaultFontPixelHeight * 0.25
                visible:                _editingLayer == _layerMission && !planControlColapsed
                QGCListView {
Gus Grubba's avatar
Gus Grubba committed
814 815 816 817 818 819 820
                    id:                 missionItemEditorListView
                    anchors.fill:       parent
                    spacing:            ScreenTools.defaultFontPixelHeight / 4
                    orientation:        ListView.Vertical
                    model:              _missionController.visualItems
                    cacheBuffer:        Math.max(height * 2, 0)
                    clip:               true
821
                    currentIndex:       _missionController.currentPlanViewSeqNum
Gus Grubba's avatar
Gus Grubba committed
822
                    highlightMoveDuration: 250
Gus Grubba's avatar
Gus Grubba committed
823
                    visible:            _editingLayer == _layerMission && !planControlColapsed
Gus Grubba's avatar
Gus Grubba committed
824 825
                    //-- List Elements
                    delegate: MissionItemEditor {
Gus Grubba's avatar
Gus Grubba committed
826
                        map:            editorMap
Gus Grubba's avatar
Gus Grubba committed
827
                        masterController:  _planMasterController
Gus Grubba's avatar
Gus Grubba committed
828 829 830
                        missionItem:    object
                        width:          parent.width
                        readOnly:       false
831
                        onClicked:      _missionController.setCurrentPlanViewSeqNum(object.sequenceNumber, false)
Gus Grubba's avatar
Gus Grubba committed
832 833 834 835 836 837
                        onRemove: {
                            var removeIndex = index
                            _missionController.removeMissionItem(removeIndex)
                            if (removeIndex >= _missionController.visualItems.count) {
                                removeIndex--
                            }
838
                            _missionController.setCurrentPlanViewSeqNum(removeIndex, true)
Gus Grubba's avatar
Gus Grubba committed
839
                        }
840
                        onSelectNextNotReadyItem:   selectNextNotReady()
Gus Grubba's avatar
Gus Grubba committed
841 842 843 844 845 846
                    }
                }
            }
            // GeoFence Editor
            GeoFenceEditor {
                anchors.top:            rightControls.bottom
Gus Grubba's avatar
Gus Grubba committed
847
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Don Gagne's avatar
Don Gagne committed
848
                anchors.bottom:         parent.bottom
Gus Grubba's avatar
Gus Grubba committed
849 850 851 852 853 854 855 856 857 858
                anchors.left:           parent.left
                anchors.right:          parent.right
                myGeoFenceController:   _geoFenceController
                flightMap:              editorMap
                visible:                _editingLayer == _layerGeoFence
            }
            // Rally Point Editor
            RallyPointEditorHeader {
                id:                     rallyPointHeader
                anchors.top:            rightControls.bottom
Gus Grubba's avatar
Gus Grubba committed
859
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
860 861 862 863 864 865 866 867
                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
868
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
869 870 871 872 873
                anchors.left:           parent.left
                anchors.right:          parent.right
                visible:                _editingLayer == _layerRallyPoints && _rallyPointController.points.count
                rallyPoint:             _rallyPointController.currentRallyPoint
                controller:             _rallyPointController
874
            }
Gus Grubba's avatar
Gus Grubba committed
875
        }
876 877 878

        MissionItemStatus {
            id:                 waypointValuesDisplay
879 880 881
            anchors.margins:    _toolsMargin
            anchors.left:       toolStrip.right
            anchors.bottom:     mapScale.top
882
            height:             ScreenTools.defaultFontPixelHeight * 7
883
            maxWidth:           rightPanel.x - x - anchors.margins
884
            missionItems:       _missionController.visualItems
885
            visible:            _internalVisible && _editingLayer === _layerMission && QGroundControl.corePlugin.options.showMissionStatus
886 887 888 889 890 891

            property bool _internalVisible: false

            function toggleVisible() {
                _internalVisible = !_internalVisible
            }
892
        }
893 894 895 896 897 898 899 900 901 902 903 904 905


        MapScale {
            id:                     mapScale
            anchors.margins:        _toolsMargin
            anchors.bottom:         parent.bottom
            anchors.left:           toolStrip.right
            mapControl:             editorMap
            buttonsOnLeft:          true
            terrainButtonVisible:   _editingLayer === _layerMission
            terrainButtonChecked:   waypointValuesDisplay.visible
            onTerrainButtonClicked: waypointValuesDisplay.toggleVisible()
        }
Gus Grubba's avatar
Gus Grubba committed
906
    }
907

908 909 910 911
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
912
            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?")
913 914
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
915
                _planMasterController.loadFromVehicle()
916 917 918 919 920 921 922 923
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
DonLakeFlyer's avatar
DonLakeFlyer committed
924
            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?")
925 926
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
927
                _planMasterController.loadFromSelectedFile()
928 929 930 931
            }
        }
    }

932 933
    property var createPlanRemoveAllPromptDialogMapCenter
    property var createPlanRemoveAllPromptDialogPlanCreator
934
    Component {
935
        id: createPlanRemoveAllPromptDialog
936
        QGCViewMessage {
937
            message: qsTr("Are you sure you want to remove current plan and create a new plan? ")
938
            function accept() {
939
                createPlanRemoveAllPromptDialogPlanCreator.createPlan(createPlanRemoveAllPromptDialogMapCenter)
940 941 942 943 944
                hideDialog()
            }
        }
    }

945 946 947 948 949
    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
950
                _planMasterController.removeAllFromVehicle()
951
                _missionController.setCurrentPlanViewSeqNum(0, true)
952 953 954 955 956
                hideDialog()
            }
        }
    }

957 958 959 960 961 962 963 964 965 966 967
    //- ToolStrip DropPanel Components

    Component {
        id: centerMapDropPanel

        CenterMapDropPanel {
            map:            editorMap
            fitFunctions:   mapFitFunctions
        }
    }

968 969 970 971 972 973 974 975 976
    Component {
        id: patternDropPanel

        ColumnLayout {
            spacing:    ScreenTools.defaultFontPixelWidth * 0.5

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

            Repeater {
977
                model: _missionController.complexMissionItemNames
978 979 980 981 982 983

                QGCButton {
                    text:               modelData
                    Layout.fillWidth:   true

                    onClicked: {
984
                        insertComplexItemAfterCurrent(modelData)
985 986 987 988 989 990
                        dropPanel.hide()
                    }
                }
            }
        } // Column
    }
991 992

    Component {
993
        id: syncDropPanel
994

995
        ColumnLayout {
996 997
            id:         columnHolder
            spacing:    _margin
998

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

1001
            QGCLabel {
1002
                id:                 unsavedChangedLabel
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
                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")
1015
                showSpacer:         false
1016 1017
            }

1018 1019
            GridLayout {
                columns:            2
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 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
                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
1090 1091
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
1092
                visible:            storageSection.visible
1093

1094
                /*QGCButton {
1095
                    text:               qsTr("New...")
1096
                    Layout.fillWidth:   true
1097
                    onClicked:  {
1098
                        dropPanel.hide()
1099 1100 1101
                        if (_planMasterController.containsItems) {
                            mainWindow.showComponentDialog(removeAllPromptDialog, qsTr("New Plan"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
                        }
1102
                    }
1103
                }*/
1104

1105
                QGCButton {
1106
                    text:               qsTr("Open...")
1107
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1108
                    enabled:            !_planMasterController.syncInProgress
1109 1110
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1111
                        if (_planMasterController.dirty) {
1112
                            mainWindow.showComponentDialog(syncLoadFromFileOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1113
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1114
                            _planMasterController.loadFromSelectedFile()
1115 1116 1117
                        }
                    }
                }
1118

1119
                QGCButton {
1120
                    text:               qsTr("Save")
1121
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1122
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.currentPlanFile !== ""
1123 1124
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1125 1126
                        if(_planMasterController.currentPlanFile !== "") {
                            _planMasterController.saveToCurrent()
1127
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1128
                            _planMasterController.saveToSelectedFile()
1129
                        }
1130 1131 1132 1133
                    }
                }

                QGCButton {
1134
                    text:               qsTr("Save As...")
1135
                    Layout.fillWidth:   true
1136
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.containsItems
1137 1138
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1139
                        _planMasterController.saveToSelectedFile()
1140 1141 1142 1143
                    }
                }

                QGCButton {
1144 1145
                    Layout.columnSpan:  3
                    Layout.fillWidth:   true
1146
                    text:               qsTr("Save Mission Waypoints As KML...")
Gus Grubba's avatar
Gus Grubba committed
1147
                    enabled:            !_planMasterController.syncInProgress && _visualItems.count > 1
1148
                    onClicked: {
1149
                        // First point does not count
1150
                        if (_visualItems.count < 2) {
1151
                            mainWindow.showComponentDialog(noItemForKML, qsTr("KML"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
1152 1153
                            return
                        }
1154
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1155
                        _planMasterController.saveKmlToSelectedFile()
1156 1157
                    }
                }
1158
            }
1159

1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
            SectionHeader {
                id:                 vehicleSection
                Layout.fillWidth:   true
                text:               qsTr("Vehicle")
            }

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

1171
                QGCButton {
1172
                    text:               qsTr("Upload")
1173
                    Layout.fillWidth:   true
1174
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress && _planMasterController.containsItems
1175 1176
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
1177
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1178
                        _planMasterController.upload()
1179 1180
                    }
                }
1181 1182 1183 1184

                QGCButton {
                    text:               qsTr("Download")
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1185
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1186 1187 1188
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1189
                        if (_planMasterController.dirty) {
1190
                            mainWindow.showComponentDialog(syncLoadFromVehicleOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1191
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1192
                            _planMasterController.loadFromVehicle()
1193 1194 1195 1196 1197
                        }
                    }
                }

                QGCButton {
1198
                    text:               qsTr("Clear")
1199 1200
                    Layout.fillWidth:   true
                    Layout.columnSpan:  2
Gus Grubba's avatar
Gus Grubba committed
1201
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1202 1203 1204
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
1205
                        mainWindow.showComponentDialog(clearVehicleMissionDialog, text, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1206 1207
                    }
                }
1208
            }
1209 1210
        }
    }
Gus Grubba's avatar
Gus Grubba committed
1211
}