FlightDisplayViewMap.qml 11.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.
 *
 ****************************************************************************/
9 10


11 12 13 14 15
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtLocation       5.3
import QtPositioning    5.3
import QtQuick.Dialogs  1.2
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

import QGroundControl               1.0
import QGroundControl.FlightDisplay 1.0
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
import QGroundControl.Vehicle       1.0
import QGroundControl.Controllers   1.0

FlightMap {
    id:             flightMap
    anchors.fill:   parent
    mapName:        _mapName

31 32 33 34
    gesture.acceptedGestures: _followVehicle ?
                                          MapGestureArea.PinchGesture :
                                          MapGestureArea.PinchGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture

35
    property alias  missionController: missionController
Don Gagne's avatar
Don Gagne committed
36
    property var    flightWidgets
37
    property var    rightPanelWidth
38
    property var    qgcView             ///< QGCView control which contains this map
Don Gagne's avatar
Don Gagne committed
39

40
    property bool   _followVehicle:                 true
Don Gagne's avatar
Don Gagne committed
41 42 43 44
    property var    _activeVehicle:                 QGroundControl.multiVehicleManager.activeVehicle
    property bool   _activeVehicleCoordinateValid:  _activeVehicle ? _activeVehicle.coordinateValid : false
    property var    activeVehicleCoordinate:        _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
    property var    _gotoHereCoordinate:            QtPositioning.coordinate()
45
    property int    _retaskSequence:                0
46
    property real   _toolButtonTopMargin:           parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2)
47

48 49
    property bool   followVehicleConnection:        _followVehicle  ///< Only use to create connection on

50 51 52 53
    Component.onCompleted: {
        QGroundControl.flightMapPosition = center
        QGroundControl.flightMapZoom = zoomLevel
    }
54
    onCenterChanged: QGroundControl.flightMapPosition = center
55
    onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
56

57
    onActiveVehicleCoordinateChanged: {
58
        if (_followVehicle && _activeVehicleCoordinateValid && activeVehicleCoordinate.isValid) {
59 60
            _initialMapPositionSet = true
            flightMap.center  = activeVehicleCoordinate
61 62 63
        }
    }

Don Gagne's avatar
Don Gagne committed
64
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
65
    QGCMapPalette { id: mapPal; lightColors: isSatelliteMap }
Don Gagne's avatar
Don Gagne committed
66

67
    MissionController {
68
        id: missionController
69 70 71
        Component.onCompleted: start(false /* editMode */)
    }

72
    GeoFenceController {
73
        id: geoFenceController
74 75 76
        Component.onCompleted: start(false /* editMode */)
    }

77 78 79 80 81
    RallyPointController {
        id: rallyPointController
        Component.onCompleted: start(false /* editMode */)
    }

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    // The following code is used to track vehicle states such that we prompt to remove mission from vehicle when mission completes

    property bool vehicleArmed:                 _activeVehicle ? _activeVehicle.armed : false
    property bool vehicleWasArmed:              false
    property bool vehicleInMissionFlightMode:   _activeVehicle ? (_activeVehicle.flightMode === _activeVehicle.missionFlightMode) : false
    property bool promptForMissionRemove:       false

    onVehicleArmedChanged: {
        if (vehicleArmed) {
            if (!promptForMissionRemove) {
                promptForMissionRemove = vehicleInMissionFlightMode
                vehicleWasArmed = true
            }
        } else {
            if (promptForMissionRemove && (missionController.containsItems || geoFenceController.containsItems || rallyPointController.containsItems)) {
                qgcView.showDialog(removeMissionDialogComponent, qsTr("Flight complete"), showDialogDefaultWidth, StandardButton.No | StandardButton.Yes)
            }
            promptForMissionRemove = false
        }
    }

    onVehicleInMissionFlightModeChanged: {
        if (!promptForMissionRemove && vehicleArmed) {
            promptForMissionRemove = true
        }
    }

    Component {
        id: removeMissionDialogComponent

        QGCViewMessage {
            message: qsTr("Do you want to remove the mission from the vehicle?")

            function accept() {
                missionController.removeAllFromVehicle()
                geoFenceController.removeAllFromVehicle()
                rallyPointController.removeAllFromVehicle()
                hideDialog()

            }
        }
    }

125
    ExclusiveGroup {
Don Gagne's avatar
Don Gagne committed
126
        id: _mapTypeButtonsExclusiveGroup
127 128
    }

Don Gagne's avatar
Don Gagne committed
129 130 131 132 133 134 135 136 137 138
    ToolStrip {
        id:                 toolStrip
        anchors.leftMargin: ScreenTools.defaultFontPixelWidth
        anchors.left:       parent.left
        anchors.topMargin:  _toolButtonTopMargin
        anchors.top:        parent.top
        color:              qgcPal.window
        title:              qsTr("Fly")
        z:                  QGroundControl.zOrderWidgets
        buttonVisible:      [ true, true, _showZoom, _showZoom ]
139
        maxHeight:          (_flightVideo.visible ? _flightVideo.y : parent.height) - toolStrip.y   // Massive reach across hack
Don Gagne's avatar
Don Gagne committed
140

Don Gagne's avatar
Don Gagne committed
141
        property bool _showZoom: !ScreenTools.isMobile
Don Gagne's avatar
Don Gagne committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

        model: [
            {
                name:               "Center",
                iconSource:         "/qmlimages/MapCenter.svg",
                dropPanelComponent: centerMapDropPanel
            },
            {
                name:               "Map",
                iconSource:         "/qmlimages/MapType.svg",
                dropPanelComponent: mapTypeDropPanel
            },
            {
                name:               "In",
                iconSource:         "/qmlimages/ZoomPlus.svg"
            },
            {
                name:               "Out",
                iconSource:         "/qmlimages/ZoomMinus.svg"
            }
        ]
163 164

        onClicked: {
Don Gagne's avatar
Don Gagne committed
165 166 167 168 169 170 171
            switch (index) {
            case 2:
                _flightMap.zoomLevel += 0.5
                break
            case 3:
                _flightMap.zoomLevel -= 0.5
                break
172 173 174 175
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
176
    // Toolstrip drop panel compomnents
Don Gagne's avatar
Don Gagne committed
177

Don Gagne's avatar
Don Gagne committed
178 179 180 181 182 183 184 185
    MapFitFunctions {
        id:                         mapFitFunctions
        map:                        _flightMap
        mapFitViewport:             Qt.rect(leftToolWidth, _toolButtonTopMargin, flightMap.width - leftToolWidth - rightPanelWidth, flightMap.height - _toolButtonTopMargin)
        usePlannedHomePosition:     false
        mapMissionController:      missionController
        mapGeoFenceController:     geoFenceController
        mapRallyPointController:   rallyPointController
186

Don Gagne's avatar
Don Gagne committed
187 188
        property real leftToolWidth:    toolStrip.x + toolStrip.width
    }
189

Don Gagne's avatar
Don Gagne committed
190 191
    Component {
        id: centerMapDropPanel
192

Don Gagne's avatar
Don Gagne committed
193
        CenterMapDropPanel {
194 195 196 197 198 199
            map:                _flightMap
            fitFunctions:       mapFitFunctions
            showFollowVehicle:  true
            followVehicle:      _followVehicle

            onFollowVehicleChanged: _followVehicle = followVehicle
Don Gagne's avatar
Don Gagne committed
200 201
        }
    }
202

Don Gagne's avatar
Don Gagne committed
203 204
    Component {
        id: mapTypeDropPanel
205

Don Gagne's avatar
Don Gagne committed
206 207
        Column {
            spacing: ScreenTools.defaultFontPixelHeight / 2
208

Don Gagne's avatar
Don Gagne committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
            QGCLabel { text: qsTr("Map type:") }
            Row {
                spacing: ScreenTools.defaultFontPixelWidth
                Repeater {
                    model: QGroundControl.flightMapSettings.mapTypes

                    QGCButton {
                        checkable:      true
                        checked:        QGroundControl.flightMapSettings.mapType === text
                        text:           modelData
                        exclusiveGroup: _mapTypeButtonsExclusiveGroup
                        onClicked: {
                            QGroundControl.flightMapSettings.mapType = text
                            dropPanel.hide()
                        }
224 225 226 227
                    }
                }
            }
        }
Don Gagne's avatar
Don Gagne committed
228
    }
229

230 231
    // Add trajectory points to the map
    MapItemView {
232
        model: _mainIsMap ? _activeVehicle ? _activeVehicle.trajectoryPoints : 0 : 0
233 234
        delegate:
            MapPolyline {
Don Gagne's avatar
Don Gagne committed
235 236 237 238
            line.width: 3
            line.color: "red"
            z:          QGroundControl.zOrderMapItems - 1
            path: [
239 240
                object.coordinate1,
                object.coordinate2,
Don Gagne's avatar
Don Gagne committed
241 242
            ]
        }
243 244 245 246
    }

    // Add the vehicles to the map
    MapItemView {
247
        model: QGroundControl.multiVehicleManager.vehicles
248 249
        delegate:
            VehicleMapItem {
Don Gagne's avatar
Don Gagne committed
250 251 252
            vehicle:        object
            coordinate:     object.coordinate
            isSatellite:    flightMap.isSatelliteMap
Gus Grubba's avatar
Gus Grubba committed
253
            size:           _mainIsMap ? ScreenTools.defaultFontPixelHeight * 3 : ScreenTools.defaultFontPixelHeight
254
            z:              QGroundControl.zOrderMapItems - 1
Don Gagne's avatar
Don Gagne committed
255
        }
256 257
    }

258 259
    // Add the mission item visuals to the map
    Repeater {
260
        model: _mainIsMap ? missionController.visualItems : 0
261 262 263 264

        delegate: MissionItemMapVisual {
            map: flightMap
        }
265 266 267 268
    }

    // Add lines between waypoints
    MissionLineView {
269
        model: _mainIsMap ? missionController.waypointLines : 0
270 271
    }

272 273 274 275 276
    GeoFenceMapVisuals {
        map:                    flightMap
        myGeoFenceController:   geoFenceController
        interactive:            false
        homePosition:           _activeVehicle && _activeVehicle.homePositionAvailable ? _activeVehicle.homePosition : undefined
277 278
    }

279 280 281 282 283 284
    // Rally points on map
    MapItemView {
        model: rallyPointController.points

        delegate: MapQuickItem {
            id:             itemIndicator
285 286
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
287 288 289 290 291 292 293 294 295 296
            coordinate:     object.coordinate
            z:              QGroundControl.zOrderMapItems

            sourceItem: MissionItemIndexLabel {
                id:         itemIndexLabel
                label:      qsTr("R", "rally point map item label")
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
297 298 299
    // GoTo here waypoint
    MapQuickItem {
        coordinate:     _gotoHereCoordinate
Don Gagne's avatar
Don Gagne committed
300
        visible:        _activeVehicle && _activeVehicle.guidedMode && _gotoHereCoordinate.isValid
Don Gagne's avatar
Don Gagne committed
301
        z:              QGroundControl.zOrderMapItems
302 303
        anchorPoint.x:  sourceItem.anchorPointX
        anchorPoint.y:  sourceItem.anchorPointY
Don Gagne's avatar
Don Gagne committed
304 305

        sourceItem: MissionItemIndexLabel {
306 307
            checked: true
            label:   qsTr("G", "Goto here waypoint") // second string is translator's hint.
Don Gagne's avatar
Don Gagne committed
308
        }
309 310 311 312 313 314 315 316 317
    }    

    MapScale {
        anchors.bottomMargin:   ScreenTools.defaultFontPixelHeight * (0.66)
        anchors.rightMargin:    ScreenTools.defaultFontPixelHeight * (0.33)
        anchors.bottom:         parent.bottom
        anchors.right:          parent.right
        mapControl:             flightMap
        visible:                !ScreenTools.isTinyScreen
Don Gagne's avatar
Don Gagne committed
318 319 320
    }

    // Handle guided mode clicks
321 322
    MouseArea {
        anchors.fill: parent
Don Gagne's avatar
Don Gagne committed
323 324

        onClicked: {
Don Gagne's avatar
Don Gagne committed
325
            if (_activeVehicle) {
326
                if (flightWidgets.guidedModeBar.state != "Shown") {
Don Gagne's avatar
Don Gagne committed
327
                    flightWidgets.guidedModeBar.state = "Shown"
328 329
                } else {
                    if (flightWidgets.gotoEnabled) {
DonLakeFlyer's avatar
DonLakeFlyer committed
330
                        _gotoHereCoordinate = flightMap.toCoordinate(Qt.point(mouse.x, mouse.y), false /* clipToViewPort */)
331 332
                        flightWidgets.guidedModeBar.confirmAction(flightWidgets.guidedModeBar.confirmGoTo)
                    }
Don Gagne's avatar
Don Gagne committed
333
                }
Don Gagne's avatar
Don Gagne committed
334 335
            }
        }
336 337
    }
}