MissionEditor.qml 41.7 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


Don Gagne's avatar
Don Gagne committed
11 12 13 14 15
import QtQuick          2.4
import QtQuick.Controls 1.3
import QtQuick.Dialogs  1.2
import QtLocation       5.3
import QtPositioning    5.3
dogmaphobic's avatar
dogmaphobic committed
16
import QtQuick.Layouts  1.2
Don Gagne's avatar
Don Gagne committed
17

18
import QGroundControl               1.0
Don Gagne's avatar
Don Gagne committed
19 20 21 22
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
Don Gagne's avatar
Don Gagne committed
23
import QGroundControl.Mavlink       1.0
24
import QGroundControl.Controllers   1.0
Don Gagne's avatar
Don Gagne committed
25 26

/// Mission Editor
Don Gagne's avatar
Don Gagne committed
27

Don Gagne's avatar
Don Gagne committed
28
QGCView {
29 30
    id:         qgcView
    viewPanel:  panel
Don Gagne's avatar
Don Gagne committed
31

32
    // zOrder comes from the Loader in MainWindow.qml
Gus Grubba's avatar
Gus Grubba committed
33
    z: QGroundControl.zOrderTopMost
34

35 36 37 38 39 40 41 42
    readonly property int       _decimalPlaces:         8
    readonly property real      _horizontalMargin:      ScreenTools.defaultFontPixelWidth  / 2
    readonly property real      _margin:                ScreenTools.defaultFontPixelHeight * 0.5
    readonly property var       _activeVehicle:         QGroundControl.multiVehicleManager.activeVehicle
    readonly property real      _rightPanelWidth:       Math.min(parent.width / 3, ScreenTools.defaultFontPixelWidth * 30)
    readonly property real      _rightPanelOpacity:     0.8
    readonly property int       _toolButtonCount:       6
    readonly property real      _toolButtonTopMargin:   parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2)
43
    readonly property var       _defaultVehicleCoordinate:   QtPositioning.coordinate(37.803784, -122.462276)
44

45
    property var    _visualItems:           missionController.visualItems
Don Gagne's avatar
Don Gagne committed
46
    property var    _currentMissionItem
47
    property int    _currentMissionIndex:   0
48 49
    property bool   _firstVehiclePosition:  true
    property var    activeVehiclePosition:  _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
50
    property bool   _lightWidgetBorders:    editorMap.isSatelliteMap
51

52 53 54 55 56 57 58
    /// The controller which should be called for load/save, send to/from vehicle calls
    property var _syncDropDownController: missionController

    readonly property int _layerMission:        1
    readonly property int _layerGeoFence:       2
    property int _editingLayer: _layerMission

59
    onActiveVehiclePositionChanged: updateMapToVehiclePosition()
60

61
    Connections {
62
        target: QGroundControl.multiVehicleManager
63 64 65 66 67 68

        onActiveVehicleChanged: {
            // When the active vehicle changes we need to allow the first vehicle position to move the map again
            _firstVehiclePosition = true
            updateMapToVehiclePosition()
        }
69
    }
70 71

    function updateMapToVehiclePosition() {
72
        if (_activeVehicle && _activeVehicle.coordinateValid && _activeVehicle.coordinate.isValid && _firstVehiclePosition) {
73 74
            _firstVehiclePosition = false
            editorMap.center = _activeVehicle.coordinate
75 76 77
        }
    }

78 79 80 81 82 83 84 85 86 87
    function normalizeLat(lat) {
        // Normalize latitude to range: 0 to 180, S to N
        return lat + 90.0
    }

    function normalizeLon(lon) {
        // Normalize longitude to range: 0 to 360, W to E
        return lon  + 180.0
    }

88
    /// Fix the map viewport to the current mission items.
89
    function fitViewportToMissionItems() {
90 91
        if (_visualItems.count == 1) {
            editorMap.center = _visualItems.get(0).coordinate
92
        } else {
93
            var missionItem = _visualItems.get(0)
94 95 96 97 98
            var north = normalizeLat(missionItem.coordinate.latitude)
            var south = north
            var east = normalizeLon(missionItem.coordinate.longitude)
            var west = east

99 100
            for (var i=1; i<_visualItems.count; i++) {
                missionItem = _visualItems.get(i)
101

102
                if (missionItem.specifiesCoordinate && !missionItem.isStandaloneCoordinate) {
103 104 105 106 107 108 109 110
                    var lat = normalizeLat(missionItem.coordinate.latitude)
                    var lon = normalizeLon(missionItem.coordinate.longitude)

                    north = Math.max(north, lat)
                    south = Math.min(south, lat)
                    east = Math.max(east, lon)
                    west = Math.min(west, lon)
                }
111
            }
112
            editorMap.visibleRegion = QtPositioning.rectangle(QtPositioning.coordinate(north - 90.0, west - 180.0), QtPositioning.coordinate(south - 90.0, east - 180.0))
113 114 115
        }
    }

116
    MissionController {
117
        id: missionController
118

119 120
        Component.onCompleted: {
            start(true /* editMode */)
121
            setCurrentItem(0)
122 123
        }

124 125
        function loadFromSelectedFile() {
            if (ScreenTools.isMobile) {
126
                qgcView.showDialog(mobileFilePicker, qsTr("Select Mission File"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
127 128 129 130 131 132 133 134 135
            } else {
                missionController.loadFromFilePicker()
                fitViewportToMissionItems()
                _currentMissionItem = _visualItems.get(0)
            }
        }

        function saveToSelectedFile() {
            if (ScreenTools.isMobile) {
136
                qgcView.showDialog(mobileFileSaver, qsTr("Save Mission File"), qgcView.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
137 138 139 140 141 142 143 144
            } else {
                missionController.saveToFilePicker()
            }
        }

        onVisualItemsChanged: {
            itemDragger.clearItem()
        }
145

146 147
        onNewItemsFromVehicle: {
            fitViewportToMissionItems()
148
            setCurrentItem(0)
149 150
        }
    }
151

152 153
    GeoFenceController {
        id: geoFenceController
154

155
        Component.onCompleted: start(true /* editMode */)
156

157 158 159 160 161 162
        onFenceSupportedChanged: {
            if (!fenceSupported && _editingLayer == _layerGeoFence) {
                _editingLayer = _layerMission
            }
        }

163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
        function saveToSelectedFile() {
            if (ScreenTools.isMobile) {
                qgcView.showDialog(mobileFileSaver, qsTr("Save Fence File"), qgcView.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
            } else {
                geoFenceController.saveToFilePicker()
            }
        }

        function loadFromSelectedFile() {
            if (ScreenTools.isMobile) {
                qgcView.showDialog(mobileFilePicker, qsTr("Select Fence File"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
            } else {
                geoFenceController.loadFromFilePicker()
            }
        }

179 180 181 182 183 184 185 186
        function validateBreachReturn() {
            if (geoFenceController.polygon.path.length > 0) {
                if (!geoFenceController.polygon.containsCoordinate(geoFenceController.breachReturnPoint)) {
                    geoFenceController.breachReturnPoint = geoFenceController.polygon.center()
                }
                if (!geoFenceController.polygon.containsCoordinate(geoFenceController.breachReturnPoint)) {
                    geoFenceController.breachReturnPoint = geoFenceController.polygon.path[0]
                }
187 188
            }
        }
189
    }
190

191
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
192

193 194 195 196 197 198
    ExclusiveGroup {
        id: _mapTypeButtonsExclusiveGroup
    }

    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
199 200
    }

201
    function setCurrentItem(sequenceNumber) {
202
        editorMap.polygonDraw.cancelPolygonEdit()
Don Gagne's avatar
Don Gagne committed
203
        _currentMissionItem = undefined
204
        for (var i=0; i<_visualItems.count; i++) {
205 206 207
            var visualItem = _visualItems.get(i)
            if (visualItem.sequenceNumber == sequenceNumber) {
                _currentMissionItem = visualItem
Don Gagne's avatar
Don Gagne committed
208
                _currentMissionItem.isCurrentItem = true
209
                _currentMissionIndex = i
Don Gagne's avatar
Don Gagne committed
210
            } else {
211
                visualItem.isCurrentItem = false
Don Gagne's avatar
Don Gagne committed
212
            }
213 214 215
        }
    }

216 217
    property int _moveDialogMissionItemIndex

218 219 220
    Component {
        id: mobileFilePicker

Don Gagne's avatar
Don Gagne committed
221
        QGCMobileFileDialog {
222
            openDialog:         true
223
            fileExtension:      _syncDropDownController == geoFenceController ? QGroundControl.fenceFileExtension : QGroundControl.missionFileExtension
224
            onFilenameReturned: _syncDropDownController.loadFromfile(filename)
225 226 227 228 229 230
        }
    }

    Component {
        id: mobileFileSaver

Don Gagne's avatar
Don Gagne committed
231
        QGCMobileFileDialog {
232
            openDialog:         false
233
            fileExtension:      _syncDropDownController == geoFenceController ? QGroundControl.fenceFileExtension : QGroundControl.missionFileExtension
234
            onFilenameReturned: _syncDropDownController.saveToFile()
235 236 237
        }
    }

238 239 240 241 242 243 244 245 246 247
    Component {
        id: moveDialog

        QGCViewDialog {
            function accept() {
                var toIndex = toCombo.currentIndex

                if (toIndex == 0) {
                    toIndex = 1
                }
248
                missionController.moveMissionItem(_moveDialogMissionItemIndex, toIndex)
249 250 251 252 253 254 255 256 257 258 259 260
                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
261
                    text:           qsTr("Move the selected mission item to the be after following mission item:")
262 263 264 265
                }

                QGCComboBox {
                    id:             toCombo
266
                    model:          _visualItems.count
267 268 269 270 271 272
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
273 274
    QGCViewPanel {
        id:             panel
275 276 277 278
        height:         ScreenTools.availableHeight
        anchors.bottom: parent.bottom
        anchors.left:   parent.left
        anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
279

Don Gagne's avatar
Don Gagne committed
280
        Item {
Don Gagne's avatar
Don Gagne committed
281 282
            anchors.fill: parent

Don Gagne's avatar
Don Gagne committed
283 284
            FlightMap {
                id:             editorMap
285
                height:         qgcView.height
286 287 288
                anchors.bottom: parent.bottom
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
289
                mapName:        "MissionEditor"
290

291 292
                readonly property real animationDuration: 500

293 294 295
                // Initial map position duplicates Fly view position
                Component.onCompleted: editorMap.center = QGroundControl.flightMapPosition

296 297 298 299 300 301 302
                Behavior on zoomLevel {
                    NumberAnimation {
                        duration:       editorMap.animationDuration
                        easing.type:    Easing.InOutQuad
                    }
                }

303 304
                QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

Don Gagne's avatar
Don Gagne committed
305
                MouseArea {
306 307
                    //-- It's a whole lot faster to just fill parent and deal with top offset below
                    //   than computing the coordinate offset.
Don Gagne's avatar
Don Gagne committed
308 309
                    anchors.fill: parent
                    onClicked: {
310 311
                        //-- Don't pay attention to items beneath the toolbar.
                        var topLimit = parent.height - ScreenTools.availableHeight
312 313 314 315 316 317 318 319 320 321 322
                        if(mouse.y < topLimit) {
                            return
                        }

                        var coordinate = editorMap.toCoordinate(Qt.point(mouse.x, mouse.y))
                        coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
                        coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
                        coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)

                        switch (_editingLayer) {
                        case _layerMission:
323
                            if (addMissionItemsButton.checked) {
324
                                var sequenceNumber = missionController.insertSimpleMissionItem(coordinate, missionController.visualItems.count)
325 326
                                setCurrentItem(sequenceNumber)
                            }
327 328 329
                            break
                        case _layerGeoFence:
                            geoFenceController.breachReturnPoint = coordinate
330
                            geoFenceController.validateBreachReturn()
331
                            break
332
                        }
Don Gagne's avatar
Don Gagne committed
333
                    }
Don Gagne's avatar
Don Gagne committed
334
                }
Don Gagne's avatar
Don Gagne committed
335

336
                // We use this item to support dragging since dragging a MapQuickItem just doesn't seem to work
Don Gagne's avatar
Don Gagne committed
337 338 339 340
                Rectangle {
                    id:             itemDragger
                    x:              missionItemIndicator ? (missionItemIndicator.x + missionItemIndicator.anchorPoint.x - (itemDragger.width / 2)) : 100
                    y:              missionItemIndicator ? (missionItemIndicator.y + missionItemIndicator.anchorPoint.y - (itemDragger.height / 2)) : 100
341 342
                    width:          ScreenTools.defaultFontPixelHeight * 2
                    height:         ScreenTools.defaultFontPixelHeight * 2
Don Gagne's avatar
Don Gagne committed
343 344 345
                    color:          "transparent"
                    visible:        false
                    z:              QGroundControl.zOrderMapItems + 1    // Above item icons
346 347 348

                    property var    missionItem
                    property var    missionItemIndicator
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
                    property bool   preventCoordinateBindingLoop: false

                    onXChanged: liveDrag()
                    onYChanged: liveDrag()

                    function liveDrag() {
                        if (!itemDragger.preventCoordinateBindingLoop && Drag.active) {
                            var point = Qt.point(itemDragger.x + (itemDragger.width  / 2), itemDragger.y + (itemDragger.height / 2))
                            var coordinate = editorMap.toCoordinate(point)
                            coordinate.altitude = itemDragger.missionItem.coordinate.altitude
                            itemDragger.preventCoordinateBindingLoop = true
                            itemDragger.missionItem.coordinate = coordinate
                            itemDragger.preventCoordinateBindingLoop = false
                        }
                    }
Don Gagne's avatar
Don Gagne committed
364

365
                    function clearItem() {
Don Gagne's avatar
Don Gagne committed
366 367 368 369 370
                        itemDragger.visible = false
                        itemDragger.missionItem = undefined
                        itemDragger.missionItemIndicator = undefined
                    }

371 372 373 374 375 376 377 378
                    Drag.active:    itemDrag.drag.active
                    Drag.hotSpot.x: width  / 2
                    Drag.hotSpot.y: height / 2

                    MouseArea {
                        id:             itemDrag
                        anchors.fill:   parent
                        drag.target:    parent
Don Gagne's avatar
Don Gagne committed
379 380 381 382
                        drag.minimumX:  0
                        drag.minimumY:  0
                        drag.maximumX:  itemDragger.parent.width - parent.width
                        drag.maximumY:  itemDragger.parent.height - parent.height
Don Gagne's avatar
Don Gagne committed
383
                    }
384
                }
385

386
                // Add the complex mission item polygon to the map
387
                MapItemView {
388
                    model: missionController.complexVisualItems
389

Don Gagne's avatar
Don Gagne committed
390
                    delegate: MapPolygon {
391 392 393 394 395 396
                        color:      'green'
                        path:       object.polygonPath
                        opacity:    0.5
                    }
                }

397 398
                // Add the complex mission item grid to the map
                MapItemView {
399
                    model: missionController.complexVisualItems
400 401 402

                    delegate: MapPolyline {
                        line.color: "white"
403
                        line.width: 2
404 405 406 407
                        path:       object.gridPoints
                    }
                }

408 409
                // Add the complex mission item exit coordinates
                MapItemView {
410
                    model: missionController.complexVisualItems
411 412 413 414 415 416 417 418 419 420 421 422 423
                    delegate:   exitCoordinateComponent
                }

                Component {
                    id: exitCoordinateComponent

                    MissionItemIndicator {
                        coordinate:     object.exitCoordinate
                        z:              QGroundControl.zOrderMapItems
                        missionItem:    object
                        sequenceNumber: object.lastSequenceNumber
                        visible:        object.specifiesCoordinate
                    }
Don Gagne's avatar
Don Gagne committed
424 425
                }

426 427
                // Add the simple mission items to the map
                MapItemView {
428
                    model:      missionController.visualItems
429 430 431
                    delegate:   missionItemComponent
                }

Don Gagne's avatar
Don Gagne committed
432
                Component {
433
                    id: missionItemComponent
Don Gagne's avatar
Don Gagne committed
434 435 436 437

                    MissionItemIndicator {
                        id:             itemIndicator
                        coordinate:     object.coordinate
438
                        visible:        object.specifiesCoordinate
Don Gagne's avatar
Don Gagne committed
439
                        z:              QGroundControl.zOrderMapItems
440
                        missionItem:    object
441
                        sequenceNumber: object.sequenceNumber
Don Gagne's avatar
Don Gagne committed
442

443 444 445
                        //-- If you don't want to allow selecting items beneath the
                        //   toolbar, the code below has to check and see if mouse.y
                        //   is greater than (map.height - ScreenTools.availableHeight)
Don Gagne's avatar
Don Gagne committed
446 447
                        onClicked: setCurrentItem(object.sequenceNumber)

448 449
                        function updateItemIndicator() {
                            if (object.isCurrentItem && itemIndicator.visible && object.specifiesCoordinate && object.isSimpleItem) {
450 451 452 453
                                // Setup our drag item
                                itemDragger.visible = true
                                itemDragger.missionItem = Qt.binding(function() { return object })
                                itemDragger.missionItemIndicator = Qt.binding(function() { return itemIndicator })
Don Gagne's avatar
Don Gagne committed
454 455 456
                            }
                        }

457 458 459
                        Connections {
                            target: object

460 461
                            onIsCurrentItemChanged:         updateItemIndicator()
                            onSpecifiesCoordinateChanged:   updateItemIndicator()
462 463
                        }

Don Gagne's avatar
Don Gagne committed
464 465 466 467 468 469 470 471 472
                        // These are the non-coordinate child mission items attached to this item
                        Row {
                            anchors.top:    parent.top
                            anchors.left:   parent.right

                            Repeater {
                                model: object.childItems

                                delegate: MissionItemIndexLabel {
473
                                    label:          object.abbreviation
Don Gagne's avatar
Don Gagne committed
474 475 476 477 478 479 480 481
                                    isCurrentItem:  object.isCurrentItem
                                    z:              2

                                    onClicked: setCurrentItem(object.sequenceNumber)
                                }
                            }
                        }
                    }
482 483 484
                }

                // Add lines between waypoints
485
                MissionLineView {
486
                    model:      _editingLayer == _layerMission ? missionController.waypointLines : undefined
Don Gagne's avatar
Don Gagne committed
487 488
                }

Don Gagne's avatar
Don Gagne committed
489 490
                // Add the vehicles to the map
                MapItemView {
491
                    model: QGroundControl.multiVehicleManager.vehicles
Don Gagne's avatar
Don Gagne committed
492 493 494 495 496 497 498 499 500 501
                    delegate:
                        VehicleMapItem {
                                vehicle:        object
                                coordinate:     object.coordinate
                                isSatellite:    editorMap.isSatelliteMap
                                size:           ScreenTools.defaultFontPixelHeight * 5
                                z:              QGroundControl.zOrderMapItems - 1
                        }
                }

Don Gagne's avatar
Don Gagne committed
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
                // Mission/GeoFence selector
                Item {
                    id:                 planElementSelector
                    anchors.topMargin:  parent.height - ScreenTools.availableHeight + _margin
                    anchors.top:        parent.top
                    anchors.leftMargin: parent.width - _rightPanelWidth
                    anchors.left:       parent.left
                    width:              planElementSelectorRow.width
                    height:             geoFenceController.fenceSupported ? planElementSelectorRow.height : 0
                    visible:            geoFenceController.fenceSupported

                    ExclusiveGroup {
                        id: planElementSelectorGroup
                        onCurrentChanged: {
                            var layerIsMission = current == planElementMission
                            _editingLayer = layerIsMission ? _layerMission : _layerGeoFence
                            _syncDropDownController = layerIsMission ? missionController : geoFenceController
                        }
                    }

                    Row {
                        id:     planElementSelectorRow
                        spacing: _horizontalMargin

                        QGCRadioButton {
                            id:             planElementMission
                            text:           qsTr("Mission")
                            checked:        true
                            exclusiveGroup: planElementSelectorGroup
                            color:          mapPal.text
                        }

                        QGCRadioButton {
                            id:             planElementGeoFence
                            text:           qsTr("GeoFence")
                            exclusiveGroup: planElementSelectorGroup
                            color:          mapPal.text
                        }
                    }
                }

543
                // Mission Item Editor
Don Gagne's avatar
Don Gagne committed
544
                Item {
Don Gagne's avatar
Don Gagne committed
545 546 547 548 549 550 551 552 553
                    id:                 missionItemEditor
                    anchors.topMargin:  _margin
                    anchors.top:        planElementSelector.bottom
                    anchors.bottom:     parent.bottom
                    anchors.right:      parent.right
                    width:              _rightPanelWidth
                    opacity:            _rightPanelOpacity
                    z:                  QGroundControl.zOrderTopMost
                    visible:            _editingLayer == _layerMission
554

Don Gagne's avatar
Don Gagne committed
555 556 557 558 559 560 561
                    MouseArea {
                         // This MouseArea prevents the Map below it from getting Mouse events. Without this
                         // things like mousewheel will scroll the Flickable and then scroll the map as well.
                         anchors.fill:       editorListView
                         onWheel:            wheel.accepted = true
                     }

562
                    ListView {
563 564 565 566
                        id:             editorListView
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        anchors.top:    parent.top
567
                        height:         parent.height
568 569
                        spacing:        _margin / 2
                        orientation:    ListView.Vertical
570
                        model:          missionController.visualItems
571
                        cacheBuffer:    height * 2
572
                        clip:           true
573
                        currentIndex:   _currentMissionIndex
574 575
                        highlightMoveDuration: 250

576
                        delegate: MissionItemEditor {
577 578
                            missionItem:    object
                            width:          parent.width
579
                            readOnly:       false
580 581 582 583

                            onClicked:  setCurrentItem(object.sequenceNumber)

                            onRemove: {
584
                                itemDragger.clearItem()
585
                                missionController.removeMissionItem(index)
586
                                editorMap.polygonDraw.cancelPolygonEdit()
587 588
                            }

589
                            onInsert: {
590
                                var sequenceNumber = missionController.insertSimpleMissionItem(editorMap.center, insertAfterIndex)
591 592 593
                                setCurrentItem(sequenceNumber)
                            }

594
                            onMoveHomeToMapCenter: _visualItems.get(0).coordinate = editorMap.center
595
                        }
596 597 598
                    } // ListView
                } // Item - Mission Item editor

599 600
                // GeoFence Editor
                Loader {
Don Gagne's avatar
Don Gagne committed
601 602
                    anchors.topMargin:  _margin
                    anchors.top:        planElementSelector.bottom
603 604 605 606 607 608 609 610 611 612 613 614 615
                    anchors.right:      parent.right
                    opacity:            _rightPanelOpacity
                    z:                  QGroundControl.zOrderTopMost
                    source:             _editingLayer == _layerGeoFence ? "qrc:/qml/GeoFenceEditor.qml" : ""

                    property real availableWidth:   _rightPanelWidth
                    property real availableHeight:  ScreenTools.availableHeight
                }

                // GeoFence polygon
                MapPolygon {
                    border.color:   "#80FF0000"
                    border.width:   3
616
                    path:           geoFenceController.polygonSupported ? geoFenceController.polygon.path : undefined
617
                    z:              QGroundControl.zOrderMapItems
618 619 620 621 622 623 624 625
                }

                // GeoFence circle
                MapCircle {
                    border.color:   "#80FF0000"
                    border.width:   3
                    center:         missionController.plannedHomePosition
                    radius:         geoFenceController.circleSupported ? geoFenceController.circleRadius : 0
626
                    z:              QGroundControl.zOrderMapItems
627 628 629 630 631 632
                }

                // GeoFence breach return point
                MapQuickItem {
                    anchorPoint:    Qt.point(sourceItem.width / 2, sourceItem.height / 2)
                    coordinate:     geoFenceController.breachReturnPoint
633 634
                    visible:        geoFenceController.breachReturnSupported
                    sourceItem:     MissionItemIndexLabel { label: "F" }
635
                    z:              QGroundControl.zOrderMapItems
636 637
                }

638 639 640 641 642 643 644 645 646 647 648
                //-- Dismiss Drop Down (if any)
                MouseArea {
                    anchors.fill:   parent
                    enabled:        _dropButtonsExclusiveGroup.current != null
                    onClicked: {
                        if(_dropButtonsExclusiveGroup.current)
                            _dropButtonsExclusiveGroup.current.checked = false
                        _dropButtonsExclusiveGroup.current = null
                    }
                }

649 650 651 652 653 654 655 656 657 658
                QGCLabel {
                    id:         planLabel
                    text:       qsTr("Plan")
                    color:      mapPal.text
                    visible:    !ScreenTools.isShortScreen
                    anchors.topMargin:          _toolButtonTopMargin
                    anchors.horizontalCenter:   toolColumn.horizontalCenter
                    anchors.top:                parent.top
                }

659 660
                //-- Vertical Tool Buttons
                Column {
661
                    id:                 toolColumn
662 663
                    anchors.topMargin:  ScreenTools.isShortScreen ? _toolButtonTopMargin : ScreenTools.defaultFontPixelHeight / 2
                    anchors.leftMargin: ScreenTools.defaultFontPixelHeight
664
                    anchors.left:       parent.left
665
                    anchors.top:        ScreenTools.isShortScreen ? parent.top : planLabel.bottom
666
                    spacing:            ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
667
                    z:                  QGroundControl.zOrderWidgets
668 669

                    RoundButton {
670 671 672
                        id:             addMissionItemsButton
                        buttonImage:    "/qmlimages/MapAddMission.svg"
                        lightBorders:   _lightWidgetBorders
673
                        visible:        _editingLayer == _layerMission
674 675
                    }

676
                    RoundButton {
677 678 679
                        id:             addShapeButton
                        buttonImage:    "/qmlimages/MapDrawShape.svg"
                        lightBorders:   _lightWidgetBorders
680
                        visible:        _editingLayer == _layerMission
681 682 683 684 685 686

                        onClicked: {
                            var coordinate = editorMap.center
                            coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
                            coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
                            coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
687
                            var sequenceNumber = missionController.insertComplexMissionItem(coordinate, missionController.visualItems.count)
688
                            setCurrentItem(sequenceNumber)
689
                            checked = false
690
                            addMissionItemsButton.checked = false
691 692 693
                        }
                    }

694 695 696
                    DropButton {
                        id:                 syncButton
                        dropDirection:      dropRight
697
                        buttonImage:        _syncDropDownController.dirty ? "/qmlimages/MapSyncChanged.svg" : "/qmlimages/MapSync.svg"
698 699 700
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
                        dropDownComponent:  syncDropDownComponent
701 702
                        enabled:            !_syncDropDownController.syncInProgress
                        rotateImage:        _syncDropDownController.syncInProgress
703
                        lightBorders:       _lightWidgetBorders
704 705
                    }

706 707 708 709 710 711
                    DropButton {
                        id:                 centerMapButton
                        dropDirection:      dropRight
                        buttonImage:        "/qmlimages/MapCenter.svg"
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
712
                        lightBorders:       _lightWidgetBorders
713

714 715
                        dropDownComponent: Component {
                            Column {
dogmaphobic's avatar
dogmaphobic committed
716
                                spacing: ScreenTools.defaultFontPixelWidth * 0.5
717
                                QGCLabel { text: qsTr("Center map:") }
718 719 720
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    QGCButton {
721
                                        text: qsTr("Home")
dogmaphobic's avatar
dogmaphobic committed
722
                                        width:  ScreenTools.defaultFontPixelWidth * 10
723 724
                                        onClicked: {
                                            centerMapButton.hideDropDown()
725
                                            editorMap.center = missionController.visualItems.get(0).coordinate
726
                                        }
727
                                    }
728
                                    QGCButton {
729
                                        text: qsTr("Mission")
dogmaphobic's avatar
dogmaphobic committed
730
                                        width:  ScreenTools.defaultFontPixelWidth * 10
731 732 733 734
                                        onClicked: {
                                            centerMapButton.hideDropDown()
                                            fitViewportToMissionItems()
                                        }
735
                                    }
736
                                    QGCButton {
737
                                        text:       qsTr("Vehicle")
dogmaphobic's avatar
dogmaphobic committed
738
                                        width:      ScreenTools.defaultFontPixelWidth * 10
739
                                        enabled:    activeVehicle && activeVehicle.latitude != 0 && activeVehicle.longitude != 0
740
                                        property var activeVehicle: _activeVehicle
741 742
                                        onClicked: {
                                            centerMapButton.hideDropDown()
743
                                            editorMap.center = activeVehicle.coordinate
744
                                        }
745 746 747 748 749 750
                                    }
                                }
                            }
                        }
                    }

751 752 753 754 755 756
                    DropButton {
                        id:                 mapTypeButton
                        dropDirection:      dropRight
                        buttonImage:        "/qmlimages/MapType.svg"
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
757
                        lightBorders:       _lightWidgetBorders
758 759 760

                        dropDownComponent: Component {
                            Column {
dogmaphobic's avatar
dogmaphobic committed
761
                                spacing: _margin
762
                                QGCLabel { text: qsTr("Map type:") }
763 764 765 766
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    Repeater {
                                        model: QGroundControl.flightMapSettings.mapTypes
767

768 769
                                        QGCButton {
                                            checkable:      true
770
                                            checked:        QGroundControl.flightMapSettings.mapType === text
771 772 773
                                            text:           modelData
                                            exclusiveGroup: _mapTypeButtonsExclusiveGroup
                                            onClicked: {
774
                                                QGroundControl.flightMapSettings.mapType = text
775 776 777
                                                checked = true
                                                mapTypeButton.hideDropDown()
                                            }
778 779 780 781 782 783 784
                                        }
                                    }
                                }
                            }
                        }
                    }

785 786
                    //-- Zoom Map In
                    RoundButton {
787 788 789 790 791
                        id:             mapZoomPlus
                        visible:        !ScreenTools.isTinyScreen && !ScreenTools.isShortScreen
                        buttonImage:    "/qmlimages/ZoomPlus.svg"
                        lightBorders:   _lightWidgetBorders

792 793 794 795 796 797 798 799 800
                        onClicked: {
                            if(editorMap)
                                editorMap.zoomLevel += 0.5
                            checked = false
                        }
                    }

                    //-- Zoom Map Out
                    RoundButton {
801 802 803 804
                        id:             mapZoomMinus
                        visible:        !ScreenTools.isTinyScreen && !ScreenTools.isShortScreen
                        buttonImage:    "/qmlimages/ZoomMinus.svg"
                        lightBorders:   _lightWidgetBorders
805 806 807 808 809 810
                        onClicked: {
                            if(editorMap)
                                editorMap.zoomLevel -= 0.5
                            checked = false
                        }
                    }
811
                }
812

813 814 815 816 817 818 819 820 821
                MapScale {
                    anchors.margins:    ScreenTools.defaultFontPixelHeight * (0.66)
                    anchors.bottom:     waypointValuesDisplay.visible ? waypointValuesDisplay.top : parent.bottom
                    anchors.left:       parent.left
                    z:                  QGroundControl.zOrderWidgets
                    mapControl:         editorMap
                    visible:            !ScreenTools.isTinyScreen
                }

822
                MissionItemStatus {
823 824 825 826 827 828 829 830 831 832 833 834 835
                    id:                     waypointValuesDisplay
                    anchors.margins:        ScreenTools.defaultFontPixelWidth
                    anchors.left:           parent.left
                    anchors.bottom:         parent.bottom
                    z:                      QGroundControl.zOrderTopMost
                    currentMissionItem:     _currentMissionItem
                    missionItems:           missionController.visualItems
                    expandedWidth:          missionItemEditor.x - (ScreenTools.defaultFontPixelWidth * 2)
                    missionDistance:        missionController.missionDistance
                    missionMaxTelemetry:    missionController.missionMaxTelemetry
                    cruiseDistance:         missionController.cruiseDistance
                    hoverDistance:          missionController.hoverDistance
                    visible:                _editingLayer == _layerMission && !ScreenTools.isShortScreen
836
                }
837
            } // FlightMap
Don Gagne's avatar
Don Gagne committed
838 839
        } // Item - split view container
    } // QGCViewPanel
840

841 842 843 844
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
845
            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?")
846 847
            function accept() {
                hideDialog()
Don Gagne's avatar
Don Gagne committed
848
                _syncDropDownController.loadFromVehicle()
849 850 851 852 853 854 855 856
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
857
            message:   qsTr("You have unsaved/unsent changes. Loading a from a file will lose these changes. Are you sure you want to load from a file?")
858 859
            function accept() {
                hideDialog()
Don Gagne's avatar
Don Gagne committed
860
                _syncDropDownController.loadFromSelectedFile()
861 862 863 864
            }
        }
    }

865 866 867
    Component {
        id: removeAllPromptDialog
        QGCViewMessage {
Don Gagne's avatar
Don Gagne committed
868
            message: qsTr("Are you sure you want to remove all items?")
869 870
            function accept() {
                itemDragger.clearItem()
Don Gagne's avatar
Don Gagne committed
871
                _syncDropDownController.removeAll()
872 873 874 875 876
                hideDialog()
            }
        }
    }

877 878
    Component {
        id: syncDropDownComponent
879

880 881 882
        Column {
            id:         columnHolder
            spacing:    _margin
883

Don Gagne's avatar
Don Gagne committed
884 885
            property string _overwriteText: (_editingLayer == _layerMission) ? qsTr("Mission overwrite") : qsTr("GeoFence overwrite")

886
            QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
887
                width:      sendSaveGrid.width
888
                wrapMode:   Text.WordWrap
889
                text:       _syncDropDownController.dirty ?
Don Gagne's avatar
Don Gagne committed
890
                                qsTr("You have unsaved changes. You should send to your vehicle, or save to a file:") :
891
                                qsTr("Sync:")
892
            }
893

dogmaphobic's avatar
dogmaphobic committed
894 895 896 897 898 899
            GridLayout {
                id:                 sendSaveGrid
                columns:            2
                anchors.margins:    _margin
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
900

901
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
902 903
                    text:               qsTr("Send To Vehicle")
                    Layout.fillWidth:   true
904
                    enabled:            _activeVehicle && !_syncDropDownController.syncInProgress
905 906
                    onClicked: {
                        syncButton.hideDropDown()
907
                        _syncDropDownController.sendToVehicle()
908 909
                    }
                }
910

911
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
912 913
                    text:               qsTr("Load From Vehicle")
                    Layout.fillWidth:   true
914
                    enabled:            _activeVehicle && !_syncDropDownController.syncInProgress
915 916
                    onClicked: {
                        syncButton.hideDropDown()
917
                        if (_syncDropDownController.dirty) {
918
                            qgcView.showDialog(syncLoadFromVehicleOverwrite, columnHolder._overwriteText, qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
919
                        } else {
920
                            _syncDropDownController.loadFromVehicle()
921
                        }
922 923
                    }
                }
924

925
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
926 927
                    text:               qsTr("Save To File...")
                    Layout.fillWidth:   true
928
                    enabled:            !_syncDropDownController.syncInProgress
929 930
                    onClicked: {
                        syncButton.hideDropDown()
931
                        _syncDropDownController.saveToSelectedFile()
932 933
                    }
                }
934

935
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
936 937
                    text:               qsTr("Load From File...")
                    Layout.fillWidth:   true
938
                    enabled:            !_syncDropDownController.syncInProgress
939 940
                    onClicked: {
                        syncButton.hideDropDown()
941
                        if (_syncDropDownController.dirty) {
942
                            qgcView.showDialog(syncLoadFromFileOverwrite, columnHolder._overwriteText, qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
943
                        } else {
944
                            _syncDropDownController.loadFromSelectedFile()
945
                        }
946 947
                    }
                }
948

dogmaphobic's avatar
dogmaphobic committed
949 950 951 952 953
                QGCButton {
                    text:               qsTr("Remove All")
                    Layout.fillWidth:   true
                    onClicked:  {
                        syncButton.hideDropDown()
954
                        _syncDropDownController.removeAll()
955
                        qgcView.showDialog(removeAllPromptDialog, qsTr("Remove all"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
dogmaphobic's avatar
dogmaphobic committed
956
                    }
957 958
                }
            }
959 960
        }
    }
Don Gagne's avatar
Don Gagne committed
961
} // QGCVIew