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


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
    /// 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
57
    readonly property int _layerRallyPoints:    3
58 59
    property int _editingLayer: _layerMission

60
    onActiveVehiclePositionChanged: updateMapToVehiclePosition()
61

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

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

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

79 80 81 82 83 84 85 86 87 88
    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
    }

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

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

103
                if (missionItem.specifiesCoordinate && !missionItem.isStandaloneCoordinate) {
104 105 106 107 108 109 110 111
                    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)
                }
112
            }
113
            editorMap.visibleRegion = QtPositioning.rectangle(QtPositioning.coordinate(north - 90.0, west - 180.0), QtPositioning.coordinate(south - 90.0, east - 180.0))
114 115 116
        }
    }

117
    MissionController {
118
        id: missionController
119

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

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

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

        onVisualItemsChanged: {
            itemDragger.clearItem()
        }
146

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

153 154
    GeoFenceController {
        id: geoFenceController
155

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

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
        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()
            }
        }

174 175 176 177 178 179 180 181
        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]
                }
182 183
            }
        }
184
    }
185

186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    RallyPointController {
        id: rallyPointController

        onCurrentRallyPointChanged: {
            if (_editingLayer == _layerRallyPoints && !currentRallyPoint) {
                itemDragger.visible = false
                itemDragger.coordinateItem = undefined
                itemDragger.mapCoordinateIndicator = undefined
            }
        }

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

        function saveToSelectedFile() {
            if (ScreenTools.isMobile) {
                qgcView.showDialog(mobileFileSaver, qsTr("Save Rally Point File"), qgcView.showDialogDefaultWidth, StandardButton.Save | StandardButton.Cancel)
            } else {
                rallyPointController.saveToFilePicker()
            }
        }

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

216
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
217

218 219 220 221 222 223
    ExclusiveGroup {
        id: _mapTypeButtonsExclusiveGroup
    }

    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
224 225
    }

226
    function setCurrentItem(sequenceNumber) {
227
        editorMap.polygonDraw.cancelPolygonEdit()
Don Gagne's avatar
Don Gagne committed
228
        _currentMissionItem = undefined
229
        for (var i=0; i<_visualItems.count; i++) {
230 231 232
            var visualItem = _visualItems.get(i)
            if (visualItem.sequenceNumber == sequenceNumber) {
                _currentMissionItem = visualItem
Don Gagne's avatar
Don Gagne committed
233
                _currentMissionItem.isCurrentItem = true
234
                _currentMissionIndex = i
Don Gagne's avatar
Don Gagne committed
235
            } else {
236
                visualItem.isCurrentItem = false
Don Gagne's avatar
Don Gagne committed
237
            }
238 239 240
        }
    }

241 242
    property int _moveDialogMissionItemIndex

243 244 245
    Component {
        id: mobileFilePicker

Don Gagne's avatar
Don Gagne committed
246
        QGCMobileFileDialog {
247
            openDialog:         true
248
            fileExtension:      _syncDropDownController.fileExtension
249
            onFilenameReturned: _syncDropDownController.loadFromfile(filename)
250 251 252 253 254 255
        }
    }

    Component {
        id: mobileFileSaver

Don Gagne's avatar
Don Gagne committed
256
        QGCMobileFileDialog {
257
            openDialog:         false
258
            fileExtension:      _syncDropDownController.fileExtension
259
            onFilenameReturned: _syncDropDownController.saveToFile()
260 261 262
        }
    }

263 264 265 266 267 268 269 270 271 272
    Component {
        id: moveDialog

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

                if (toIndex == 0) {
                    toIndex = 1
                }
273
                missionController.moveMissionItem(_moveDialogMissionItemIndex, toIndex)
274 275 276 277 278 279 280 281 282 283 284 285
                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
286
                    text:           qsTr("Move the selected mission item to the be after following mission item:")
287 288 289 290
                }

                QGCComboBox {
                    id:             toCombo
291
                    model:          _visualItems.count
292 293 294 295 296 297
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
298 299
    QGCViewPanel {
        id:             panel
300 301 302 303
        height:         ScreenTools.availableHeight
        anchors.bottom: parent.bottom
        anchors.left:   parent.left
        anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
304

Don Gagne's avatar
Don Gagne committed
305
        Item {
Don Gagne's avatar
Don Gagne committed
306 307
            anchors.fill: parent

Don Gagne's avatar
Don Gagne committed
308 309
            FlightMap {
                id:             editorMap
310
                height:         qgcView.height
311 312 313
                anchors.bottom: parent.bottom
                anchors.left:   parent.left
                anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
314
                mapName:        "MissionEditor"
315

316 317
                readonly property real animationDuration: 500

318 319 320
                // Initial map position duplicates Fly view position
                Component.onCompleted: editorMap.center = QGroundControl.flightMapPosition

321 322 323 324 325 326 327
                Behavior on zoomLevel {
                    NumberAnimation {
                        duration:       editorMap.animationDuration
                        easing.type:    Easing.InOutQuad
                    }
                }

328 329
                QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

Don Gagne's avatar
Don Gagne committed
330
                MouseArea {
331 332
                    //-- 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
333 334
                    anchors.fill: parent
                    onClicked: {
335 336
                        //-- Don't pay attention to items beneath the toolbar.
                        var topLimit = parent.height - ScreenTools.availableHeight
337 338 339 340 341 342 343 344 345 346 347
                        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:
348
                            if (addMissionItemsButton.checked) {
349
                                var sequenceNumber = missionController.insertSimpleMissionItem(coordinate, missionController.visualItems.count)
350 351
                                setCurrentItem(sequenceNumber)
                            }
352 353
                            break
                        case _layerGeoFence:
354 355 356 357 358 359 360 361 362
                            if (geoFenceController.breachReturnSupported) {
                                geoFenceController.breachReturnPoint = coordinate
                                geoFenceController.validateBreachReturn()
                            }
                            break
                        case _layerRallyPoints:
                            if (rallyPointController.rallyPointsSupported) {
                                rallyPointController.addPoint(coordinate)
                            }
363
                            break
364
                        }
Don Gagne's avatar
Don Gagne committed
365
                    }
Don Gagne's avatar
Don Gagne committed
366
                }
Don Gagne's avatar
Don Gagne committed
367

368
                // We use this item to support dragging since dragging a MapQuickItem just doesn't seem to work
Don Gagne's avatar
Don Gagne committed
369 370
                Rectangle {
                    id:             itemDragger
371 372
                    x:              mapCoordinateIndicator ? (mapCoordinateIndicator.x + mapCoordinateIndicator.anchorPoint.x - (itemDragger.width / 2)) : 100
                    y:              mapCoordinateIndicator ? (mapCoordinateIndicator.y + mapCoordinateIndicator.anchorPoint.y - (itemDragger.height / 2)) : 100
373 374
                    width:          ScreenTools.defaultFontPixelHeight * 2
                    height:         ScreenTools.defaultFontPixelHeight * 2
Don Gagne's avatar
Don Gagne committed
375 376 377
                    color:          "transparent"
                    visible:        false
                    z:              QGroundControl.zOrderMapItems + 1    // Above item icons
378

379 380
                    property var    coordinateItem
                    property var    mapCoordinateIndicator
381 382 383 384 385 386 387 388 389
                    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)
390
                            coordinate.altitude = itemDragger.coordinateItem.coordinate.altitude
391
                            itemDragger.preventCoordinateBindingLoop = true
392
                            itemDragger.coordinateItem.coordinate = coordinate
393 394 395
                            itemDragger.preventCoordinateBindingLoop = false
                        }
                    }
Don Gagne's avatar
Don Gagne committed
396

397
                    function clearItem() {
Don Gagne's avatar
Don Gagne committed
398
                        itemDragger.visible = false
399 400
                        itemDragger.coordinateItem = undefined
                        itemDragger.mapCoordinateIndicator = undefined
Don Gagne's avatar
Don Gagne committed
401 402
                    }

403 404 405 406 407 408 409 410
                    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
411 412 413 414
                        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
415
                    }
416
                }
417

418
                // Add the complex mission item polygon to the map
419
                MapItemView {
420
                    model: missionController.complexVisualItems
421

Don Gagne's avatar
Don Gagne committed
422
                    delegate: MapPolygon {
423 424 425 426 427 428
                        color:      'green'
                        path:       object.polygonPath
                        opacity:    0.5
                    }
                }

429 430
                // Add the complex mission item grid to the map
                MapItemView {
431
                    model: missionController.complexVisualItems
432 433 434

                    delegate: MapPolyline {
                        line.color: "white"
435
                        line.width: 2
436 437 438 439
                        path:       object.gridPoints
                    }
                }

440 441
                // Add the complex mission item exit coordinates
                MapItemView {
442
                    model: missionController.complexVisualItems
443 444 445 446 447 448 449 450 451 452 453 454 455
                    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
456 457
                }

458 459
                // Add the simple mission items to the map
                MapItemView {
460
                    model:      missionController.visualItems
461 462 463
                    delegate:   missionItemComponent
                }

Don Gagne's avatar
Don Gagne committed
464
                Component {
465
                    id: missionItemComponent
Don Gagne's avatar
Don Gagne committed
466 467 468 469

                    MissionItemIndicator {
                        id:             itemIndicator
                        coordinate:     object.coordinate
470
                        visible:        object.specifiesCoordinate
Don Gagne's avatar
Don Gagne committed
471
                        z:              QGroundControl.zOrderMapItems
472
                        missionItem:    object
473
                        sequenceNumber: object.sequenceNumber
Don Gagne's avatar
Don Gagne committed
474

475 476 477
                        //-- 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
478 479
                        onClicked: setCurrentItem(object.sequenceNumber)

480 481
                        function updateItemIndicator() {
                            if (object.isCurrentItem && itemIndicator.visible && object.specifiesCoordinate && object.isSimpleItem) {
482 483
                                // Setup our drag item
                                itemDragger.visible = true
484 485
                                itemDragger.coordinateItem = Qt.binding(function() { return object })
                                itemDragger.mapCoordinateIndicator = Qt.binding(function() { return itemIndicator })
Don Gagne's avatar
Don Gagne committed
486 487 488
                            }
                        }

489 490 491
                        Connections {
                            target: object

492 493
                            onIsCurrentItemChanged:         updateItemIndicator()
                            onSpecifiesCoordinateChanged:   updateItemIndicator()
494 495
                        }

Don Gagne's avatar
Don Gagne committed
496 497 498 499 500 501 502 503 504
                        // 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 {
505 506 507
                                    label:      object.abbreviation
                                    checked:    object.isCurrentItem
                                    z:          2
Don Gagne's avatar
Don Gagne committed
508 509 510 511 512 513

                                    onClicked: setCurrentItem(object.sequenceNumber)
                                }
                            }
                        }
                    }
514 515 516
                }

                // Add lines between waypoints
517
                MissionLineView {
518
                    model:      _editingLayer == _layerMission ? missionController.waypointLines : undefined
Don Gagne's avatar
Don Gagne committed
519 520
                }

Don Gagne's avatar
Don Gagne committed
521 522
                // Add the vehicles to the map
                MapItemView {
523
                    model: QGroundControl.multiVehicleManager.vehicles
Don Gagne's avatar
Don Gagne committed
524 525
                    delegate:
                        VehicleMapItem {
526 527 528 529 530 531
                        vehicle:        object
                        coordinate:     object.coordinate
                        isSatellite:    editorMap.isSatelliteMap
                        size:           ScreenTools.defaultFontPixelHeight * 5
                        z:              QGroundControl.zOrderMapItems - 1
                    }
Don Gagne's avatar
Don Gagne committed
532 533
                }

534 535 536
                // Plan Element selector (Mission/Fence/Rally)
                Row {
                    id:                 planElementSelectorRow
Don Gagne's avatar
Don Gagne committed
537 538 539 540
                    anchors.topMargin:  parent.height - ScreenTools.availableHeight + _margin
                    anchors.top:        parent.top
                    anchors.leftMargin: parent.width - _rightPanelWidth
                    anchors.left:       parent.left
541 542 543
                    spacing:            _horizontalMargin

                    readonly property real _buttonRadius: ScreenTools.defaultFontPixelHeight * 0.75
Don Gagne's avatar
Don Gagne committed
544 545 546 547

                    ExclusiveGroup {
                        id: planElementSelectorGroup
                        onCurrentChanged: {
548 549 550 551 552 553 554 555 556 557 558 559 560 561
                            switch (current) {
                            case planElementMission:
                                _editingLayer = _layerMission
                                _syncDropDownController = missionController
                                break
                            case planElementGeoFence:
                                _editingLayer = _layerGeoFence
                                _syncDropDownController = geoFenceController
                                break
                            case planElementRallyPoints:
                                _editingLayer = _layerRallyPoints
                                _syncDropDownController = rallyPointController
                                break
                            }
Don Gagne's avatar
Don Gagne committed
562 563 564
                        }
                    }

565 566 567 568 569 570 571 572 573 574 575 576 577
                    RoundButton {
                        id:             planElementMission
                        radius:         parent._buttonRadius
                        buttonImage:    "/qmlimages/Plan.svg"
                        lightBorders:   _lightWidgetBorders
                        exclusiveGroup: planElementSelectorGroup
                        checked:        true
                    }

                    QGCLabel {
                        text:                   qsTr("Mission")
                        color:                  mapPal.text
                        anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
578

579 580 581
                        MouseArea {
                            anchors.fill:   parent
                            onClicked:      planElementMission.checked = true
Don Gagne's avatar
Don Gagne committed
582
                        }
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
                    }

                    Item { height: 1; width: 1 }

                    RoundButton {
                        id:             planElementGeoFence
                        radius:         parent._buttonRadius
                        buttonImage:    "/qmlimages/Plan.svg"
                        lightBorders:   _lightWidgetBorders
                        exclusiveGroup: planElementSelectorGroup
                    }

                    QGCLabel {
                        text:                   qsTr("Fence")
                        color:                  mapPal.text
                        anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
599

600 601 602
                        MouseArea {
                            anchors.fill:   parent
                            onClicked:      planElementGeoFence.checked = true
Don Gagne's avatar
Don Gagne committed
603 604
                        }
                    }
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626

                    Item { height: 1; width: 1 }

                    RoundButton {
                        id:             planElementRallyPoints
                        radius:         parent._buttonRadius
                        buttonImage:    "/qmlimages/Plan.svg"
                        lightBorders:   _lightWidgetBorders
                        exclusiveGroup: planElementSelectorGroup
                    }

                    QGCLabel {
                        text:                   qsTr("Rally")
                        color:                  mapPal.text
                        anchors.verticalCenter: parent.verticalCenter

                        MouseArea {
                            anchors.fill:   parent
                            onClicked:      planElementRallyPoints.checked = true
                        }
                    }
                } // Row - Plan Element Selector
Don Gagne's avatar
Don Gagne committed
627

628
                // Mission Item Editor
Don Gagne's avatar
Don Gagne committed
629
                Item {
Don Gagne's avatar
Don Gagne committed
630 631
                    id:                 missionItemEditor
                    anchors.topMargin:  _margin
632
                    anchors.top:        planElementSelectorRow.bottom
Don Gagne's avatar
Don Gagne committed
633 634 635 636 637 638
                    anchors.bottom:     parent.bottom
                    anchors.right:      parent.right
                    width:              _rightPanelWidth
                    opacity:            _rightPanelOpacity
                    z:                  QGroundControl.zOrderTopMost
                    visible:            _editingLayer == _layerMission
639

Don Gagne's avatar
Don Gagne committed
640
                    MouseArea {
641 642 643 644 645
                        // 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:       missionItemEditorListView
                        onWheel:            wheel.accepted = true
                    }
Don Gagne's avatar
Don Gagne committed
646

647
                    ListView {
648
                        id:             missionItemEditorListView
649 650 651
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        anchors.top:    parent.top
652
                        height:         parent.height
653 654
                        spacing:        _margin / 2
                        orientation:    ListView.Vertical
655
                        model:          missionController.visualItems
656
                        cacheBuffer:    height * 2
657
                        clip:           true
658
                        currentIndex:   _currentMissionIndex
659 660
                        highlightMoveDuration: 250

661
                        delegate: MissionItemEditor {
662 663
                            missionItem:    object
                            width:          parent.width
664
                            readOnly:       false
665 666 667 668

                            onClicked:  setCurrentItem(object.sequenceNumber)

                            onRemove: {
669
                                itemDragger.clearItem()
670
                                missionController.removeMissionItem(index)
671
                                editorMap.polygonDraw.cancelPolygonEdit()
672 673
                            }

674
                            onInsert: {
675
                                var sequenceNumber = missionController.insertSimpleMissionItem(editorMap.center, insertAfterIndex)
676 677 678
                                setCurrentItem(sequenceNumber)
                            }

679
                            onMoveHomeToMapCenter: _visualItems.get(0).coordinate = editorMap.center
680
                        }
681 682 683
                    } // ListView
                } // Item - Mission Item editor

684 685
                // GeoFence Editor
                Loader {
Don Gagne's avatar
Don Gagne committed
686
                    anchors.topMargin:  _margin
687
                    anchors.top:        planElementSelectorRow.bottom
688 689 690 691 692 693 694 695 696 697 698 699 700
                    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
701
                    path:           geoFenceController.polygonSupported ? geoFenceController.polygon.path : undefined
702
                    z:              QGroundControl.zOrderMapItems
703 704 705 706 707 708 709 710
                }

                // GeoFence circle
                MapCircle {
                    border.color:   "#80FF0000"
                    border.width:   3
                    center:         missionController.plannedHomePosition
                    radius:         geoFenceController.circleSupported ? geoFenceController.circleRadius : 0
711
                    z:              QGroundControl.zOrderMapItems
712 713 714 715 716 717
                }

                // GeoFence breach return point
                MapQuickItem {
                    anchorPoint:    Qt.point(sourceItem.width / 2, sourceItem.height / 2)
                    coordinate:     geoFenceController.breachReturnPoint
718 719
                    visible:        geoFenceController.breachReturnSupported
                    sourceItem:     MissionItemIndexLabel { label: "F" }
720
                    z:              QGroundControl.zOrderMapItems
721 722
                }

723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
                // Rally Point Editor

                RallyPointEditorHeader {
                    id:                 rallyPointHeader
                    anchors.topMargin:  _margin
                    anchors.top:        planElementSelectorRow.bottom
                    anchors.right:      parent.right
                    width:              _rightPanelWidth
                    opacity:            _rightPanelOpacity
                    z:                  QGroundControl.zOrderTopMost
                    visible:            _editingLayer == _layerRallyPoints
                    controller:         rallyPointController
                }

                RallyPointItemEditor {
                    id:                 rallyPointEditor
                    anchors.topMargin:  _margin
                    anchors.top:        rallyPointHeader.bottom
                    anchors.right:      parent.right
                    width:              _rightPanelWidth
                    opacity:            _rightPanelOpacity
                    z:                  QGroundControl.zOrderTopMost
                    visible:            _editingLayer == _layerRallyPoints && rallyPointController.points.count
                    rallyPoint:         rallyPointController.currentRallyPoint
                    controller:         rallyPointController
                }

                // Rally points on map

                MapItemView {
                    model: rallyPointController.points

                    delegate: MapQuickItem {
                        id:             itemIndicator
                        anchorPoint:    Qt.point(sourceItem.width / 2, sourceItem.height / 2)
                        coordinate:     object.coordinate
                        z:              QGroundControl.zOrderMapItems

                        sourceItem: MissionItemIndexLabel {
                            id:         itemIndexLabel
                            label:      qsTr("R", "rally point map item label")
                            checked:    _editingLayer == _layerRallyPoints ? object == rallyPointController.currentRallyPoint : false

                            onClicked: rallyPointController.currentRallyPoint = object

                            onCheckedChanged: {
                                if (checked) {
                                    // Setup our drag item
                                    itemDragger.visible = true
                                    itemDragger.coordinateItem = Qt.binding(function() { return object })
                                    itemDragger.mapCoordinateIndicator = Qt.binding(function() { return itemIndicator })
                                }
                            }
                        }
                    }
                }

780 781 782 783 784 785 786 787 788 789 790
                //-- Dismiss Drop Down (if any)
                MouseArea {
                    anchors.fill:   parent
                    enabled:        _dropButtonsExclusiveGroup.current != null
                    onClicked: {
                        if(_dropButtonsExclusiveGroup.current)
                            _dropButtonsExclusiveGroup.current.checked = false
                        _dropButtonsExclusiveGroup.current = null
                    }
                }

791 792 793 794 795 796 797 798 799 800
                QGCLabel {
                    id:         planLabel
                    text:       qsTr("Plan")
                    color:      mapPal.text
                    visible:    !ScreenTools.isShortScreen
                    anchors.topMargin:          _toolButtonTopMargin
                    anchors.horizontalCenter:   toolColumn.horizontalCenter
                    anchors.top:                parent.top
                }

801 802
                //-- Vertical Tool Buttons
                Column {
803
                    id:                 toolColumn
804 805
                    anchors.topMargin:  ScreenTools.isShortScreen ? _toolButtonTopMargin : ScreenTools.defaultFontPixelHeight / 2
                    anchors.leftMargin: ScreenTools.defaultFontPixelHeight
806
                    anchors.left:       parent.left
807
                    anchors.top:        ScreenTools.isShortScreen ? parent.top : planLabel.bottom
808
                    spacing:            ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
809
                    z:                  QGroundControl.zOrderWidgets
810 811

                    RoundButton {
812 813 814
                        id:             addMissionItemsButton
                        buttonImage:    "/qmlimages/MapAddMission.svg"
                        lightBorders:   _lightWidgetBorders
815
                        visible:        _editingLayer == _layerMission
816 817
                    }

818
                    RoundButton {
819 820 821
                        id:             addShapeButton
                        buttonImage:    "/qmlimages/MapDrawShape.svg"
                        lightBorders:   _lightWidgetBorders
822
                        visible:        _editingLayer == _layerMission
823 824 825 826 827 828

                        onClicked: {
                            var coordinate = editorMap.center
                            coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
                            coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
                            coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
829
                            var sequenceNumber = missionController.insertComplexMissionItem(coordinate, missionController.visualItems.count)
830
                            setCurrentItem(sequenceNumber)
831
                            checked = false
832
                            addMissionItemsButton.checked = false
833 834 835
                        }
                    }

836 837 838
                    DropButton {
                        id:                 syncButton
                        dropDirection:      dropRight
839
                        buttonImage:        _syncDropDownController.dirty ? "/qmlimages/MapSyncChanged.svg" : "/qmlimages/MapSync.svg"
840 841 842
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
                        dropDownComponent:  syncDropDownComponent
843 844
                        enabled:            !_syncDropDownController.syncInProgress
                        rotateImage:        _syncDropDownController.syncInProgress
845
                        lightBorders:       _lightWidgetBorders
846 847
                    }

848 849 850 851 852 853
                    DropButton {
                        id:                 centerMapButton
                        dropDirection:      dropRight
                        buttonImage:        "/qmlimages/MapCenter.svg"
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
854
                        lightBorders:       _lightWidgetBorders
855

856 857
                        dropDownComponent: Component {
                            Column {
dogmaphobic's avatar
dogmaphobic committed
858
                                spacing: ScreenTools.defaultFontPixelWidth * 0.5
859
                                QGCLabel { text: qsTr("Center map:") }
860 861 862
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    QGCButton {
863
                                        text: qsTr("Home")
dogmaphobic's avatar
dogmaphobic committed
864
                                        width:  ScreenTools.defaultFontPixelWidth * 10
865 866
                                        onClicked: {
                                            centerMapButton.hideDropDown()
867
                                            editorMap.center = missionController.visualItems.get(0).coordinate
868
                                        }
869
                                    }
870
                                    QGCButton {
871
                                        text: qsTr("Mission")
dogmaphobic's avatar
dogmaphobic committed
872
                                        width:  ScreenTools.defaultFontPixelWidth * 10
873 874 875 876
                                        onClicked: {
                                            centerMapButton.hideDropDown()
                                            fitViewportToMissionItems()
                                        }
877
                                    }
878
                                    QGCButton {
879
                                        text:       qsTr("Vehicle")
dogmaphobic's avatar
dogmaphobic committed
880
                                        width:      ScreenTools.defaultFontPixelWidth * 10
881
                                        enabled:    activeVehicle && activeVehicle.latitude != 0 && activeVehicle.longitude != 0
882
                                        property var activeVehicle: _activeVehicle
883 884
                                        onClicked: {
                                            centerMapButton.hideDropDown()
885
                                            editorMap.center = activeVehicle.coordinate
886
                                        }
887 888 889 890 891 892
                                    }
                                }
                            }
                        }
                    }

893 894 895 896 897 898
                    DropButton {
                        id:                 mapTypeButton
                        dropDirection:      dropRight
                        buttonImage:        "/qmlimages/MapType.svg"
                        viewportMargins:    ScreenTools.defaultFontPixelWidth / 2
                        exclusiveGroup:     _dropButtonsExclusiveGroup
899
                        lightBorders:       _lightWidgetBorders
900 901 902

                        dropDownComponent: Component {
                            Column {
dogmaphobic's avatar
dogmaphobic committed
903
                                spacing: _margin
904
                                QGCLabel { text: qsTr("Map type:") }
905 906 907 908
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    Repeater {
                                        model: QGroundControl.flightMapSettings.mapTypes
909

910 911
                                        QGCButton {
                                            checkable:      true
912
                                            checked:        QGroundControl.flightMapSettings.mapType === text
913 914 915
                                            text:           modelData
                                            exclusiveGroup: _mapTypeButtonsExclusiveGroup
                                            onClicked: {
916
                                                QGroundControl.flightMapSettings.mapType = text
917 918 919
                                                checked = true
                                                mapTypeButton.hideDropDown()
                                            }
920 921 922 923 924 925 926
                                        }
                                    }
                                }
                            }
                        }
                    }

927 928
                    //-- Zoom Map In
                    RoundButton {
929 930 931 932 933
                        id:             mapZoomPlus
                        visible:        !ScreenTools.isTinyScreen && !ScreenTools.isShortScreen
                        buttonImage:    "/qmlimages/ZoomPlus.svg"
                        lightBorders:   _lightWidgetBorders

934 935 936 937 938 939 940 941 942
                        onClicked: {
                            if(editorMap)
                                editorMap.zoomLevel += 0.5
                            checked = false
                        }
                    }

                    //-- Zoom Map Out
                    RoundButton {
943 944 945 946
                        id:             mapZoomMinus
                        visible:        !ScreenTools.isTinyScreen && !ScreenTools.isShortScreen
                        buttonImage:    "/qmlimages/ZoomMinus.svg"
                        lightBorders:   _lightWidgetBorders
947 948 949 950 951 952
                        onClicked: {
                            if(editorMap)
                                editorMap.zoomLevel -= 0.5
                            checked = false
                        }
                    }
953
                }
954

955 956 957 958 959 960 961 962 963
                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
                }

964
                MissionItemStatus {
965 966 967 968 969 970 971 972 973 974 975 976 977
                    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
978
                }
979
            } // FlightMap
Don Gagne's avatar
Don Gagne committed
980 981
        } // Item - split view container
    } // QGCViewPanel
982

983 984 985 986
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
987
            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?")
988 989
            function accept() {
                hideDialog()
Don Gagne's avatar
Don Gagne committed
990
                _syncDropDownController.loadFromVehicle()
991 992 993 994 995 996 997 998
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
999
            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?")
1000 1001
            function accept() {
                hideDialog()
Don Gagne's avatar
Don Gagne committed
1002
                _syncDropDownController.loadFromSelectedFile()
1003 1004 1005 1006
            }
        }
    }

1007 1008 1009
    Component {
        id: removeAllPromptDialog
        QGCViewMessage {
Don Gagne's avatar
Don Gagne committed
1010
            message: qsTr("Are you sure you want to remove all items?")
1011 1012
            function accept() {
                itemDragger.clearItem()
Don Gagne's avatar
Don Gagne committed
1013
                _syncDropDownController.removeAll()
1014 1015 1016 1017 1018
                hideDialog()
            }
        }
    }

1019 1020
    Component {
        id: syncDropDownComponent
1021

1022 1023 1024
        Column {
            id:         columnHolder
            spacing:    _margin
1025

1026
            property string _overwriteText: (_editingLayer == _layerMission) ? qsTr("Mission overwrite") : ((_editingLayer == _layerGeoFence) ? qsTr("GeoFence overwrite") : qsTr("Rally Points overwrite"))
Don Gagne's avatar
Don Gagne committed
1027

1028
            QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
1029
                width:      sendSaveGrid.width
1030
                wrapMode:   Text.WordWrap
1031
                text:       _syncDropDownController.dirty ?
Don Gagne's avatar
Don Gagne committed
1032
                                qsTr("You have unsaved changes. You should send to your vehicle, or save to a file:") :
1033
                                qsTr("Sync:")
1034
            }
1035

dogmaphobic's avatar
dogmaphobic committed
1036 1037 1038 1039 1040 1041
            GridLayout {
                id:                 sendSaveGrid
                columns:            2
                anchors.margins:    _margin
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
1042

1043
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
1044 1045
                    text:               qsTr("Send To Vehicle")
                    Layout.fillWidth:   true
1046
                    enabled:            _activeVehicle && !_syncDropDownController.syncInProgress
1047 1048
                    onClicked: {
                        syncButton.hideDropDown()
1049
                        _syncDropDownController.sendToVehicle()
1050 1051
                    }
                }
1052

1053
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
1054 1055
                    text:               qsTr("Load From Vehicle")
                    Layout.fillWidth:   true
1056
                    enabled:            _activeVehicle && !_syncDropDownController.syncInProgress
1057 1058
                    onClicked: {
                        syncButton.hideDropDown()
1059
                        if (_syncDropDownController.dirty) {
1060
                            qgcView.showDialog(syncLoadFromVehicleOverwrite, columnHolder._overwriteText, qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1061
                        } else {
1062
                            _syncDropDownController.loadFromVehicle()
1063
                        }
1064 1065
                    }
                }
1066

1067
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
1068 1069
                    text:               qsTr("Save To File...")
                    Layout.fillWidth:   true
1070
                    enabled:            !_syncDropDownController.syncInProgress
1071 1072
                    onClicked: {
                        syncButton.hideDropDown()
1073
                        _syncDropDownController.saveToSelectedFile()
1074 1075
                    }
                }
1076

1077
                QGCButton {
dogmaphobic's avatar
dogmaphobic committed
1078 1079
                    text:               qsTr("Load From File...")
                    Layout.fillWidth:   true
1080
                    enabled:            !_syncDropDownController.syncInProgress
1081 1082
                    onClicked: {
                        syncButton.hideDropDown()
1083
                        if (_syncDropDownController.dirty) {
1084
                            qgcView.showDialog(syncLoadFromFileOverwrite, columnHolder._overwriteText, qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
1085
                        } else {
1086
                            _syncDropDownController.loadFromSelectedFile()
1087
                        }
1088 1089
                    }
                }
1090

dogmaphobic's avatar
dogmaphobic committed
1091 1092 1093 1094 1095
                QGCButton {
                    text:               qsTr("Remove All")
                    Layout.fillWidth:   true
                    onClicked:  {
                        syncButton.hideDropDown()
1096
                        _syncDropDownController.removeAll()
1097
                        qgcView.showDialog(removeAllPromptDialog, qsTr("Remove all"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
dogmaphobic's avatar
dogmaphobic committed
1098
                    }
1099 1100
                }
            }
1101 1102
        }
    }
Don Gagne's avatar
Don Gagne committed
1103
} // QGCVIew