PlanView.qml 53.9 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
DonLakeFlyer's avatar
DonLakeFlyer committed
37
    readonly property real  _toolsTopMargin:            ScreenTools.defaultFontPixelHeight * 0.5
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 64
    function addComplexItem(complexItemName) {
        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
        insertComplexMissionItem(complexItemName, coordinate, _missionController.visualItems.count)
69 70 71
    }

    function insertComplexMissionItem(complexItemName, coordinate, index) {
72
        _missionController.insertComplexMissionItem(complexItemName, coordinate, index, true /* makeCurrentItem */)
73 74
    }

75
    function insertComplexMissionItemFromKMLOrSHP(complexItemName, file, index) {
76
        _missionController.insertComplexMissionItemFromKMLOrSHP(complexItemName, file, index, true /* makeCurrentItem */)
77 78
    }

79
    function updateAirspace(reset) {
80 81 82 83
        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) {
84
                QGroundControl.airspaceManager.setROI(coordinateNW, coordinateSE, true /*planView*/, reset)
85 86 87 88
            }
        }
    }

89 90 91 92 93
    property bool _firstMissionLoadComplete:    false
    property bool _firstFenceLoadComplete:      false
    property bool _firstRallyLoadComplete:      false
    property bool _firstLoadComplete:           false

94
    MapFitFunctions {
95
        id:                         mapFitFunctions  // The name for this id cannot be changed without breaking references outside of this code. Beware!
96 97
        map:                        editorMap
        usePlannedHomePosition:     true
98
        planMasterController:       _planMasterController
99 100
    }

101
    on_AirspaceEnabledChanged: {
102
        if(QGroundControl.airmapSupported) {
103 104
            if(_airspaceEnabled) {
                planControlColapsed = QGroundControl.airspaceManager.airspaceVisible
105
                updateAirspace(true)
106 107 108
            } else {
                planControlColapsed = false
            }
109
        } else {
Gus Grubba's avatar
Gus Grubba committed
110 111 112 113
            planControlColapsed = false
        }
    }

114 115 116 117 118 119
    onVisibleChanged: {
        if (visible && !_planMasterController.containsItems) {
            toolStrip.simulateClick(toolStrip.fileButtonIndex)
        }
    }

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

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

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    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
159
                        activeVehicle.flightMode = activeVehicle.pauseFlightMode
160
                        _planMasterController.sendToVehicle()
161
                        hideDialog()
162 163 164 165 166 167
                    }
                }
            }
        }
    }

Gus Grubba's avatar
Gus Grubba committed
168
    Connections {
169
        target: QGroundControl.airspaceManager
170
        onAirspaceVisibleChanged: {
171
            planControlColapsed = QGroundControl.airspaceManager.airspaceVisible
Gus Grubba's avatar
Gus Grubba committed
172 173 174
        }
    }

175 176 177 178 179 180 181
    Component {
        id: noItemForKML
        QGCViewMessage {
            message:    qsTr("You need at least one item to create a KML.")
        }
    }

182
    PlanMasterController {
Gus Grubba's avatar
Gus Grubba committed
183
        id: _planMasterController
184

185
        Component.onCompleted: {
186
            _planMasterController.start(false /* flyView */)
187
            _missionController.setCurrentPlanViewIndex(0, true)
Gus Grubba's avatar
Gus Grubba committed
188
            mainWindow.planMasterControllerPlan = _planMasterController
189 190
        }

191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
        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
210 211
        }

212
        function upload() {
213
            if (!checkReadyForSaveUpload(false /* save */)) {
214 215
                return
            }
Gus Grubba's avatar
Gus Grubba committed
216
            if (activeVehicle && activeVehicle.armed && activeVehicle.flightMode === activeVehicle.missionFlightMode) {
217
                mainWindow.showComponentDialog(activeMissionUploadDialogComponent, qsTr("Plan Upload"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
218
            } else {
219 220
                sendToVehicle()
            }
DonLakeFlyer's avatar
DonLakeFlyer committed
221 222
        }

223
        function loadFromSelectedFile() {
224
            fileDialog.title =          qsTr("Select Plan File")
DonLakeFlyer's avatar
DonLakeFlyer committed
225
            fileDialog.planFiles =      true
226
            fileDialog.selectExisting = true
Gus Grubba's avatar
Gus Grubba committed
227
            fileDialog.nameFilters =    _planMasterController.loadNameFilters
228 229
            fileDialog.fileExtension =  _appSettings.planFileExtension
            fileDialog.fileExtension2 = _appSettings.missionFileExtension
230
            fileDialog.openForLoad()
231 232 233
        }

        function saveToSelectedFile() {
234
            if (!checkReadyForSaveUpload(true /* save */)) {
235 236
                return
            }
237
            fileDialog.title =          qsTr("Save Plan")
238
            fileDialog.planFiles =      true
239
            fileDialog.selectExisting = false
Gus Grubba's avatar
Gus Grubba committed
240
            fileDialog.nameFilters =    _planMasterController.saveNameFilters
241 242
            fileDialog.fileExtension =  _appSettings.planFileExtension
            fileDialog.fileExtension2 = _appSettings.missionFileExtension
243
            fileDialog.openForSave()
244 245
        }

246
        function fitViewportToItems() {
247
            mapFitFunctions.fitMapViewportToMissionItems()
248
        }
249

250 251
        function loadShapeFromSelectedFile() {
            fileDialog.title =          qsTr("Load Shape")
252 253
            fileDialog.planFiles =      false
            fileDialog.selectExisting = true
254 255 256
            fileDialog.nameFilters =    ShapeFileHelper.fileDialogKMLOrSHPFilters
            fileDialog.fileExtension =  _appSettings.kmlFileExtension
            fileDialog.fileExtension2 = _appSettings.shpFileExtension
257 258 259
            fileDialog.openForLoad()
        }

260
        function saveKmlToSelectedFile() {
261
            if (!checkReadyForSaveUpload(true /* save */)) {
262 263
                return
            }
264
            fileDialog.title =          qsTr("Save KML")
265
            fileDialog.planFiles =      false
266
            fileDialog.selectExisting = false
267 268
            fileDialog.nameFilters =    ShapeFileHelper.fileDialogKMLFilters
            fileDialog.fileExtension =  _appSettings.kmlFileExtension
269
            fileDialog.fileExtension2 = ""
270 271
            fileDialog.openForSave()
        }
272
    }
273

274 275
    Connections {
        target: _missionController
276

277
        onNewItemsFromVehicle: {
Gus Grubba's avatar
Gus Grubba committed
278
            if (_visualItems && _visualItems.count !== 1) {
279 280
                mapFitFunctions.fitMapViewportToMissionItems()
            }
281
            _missionController.setCurrentPlanViewIndex(0, true)
282 283
        }
    }
284

285 286 287 288
    /// Inserts a new simple mission item
    ///     @param coordinate Location to insert item
    ///     @param index Insert item at this index
    function insertSimpleMissionItem(coordinate, index) {
289
        _missionController.insertSimpleMissionItem(coordinate, index, true /* makeCurrentItem */)
290 291
    }

292 293 294 295 296 297 298
    /// Inserts a new ROI mission item
    ///     @param coordinate Location to insert item
    ///     @param index Insert item at this index
    function insertROIMissionItem(coordinate, index) {
        var sequenceNumber = _missionController.insertROIMissionItem(coordinate, index)
        _missionController.setCurrentPlanViewIndex(sequenceNumber, true)
        _addROIOnClick = false
299
        toolStrip.lastClickedButton.checked = false
300 301
    }

302 303 304 305 306 307 308 309 310 311 312
    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) {
                _missionController.setCurrentPlanViewIndex(vmi.sequenceNumber, true)
                break
            }
        }
    }

313 314
    property int _moveDialogMissionItemIndex

315 316
    QGCFileDialog {
        id:             fileDialog
Gus Grubba's avatar
Gus Grubba committed
317
        folder:         _appSettings ? _appSettings.missionSavePath : ""
318

319 320
        property bool planFiles: true    ///< true: working with plan files, false: working with kml file

321
        onAcceptedForSave: {
322
            if (planFiles) {
Gus Grubba's avatar
Gus Grubba committed
323
                _planMasterController.saveToFile(file)
324
            } else {
Gus Grubba's avatar
Gus Grubba committed
325
                _planMasterController.saveToKml(file)
326
            }
327
            close()
328 329
        }

330
        onAcceptedForLoad: {
331
            if (planFiles) {
Gus Grubba's avatar
Gus Grubba committed
332 333
                _planMasterController.loadFromFile(file)
                _planMasterController.fitViewportToItems()
334 335
                _missionController.setCurrentPlanViewIndex(0, true)
            } else {
336 337
                var retList = ShapeFileHelper.determineShapeType(file)
                if (retList[0] == ShapeFileHelper.Error) {
338
                    mainWindow.showMessageDialog("Error", retList[1])
339
                } else if (retList[0] == ShapeFileHelper.Polygon) {
340
                    var editVehicle = activeVehicle ? activeVehicle : QGroundControl.multiVehicleManager.offlineEditingVehicle
341 342 343 344
                    if (editVehicle.fixedWing) {
                        insertComplexMissionItemFromKMLOrSHP(_missionController.surveyComplexItemName, file, -1)
                    } else {
                        polygonSelectPatternFile = file
345
                        mainWindow.showComponentDialog(patternPolygonSelectDialog, fileDialog.title, mainWindow.showDialogDefaultWidth, StandardButton.Ok | StandardButton.Cancel)
346
                    }
347 348
                } else if (retList[0] == ShapeFileHelper.Polyline) {
                    insertComplexMissionItemFromKMLOrSHP(_missionController.corridorScanComplexItemName, file, -1)
349 350
                }
            }
351
            close()
352 353 354
        }
    }

355
    property string polygonSelectPatternFile
356
    Component {
357
        id: patternPolygonSelectDialog
358 359 360 361 362 363 364 365
        QGCViewDialog {
            function accept() {
                var complexItemName
                if (surveyRadio.checked) {
                    complexItemName = _missionController.surveyComplexItemName
                } else {
                    complexItemName = _missionController.structureScanComplexItemName
                }
366
                insertComplexMissionItemFromKMLOrSHP(complexItemName, polygonSelectPatternFile, -1)
367 368 369 370 371 372 373 374 375 376
                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
377
                    text:           qsTr("Create which pattern type?")
378 379 380 381 382 383 384 385 386 387 388 389 390
                }
                QGCRadioButton {
                    id:             surveyRadio
                    text:           qsTr("Survey")
                    checked:        true
                }
                QGCRadioButton {
                    text:           qsTr("Structure Scan")
                }
            }
        }
    }

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

                QGCComboBox {
                    id:             toCombo
416
                    model:          _visualItems.count
417 418 419 420 421 422
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

423
    Item {
Don Gagne's avatar
Don Gagne committed
424
        id:             panel
425
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
426

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

435
            // This is the center rectangle of the map which is not obscured by tools
DonLakeFlyer's avatar
DonLakeFlyer committed
436
            property rect centerViewport:   Qt.rect(_leftToolWidth + _margin, _toolsTopMargin, editorMap.width - _leftToolWidth - _rightToolWidth - (_margin * 2), mapScale.y - _margin - _toolsTopMargin)
437

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

441
            readonly property real animationDuration: 500
442

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

446 447 448 449 450 451
            Behavior on zoomLevel {
                NumberAnimation {
                    duration:       editorMap.animationDuration
                    easing.type:    Easing.InOutQuad
                }
            }
452

453 454
            QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

455 456
            onZoomLevelChanged: updateAirspace(false)
            onCenterChanged:    updateAirspace(false)
457

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

468 469 470
                    switch (_editingLayer) {
                    case _layerMission:
                        if (_addWaypointOnClick) {
471
                            insertSimpleMissionItem(coordinate, _missionController.visualItems.count)
472 473 474
                        } else if (_addROIOnClick) {
                            _addROIOnClick = false
                            insertROIMissionItem(coordinate, _missionController.visualItems.count)
475
                        }
476 477
                        break
                    case _layerRallyPoints:
Gus Grubba's avatar
Gus Grubba committed
478
                        if (_rallyPointController.supported && _addWaypointOnClick) {
479
                            _rallyPointController.addPoint(coordinate)
480
                        }
481
                        break
Don Gagne's avatar
Don Gagne committed
482
                    }
Don Gagne's avatar
Don Gagne committed
483
                }
484
            }
Don Gagne's avatar
Don Gagne committed
485

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

496 497
            // Add lines between waypoints
            MissionLineView {
498
                model: _editingLayer == _layerMission ? _missionController.waypointLines : undefined
499
            }
500

501 502 503 504 505 506
            MapItemView {
                model: _editingLayer == _layerMission ? _missionController.directionArrows : undefined

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

            // UI for splitting the current segment
            MapQuickItem {
                id:             splitSegmentItem
                anchorPoint.x:  sourceItem.width / 2
                anchorPoint.y:  sourceItem.height / 2
                z:              QGroundControl.zOrderWaypointLines + 1

                sourceItem: SplitIndicator {
Don Gagne's avatar
Don Gagne committed
520
                    onClicked:  insertSimpleMissionItem(splitSegmentItem.coordinate, _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex))
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
                }

                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()
542 543 544
                }
            }

545 546 547 548 549 550 551
            // Add the vehicles to the map
            MapItemView {
                model: QGroundControl.multiVehicleManager.vehicles
                delegate:
                    VehicleMapItem {
                    vehicle:        object
                    coordinate:     object.coordinate
552
                    map:            editorMap
553 554
                    size:           ScreenTools.defaultFontPixelHeight * 3
                    z:              QGroundControl.zOrderMapItems - 1
555
                }
556
            }
557

558 559
            GeoFenceMapVisuals {
                map:                    editorMap
560
                myGeoFenceController:   _geoFenceController
561
                interactive:            _editingLayer == _layerGeoFence
562
                homePosition:           _missionController.plannedHomePosition
563 564
                planView:               true
            }
565

566 567
            RallyPointMapVisuals {
                map:                    editorMap
568
                myRallyPointController: _rallyPointController
569 570
                interactive:            _editingLayer == _layerRallyPoints
                planView:               true
571
            }
572

573 574
            // Airspace overlap support
            MapItemView {
575
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.circles : []
576 577 578
                delegate: MapCircle {
                    center:         object.center
                    radius:         object.radius
579
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
580 581
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
582 583 584 585
                }
            }

            MapItemView {
586
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : []
587 588
                delegate: MapPolygon {
                    path:           object.polygon
589
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
590 591
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
592 593
                }
            }
594
        }
595

596 597
        //-----------------------------------------------------------
        // Left tool strip
Gus Grubba's avatar
Gus Grubba committed
598
        ToolStrip {
599
            id:                 toolStrip
600
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth * 2
601
            anchors.left:       parent.left
DonLakeFlyer's avatar
DonLakeFlyer committed
602
            anchors.topMargin:  _toolsTopMargin
603 604
            anchors.top:        parent.top
            z:                  QGroundControl.zOrderWidgets
Gus Grubba's avatar
Gus Grubba committed
605
            maxHeight:          mapScale.y - toolStrip.y
606

607 608
            property int fileButtonIndex: 1

Gus Grubba's avatar
Gus Grubba committed
609
            property bool _isRally:     _editingLayer == _layerRallyPoints
610

Gus Grubba's avatar
Gus Grubba committed
611 612 613 614 615 616
            model: [
                {
                    name:               qsTr("Fly"),
                    iconSource:         "/qmlimages/PaperPlane.svg",
                    buttonEnabled:      true,
                    buttonVisible:      true,
617
                },
618
                {
Gus Grubba's avatar
Gus Grubba committed
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
                    name:               qsTr("File"),
                    iconSource:         "/qmlimages/MapSync.svg",
                    buttonEnabled:      !_planMasterController.syncInProgress,
                    buttonVisible:      true,
                    showAlternateIcon:  _planMasterController.dirty,
                    alternateIconSource:"/qmlimages/MapSyncChanged.svg",
                    dropPanelComponent: syncDropPanel
                },
                {
                    name:               _editingLayer == _layerRallyPoints ? qsTr("Rally Point") : qsTr("Waypoint"),
                    iconSource:         "/qmlimages/MapAddMission.svg",
                    buttonEnabled:      true,
                    buttonVisible:      true,
                    toggle:             true,
                    checked:            _addWaypointOnClick
                },
                {
                    name:               qsTr("ROI"),
                    iconSource:         "/qmlimages/MapAddMission.svg",
                    buttonEnabled:      true,
                    buttonVisible:      !_isRally && _waypointsOnlyMode,
                    toggle:             true
                },
                {
                    name:               _singleComplexItem ? _missionController.complexMissionItemNames[0] : qsTr("Pattern"),
                    iconSource:         "/qmlimages/MapDrawShape.svg",
                    buttonEnabled:      true,
                    buttonVisible:      !_isRally,
                    dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel
                },
                {
                    name:               qsTr("Center"),
                    iconSource:         "/qmlimages/MapCenter.svg",
                    buttonEnabled:      true,
                    buttonVisible:      true,
                    dropPanelComponent: centerMapDropPanel
                }
            ]
657

Gus Grubba's avatar
Gus Grubba committed
658 659
            onClicked: {
                switch (index) {
660 661 662 663
                case 0:
                    mainWindow.showFlyView()
                    break;
                case 2:
Gus Grubba's avatar
Gus Grubba committed
664 665 666 667 668 669
                    if(_addWaypointOnClick) {
                        //-- Toggle it off
                        _addWaypointOnClick = false
                        _addROIOnClick = false
                        setChecked(index, false)
                    } else {
670
                        _addWaypointOnClick = checked
671
                        _addROIOnClick = false
Gus Grubba's avatar
Gus Grubba committed
672 673
                    }
                    break
674
                case 3:
Gus Grubba's avatar
Gus Grubba committed
675 676 677
                    _addROIOnClick = checked
                    _addWaypointOnClick = false
                    break
678
                case 4:
Gus Grubba's avatar
Gus Grubba committed
679 680 681 682
                    if (_singleComplexItem) {
                        addComplexItem(_missionController.complexMissionItemNames[0])
                    }
                    break
683 684
                }
            }
Gus Grubba's avatar
Gus Grubba committed
685
        }
686

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

        MapScale {
884 885 886 887 888 889 890 891 892 893 894
            id:                     mapScale
            anchors.margins:        ScreenTools.defaultFontPixelHeight * (0.66)
            anchors.bottom:         waypointValuesDisplay.visible ? waypointValuesDisplay.top : parent.bottom
            anchors.left:           parent.left
            mapControl:             editorMap
            buttonsOnLeft:          true
            terrainButtonVisible:   true
            visible:                _toolStripBottom < y && _editingLayer === _layerMission
            terrainButtonChecked:   waypointValuesDisplay.visible

            onTerrainButtonClicked: waypointValuesDisplay.toggleVisible()
895 896 897 898 899 900
        }

        MissionItemStatus {
            id:                 waypointValuesDisplay
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.left:       parent.left
901
            height:             ScreenTools.defaultFontPixelHeight * 7
902
            maxWidth:           parent.width - rightPanel.width - x
903
            anchors.bottom:     parent.bottom
904
            missionItems:       _missionController.visualItems
905 906 907 908 909 910 911
            visible:            _internalVisible && _editingLayer === _layerMission && (_toolStripBottom + mapScale.height) < y && QGroundControl.corePlugin.options.showMissionStatus

            property bool _internalVisible: false

            function toggleVisible() {
                _internalVisible = !_internalVisible
            }
912
        }
Gus Grubba's avatar
Gus Grubba committed
913
    }
914

915 916 917 918
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
919
            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?")
920 921
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
922
                _planMasterController.loadFromVehicle()
923 924 925 926 927 928 929 930
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
DonLakeFlyer's avatar
DonLakeFlyer committed
931
            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?")
932 933
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
934
                _planMasterController.loadFromSelectedFile()
935 936 937 938
            }
        }
    }

939 940
    property var createPlanRemoveAllPromptDialogMapCenter
    property var createPlanRemoveAllPromptDialogPlanCreator
941
    Component {
942
        id: createPlanRemoveAllPromptDialog
943
        QGCViewMessage {
944
            message: qsTr("Are you sure you want to remove current plan and create a new plan? ")
945
            function accept() {
946
                createPlanRemoveAllPromptDialogPlanCreator.createPlan(createPlanRemoveAllPromptDialogMapCenter)
947 948 949 950 951
                hideDialog()
            }
        }
    }

952 953 954 955 956
    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
957
                _planMasterController.removeAllFromVehicle()
958
                _missionController.setCurrentPlanViewIndex(0, true)
959 960 961 962 963
                hideDialog()
            }
        }
    }

964 965 966 967 968 969 970 971 972 973 974
    //- ToolStrip DropPanel Components

    Component {
        id: centerMapDropPanel

        CenterMapDropPanel {
            map:            editorMap
            fitFunctions:   mapFitFunctions
        }
    }

975 976 977 978 979 980 981 982 983
    Component {
        id: patternDropPanel

        ColumnLayout {
            spacing:    ScreenTools.defaultFontPixelWidth * 0.5

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

            Repeater {
984
                model: _missionController.complexMissionItemNames
985 986 987 988 989 990

                QGCButton {
                    text:               modelData
                    Layout.fillWidth:   true

                    onClicked: {
991
                        addComplexItem(modelData)
992 993 994 995
                        dropPanel.hide()
                    }
                }
            }
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008

            Rectangle {
                width:              parent.width * 0.8
                height:             1
                color:              qgcPal.text
                opacity:            0.5
                Layout.fillWidth:   true
                Layout.columnSpan:  2
            }

            QGCButton {
                text:               qsTr("Load KML/SHP...")
                Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1009
                enabled:            !_planMasterController.syncInProgress
1010
                onClicked: {
Gus Grubba's avatar
Gus Grubba committed
1011
                    _planMasterController.loadShapeFromSelectedFile()
1012 1013 1014
                    dropPanel.hide()
                }
            }
1015 1016
        } // Column
    }
1017 1018

    Component {
1019
        id: syncDropPanel
1020

1021
        ColumnLayout {
1022 1023
            id:         columnHolder
            spacing:    _margin
1024

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

1027
            QGCLabel {
1028
                id:                 unsavedChangedLabel
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
                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")
1041
                showSpacer:         false
1042 1043
            }

1044 1045
            GridLayout {
                columns:            2
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 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
                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
1116 1117
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
1118
                visible:            storageSection.visible
1119

1120
                /*QGCButton {
1121
                    text:               qsTr("New...")
1122
                    Layout.fillWidth:   true
1123
                    onClicked:  {
1124
                        dropPanel.hide()
1125 1126 1127
                        if (_planMasterController.containsItems) {
                            mainWindow.showComponentDialog(removeAllPromptDialog, qsTr("New Plan"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
                        }
1128
                    }
1129
                }*/
1130

1131
                QGCButton {
1132
                    text:               qsTr("Open...")
1133
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1134
                    enabled:            !_planMasterController.syncInProgress
1135 1136
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1137
                        if (_planMasterController.dirty) {
1138
                            mainWindow.showComponentDialog(syncLoadFromFileOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1139
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1140
                            _planMasterController.loadFromSelectedFile()
1141 1142 1143
                        }
                    }
                }
1144

1145
                QGCButton {
1146
                    text:               qsTr("Save")
1147
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1148
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.currentPlanFile !== ""
1149 1150
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1151 1152
                        if(_planMasterController.currentPlanFile !== "") {
                            _planMasterController.saveToCurrent()
1153
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1154
                            _planMasterController.saveToSelectedFile()
1155
                        }
1156 1157 1158 1159
                    }
                }

                QGCButton {
1160
                    text:               qsTr("Save As...")
1161
                    Layout.fillWidth:   true
1162
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.containsItems
1163 1164
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1165
                        _planMasterController.saveToSelectedFile()
1166 1167 1168 1169
                    }
                }

                QGCButton {
1170 1171
                    Layout.columnSpan:  3
                    Layout.fillWidth:   true
1172
                    text:               qsTr("Save Mission Waypoints As KML...")
Gus Grubba's avatar
Gus Grubba committed
1173
                    enabled:            !_planMasterController.syncInProgress && _visualItems.count > 1
1174
                    onClicked: {
1175
                        // First point does not count
1176
                        if (_visualItems.count < 2) {
1177
                            mainWindow.showComponentDialog(noItemForKML, qsTr("KML"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
1178 1179
                            return
                        }
1180
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1181
                        _planMasterController.saveKmlToSelectedFile()
1182 1183
                    }
                }
1184
            }
1185

1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
            SectionHeader {
                id:                 vehicleSection
                Layout.fillWidth:   true
                text:               qsTr("Vehicle")
            }

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

1197
                QGCButton {
1198
                    text:               qsTr("Upload")
1199
                    Layout.fillWidth:   true
1200
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress && _planMasterController.containsItems
1201 1202
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
1203
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1204
                        _planMasterController.upload()
1205 1206
                    }
                }
1207 1208 1209 1210

                QGCButton {
                    text:               qsTr("Download")
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1211
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1212 1213 1214
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1215
                        if (_planMasterController.dirty) {
1216
                            mainWindow.showComponentDialog(syncLoadFromVehicleOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1217
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1218
                            _planMasterController.loadFromVehicle()
1219 1220 1221 1222 1223
                        }
                    }
                }

                QGCButton {
1224
                    text:               qsTr("Clear")
1225 1226
                    Layout.fillWidth:   true
                    Layout.columnSpan:  2
Gus Grubba's avatar
Gus Grubba committed
1227
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1228 1229 1230
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
1231
                        mainWindow.showComponentDialog(clearVehicleMissionDialog, text, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1232 1233
                    }
                }
1234
            }
1235 1236


1237 1238
        }
    }