PlanView.qml 56.1 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
    function mapCenter() {
64
        var coordinate = editorMap.center
65
        coordinate.latitude  = coordinate.latitude.toFixed(_decimalPlaces)
66
        coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
67
        coordinate.altitude  = coordinate.altitude.toFixed(_decimalPlaces)
68 69 70 71
        return coordinate
    }

    function addComplexItem(complexItemName) {
72 73 74
        var next_index = _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex)+1
        if(next_index ==1 && _missionController.visualItems.count >1){
            console.log(next_index, _missionController.visualItems.count)
75
            insertComplexMissionItem(complexItemName, mapCenter(), next_index+1)
76 77
        }
        else if(next_index <= _missionController.visualItems.count){
78
            insertComplexMissionItem(complexItemName, mapCenter(), next_index)
79
        }
80 81 82
    }

    function insertComplexMissionItem(complexItemName, coordinate, index) {
83
        _missionController.insertComplexMissionItem(complexItemName, coordinate, index, true /* makeCurrentItem */)
84 85
    }

86
    function insertComplexMissionItemFromKMLOrSHP(complexItemName, file, index) {
87
        _missionController.insertComplexMissionItemFromKMLOrSHP(complexItemName, file, index, true /* makeCurrentItem */)
88 89
    }

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

100 101 102 103 104
    property bool _firstMissionLoadComplete:    false
    property bool _firstFenceLoadComplete:      false
    property bool _firstRallyLoadComplete:      false
    property bool _firstLoadComplete:           false

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

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

125 126 127 128 129 130
    onVisibleChanged: {
        if (visible && !_planMasterController.containsItems) {
            toolStrip.simulateClick(toolStrip.fileButtonIndex)
        }
    }

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

    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()
146
                _missionController.applyDefaultMissionAltitude()
DonLakeFlyer's avatar
DonLakeFlyer committed
147 148 149 150
            }
        }
    }

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

Gus Grubba's avatar
Gus Grubba committed
179
    Connections {
180
        target: QGroundControl.airspaceManager
181
        onAirspaceVisibleChanged: {
182
            planControlColapsed = QGroundControl.airspaceManager.airspaceVisible
Gus Grubba's avatar
Gus Grubba committed
183 184 185
        }
    }

186 187 188 189 190 191 192
    Component {
        id: noItemForKML
        QGCViewMessage {
            message:    qsTr("You need at least one item to create a KML.")
        }
    }

193
    PlanMasterController {
Gus Grubba's avatar
Gus Grubba committed
194
        id: _planMasterController
195

196
        Component.onCompleted: {
197
            _planMasterController.start(false /* flyView */)
198
            _missionController.setCurrentPlanViewIndex(0, true)
Gus Grubba's avatar
Gus Grubba committed
199
            mainWindow.planMasterControllerPlan = _planMasterController
200 201
        }

202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
        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
221 222
        }

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

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

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

257
        function fitViewportToItems() {
258
            mapFitFunctions.fitMapViewportToMissionItems()
259
        }
260

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

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

285 286
    Connections {
        target: _missionController
287

288
        onNewItemsFromVehicle: {
Gus Grubba's avatar
Gus Grubba committed
289
            if (_visualItems && _visualItems.count !== 1) {
290 291
                mapFitFunctions.fitMapViewportToMissionItems()
            }
292
            _missionController.setCurrentPlanViewIndex(0, true)
293 294
        }
    }
295

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

303 304 305 306
    /// Inserts a new ROI mission item
    ///     @param coordinate Location to insert item
    ///     @param index Insert item at this index
    function insertROIMissionItem(coordinate, index) {
307
        _missionController.insertROIMissionItem(coordinate, index, true /* makeCurrentItem */)
308 309 310
        _addROIOnClick = false
    }

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

322 323
    property int _moveDialogMissionItemIndex

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

328 329
        property bool planFiles: true    ///< true: working with plan files, false: working with kml file

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

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

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

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

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

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

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

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

447 448
            property real _leftToolWidth:       toolStrip.x + toolStrip.width
            property real _rightToolWidth:      rightPanel.width + rightPanel.anchors.rightMargin
449

450
            readonly property real animationDuration: 500
451

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

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

462 463
            QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

464 465
            onZoomLevelChanged: updateAirspace(false)
            onCenterChanged:    updateAirspace(false)
466

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

477 478 479
                    switch (_editingLayer) {
                    case _layerMission:
                        if (_addWaypointOnClick) {
480 481 482 483 484 485 486 487
                            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)
                            }
488 489 490
                        } else if (_addROIOnClick) {
                            _addROIOnClick = false
                            insertROIMissionItem(coordinate, _missionController.visualItems.count)
491
                        }
492

493 494
                        break
                    case _layerRallyPoints:
Gus Grubba's avatar
Gus Grubba committed
495
                        if (_rallyPointController.supported && _addWaypointOnClick) {
496
                            _rallyPointController.addPoint(coordinate)
497
                        }
498
                        break
Don Gagne's avatar
Don Gagne committed
499
                    }
Don Gagne's avatar
Don Gagne committed
500
                }
501
            }
Don Gagne's avatar
Don Gagne committed
502

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

513 514
            // Add lines between waypoints
            MissionLineView {
515
                model: _editingLayer == _layerMission ? _missionController.waypointLines : undefined
516
            }
517

518 519 520 521 522 523
            MapItemView {
                model: _editingLayer == _layerMission ? _missionController.directionArrows : undefined

                delegate: MapLineArrow {
                    fromCoord:      object ? object.coordinate1 : undefined
                    toCoord:        object ? object.coordinate2 : undefined
524 525 526 527 528 529 530 531 532 533 534
                    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
535
                visible:        _editingLayer == _layerMission
536 537

                sourceItem: SplitIndicator {
Don Gagne's avatar
Don Gagne committed
538
                    onClicked:  insertSimpleMissionItem(splitSegmentItem.coordinate, _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex))
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
                }

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

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

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

584 585
            RallyPointMapVisuals {
                map:                    editorMap
586
                myRallyPointController: _rallyPointController
587 588
                interactive:            _editingLayer == _layerRallyPoints
                planView:               true
589
            }
590

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

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

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

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

634 635
            property bool _isRallyLayer:    _editingLayer == _layerRallyPoints
            property bool _isMissionLayer:  _editingLayer == _layerMission
636

Gus Grubba's avatar
Gus Grubba committed
637 638 639 640 641 642
            model: [
                {
                    name:               qsTr("Fly"),
                    iconSource:         "/qmlimages/PaperPlane.svg",
                    buttonEnabled:      true,
                    buttonVisible:      true,
643
                },
644
                {
Gus Grubba's avatar
Gus Grubba committed
645 646 647 648 649 650 651 652
                    name:               qsTr("File"),
                    iconSource:         "/qmlimages/MapSync.svg",
                    buttonEnabled:      !_planMasterController.syncInProgress,
                    buttonVisible:      true,
                    showAlternateIcon:  _planMasterController.dirty,
                    alternateIconSource:"/qmlimages/MapSyncChanged.svg",
                    dropPanelComponent: syncDropPanel
                },
653 654 655 656
                {
                    name:               qsTr("Takeoff"),
                    iconSource:         "/res/takeoff.svg",
                    buttonEnabled:      _missionController.isInsertTakeoffValid,
657
                    buttonVisible:      _isMissionLayer
658
                },
Gus Grubba's avatar
Gus Grubba committed
659 660 661
                {
                    name:               _editingLayer == _layerRallyPoints ? qsTr("Rally Point") : qsTr("Waypoint"),
                    iconSource:         "/qmlimages/MapAddMission.svg",
662 663
                    buttonEnabled:      _isRallyLayer ? true : _missionController.flyThroughCommandsAllowed,
                    buttonVisible:      _isRallyLayer || _isMissionLayer,
Gus Grubba's avatar
Gus Grubba committed
664 665 666 667 668 669 670
                    toggle:             true,
                    checked:            _addWaypointOnClick
                },
                {
                    name:               qsTr("ROI"),
                    iconSource:         "/qmlimages/MapAddMission.svg",
                    buttonEnabled:      true,
671
                    buttonVisible:      _isMissionLayer,
Gus Grubba's avatar
Gus Grubba committed
672 673 674 675 676
                    toggle:             true
                },
                {
                    name:               _singleComplexItem ? _missionController.complexMissionItemNames[0] : qsTr("Pattern"),
                    iconSource:         "/qmlimages/MapDrawShape.svg",
677 678
                    buttonEnabled:      _missionController.flyThroughCommandsAllowed,
                    buttonVisible:      _isMissionLayer,
Gus Grubba's avatar
Gus Grubba committed
679 680
                    dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel
                },
681 682 683 684
                {
                    name:               _planMasterController.controllerVehicle.fixedWing ? qsTr("Land") : qsTr("Return"),
                    iconSource:         "/res/rtl.svg",
                    buttonEnabled:      _missionController.isInsertLandValid,
685
                    buttonVisible:      _isMissionLayer
686
                },
Gus Grubba's avatar
Gus Grubba committed
687 688 689 690 691 692 693 694
                {
                    name:               qsTr("Center"),
                    iconSource:         "/qmlimages/MapCenter.svg",
                    buttonEnabled:      true,
                    buttonVisible:      true,
                    dropPanelComponent: centerMapDropPanel
                }
            ]
695

696 697 698 699 700
            function allAddClickBoolsOff() {
                _addROIOnClick =        false
                _addWaypointOnClick =   false
            }

Gus Grubba's avatar
Gus Grubba committed
701 702
            onClicked: {
                switch (index) {
703
                case flyButtonIndex:
704
                    mainWindow.showFlyView()
705 706
                    break
                case takeoffButtonIndex:
707
                    allAddClickBoolsOff()
708 709 710
                    _missionController.insertTakeoffItem(mapCenter(), _missionController.currentMissionIndex, true /* makeCurrentItem */)
                    break
                case waypointButtonIndex:
711 712
                    if (_addWaypointOnClick) {
                        allAddClickBoolsOff()
Gus Grubba's avatar
Gus Grubba committed
713 714
                        setChecked(index, false)
                    } else {
715
                        allAddClickBoolsOff()
716
                        _addWaypointOnClick = checked
Gus Grubba's avatar
Gus Grubba committed
717 718
                    }
                    break
719
                case roiButtonIndex:
720
                    allAddClickBoolsOff()
Gus Grubba's avatar
Gus Grubba committed
721 722
                    _addROIOnClick = checked
                    break
723
                case patternButtonIndex:
724
                    allAddClickBoolsOff()
Gus Grubba's avatar
Gus Grubba committed
725 726 727 728
                    if (_singleComplexItem) {
                        addComplexItem(_missionController.complexMissionItemNames[0])
                    }
                    break
729
                case landButtonIndex:
730
                    allAddClickBoolsOff()
731 732
                    _missionController.insertLandItem(mapCenter(), _missionController.currentMissionIndex, true /* makeCurrentItem */)
                    break
733 734
                }
            }
735 736 737 738

            onDropped: {
                allAddClickBoolsOff()
            }
Gus Grubba's avatar
Gus Grubba committed
739
        }
740

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

        MapScale {
938 939 940 941 942 943 944 945 946 947 948
            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()
949 950 951 952 953 954
        }

        MissionItemStatus {
            id:                 waypointValuesDisplay
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.left:       parent.left
955
            height:             ScreenTools.defaultFontPixelHeight * 7
956
            maxWidth:           parent.width - rightPanel.width - x
957
            anchors.bottom:     parent.bottom
958
            missionItems:       _missionController.visualItems
959 960 961 962 963 964 965
            visible:            _internalVisible && _editingLayer === _layerMission && (_toolStripBottom + mapScale.height) < y && QGroundControl.corePlugin.options.showMissionStatus

            property bool _internalVisible: false

            function toggleVisible() {
                _internalVisible = !_internalVisible
            }
966
        }
Gus Grubba's avatar
Gus Grubba committed
967
    }
968

969 970 971 972
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
973
            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?")
974 975
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
976
                _planMasterController.loadFromVehicle()
977 978 979 980 981 982 983 984
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
DonLakeFlyer's avatar
DonLakeFlyer committed
985
            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?")
986 987
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
988
                _planMasterController.loadFromSelectedFile()
989 990 991 992
            }
        }
    }

993 994
    property var createPlanRemoveAllPromptDialogMapCenter
    property var createPlanRemoveAllPromptDialogPlanCreator
995
    Component {
996
        id: createPlanRemoveAllPromptDialog
997
        QGCViewMessage {
998
            message: qsTr("Are you sure you want to remove current plan and create a new plan? ")
999
            function accept() {
1000
                createPlanRemoveAllPromptDialogPlanCreator.createPlan(createPlanRemoveAllPromptDialogMapCenter)
1001 1002 1003 1004 1005
                hideDialog()
            }
        }
    }

1006 1007 1008 1009 1010
    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
1011
                _planMasterController.removeAllFromVehicle()
1012
                _missionController.setCurrentPlanViewIndex(0, true)
1013 1014 1015 1016 1017
                hideDialog()
            }
        }
    }

1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
    //- ToolStrip DropPanel Components

    Component {
        id: centerMapDropPanel

        CenterMapDropPanel {
            map:            editorMap
            fitFunctions:   mapFitFunctions
        }
    }

1029 1030 1031 1032 1033 1034 1035 1036 1037
    Component {
        id: patternDropPanel

        ColumnLayout {
            spacing:    ScreenTools.defaultFontPixelWidth * 0.5

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

            Repeater {
1038
                model: _missionController.complexMissionItemNames
1039 1040 1041 1042 1043 1044

                QGCButton {
                    text:               modelData
                    Layout.fillWidth:   true

                    onClicked: {
1045
                        addComplexItem(modelData)
1046 1047 1048 1049 1050 1051
                        dropPanel.hide()
                    }
                }
            }
        } // Column
    }
1052 1053

    Component {
1054
        id: syncDropPanel
1055

1056
        ColumnLayout {
1057 1058
            id:         columnHolder
            spacing:    _margin
1059

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

1062
            QGCLabel {
1063
                id:                 unsavedChangedLabel
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
                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")
1076
                showSpacer:         false
1077 1078
            }

1079 1080
            GridLayout {
                columns:            2
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 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
                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
1151 1152
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
1153
                visible:            storageSection.visible
1154

1155
                /*QGCButton {
1156
                    text:               qsTr("New...")
1157
                    Layout.fillWidth:   true
1158
                    onClicked:  {
1159
                        dropPanel.hide()
1160 1161 1162
                        if (_planMasterController.containsItems) {
                            mainWindow.showComponentDialog(removeAllPromptDialog, qsTr("New Plan"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
                        }
1163
                    }
1164
                }*/
1165

1166
                QGCButton {
1167
                    text:               qsTr("Open...")
1168
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1169
                    enabled:            !_planMasterController.syncInProgress
1170 1171
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1172
                        if (_planMasterController.dirty) {
1173
                            mainWindow.showComponentDialog(syncLoadFromFileOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1174
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1175
                            _planMasterController.loadFromSelectedFile()
1176 1177 1178
                        }
                    }
                }
1179

1180
                QGCButton {
1181
                    text:               qsTr("Save")
1182
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1183
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.currentPlanFile !== ""
1184 1185
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1186 1187
                        if(_planMasterController.currentPlanFile !== "") {
                            _planMasterController.saveToCurrent()
1188
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1189
                            _planMasterController.saveToSelectedFile()
1190
                        }
1191 1192 1193 1194
                    }
                }

                QGCButton {
1195
                    text:               qsTr("Save As...")
1196
                    Layout.fillWidth:   true
1197
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.containsItems
1198 1199
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1200
                        _planMasterController.saveToSelectedFile()
1201 1202 1203 1204
                    }
                }

                QGCButton {
1205 1206
                    Layout.columnSpan:  3
                    Layout.fillWidth:   true
1207
                    text:               qsTr("Save Mission Waypoints As KML...")
Gus Grubba's avatar
Gus Grubba committed
1208
                    enabled:            !_planMasterController.syncInProgress && _visualItems.count > 1
1209
                    onClicked: {
1210
                        // First point does not count
1211
                        if (_visualItems.count < 2) {
1212
                            mainWindow.showComponentDialog(noItemForKML, qsTr("KML"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
1213 1214
                            return
                        }
1215
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1216
                        _planMasterController.saveKmlToSelectedFile()
1217 1218
                    }
                }
1219
            }
1220

1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
            SectionHeader {
                id:                 vehicleSection
                Layout.fillWidth:   true
                text:               qsTr("Vehicle")
            }

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

1232
                QGCButton {
1233
                    text:               qsTr("Upload")
1234
                    Layout.fillWidth:   true
1235
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress && _planMasterController.containsItems
1236 1237
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
1238
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1239
                        _planMasterController.upload()
1240 1241
                    }
                }
1242 1243 1244 1245

                QGCButton {
                    text:               qsTr("Download")
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1246
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1247 1248 1249
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1250
                        if (_planMasterController.dirty) {
1251
                            mainWindow.showComponentDialog(syncLoadFromVehicleOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1252
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1253
                            _planMasterController.loadFromVehicle()
1254 1255 1256 1257 1258
                        }
                    }
                }

                QGCButton {
1259
                    text:               qsTr("Clear")
1260 1261
                    Layout.fillWidth:   true
                    Layout.columnSpan:  2
Gus Grubba's avatar
Gus Grubba committed
1262
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1263 1264 1265
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
1266
                        mainWindow.showComponentDialog(clearVehicleMissionDialog, text, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1267 1268
                    }
                }
1269
            }
1270 1271
        }
    }
Gus Grubba's avatar
Gus Grubba committed
1272
}