PlanView.qml 54.8 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 69 70 71 72 73 74 75
        var next_index = _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex)+1
        if(next_index ==1 && _missionController.visualItems.count >1){
            console.log(next_index, _missionController.visualItems.count)
            insertComplexMissionItem(complexItemName, coordinate, next_index+1)
        }
        else if(next_index <= _missionController.visualItems.count){
            insertComplexMissionItem(complexItemName, coordinate, next_index)
        }
76 77 78
    }

    function insertComplexMissionItem(complexItemName, coordinate, index) {
79
        _missionController.insertComplexMissionItem(complexItemName, coordinate, index, true /* makeCurrentItem */)
80 81
    }

82
    function insertComplexMissionItemFromKMLOrSHP(complexItemName, file, index) {
83
        _missionController.insertComplexMissionItemFromKMLOrSHP(complexItemName, file, index, true /* makeCurrentItem */)
84 85
    }

86
    function updateAirspace(reset) {
87 88 89 90
        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) {
91
                QGroundControl.airspaceManager.setROI(coordinateNW, coordinateSE, true /*planView*/, reset)
92 93 94 95
            }
        }
    }

96 97 98 99 100
    property bool _firstMissionLoadComplete:    false
    property bool _firstFenceLoadComplete:      false
    property bool _firstRallyLoadComplete:      false
    property bool _firstLoadComplete:           false

101
    MapFitFunctions {
102
        id:                         mapFitFunctions  // The name for this id cannot be changed without breaking references outside of this code. Beware!
103 104
        map:                        editorMap
        usePlannedHomePosition:     true
105
        planMasterController:       _planMasterController
106 107
    }

108
    on_AirspaceEnabledChanged: {
109
        if(QGroundControl.airmapSupported) {
110 111
            if(_airspaceEnabled) {
                planControlColapsed = QGroundControl.airspaceManager.airspaceVisible
112
                updateAirspace(true)
113 114 115
            } else {
                planControlColapsed = false
            }
116
        } else {
Gus Grubba's avatar
Gus Grubba committed
117 118 119 120
            planControlColapsed = false
        }
    }

121 122 123 124 125 126
    onVisibleChanged: {
        if (visible && !_planMasterController.containsItems) {
            toolStrip.simulateClick(toolStrip.fileButtonIndex)
        }
    }

DonLakeFlyer's avatar
DonLakeFlyer committed
127
    Connections {
Gus Grubba's avatar
Gus Grubba committed
128
        target: _appSettings ? _appSettings.defaultMissionItemAltitude : null
DonLakeFlyer's avatar
DonLakeFlyer committed
129 130
        onRawValueChanged: {
            if (_visualItems.count > 1) {
131
                mainWindow.showComponentDialog(applyNewAltitude, qsTr("Apply new alititude"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
DonLakeFlyer's avatar
DonLakeFlyer committed
132 133 134 135 136 137 138 139 140 141
            }
        }
    }

    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()
142
                _missionController.applyDefaultMissionAltitude()
DonLakeFlyer's avatar
DonLakeFlyer committed
143 144 145 146
            }
        }
    }

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    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
166
                        activeVehicle.flightMode = activeVehicle.pauseFlightMode
167
                        _planMasterController.sendToVehicle()
168
                        hideDialog()
169 170 171 172 173 174
                    }
                }
            }
        }
    }

Gus Grubba's avatar
Gus Grubba committed
175
    Connections {
176
        target: QGroundControl.airspaceManager
177
        onAirspaceVisibleChanged: {
178
            planControlColapsed = QGroundControl.airspaceManager.airspaceVisible
Gus Grubba's avatar
Gus Grubba committed
179 180 181
        }
    }

182 183 184 185 186 187 188
    Component {
        id: noItemForKML
        QGCViewMessage {
            message:    qsTr("You need at least one item to create a KML.")
        }
    }

189
    PlanMasterController {
Gus Grubba's avatar
Gus Grubba committed
190
        id: _planMasterController
191

192
        Component.onCompleted: {
193
            _planMasterController.start(false /* flyView */)
194
            _missionController.setCurrentPlanViewIndex(0, true)
Gus Grubba's avatar
Gus Grubba committed
195
            mainWindow.planMasterControllerPlan = _planMasterController
196 197
        }

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
        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
217 218
        }

219
        function upload() {
220
            if (!checkReadyForSaveUpload(false /* save */)) {
221 222
                return
            }
Gus Grubba's avatar
Gus Grubba committed
223
            if (activeVehicle && activeVehicle.armed && activeVehicle.flightMode === activeVehicle.missionFlightMode) {
224
                mainWindow.showComponentDialog(activeMissionUploadDialogComponent, qsTr("Plan Upload"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
225
            } else {
226 227
                sendToVehicle()
            }
DonLakeFlyer's avatar
DonLakeFlyer committed
228 229
        }

230
        function loadFromSelectedFile() {
231
            fileDialog.title =          qsTr("Select Plan File")
DonLakeFlyer's avatar
DonLakeFlyer committed
232
            fileDialog.planFiles =      true
233
            fileDialog.selectExisting = true
Gus Grubba's avatar
Gus Grubba committed
234
            fileDialog.nameFilters =    _planMasterController.loadNameFilters
235 236
            fileDialog.fileExtension =  _appSettings.planFileExtension
            fileDialog.fileExtension2 = _appSettings.missionFileExtension
237
            fileDialog.openForLoad()
238 239 240
        }

        function saveToSelectedFile() {
241
            if (!checkReadyForSaveUpload(true /* save */)) {
242 243
                return
            }
244
            fileDialog.title =          qsTr("Save Plan")
245
            fileDialog.planFiles =      true
246
            fileDialog.selectExisting = false
Gus Grubba's avatar
Gus Grubba committed
247
            fileDialog.nameFilters =    _planMasterController.saveNameFilters
248 249
            fileDialog.fileExtension =  _appSettings.planFileExtension
            fileDialog.fileExtension2 = _appSettings.missionFileExtension
250
            fileDialog.openForSave()
251 252
        }

253
        function fitViewportToItems() {
254
            mapFitFunctions.fitMapViewportToMissionItems()
255
        }
256

257 258
        function loadShapeFromSelectedFile() {
            fileDialog.title =          qsTr("Load Shape")
259 260
            fileDialog.planFiles =      false
            fileDialog.selectExisting = true
261 262 263
            fileDialog.nameFilters =    ShapeFileHelper.fileDialogKMLOrSHPFilters
            fileDialog.fileExtension =  _appSettings.kmlFileExtension
            fileDialog.fileExtension2 = _appSettings.shpFileExtension
264 265 266
            fileDialog.openForLoad()
        }

267
        function saveKmlToSelectedFile() {
268
            if (!checkReadyForSaveUpload(true /* save */)) {
269 270
                return
            }
271
            fileDialog.title =          qsTr("Save KML")
272
            fileDialog.planFiles =      false
273
            fileDialog.selectExisting = false
274 275
            fileDialog.nameFilters =    ShapeFileHelper.fileDialogKMLFilters
            fileDialog.fileExtension =  _appSettings.kmlFileExtension
276
            fileDialog.fileExtension2 = ""
277 278
            fileDialog.openForSave()
        }
279
    }
280

281 282
    Connections {
        target: _missionController
283

284
        onNewItemsFromVehicle: {
Gus Grubba's avatar
Gus Grubba committed
285
            if (_visualItems && _visualItems.count !== 1) {
286 287
                mapFitFunctions.fitMapViewportToMissionItems()
            }
288
            _missionController.setCurrentPlanViewIndex(0, true)
289 290
        }
    }
291

292 293 294 295
    /// Inserts a new simple mission item
    ///     @param coordinate Location to insert item
    ///     @param index Insert item at this index
    function insertSimpleMissionItem(coordinate, index) {
296
        _missionController.insertSimpleMissionItem(coordinate, index, true /* makeCurrentItem */)
297 298
    }

299 300 301 302 303 304 305
    /// 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
306
        toolStrip.lastClickedButton.checked = false
307 308
    }

309 310 311 312 313 314 315 316 317 318 319
    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
            }
        }
    }

320 321
    property int _moveDialogMissionItemIndex

322 323
    QGCFileDialog {
        id:             fileDialog
Gus Grubba's avatar
Gus Grubba committed
324
        folder:         _appSettings ? _appSettings.missionSavePath : ""
325

326 327
        property bool planFiles: true    ///< true: working with plan files, false: working with kml file

328
        onAcceptedForSave: {
329
            if (planFiles) {
Gus Grubba's avatar
Gus Grubba committed
330
                _planMasterController.saveToFile(file)
331
            } else {
Gus Grubba's avatar
Gus Grubba committed
332
                _planMasterController.saveToKml(file)
333
            }
334
            close()
335 336
        }

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

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

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

                QGCComboBox {
                    id:             toCombo
423
                    model:          _visualItems.count
424 425 426 427 428 429
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

430
    Item {
Don Gagne's avatar
Don Gagne committed
431
        id:             panel
432
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
433

434
        FlightMap {
435 436 437 438 439
            id:                         editorMap
            anchors.fill:               parent
            mapName:                    "MissionEditor"
            allowGCSLocationCenter:     true
            allowVehicleLocationCenter: true
440
            planView:                   true
Don Gagne's avatar
Don Gagne committed
441

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

445 446
            property real _leftToolWidth:       toolStrip.x + toolStrip.width
            property real _rightToolWidth:      rightPanel.width + rightPanel.anchors.rightMargin
447

448
            readonly property real animationDuration: 500
449

450 451
            // Initial map position duplicates Fly view position
            Component.onCompleted: editorMap.center = QGroundControl.flightMapPosition
452

453 454 455 456 457 458
            Behavior on zoomLevel {
                NumberAnimation {
                    duration:       editorMap.animationDuration
                    easing.type:    Easing.InOutQuad
                }
            }
459

460 461
            QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

462 463
            onZoomLevelChanged: updateAirspace(false)
            onCenterChanged:    updateAirspace(false)
464

465 466 467
            MouseArea {
                anchors.fill: parent
                onClicked: {
468 469
                    // Take focus to close any previous editing
                    editorMap.focus = true
470 471 472 473
                    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)
474

475 476 477
                    switch (_editingLayer) {
                    case _layerMission:
                        if (_addWaypointOnClick) {
478 479 480 481 482 483 484 485
                            var next_index = _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex)+1
                            if(next_index ==1 && _missionController.visualItems.count >1){
                                console.log(next_index, _missionController.visualItems.count)
                                insertSimpleMissionItem(coordinate, next_index+1)
                            }
                            else if(next_index <= _missionController.visualItems.count){
                                    insertSimpleMissionItem(coordinate, next_index)
                            }
486 487 488
                        } else if (_addROIOnClick) {
                            _addROIOnClick = false
                            insertROIMissionItem(coordinate, _missionController.visualItems.count)
489
                        }
490 491
                        break
                    case _layerRallyPoints:
Gus Grubba's avatar
Gus Grubba committed
492
                        if (_rallyPointController.supported && _addWaypointOnClick) {
493
                            _rallyPointController.addPoint(coordinate)
494
                        }
495
                        break
Don Gagne's avatar
Don Gagne committed
496
                    }
Don Gagne's avatar
Don Gagne committed
497
                }
498
            }
Don Gagne's avatar
Don Gagne committed
499

500 501
            // Add the mission item visuals to the map
            Repeater {
502
                model: _editingLayer == _layerMission ? _missionController.visualItems : undefined
503 504
                delegate: MissionItemMapVisual {
                    map:        editorMap
505
                    onClicked:  _missionController.setCurrentPlanViewIndex(sequenceNumber, false)
506
                    visible:    _editingLayer == _layerMission
507
                }
508
            }
509

510 511
            // Add lines between waypoints
            MissionLineView {
512
                model: _editingLayer == _layerMission ? _missionController.waypointLines : undefined
513
            }
514

515 516 517 518 519 520
            MapItemView {
                model: _editingLayer == _layerMission ? _missionController.directionArrows : undefined

                delegate: MapLineArrow {
                    fromCoord:      object ? object.coordinate1 : undefined
                    toCoord:        object ? object.coordinate2 : undefined
521 522 523 524 525 526 527 528 529 530 531 532 533
                    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
534
                    onClicked:  insertSimpleMissionItem(splitSegmentItem.coordinate, _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex))
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
                }

                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()
556 557 558
                }
            }

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

572 573
            GeoFenceMapVisuals {
                map:                    editorMap
574
                myGeoFenceController:   _geoFenceController
575
                interactive:            _editingLayer == _layerGeoFence
576
                homePosition:           _missionController.plannedHomePosition
577 578
                planView:               true
            }
579

580 581
            RallyPointMapVisuals {
                map:                    editorMap
582
                myRallyPointController: _rallyPointController
583 584
                interactive:            _editingLayer == _layerRallyPoints
                planView:               true
585
            }
586

587 588
            // Airspace overlap support
            MapItemView {
589
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.circles : []
590 591 592
                delegate: MapCircle {
                    center:         object.center
                    radius:         object.radius
593
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
594 595
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
596 597 598 599
                }
            }

            MapItemView {
600
                model:              _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : []
601 602
                delegate: MapPolygon {
                    path:           object.polygon
603
                    color:          object.color
Gus Grubba's avatar
Gus Grubba committed
604 605
                    border.color:   object.lineColor
                    border.width:   object.lineWidth
606 607
                }
            }
608
        }
609

610 611
        //-----------------------------------------------------------
        // Left tool strip
Gus Grubba's avatar
Gus Grubba committed
612
        ToolStrip {
613
            id:                 toolStrip
614
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth * 2
615
            anchors.left:       parent.left
DonLakeFlyer's avatar
DonLakeFlyer committed
616
            anchors.topMargin:  _toolsTopMargin
617 618
            anchors.top:        parent.top
            z:                  QGroundControl.zOrderWidgets
Gus Grubba's avatar
Gus Grubba committed
619
            maxHeight:          mapScale.y - toolStrip.y
620

621 622
            property int fileButtonIndex: 1

Gus Grubba's avatar
Gus Grubba committed
623
            property bool _isRally:     _editingLayer == _layerRallyPoints
624

Gus Grubba's avatar
Gus Grubba committed
625 626 627 628 629 630
            model: [
                {
                    name:               qsTr("Fly"),
                    iconSource:         "/qmlimages/PaperPlane.svg",
                    buttonEnabled:      true,
                    buttonVisible:      true,
631
                },
632
                {
Gus Grubba's avatar
Gus Grubba committed
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
                    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
                }
            ]
671

Gus Grubba's avatar
Gus Grubba committed
672 673
            onClicked: {
                switch (index) {
674 675 676 677
                case 0:
                    mainWindow.showFlyView()
                    break;
                case 2:
Gus Grubba's avatar
Gus Grubba committed
678 679 680 681 682 683
                    if(_addWaypointOnClick) {
                        //-- Toggle it off
                        _addWaypointOnClick = false
                        _addROIOnClick = false
                        setChecked(index, false)
                    } else {
684
                        _addWaypointOnClick = checked
685
                        _addROIOnClick = false
Gus Grubba's avatar
Gus Grubba committed
686 687
                    }
                    break
688
                case 3:
Gus Grubba's avatar
Gus Grubba committed
689 690 691
                    _addROIOnClick = checked
                    _addWaypointOnClick = false
                    break
692
                case 4:
Gus Grubba's avatar
Gus Grubba committed
693 694 695 696
                    if (_singleComplexItem) {
                        addComplexItem(_missionController.complexMissionItemNames[0])
                    }
                    break
697 698
                }
            }
Gus Grubba's avatar
Gus Grubba committed
699
        }
700

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

        MapScale {
898 899 900 901 902 903 904 905 906 907 908
            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()
909 910 911 912 913 914
        }

        MissionItemStatus {
            id:                 waypointValuesDisplay
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.left:       parent.left
915
            height:             ScreenTools.defaultFontPixelHeight * 7
916
            maxWidth:           parent.width - rightPanel.width - x
917
            anchors.bottom:     parent.bottom
918
            missionItems:       _missionController.visualItems
919 920 921 922 923 924 925
            visible:            _internalVisible && _editingLayer === _layerMission && (_toolStripBottom + mapScale.height) < y && QGroundControl.corePlugin.options.showMissionStatus

            property bool _internalVisible: false

            function toggleVisible() {
                _internalVisible = !_internalVisible
            }
926
        }
Gus Grubba's avatar
Gus Grubba committed
927
    }
928

929 930 931 932
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
933
            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?")
934 935
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
936
                _planMasterController.loadFromVehicle()
937 938 939 940 941 942 943 944
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
DonLakeFlyer's avatar
DonLakeFlyer committed
945
            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?")
946 947
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
948
                _planMasterController.loadFromSelectedFile()
949 950 951 952
            }
        }
    }

953 954
    property var createPlanRemoveAllPromptDialogMapCenter
    property var createPlanRemoveAllPromptDialogPlanCreator
955
    Component {
956
        id: createPlanRemoveAllPromptDialog
957
        QGCViewMessage {
958
            message: qsTr("Are you sure you want to remove current plan and create a new plan? ")
959
            function accept() {
960
                createPlanRemoveAllPromptDialogPlanCreator.createPlan(createPlanRemoveAllPromptDialogMapCenter)
961 962 963 964 965
                hideDialog()
            }
        }
    }

966 967 968 969 970
    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
971
                _planMasterController.removeAllFromVehicle()
972
                _missionController.setCurrentPlanViewIndex(0, true)
973 974 975 976 977
                hideDialog()
            }
        }
    }

978 979 980 981 982 983 984 985 986 987 988
    //- ToolStrip DropPanel Components

    Component {
        id: centerMapDropPanel

        CenterMapDropPanel {
            map:            editorMap
            fitFunctions:   mapFitFunctions
        }
    }

989 990 991 992 993 994 995 996 997
    Component {
        id: patternDropPanel

        ColumnLayout {
            spacing:    ScreenTools.defaultFontPixelWidth * 0.5

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

            Repeater {
998
                model: _missionController.complexMissionItemNames
999 1000 1001 1002 1003 1004

                QGCButton {
                    text:               modelData
                    Layout.fillWidth:   true

                    onClicked: {
1005
                        addComplexItem(modelData)
1006 1007 1008 1009
                        dropPanel.hide()
                    }
                }
            }
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022

            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
1023
                enabled:            !_planMasterController.syncInProgress
1024
                onClicked: {
Gus Grubba's avatar
Gus Grubba committed
1025
                    _planMasterController.loadShapeFromSelectedFile()
1026 1027 1028
                    dropPanel.hide()
                }
            }
1029 1030
        } // Column
    }
1031 1032

    Component {
1033
        id: syncDropPanel
1034

1035
        ColumnLayout {
1036 1037
            id:         columnHolder
            spacing:    _margin
1038

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

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

1058 1059
            GridLayout {
                columns:            2
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 1128 1129
                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
1130 1131
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
1132
                visible:            storageSection.visible
1133

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

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

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

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

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

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

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

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

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

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


1251 1252
        }
    }
Gus Grubba's avatar
Gus Grubba committed
1253
}