PlanView.qml 56 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
    property bool   _promptForPlanUsageShowing:         false
57

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

60 61 62 63
    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?")
64

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

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

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

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

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

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

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

    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()
133
                _missionController.applyDefaultMissionAltitude()
DonLakeFlyer's avatar
DonLakeFlyer committed
134 135 136 137
            }
        }
    }

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    Component {
        id: promptForPlanUsageOnVehicleChangePopupComponent
        QGCPopupDialog {
            title:      _planMasterController.managerVehicle.isOfflineEditingVehicle ? qsTr("Plan View - Vehicle Disconnected") : qsTr("Plan View - Vehicle Changed")
            buttons:    StandardButton.NoButton

            ColumnLayout {
                QGCLabel {
                    Layout.maximumWidth:    parent.width
                    wrapMode:               QGCLabel.WordWrap
                    text:                   _planMasterController.managerVehicle.isOfflineEditingVehicle ?
                                                qsTr("The vehicle associated with the plan in the Plan View is no longer available. What would you like to do with that plan?") :
                                                qsTr("The plan being worked on in the Plan View is not from the current vehicle. What would you like to do with that plan?")
                }

                QGCButton {
                    Layout.fillWidth:   true
                    text:               _planMasterController.dirty ?
                                            (_planMasterController.managerVehicle.isOfflineEditingVehicle ?
                                                 qsTr("Discard Unsaved Changes") :
                                                 qsTr("Discard Unsaved Changes, Load New Plan From Vehicle")) :
                                            qsTr("Load New Plan From Vehicle")
                    onClicked: {
                        _planMasterController.showPlanFromManagerVehicle()
                        _promptForPlanUsageShowing = false
                        hideDialog();
                    }
                }

                QGCButton {
                    Layout.fillWidth:   true
                    text:               _planMasterController.managerVehicle.isOfflineEditingVehicle ?
                                            qsTr("Keep Current Plan") :
                                            qsTr("Keep Current Plan, Don't Update From Vehicle")
                    onClicked: {
                        if (!_planMasterController.managerVehicle.isOfflineEditingVehicle) {
                            _planMasterController.dirty = true
                        }
                        _promptForPlanUsageShowing = false
                        hideDialog()
                    }
                }
            }
        }
    }


185
    Component {
186 187 188 189 190 191 192 193 194 195
        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()
196 197 198 199
            }
        }
    }

Gus Grubba's avatar
Gus Grubba committed
200
    Connections {
201
        target: QGroundControl.airspaceManager
202
        onAirspaceVisibleChanged: {
203
            planControlColapsed = QGroundControl.airspaceManager.airspaceVisible
Gus Grubba's avatar
Gus Grubba committed
204 205 206
        }
    }

207 208 209 210 211 212 213
    Component {
        id: noItemForKML
        QGCViewMessage {
            message:    qsTr("You need at least one item to create a KML.")
        }
    }

214
    PlanMasterController {
215 216
        id:         _planMasterController
        flyView:    false
217

218
        Component.onCompleted: {
219
            _planMasterController.start()
220
            _missionController.setCurrentPlanViewSeqNum(0, true)
221
            mainWindow.planMasterControllerPlanView = _planMasterController
222 223
        }

224 225 226 227 228 229 230
        onPromptForPlanUsageOnVehicleChange: {
            if (!_promptForPlanUsageShowing) {
                _promptForPlanUsageShowing = true
                mainWindow.showPopupDialogFromComponent(promptForPlanUsageOnVehicleChangePopupComponent)
            }
        }

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
        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
250 251
        }

252
        function upload() {
253
            if (!checkReadyForSaveUpload(false /* save */)) {
254 255
                return
            }
256 257 258 259 260 261 262 263 264 265
            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
266
            }
DonLakeFlyer's avatar
DonLakeFlyer committed
267 268
        }

269
        function loadFromSelectedFile() {
270
            fileDialog.title =          qsTr("Select Plan File")
DonLakeFlyer's avatar
DonLakeFlyer committed
271
            fileDialog.planFiles =      true
272
            fileDialog.selectExisting = true
Gus Grubba's avatar
Gus Grubba committed
273
            fileDialog.nameFilters =    _planMasterController.loadNameFilters
274 275
            fileDialog.fileExtension =  _appSettings.planFileExtension
            fileDialog.fileExtension2 = _appSettings.missionFileExtension
276
            fileDialog.openForLoad()
277 278 279
        }

        function saveToSelectedFile() {
280
            if (!checkReadyForSaveUpload(true /* save */)) {
281 282
                return
            }
283
            fileDialog.title =          qsTr("Save Plan")
284
            fileDialog.planFiles =      true
285
            fileDialog.selectExisting = false
Gus Grubba's avatar
Gus Grubba committed
286
            fileDialog.nameFilters =    _planMasterController.saveNameFilters
287 288
            fileDialog.fileExtension =  _appSettings.planFileExtension
            fileDialog.fileExtension2 = _appSettings.missionFileExtension
289
            fileDialog.openForSave()
290 291
        }

292
        function fitViewportToItems() {
293
            mapFitFunctions.fitMapViewportToMissionItems()
294
        }
295 296

        function saveKmlToSelectedFile() {
297
            if (!checkReadyForSaveUpload(true /* save */)) {
298 299
                return
            }
300
            fileDialog.title =          qsTr("Save KML")
301
            fileDialog.planFiles =      false
302
            fileDialog.selectExisting = false
303 304
            fileDialog.nameFilters =    ShapeFileHelper.fileDialogKMLFilters
            fileDialog.fileExtension =  _appSettings.kmlFileExtension
305
            fileDialog.fileExtension2 = ""
306 307
            fileDialog.openForSave()
        }
308
    }
309

310 311
    Connections {
        target: _missionController
312

313
        onNewItemsFromVehicle: {
Gus Grubba's avatar
Gus Grubba committed
314
            if (_visualItems && _visualItems.count !== 1) {
315 316
                mapFitFunctions.fitMapViewportToMissionItems()
            }
317
            _missionController.setCurrentPlanViewSeqNum(0, true)
318 319
        }
    }
320

321 322 323 324 325 326 327 328
    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 */)
329 330
    }

331 332 333
    function insertCancelROIAfterCurrent() {
        var nextIndex = _missionController.currentPlanViewVIIndex + 1
        _missionController.insertCancelROIMissionItem(nextIndex, true /* makeCurrentItem */)
334 335
    }

336 337 338 339 340
    function insertComplexItemAfterCurrent(complexItemName) {
        var nextIndex = _missionController.currentPlanViewVIIndex + 1
        _missionController.insertComplexMissionItem(complexItemName, mapCenter(), nextIndex, true /* makeCurrentItem */)
    }

341 342 343 344 345 346 347 348 349 350 351
    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 */)
    }


352 353 354 355 356
    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) {
357
                _missionController.setCurrentPlanViewSeqNum(vmi.sequenceNumber, true)
358 359 360 361 362
                break
            }
        }
    }

363 364
    property int _moveDialogMissionItemIndex

365 366
    QGCFileDialog {
        id:             fileDialog
Gus Grubba's avatar
Gus Grubba committed
367
        folder:         _appSettings ? _appSettings.missionSavePath : ""
368

369 370
        property bool planFiles: true    ///< true: working with plan files, false: working with kml file

371
        onAcceptedForSave: {
372
            if (planFiles) {
Gus Grubba's avatar
Gus Grubba committed
373
                _planMasterController.saveToFile(file)
374
            } else {
Gus Grubba's avatar
Gus Grubba committed
375
                _planMasterController.saveToKml(file)
376
            }
377
            close()
378 379
        }

380
        onAcceptedForLoad: {
381 382 383
            _planMasterController.loadFromFile(file)
            _planMasterController.fitViewportToItems()
            _missionController.setCurrentPlanViewSeqNum(0, true)
384
            close()
385 386 387
        }
    }

388 389 390 391 392
    Component {
        id: moveDialog
        QGCViewDialog {
            function accept() {
                var toIndex = toCombo.currentIndex
Gus Grubba's avatar
Gus Grubba committed
393
                if (toIndex === 0) {
394 395
                    toIndex = 1
                }
396
                _missionController.moveMissionItem(_moveDialogMissionItemIndex, toIndex)
397 398 399 400 401 402 403 404 405 406 407
                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
408
                    text:           qsTr("Move the selected mission item to the be after following mission item:")
409 410 411 412
                }

                QGCComboBox {
                    id:             toCombo
413
                    model:          _visualItems.count
414 415 416 417 418 419
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

420
    Item {
Don Gagne's avatar
Don Gagne committed
421
        id:             panel
422
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
423

424
        FlightMap {
425 426 427 428 429
            id:                         editorMap
            anchors.fill:               parent
            mapName:                    "MissionEditor"
            allowGCSLocationCenter:     true
            allowVehicleLocationCenter: true
430
            planView:                   true
Don Gagne's avatar
Don Gagne committed
431

432 433 434
            zoomLevel:                  QGroundControl.flightMapZoom
            center:                     QGroundControl.flightMapPosition

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

438 439
            property real _leftToolWidth:       toolStrip.x + toolStrip.width
            property real _rightToolWidth:      rightPanel.width + rightPanel.anchors.rightMargin
440
            property real _nonInteractiveOpacity:  0.5
441

442 443
            // Initial map position duplicates Fly view position
            Component.onCompleted: editorMap.center = QGroundControl.flightMapPosition
444

445 446
            QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

447 448 449 450 451 452 453 454
            onZoomLevelChanged: {
                QGroundControl.flightMapZoom = zoomLevel
                updateAirspace(false)
            }
            onCenterChanged: {
                QGroundControl.flightMapPosition = center
                updateAirspace(false)
            }
455

456 457 458
            MouseArea {
                anchors.fill: parent
                onClicked: {
459 460
                    // Take focus to close any previous editing
                    editorMap.focus = true
461 462 463 464
                    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)
465

466 467 468
                    switch (_editingLayer) {
                    case _layerMission:
                        if (_addWaypointOnClick) {
469
                            insertSimpleItemAfterCurrent(coordinate)
470
                        } else if (_addROIOnClick) {
471
                            insertROIAfterCurrent(coordinate)
472
                            _addROIOnClick = false
473
                        }
474

475 476
                        break
                    case _layerRallyPoints:
Gus Grubba's avatar
Gus Grubba committed
477
                        if (_rallyPointController.supported && _addWaypointOnClick) {
478
                            _rallyPointController.addPoint(coordinate)
479
                        }
480
                        break
Don Gagne's avatar
Don Gagne committed
481
                    }
Don Gagne's avatar
Don Gagne committed
482
                }
483
            }
Don Gagne's avatar
Don Gagne committed
484

485 486
            // Add the mission item visuals to the map
            Repeater {
487
                model: _missionController.visualItems
488 489
                delegate: MissionItemMapVisual {
                    map:        editorMap
490
                    onClicked:  _missionController.setCurrentPlanViewSeqNum(sequenceNumber, false)
491 492
                    opacity:    _editingLayer == _layerMission ? 1 : editorMap._nonInteractiveOpacity
                    interactive: _editingLayer == _layerMission
493
                }
494
            }
495

496 497
            // Add lines between waypoints
            MissionLineView {
498
                showSpecialVisual:  _missionController.isROIBeginCurrentItem
499
                model:              _missionController.simpleFlightPathSegments
500
                opacity:            _editingLayer == _layerMission ? 1 : editorMap._nonInteractiveOpacity
501
            }
502

503
            // Direction arrows in waypoint lines
504 505 506 507 508 509
            MapItemView {
                model: _editingLayer == _layerMission ? _missionController.directionArrows : undefined

                delegate: MapLineArrow {
                    fromCoord:      object ? object.coordinate1 : undefined
                    toCoord:        object ? object.coordinate2 : undefined
510 511 512 513
                    arrowPosition:  3
                    z:              QGroundControl.zOrderWaypointLines + 1
                }
            }
514 515 516

            // Incomplete segment lines
            MapItemView {
517
                model: _missionController.incompleteComplexItemLines
518 519 520 521 522 523

                delegate: MapPolyline {
                    path:       [ object.coordinate1, object.coordinate2 ]
                    line.width: 1
                    line.color: "red"
                    z:          QGroundControl.zOrderWaypointLines
524
                    opacity:    _editingLayer == _layerMission ? 1 : editorMap._nonInteractiveOpacity
525 526
                }
            }
527 528 529 530 531 532 533

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

                sourceItem: SplitIndicator {
537 538 539
                    onClicked:  _missionController.insertSimpleMissionItem(splitSegmentItem.coordinate,
                                                                           _missionController.currentPlanViewVIIndex,
                                                                           true /* makeCurrentItem */)
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
                }

                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()
561 562 563
                }
            }

564 565 566
            // Add the vehicles to the map
            MapItemView {
                model: QGroundControl.multiVehicleManager.vehicles
567
                delegate: VehicleMapItem {
568 569
                    vehicle:        object
                    coordinate:     object.coordinate
570
                    map:            editorMap
571 572
                    size:           ScreenTools.defaultFontPixelHeight * 3
                    z:              QGroundControl.zOrderMapItems - 1
573
                }
574
            }
575

576 577
            GeoFenceMapVisuals {
                map:                    editorMap
578
                myGeoFenceController:   _geoFenceController
579
                interactive:            _editingLayer == _layerGeoFence
580
                homePosition:           _missionController.plannedHomePosition
581
                planView:               true
582
                opacity:                _editingLayer != _layerGeoFence ? editorMap._nonInteractiveOpacity : 1
583
            }
584

585 586
            RallyPointMapVisuals {
                map:                    editorMap
587
                myRallyPointController: _rallyPointController
588 589
                interactive:            _editingLayer == _layerRallyPoints
                planView:               true
590
                opacity:                _editingLayer != _layerRallyPoints ? editorMap._nonInteractiveOpacity : 1
591
            }
592

593 594
            // Airspace overlap support
            MapItemView {
595
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.circles : []
596 597 598
                delegate: MapCircle {
                    center:         object.center
                    radius:         object.radius
599
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
600 601
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
602 603 604 605
                }
            }

            MapItemView {
606
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : []
607 608
                delegate: MapPolygon {
                    path:           object.polygon
609
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
610 611
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
612 613
                }
            }
614
        }
615

616 617
        //-----------------------------------------------------------
        // Left tool strip
Gus Grubba's avatar
Gus Grubba committed
618
        ToolStrip {
619
            id:                 toolStrip
620
            anchors.margins:    _toolsMargin
621 622 623
            anchors.left:       parent.left
            anchors.top:        parent.top
            z:                  QGroundControl.zOrderWidgets
624
            maxHeight:          parent.height - toolStrip.y
625
            title:              qsTr("Plan")
626

627 628 629 630 631 632 633 634
            readonly property int flyButtonIndex:       0
            readonly property int fileButtonIndex:      1
            readonly property int takeoffButtonIndex:   2
            readonly property int waypointButtonIndex:  3
            readonly property int roiButtonIndex:       4
            readonly property int patternButtonIndex:   5
            readonly property int landButtonIndex:      6
            readonly property int centerButtonIndex:    7
635

636 637
            property bool _isRallyLayer:    _editingLayer == _layerRallyPoints
            property bool _isMissionLayer:  _editingLayer == _layerMission
638

639 640 641
            ToolStripActionList {
                id: toolStripActionList
                model: [
642 643 644 645 646
                    ToolStripAction {
                        text:           qsTr("Fly")
                        iconSource:     "/qmlimages/PaperPlane.svg"
                        onTriggered:    mainWindow.showFlyView()
                    },
647 648 649 650 651 652 653 654 655 656 657 658 659
                    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
660
                        visible:    toolStrip._isMissionLayer && !_planMasterController.controllerVehicle.rover
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
                        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
726

727 728 729 730 731
            function allAddClickBoolsOff() {
                _addROIOnClick =        false
                _addWaypointOnClick =   false
            }

732
            onDropped: allAddClickBoolsOff()
Gus Grubba's avatar
Gus Grubba committed
733
        }
734

Gus Grubba's avatar
Gus Grubba committed
735
        //-----------------------------------------------------------
736 737 738
        // Right pane for mission editing controls
        Rectangle {
            id:                 rightPanel
739
            height:             parent.height
740 741
            width:              _rightPanelWidth
            color:              qgcPal.window
742
            opacity:            layerTabBar.visible ? 0.2 : 0
Gus Grubba's avatar
Gus Grubba committed
743 744
            anchors.bottom:     parent.bottom
            anchors.right:      parent.right
745
            anchors.rightMargin: _toolsMargin
746
        }
Gus Grubba's avatar
Gus Grubba committed
747 748
        //-------------------------------------------------------
        // Right Panel Controls
749
        Item {
Gus Grubba's avatar
Gus Grubba committed
750
            anchors.fill:           rightPanel
751
            anchors.topMargin:      _toolsMargin
Gus Grubba's avatar
Gus Grubba committed
752 753 754
            DeadMouseArea {
                anchors.fill:   parent
            }
Gus Grubba's avatar
Gus Grubba committed
755 756
            Column {
                id:                 rightControls
Gus Grubba's avatar
Gus Grubba committed
757
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
758 759
                anchors.left:       parent.left
                anchors.right:      parent.right
Gus Grubba's avatar
Gus Grubba committed
760 761 762 763
                anchors.top:        parent.top
                //-------------------------------------------------------
                // Airmap Airspace Control
                AirspaceControl {
Gus Grubba's avatar
Gus Grubba committed
764 765
                    id:             airspaceControl
                    width:          parent.width
766
                    visible:        _airspaceEnabled
767
                    planView:       true
768
                    showColapse:    true
769
                }
Gus Grubba's avatar
Gus Grubba committed
770 771 772 773
                //-------------------------------------------------------
                // Mission Controls (Colapsed)
                Rectangle {
                    width:      parent.width
Gus Grubba's avatar
Gus Grubba committed
774
                    height:     planControlColapsed ? colapsedRow.height + ScreenTools.defaultFontPixelHeight : 0
Gus Grubba's avatar
Gus Grubba committed
775 776
                    color:      qgcPal.missionItemEditor
                    radius:     _radius
777
                    visible:    planControlColapsed && _airspaceEnabled
Gus Grubba's avatar
Gus Grubba committed
778 779 780 781 782 783 784
                    Row {
                        id:                     colapsedRow
                        spacing:                ScreenTools.defaultFontPixelWidth
                        anchors.left:           parent.left
                        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
                        anchors.verticalCenter: parent.verticalCenter
                        QGCColoredImage {
785 786 787 788 789
                            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
790 791 792
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        QGCLabel {
793 794
                            text:               qsTr("Plan")
                            color:              qgcPal.text
Gus Grubba's avatar
Gus Grubba committed
795
                            anchors.verticalCenter: parent.verticalCenter
796 797
                        }
                    }
Gus Grubba's avatar
Gus Grubba committed
798 799 800 801
                    QGCColoredImage {
                        width:                  height
                        height:                 ScreenTools.defaultFontPixelWidth * 2.5
                        sourceSize.height:      height
802
                        source:                 QGroundControl.airmapSupported ? "qrc:/airmap/expand.svg" : ""
803
                        color:                  "white"
804
                        visible:                QGroundControl.airmapSupported
Gus Grubba's avatar
Gus Grubba committed
805 806 807 808 809 810
                        anchors.right:          parent.right
                        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                        anchors.verticalCenter: parent.verticalCenter
                    }
                    MouseArea {
                        anchors.fill:   parent
811
                        enabled:        QGroundControl.airmapSupported
Gus Grubba's avatar
Gus Grubba committed
812
                        onClicked: {
813
                            QGroundControl.airspaceManager.airspaceVisible = false
Gus Grubba's avatar
Gus Grubba committed
814 815
                        }
                    }
Gus Grubba's avatar
Gus Grubba committed
816
                }
Gus Grubba's avatar
Gus Grubba committed
817 818
                //-------------------------------------------------------
                // Mission Controls (Expanded)
819 820
                QGCTabBar {
                    id:         layerTabBar
Gus Grubba's avatar
Gus Grubba committed
821
                    width:      parent.width
Gus Grubba's avatar
Gus Grubba committed
822
                    visible:    (!planControlColapsed || !_airspaceEnabled) && QGroundControl.corePlugin.options.enablePlanViewSelector
823 824 825 826 827 828 829 830 831 832 833
                    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
834 835 836 837 838 839 840 841 842 843
                    }
                }
            }
            //-------------------------------------------------------
            // 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
844
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
845 846 847 848
                anchors.bottom:         parent.bottom
                anchors.bottomMargin:   ScreenTools.defaultFontPixelHeight * 0.25
                visible:                _editingLayer == _layerMission && !planControlColapsed
                QGCListView {
Gus Grubba's avatar
Gus Grubba committed
849 850 851 852 853 854 855
                    id:                 missionItemEditorListView
                    anchors.fill:       parent
                    spacing:            ScreenTools.defaultFontPixelHeight / 4
                    orientation:        ListView.Vertical
                    model:              _missionController.visualItems
                    cacheBuffer:        Math.max(height * 2, 0)
                    clip:               true
856
                    currentIndex:       _missionController.currentPlanViewSeqNum
Gus Grubba's avatar
Gus Grubba committed
857
                    highlightMoveDuration: 250
Gus Grubba's avatar
Gus Grubba committed
858
                    visible:            _editingLayer == _layerMission && !planControlColapsed
Gus Grubba's avatar
Gus Grubba committed
859 860
                    //-- List Elements
                    delegate: MissionItemEditor {
Gus Grubba's avatar
Gus Grubba committed
861
                        map:            editorMap
Gus Grubba's avatar
Gus Grubba committed
862
                        masterController:  _planMasterController
Gus Grubba's avatar
Gus Grubba committed
863 864 865
                        missionItem:    object
                        width:          parent.width
                        readOnly:       false
866
                        onClicked:      _missionController.setCurrentPlanViewSeqNum(object.sequenceNumber, false)
Gus Grubba's avatar
Gus Grubba committed
867
                        onRemove: {
868
                            var removeVIIndex = index
869
                            _missionController.removeVisualItem(removeVIIndex)
870 871
                            if (removeVIIndex >= _missionController.visualItems.count) {
                                removeVIIndex--
Gus Grubba's avatar
Gus Grubba committed
872 873
                            }
                        }
874
                        onSelectNextNotReadyItem:   selectNextNotReady()
Gus Grubba's avatar
Gus Grubba committed
875 876 877 878 879 880
                    }
                }
            }
            // GeoFence Editor
            GeoFenceEditor {
                anchors.top:            rightControls.bottom
Gus Grubba's avatar
Gus Grubba committed
881
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Don Gagne's avatar
Don Gagne committed
882
                anchors.bottom:         parent.bottom
Gus Grubba's avatar
Gus Grubba committed
883 884 885 886 887 888
                anchors.left:           parent.left
                anchors.right:          parent.right
                myGeoFenceController:   _geoFenceController
                flightMap:              editorMap
                visible:                _editingLayer == _layerGeoFence
            }
889

Gus Grubba's avatar
Gus Grubba committed
890 891 892 893
            // Rally Point Editor
            RallyPointEditorHeader {
                id:                     rallyPointHeader
                anchors.top:            rightControls.bottom
Gus Grubba's avatar
Gus Grubba committed
894
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
895 896 897 898 899 900 901 902
                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
903
                anchors.topMargin:      ScreenTools.defaultFontPixelHeight * 0.25
Gus Grubba's avatar
Gus Grubba committed
904 905 906 907 908
                anchors.left:           parent.left
                anchors.right:          parent.right
                visible:                _editingLayer == _layerRallyPoints && _rallyPointController.points.count
                rallyPoint:             _rallyPointController.currentRallyPoint
                controller:             _rallyPointController
909
            }
Gus Grubba's avatar
Gus Grubba committed
910
        }
911

912 913 914 915 916 917 918 919 920 921 922 923
        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)
924

925 926 927 928 929 930 931
            property bool _internalVisible: _planViewSettings.showMissionItemStatus.rawValue

            function toggleVisible() {
                _internalVisible = !_internalVisible
                _planViewSettings.showMissionItemStatus.rawValue = _internalVisible
            }
        }
932 933 934 935

        MapScale {
            id:                     mapScale
            anchors.margins:        _toolsMargin
936 937
            anchors.bottom:         terrainStatus.visible ? terrainStatus.top : parent.bottom
            anchors.left:           toolStrip.y + toolStrip.height + _toolsMargin > mapScale.y ? toolStrip.right: parent.left
938 939 940
            mapControl:             editorMap
            buttonsOnLeft:          true
            terrainButtonVisible:   _editingLayer === _layerMission
941 942
            terrainButtonChecked:   terrainStatus.visible
            onTerrainButtonClicked: terrainStatus.toggleVisible()
943
        }
Gus Grubba's avatar
Gus Grubba committed
944
    }
945

946 947 948 949
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
950
            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?")
951 952
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
953
                _planMasterController.loadFromVehicle()
954 955 956 957 958 959 960 961
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
DonLakeFlyer's avatar
DonLakeFlyer committed
962
            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?")
963 964
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
965
                _planMasterController.loadFromSelectedFile()
966 967 968 969
            }
        }
    }

970 971
    property var createPlanRemoveAllPromptDialogMapCenter
    property var createPlanRemoveAllPromptDialogPlanCreator
972
    Component {
973
        id: createPlanRemoveAllPromptDialog
974
        QGCViewMessage {
975
            message: qsTr("Are you sure you want to remove current plan and create a new plan? ")
976
            function accept() {
977
                createPlanRemoveAllPromptDialogPlanCreator.createPlan(createPlanRemoveAllPromptDialogMapCenter)
978 979 980 981 982
                hideDialog()
            }
        }
    }

983 984 985 986 987
    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
988
                _planMasterController.removeAllFromVehicle()
989
                _missionController.setCurrentPlanViewSeqNum(0, true)
990 991 992 993 994
                hideDialog()
            }
        }
    }

995 996 997 998 999 1000 1001 1002 1003 1004 1005
    //- ToolStrip DropPanel Components

    Component {
        id: centerMapDropPanel

        CenterMapDropPanel {
            map:            editorMap
            fitFunctions:   mapFitFunctions
        }
    }

1006 1007 1008 1009 1010 1011 1012 1013 1014
    Component {
        id: patternDropPanel

        ColumnLayout {
            spacing:    ScreenTools.defaultFontPixelWidth * 0.5

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

            Repeater {
1015
                model: _missionController.complexMissionItemNames
1016 1017 1018 1019 1020 1021

                QGCButton {
                    text:               modelData
                    Layout.fillWidth:   true

                    onClicked: {
1022
                        insertComplexItemAfterCurrent(modelData)
1023 1024 1025 1026 1027 1028
                        dropPanel.hide()
                    }
                }
            }
        } // Column
    }
1029 1030

    Component {
1031
        id: syncDropPanel
1032

1033
        ColumnLayout {
1034 1035
            id:         columnHolder
            spacing:    _margin
1036

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

1039
            QGCLabel {
1040
                id:                 unsavedChangedLabel
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
                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")
1053
                showSpacer:         false
1054 1055
            }

1056 1057
            GridLayout {
                columns:            2
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 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
                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
1128 1129
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
1130
                visible:            storageSection.visible
1131

1132
                /*QGCButton {
1133
                    text:               qsTr("New...")
1134
                    Layout.fillWidth:   true
1135
                    onClicked:  {
1136
                        dropPanel.hide()
1137 1138 1139
                        if (_planMasterController.containsItems) {
                            mainWindow.showComponentDialog(removeAllPromptDialog, qsTr("New Plan"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
                        }
1140
                    }
1141
                }*/
1142

1143
                QGCButton {
1144
                    text:               qsTr("Open...")
1145
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1146
                    enabled:            !_planMasterController.syncInProgress
1147 1148
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1149
                        if (_planMasterController.dirty) {
1150
                            mainWindow.showComponentDialog(syncLoadFromFileOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1151
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1152
                            _planMasterController.loadFromSelectedFile()
1153 1154 1155
                        }
                    }
                }
1156

1157
                QGCButton {
1158
                    text:               qsTr("Save")
1159
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1160
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.currentPlanFile !== ""
1161 1162
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1163 1164
                        if(_planMasterController.currentPlanFile !== "") {
                            _planMasterController.saveToCurrent()
1165
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1166
                            _planMasterController.saveToSelectedFile()
1167
                        }
1168 1169 1170 1171
                    }
                }

                QGCButton {
1172
                    text:               qsTr("Save As...")
1173
                    Layout.fillWidth:   true
1174
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.containsItems
1175 1176
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1177
                        _planMasterController.saveToSelectedFile()
1178 1179 1180 1181
                    }
                }

                QGCButton {
1182 1183
                    Layout.columnSpan:  3
                    Layout.fillWidth:   true
1184
                    text:               qsTr("Save Mission Waypoints As KML...")
Gus Grubba's avatar
Gus Grubba committed
1185
                    enabled:            !_planMasterController.syncInProgress && _visualItems.count > 1
1186
                    onClicked: {
1187
                        // First point does not count
1188
                        if (_visualItems.count < 2) {
1189
                            mainWindow.showComponentDialog(noItemForKML, qsTr("KML"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
1190 1191
                            return
                        }
1192
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1193
                        _planMasterController.saveKmlToSelectedFile()
1194 1195
                    }
                }
1196
            }
1197

1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
            SectionHeader {
                id:                 vehicleSection
                Layout.fillWidth:   true
                text:               qsTr("Vehicle")
            }

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

1209
                QGCButton {
1210
                    text:               qsTr("Upload")
1211
                    Layout.fillWidth:   true
1212
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress && _planMasterController.containsItems
1213 1214
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
1215
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1216
                        _planMasterController.upload()
1217 1218
                    }
                }
1219 1220 1221 1222

                QGCButton {
                    text:               qsTr("Download")
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1223
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1224 1225 1226
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1227
                        if (_planMasterController.dirty) {
1228
                            mainWindow.showComponentDialog(syncLoadFromVehicleOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1229
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1230
                            _planMasterController.loadFromVehicle()
1231 1232 1233 1234 1235
                        }
                    }
                }

                QGCButton {
1236
                    text:               qsTr("Clear")
1237 1238
                    Layout.fillWidth:   true
                    Layout.columnSpan:  2
Gus Grubba's avatar
Gus Grubba committed
1239
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1240 1241 1242
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
1243
                        mainWindow.showComponentDialog(clearVehicleMissionDialog, text, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1244 1245
                    }
                }
1246
            }
1247 1248
        }
    }
Gus Grubba's avatar
Gus Grubba committed
1249
}