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 536 537
                    arrowPosition:  3
                    z:              QGroundControl.zOrderWaypointLines + 1
                }
            }

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

                sourceItem: SplitIndicator {
Don Gagne's avatar
Don Gagne committed
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 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
            readonly property int centerButtonIndex:    6
632

Gus Grubba's avatar
Gus Grubba committed
633
            property bool _isRally:     _editingLayer == _layerRallyPoints
634

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

Gus Grubba's avatar
Gus Grubba committed
688 689
            onClicked: {
                switch (index) {
690
                case flyButtonIndex:
691
                    mainWindow.showFlyView()
692 693 694 695 696
                    break
                case takeoffButtonIndex:
                    _missionController.insertTakeoffItem(mapCenter(), _missionController.currentMissionIndex, true /* makeCurrentItem */)
                    break
                case waypointButtonIndex:
Gus Grubba's avatar
Gus Grubba committed
697 698 699 700 701 702
                    if(_addWaypointOnClick) {
                        //-- Toggle it off
                        _addWaypointOnClick = false
                        _addROIOnClick = false
                        setChecked(index, false)
                    } else {
703
                        _addWaypointOnClick = checked
704
                        _addROIOnClick = false
Gus Grubba's avatar
Gus Grubba committed
705 706
                    }
                    break
707
                case roiButtonIndex:
Gus Grubba's avatar
Gus Grubba committed
708 709 710
                    _addROIOnClick = checked
                    _addWaypointOnClick = false
                    break
711
                case patternButtonIndex:
Gus Grubba's avatar
Gus Grubba committed
712 713 714 715
                    if (_singleComplexItem) {
                        addComplexItem(_missionController.complexMissionItemNames[0])
                    }
                    break
716 717
                }
            }
Gus Grubba's avatar
Gus Grubba committed
718
        }
719

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

        MapScale {
917 918 919 920 921 922 923 924 925 926 927
            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()
928 929 930 931 932 933
        }

        MissionItemStatus {
            id:                 waypointValuesDisplay
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.left:       parent.left
934
            height:             ScreenTools.defaultFontPixelHeight * 7
935
            maxWidth:           parent.width - rightPanel.width - x
936
            anchors.bottom:     parent.bottom
937
            missionItems:       _missionController.visualItems
938 939 940 941 942 943 944
            visible:            _internalVisible && _editingLayer === _layerMission && (_toolStripBottom + mapScale.height) < y && QGroundControl.corePlugin.options.showMissionStatus

            property bool _internalVisible: false

            function toggleVisible() {
                _internalVisible = !_internalVisible
            }
945
        }
Gus Grubba's avatar
Gus Grubba committed
946
    }
947

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

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

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

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

997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
    //- ToolStrip DropPanel Components

    Component {
        id: centerMapDropPanel

        CenterMapDropPanel {
            map:            editorMap
            fitFunctions:   mapFitFunctions
        }
    }

1008 1009 1010 1011 1012 1013 1014 1015 1016
    Component {
        id: patternDropPanel

        ColumnLayout {
            spacing:    ScreenTools.defaultFontPixelWidth * 0.5

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

            Repeater {
1017
                model: _missionController.complexMissionItemNames
1018 1019 1020 1021 1022 1023

                QGCButton {
                    text:               modelData
                    Layout.fillWidth:   true

                    onClicked: {
1024
                        addComplexItem(modelData)
1025 1026 1027 1028
                        dropPanel.hide()
                    }
                }
            }
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041

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

            QGCButton {
                text:               qsTr("Load KML/SHP...")
                Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
1042
                enabled:            !_planMasterController.syncInProgress
1043
                onClicked: {
Gus Grubba's avatar
Gus Grubba committed
1044
                    _planMasterController.loadShapeFromSelectedFile()
1045 1046 1047
                    dropPanel.hide()
                }
            }
1048 1049
        } // Column
    }
1050 1051

    Component {
1052
        id: syncDropPanel
1053

1054
        ColumnLayout {
1055 1056
            id:         columnHolder
            spacing:    _margin
1057

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

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

1077 1078
            GridLayout {
                columns:            2
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 1141 1142 1143 1144 1145 1146 1147 1148
                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
1149 1150
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
1151
                visible:            storageSection.visible
1152

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

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

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

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

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

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

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

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

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

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


1270 1271
        }
    }
Gus Grubba's avatar
Gus Grubba committed
1272
}