PlanView.qml 55.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
    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 307 308 309
    /// 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
310
        toolStrip.lastClickedButton.checked = false
311 312
    }

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

324 325
    property int _moveDialogMissionItemIndex

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

330 331
        property bool planFiles: true    ///< true: working with plan files, false: working with kml file

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

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

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

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

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

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

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

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

449 450
            property real _leftToolWidth:       toolStrip.x + toolStrip.width
            property real _rightToolWidth:      rightPanel.width + rightPanel.anchors.rightMargin
451

452
            readonly property real animationDuration: 500
453

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

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

464 465
            QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

466 467
            onZoomLevelChanged: updateAirspace(false)
            onCenterChanged:    updateAirspace(false)
468

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

479 480 481
                    switch (_editingLayer) {
                    case _layerMission:
                        if (_addWaypointOnClick) {
482 483 484 485 486 487 488 489
                            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)
                            }
490 491 492
                        } else if (_addROIOnClick) {
                            _addROIOnClick = false
                            insertROIMissionItem(coordinate, _missionController.visualItems.count)
493
                        }
494 495
                        break
                    case _layerRallyPoints:
Gus Grubba's avatar
Gus Grubba committed
496
                        if (_rallyPointController.supported && _addWaypointOnClick) {
497
                            _rallyPointController.addPoint(coordinate)
498
                        }
499
                        break
Don Gagne's avatar
Don Gagne committed
500
                    }
Don Gagne's avatar
Don Gagne committed
501
                }
502
            }
Don Gagne's avatar
Don Gagne committed
503

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

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

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

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

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

                function _updateSplitCoord() {
                    if (_missionController.splitSegment) {
                        var distance = _missionController.splitSegment.coordinate1.distanceTo(_missionController.splitSegment.coordinate2)
                        var azimuth = _missionController.splitSegment.coordinate1.azimuthTo(_missionController.splitSegment.coordinate2)
                        splitSegmentItem.coordinate = _missionController.splitSegment.coordinate1.atDistanceAndAzimuth(distance / 2, azimuth)
                    } else {
                        coordinate = QtPositioning.coordinate()
                    }
                }

                Connections {
                    target:                 _missionController
                    onSplitSegmentChanged:  splitSegmentItem._updateSplitCoord()
                }

                Connections {
                    target:                 _missionController.splitSegment
                    onCoordinate1Changed:   splitSegmentItem._updateSplitCoord()
                    onCoordinate2Changed:   splitSegmentItem._updateSplitCoord()
561 562 563
                }
            }

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

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

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

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

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

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

626 627 628 629 630 631
            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
632 633
            readonly property int landButtonIndex:      6
            readonly property int centerButtonIndex:    7
634

Gus Grubba's avatar
Gus Grubba committed
635
            property bool _isRally:     _editingLayer == _layerRallyPoints
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 657 658
                {
                    name:               qsTr("Takeoff"),
                    iconSource:         "/res/takeoff.svg",
                    buttonEnabled:      _missionController.isInsertTakeoffValid,
                    buttonVisible:      _editingLayer == _layerMission
                },
Gus Grubba's avatar
Gus Grubba committed
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
                {
                    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
                },
681 682 683 684 685 686
                {
                    name:               _planMasterController.controllerVehicle.fixedWing ? qsTr("Land") : qsTr("Return"),
                    iconSource:         "/res/rtl.svg",
                    buttonEnabled:      _missionController.isInsertLandValid,
                    buttonVisible:      _editingLayer == _layerMission
                },
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

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

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

        MapScale {
928 929 930 931 932 933 934 935 936 937 938
            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()
939 940 941 942 943 944
        }

        MissionItemStatus {
            id:                 waypointValuesDisplay
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.left:       parent.left
945
            height:             ScreenTools.defaultFontPixelHeight * 7
946
            maxWidth:           parent.width - rightPanel.width - x
947
            anchors.bottom:     parent.bottom
948
            missionItems:       _missionController.visualItems
949 950 951 952 953 954 955
            visible:            _internalVisible && _editingLayer === _layerMission && (_toolStripBottom + mapScale.height) < y && QGroundControl.corePlugin.options.showMissionStatus

            property bool _internalVisible: false

            function toggleVisible() {
                _internalVisible = !_internalVisible
            }
956
        }
Gus Grubba's avatar
Gus Grubba committed
957
    }
958

959 960 961 962
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
963
            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?")
964 965
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
966
                _planMasterController.loadFromVehicle()
967 968 969 970 971 972 973 974
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
DonLakeFlyer's avatar
DonLakeFlyer committed
975
            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?")
976 977
            function accept() {
                hideDialog()
Gus Grubba's avatar
Gus Grubba committed
978
                _planMasterController.loadFromSelectedFile()
979 980 981 982
            }
        }
    }

983 984
    property var createPlanRemoveAllPromptDialogMapCenter
    property var createPlanRemoveAllPromptDialogPlanCreator
985
    Component {
986
        id: createPlanRemoveAllPromptDialog
987
        QGCViewMessage {
988
            message: qsTr("Are you sure you want to remove current plan and create a new plan? ")
989
            function accept() {
990
                createPlanRemoveAllPromptDialogPlanCreator.createPlan(createPlanRemoveAllPromptDialogMapCenter)
991 992 993 994 995
                hideDialog()
            }
        }
    }

996 997 998 999 1000
    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
1001
                _planMasterController.removeAllFromVehicle()
1002
                _missionController.setCurrentPlanViewIndex(0, true)
1003 1004 1005 1006 1007
                hideDialog()
            }
        }
    }

1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
    //- ToolStrip DropPanel Components

    Component {
        id: centerMapDropPanel

        CenterMapDropPanel {
            map:            editorMap
            fitFunctions:   mapFitFunctions
        }
    }

1019 1020 1021 1022 1023 1024 1025 1026 1027
    Component {
        id: patternDropPanel

        ColumnLayout {
            spacing:    ScreenTools.defaultFontPixelWidth * 0.5

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

            Repeater {
1028
                model: _missionController.complexMissionItemNames
1029 1030 1031 1032 1033 1034

                QGCButton {
                    text:               modelData
                    Layout.fillWidth:   true

                    onClicked: {
1035
                        addComplexItem(modelData)
1036 1037 1038 1039 1040 1041
                        dropPanel.hide()
                    }
                }
            }
        } // Column
    }
1042 1043

    Component {
1044
        id: syncDropPanel
1045

1046
        ColumnLayout {
1047 1048
            id:         columnHolder
            spacing:    _margin
1049

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

1052
            QGCLabel {
1053
                id:                 unsavedChangedLabel
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
                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")
1066
                showSpacer:         false
1067 1068
            }

1069 1070
            GridLayout {
                columns:            2
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 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
                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
1141 1142
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
1143
                visible:            storageSection.visible
1144

1145
                /*QGCButton {
1146
                    text:               qsTr("New...")
1147
                    Layout.fillWidth:   true
1148
                    onClicked:  {
1149
                        dropPanel.hide()
1150 1151 1152
                        if (_planMasterController.containsItems) {
                            mainWindow.showComponentDialog(removeAllPromptDialog, qsTr("New Plan"), mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
                        }
1153
                    }
1154
                }*/
1155

1156
                QGCButton {
1157
                    text:               qsTr("Open...")
1158
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1159
                    enabled:            !_planMasterController.syncInProgress
1160 1161
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1162
                        if (_planMasterController.dirty) {
1163
                            mainWindow.showComponentDialog(syncLoadFromFileOverwrite, columnHolder._overwriteText, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1164
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1165
                            _planMasterController.loadFromSelectedFile()
1166 1167 1168
                        }
                    }
                }
1169

1170
                QGCButton {
1171
                    text:               qsTr("Save")
1172
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1173
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.currentPlanFile !== ""
1174 1175
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1176 1177
                        if(_planMasterController.currentPlanFile !== "") {
                            _planMasterController.saveToCurrent()
1178
                        } else {
Gus Grubba's avatar
Gus Grubba committed
1179
                            _planMasterController.saveToSelectedFile()
1180
                        }
1181 1182 1183 1184
                    }
                }

                QGCButton {
1185
                    text:               qsTr("Save As...")
1186
                    Layout.fillWidth:   true
1187
                    enabled:            !_planMasterController.syncInProgress && _planMasterController.containsItems
1188 1189
                    onClicked: {
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1190
                        _planMasterController.saveToSelectedFile()
1191 1192 1193 1194
                    }
                }

                QGCButton {
1195 1196
                    Layout.columnSpan:  3
                    Layout.fillWidth:   true
1197
                    text:               qsTr("Save Mission Waypoints As KML...")
Gus Grubba's avatar
Gus Grubba committed
1198
                    enabled:            !_planMasterController.syncInProgress && _visualItems.count > 1
1199
                    onClicked: {
1200
                        // First point does not count
1201
                        if (_visualItems.count < 2) {
1202
                            mainWindow.showComponentDialog(noItemForKML, qsTr("KML"), mainWindow.showDialogDefaultWidth, StandardButton.Cancel)
1203 1204
                            return
                        }
1205
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1206
                        _planMasterController.saveKmlToSelectedFile()
1207 1208
                    }
                }
1209
            }
1210

1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
            SectionHeader {
                id:                 vehicleSection
                Layout.fillWidth:   true
                text:               qsTr("Vehicle")
            }

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

1222
                QGCButton {
1223
                    text:               qsTr("Upload")
1224
                    Layout.fillWidth:   true
1225
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress && _planMasterController.containsItems
1226 1227
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
1228
                        dropPanel.hide()
Gus Grubba's avatar
Gus Grubba committed
1229
                        _planMasterController.upload()
1230 1231
                    }
                }
1232 1233 1234 1235

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

                QGCButton {
1249
                    text:               qsTr("Clear")
1250 1251
                    Layout.fillWidth:   true
                    Layout.columnSpan:  2
Gus Grubba's avatar
Gus Grubba committed
1252
                    enabled:            !_planMasterController.offline && !_planMasterController.syncInProgress
1253 1254 1255
                    visible:            !QGroundControl.corePlugin.options.disableVehicleConnection
                    onClicked: {
                        dropPanel.hide()
1256
                        mainWindow.showComponentDialog(clearVehicleMissionDialog, text, mainWindow.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1257 1258
                    }
                }
1259
            }
1260 1261


1262 1263
        }
    }
Gus Grubba's avatar
Gus Grubba committed
1264
}