GuidedActionsController.qml 26.9 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

import QtQuick                  2.3
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.4
import QtQuick.Dialogs          1.2
import QtLocation               5.3
import QtPositioning            5.3
import QtQuick.Layouts          1.2

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

/// This provides the smarts behind the guided mode commands, minus the user interface. This way you can change UI
/// without affecting the underlying functionality.
Item {
    id: _root

    property var missionController
31
    property var confirmDialog
DonLakeFlyer's avatar
DonLakeFlyer committed
32
    property var actionList
Don Gagne's avatar
Don Gagne committed
33
    property var altitudeSlider
34
    property var orbitMapCircle
35

36
    readonly property string emergencyStopTitle:            qsTr("EMERGENCY STOP")
37
    readonly property string armTitle:                      qsTr("Arm")
38
    readonly property string forceArmTitle:                 qsTr("Force Arm")
39
    readonly property string disarmTitle:                   qsTr("Disarm")
40
    readonly property string rtlTitle:                      qsTr("Return")
41 42 43
    readonly property string takeoffTitle:                  qsTr("Takeoff")
    readonly property string landTitle:                     qsTr("Land")
    readonly property string startMissionTitle:             qsTr("Start Mission")
44
    readonly property string mvStartMissionTitle:           qsTr("Start Mission (MV)")
45 46 47
    readonly property string continueMissionTitle:          qsTr("Continue Mission")
    readonly property string resumeMissionUploadFailTitle:  qsTr("Resume FAILED")
    readonly property string pauseTitle:                    qsTr("Pause")
48
    readonly property string mvPauseTitle:                  qsTr("Pause (MV)")
49 50 51 52
    readonly property string changeAltTitle:                qsTr("Change Altitude")
    readonly property string orbitTitle:                    qsTr("Orbit")
    readonly property string landAbortTitle:                qsTr("Land Abort")
    readonly property string setWaypointTitle:              qsTr("Set Waypoint")
53
    readonly property string gotoTitle:                     qsTr("Go To Location")
54
    readonly property string vtolTransitionTitle:           qsTr("VTOL Transition")
Gus Grubba's avatar
Gus Grubba committed
55
    readonly property string roiTitle:                      qsTr("ROI")
56
    readonly property string actionListTitle:               qsTr("Action")
57

58
    readonly property string armMessage:                        qsTr("Arm the vehicle.")
59
    readonly property string forceArmMessage:                   qsTr("WARNING: This will force arming of the vehicle bypassing any safety checks.")
60
    readonly property string disarmMessage:                     qsTr("Disarm the vehicle")
61
    readonly property string emergencyStopMessage:              qsTr("WARNING: THIS WILL STOP ALL MOTORS. IF VEHICLE IS CURRENTLY IN THE AIR IT WILL CRASH.")
62 63 64
    readonly property string takeoffMessage:                    qsTr("Takeoff from ground and hold position.")
    readonly property string startMissionMessage:               qsTr("Takeoff from ground and start the current mission.")
    readonly property string continueMissionMessage:            qsTr("Continue the mission from the current waypoint.")
Don Gagne's avatar
Don Gagne committed
65
    readonly property string resumeMissionUploadFailMessage:    qsTr("Upload of resume mission failed. Confirm to retry upload")
66
    readonly property string landMessage:                       qsTr("Land the vehicle at the current position.")
67
    readonly property string rtlMessage:                        qsTr("Return to the launch position of the vehicle.")
68
    readonly property string changeAltMessage:                  qsTr("Change the altitude of the vehicle up or down.")
DonLakeFlyer's avatar
DonLakeFlyer committed
69
    readonly property string gotoMessage:                       qsTr("Move the vehicle to the specified location.")
70
             property string setWaypointMessage:                qsTr("Adjust current waypoint to %1.").arg(_actionData)
Don Gagne's avatar
Don Gagne committed
71
    readonly property string orbitMessage:                      qsTr("Orbit the vehicle around the specified location.")
72
    readonly property string landAbortMessage:                  qsTr("Abort the landing sequence.")
73
    readonly property string pauseMessage:                      qsTr("Pause the vehicle at it's current position, adjusting altitude up or down as needed.")
74
    readonly property string mvPauseMessage:                    qsTr("Pause all vehicles at their current position.")
75 76
    readonly property string vtolTransitionFwdMessage:          qsTr("Transition VTOL to fixed wing flight.")
    readonly property string vtolTransitionMRMessage:           qsTr("Transition VTOL to multi-rotor flight.")
Gus Grubba's avatar
Gus Grubba committed
77
    readonly property string roiMessage:                        qsTr("Make the specified location a Region Of Interest.")
78

79 80 81 82 83 84 85 86 87 88 89 90 91 92
    readonly property int actionRTL:                        1
    readonly property int actionLand:                       2
    readonly property int actionTakeoff:                    3
    readonly property int actionArm:                        4
    readonly property int actionDisarm:                     5
    readonly property int actionEmergencyStop:              6
    readonly property int actionChangeAlt:                  7
    readonly property int actionGoto:                       8
    readonly property int actionSetWaypoint:                9
    readonly property int actionOrbit:                      10
    readonly property int actionLandAbort:                  11
    readonly property int actionStartMission:               12
    readonly property int actionContinueMission:            13
    readonly property int actionResumeMission:              14
Don Gagne's avatar
Don Gagne committed
93
    readonly property int _actionUnused:                    15
94 95
    readonly property int actionResumeMissionUploadFail:    16
    readonly property int actionPause:                      17
96 97
    readonly property int actionMVPause:                    18
    readonly property int actionMVStartMission:             19
98 99
    readonly property int actionVtolTransitionToFwdFlight:  20
    readonly property int actionVtolTransitionToMRFlight:   21
Gus Grubba's avatar
Gus Grubba committed
100
    readonly property int actionROI:                        22
101
    readonly property int actionActionList:                 23
102
    readonly property int actionForceArm:                   24
103

104 105 106 107
    property bool   _useChecklist:              QGroundControl.settingsManager.appSettings.useChecklist.rawValue && QGroundControl.corePlugin.options.preFlightChecklistUrl.toString().length
    property bool   _enforceChecklist:          _useChecklist && QGroundControl.settingsManager.appSettings.enforceChecklist.rawValue
    property bool   _canArm:                    activeVehicle ? (_useChecklist ? (_enforceChecklist ? activeVehicle.checkListState === Vehicle.CheckListPassed : true) : true) : false

108
    property bool showEmergenyStop:     _guidedActionsEnabled && !_hideEmergenyStop && _vehicleArmed && _vehicleFlying
109
    property bool showArm:              _guidedActionsEnabled && !_vehicleArmed && _canArm
110
    property bool showForceArm:         _guidedActionsEnabled && !_vehicleArmed
111
    property bool showDisarm:           _guidedActionsEnabled && _vehicleArmed && !_vehicleFlying
112
    property bool showRTL:              _guidedActionsEnabled && _vehicleArmed && activeVehicle.guidedModeSupported && _vehicleFlying && !_vehicleInRTLMode
113
    property bool showTakeoff:          _guidedActionsEnabled && activeVehicle.takeoffVehicleSupported && !_vehicleFlying && _canArm
114
    property bool showLand:             _guidedActionsEnabled && activeVehicle.guidedModeSupported && _vehicleArmed && !activeVehicle.fixedWing && !_vehicleInLandMode
115
    property bool showStartMission:     _guidedActionsEnabled && _missionAvailable && !_missionActive && !_vehicleFlying && _canArm
116
    property bool showContinueMission:  _guidedActionsEnabled && _missionAvailable && !_missionActive && _vehicleArmed && _vehicleFlying && (_currentMissionIndex < _missionItemCount - 1)
117 118
    property bool showPause:            _guidedActionsEnabled && _vehicleArmed && activeVehicle.pauseVehicleSupported && _vehicleFlying && !_vehiclePaused && !_fixedWingOnApproach
    property bool showChangeAlt:        _guidedActionsEnabled && _vehicleFlying && activeVehicle.guidedModeSupported && _vehicleArmed && !_missionActive
119 120
    property bool showOrbit:            _guidedActionsEnabled && _vehicleFlying && __orbitSupported && !_missionActive
    property bool showROI:              _guidedActionsEnabled && _vehicleFlying && __roiSupported && !_missionActive
121
    property bool showLandAbort:        _guidedActionsEnabled && _vehicleFlying && _fixedWingOnApproach
122
    property bool showGotoLocation:     _guidedActionsEnabled && _vehicleFlying
123
    property bool showActionList:       _guidedActionsEnabled && (showStartMission || showResumeMission || showChangeAlt || showLandAbort)
124

125
    // Note: The '_missionItemCount - 2' is a hack to not trigger resume mission when a mission ends with an RTL item
126
    property bool showResumeMission:    activeVehicle && !_vehicleArmed && _vehicleWasFlying && _missionAvailable && _resumeMissionIndex > 0 && (_resumeMissionIndex < _missionItemCount - 2)
127

128
    property bool guidedUIVisible:      confirmDialog.visible || actionList.visible
DonLakeFlyer's avatar
DonLakeFlyer committed
129

130
    property var    _corePlugin:            QGroundControl.corePlugin
131 132
    property var    _corePluginOptions:     QGroundControl.corePlugin.options
    property bool   _guidedActionsEnabled:  (!ScreenTools.isDebug && _corePluginOptions.guidedActionsRequireRCRSSI && activeVehicle) ? _rcRSSIAvailable : activeVehicle
133
    property string _flightMode:            activeVehicle ? activeVehicle.flightMode : ""
134
    property bool   _missionAvailable:      missionController.containsItems
135 136 137 138
    property bool   _missionActive:         activeVehicle ? _vehicleArmed && (_vehicleInLandMode || _vehicleInRTLMode || _vehicleInMissionMode) : false
    property bool   _vehicleArmed:          activeVehicle ? activeVehicle.armed  : false
    property bool   _vehicleFlying:         activeVehicle ? activeVehicle.flying  : false
    property bool   _vehicleLanding:        activeVehicle ? activeVehicle.landing  : false
139 140 141 142
    property bool   _vehiclePaused:         false
    property bool   _vehicleInMissionMode:  false
    property bool   _vehicleInRTLMode:      false
    property bool   _vehicleInLandMode:     false
143
    property int    _missionItemCount:      missionController.missionItemCount
144
    property int    _currentMissionIndex:   missionController.currentMissionIndex
145
    property int    _resumeMissionIndex:    missionController.resumeMissionIndex
146 147 148
    property bool   _hideEmergenyStop:      !_corePluginOptions.flyView.guidedBarShowEmergencyStop
    property bool   _hideOrbit:             !_corePluginOptions.flyView.guidedBarShowOrbit
    property bool   _hideROI:               !_corePluginOptions.flyView.guidedBarShowROI
149
    property bool   _vehicleWasFlying:      false
150 151
    property bool   _rcRSSIAvailable:       activeVehicle ? activeVehicle.rcRSSI > 0 && activeVehicle.rcRSSI <= 100 : false
    property bool   _fixedWingOnApproach:   activeVehicle ? activeVehicle.fixedWing && _vehicleLanding : false
152

153
    // You can turn on log output for GuidedActionsController by turning on GuidedActionsControllerLog category
154 155
    property bool __guidedModeSupported:    activeVehicle ? activeVehicle.guidedModeSupported : false
    property bool __pauseVehicleSupported:  activeVehicle ? activeVehicle.pauseVehicleSupported : false
156 157
    property bool __roiSupported:           activeVehicle ? !_hideROI && activeVehicle.roiModeSupported : false
    property bool __orbitSupported:         activeVehicle ? !_hideOrbit && activeVehicle.orbitModeSupported : false
158
    property bool __flightMode:             _flightMode
159 160

    function _outputState() {
161
        if (_corePlugin.guidedActionsControllerLogging()) {
162
            console.log(qsTr("activeVehicle(%1) _vehicleArmed(%2) guidedModeSupported(%3) _vehicleFlying(%4) _vehicleWasFlying(%5) _vehicleInRTLMode(%6) pauseVehicleSupported(%7) _vehiclePaused(%8) _flightMode(%9) _missionItemCount(%10) roiSupported(%11) orbitSupported(%12) _missionActive(%13) _hideROI(%14) _hideOrbit(%15)").arg(activeVehicle ? 1 : 0).arg(_vehicleArmed ? 1 : 0).arg(__guidedModeSupported ? 1 : 0).arg(_vehicleFlying ? 1 : 0).arg(_vehicleWasFlying ? 1 : 0).arg(_vehicleInRTLMode ? 1 : 0).arg(__pauseVehicleSupported ? 1 : 0).arg(_vehiclePaused ? 1 : 0).arg(_flightMode).arg(_missionItemCount).arg(__roiSupported).arg(__orbitSupported).arg(_missionActive).arg(_hideROI).arg(_hideOrbit))
Gus Grubba's avatar
Gus Grubba committed
163 164 165 166 167 168 169
        }
    }

    Connections {
        target: mainWindow
        onActiveVehicleChanged: {
            _outputState()
170
        }
171 172
    }

173 174 175 176 177 178 179
    Component.onCompleted:              _outputState()
    on_VehicleArmedChanged:             _outputState()
    on_VehicleInRTLModeChanged:         _outputState()
    on_VehiclePausedChanged:            _outputState()
    on__FlightModeChanged:              _outputState()
    on__GuidedModeSupportedChanged:     _outputState()
    on__PauseVehicleSupportedChanged:   _outputState()
180 181
    on__RoiSupportedChanged:            _outputState()
    on__OrbitSupportedChanged:          _outputState()
182
    on_MissionItemCountChanged:         _outputState()
183
    on_MissionActiveChanged:            _outputState()
184

DonLakeFlyer's avatar
DonLakeFlyer committed
185
    on_CurrentMissionIndexChanged: {
186
        if (_corePlugin.guidedActionsControllerLogging()) {
DonLakeFlyer's avatar
DonLakeFlyer committed
187 188 189 190
            console.log("_currentMissionIndex", _currentMissionIndex)
        }
    }
    on_ResumeMissionIndexChanged: {
191
        if (_corePlugin.guidedActionsControllerLogging()) {
DonLakeFlyer's avatar
DonLakeFlyer committed
192 193 194
            console.log("_resumeMissionIndex", _resumeMissionIndex)
        }
    }
195
    onShowResumeMissionChanged: {
196
        if (_corePlugin.guidedActionsControllerLogging()) {
197 198
            console.log("showResumeMission", showResumeMission)
        }
199 200 201
        _outputState()
    }
    onShowStartMissionChanged: {
202
        if (_corePlugin.guidedActionsControllerLogging()) {
203 204
            console.log("showStartMission", showStartMission)
        }
205
        _outputState()
206 207 208
        if (showStartMission) {
            confirmAction(actionStartMission)
        }
209 210
    }
    onShowContinueMissionChanged: {
211
        if (_corePlugin.guidedActionsControllerLogging()) {
212 213
            console.log("showContinueMission", showContinueMission)
        }
214
        _outputState()
215 216 217
        if (showContinueMission) {
            confirmAction(actionContinueMission)
        }
218
    }
Don Gagne's avatar
Don Gagne committed
219 220 221 222 223 224
    onShowRTLChanged: {
        if (_corePlugin.guidedActionsControllerLogging()) {
            console.log("showRTL", showRTL)
        }
        _outputState()
    }
225 226 227 228 229
    onShowChangeAltChanged: {
        if (_corePlugin.guidedActionsControllerLogging()) {
            console.log("showChangeAlt", showChangeAlt)
        }
        _outputState()
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
    }
    onShowROIChanged: {
        if (_corePlugin.guidedActionsControllerLogging()) {
            console.log("showROI", showROI)
        }
        _outputState()
    }
    onShowOrbitChanged: {
        if (_corePlugin.guidedActionsControllerLogging()) {
            console.log("showOrbit", showOrbit)
        }
        _outputState()
    }
    onShowGotoLocationChanged: {
        if (_corePlugin.guidedActionsControllerLogging()) {
            console.log("showGotoLocation", showGotoLocation)
        }
        _outputState()
248
    }
249 250 251 252 253
    onShowLandAbortChanged: {
        if (showLandAbort) {
            confirmAction(actionLandAbort)
        }
    }
254

255
    on_VehicleFlyingChanged: {
256
        _outputState()
257 258 259 260 261 262
        if (!_vehicleFlying) {
            // We use _vehicleWasFLying to help trigger Resume Mission only if the vehicle actually flew and came back down.
            // Otherwise it may trigger during the Start Mission sequence due to signal ordering or armed and resume mission index.
            _vehicleWasFlying = true
        }
    }
DonLakeFlyer's avatar
DonLakeFlyer committed
263 264

    property var _actionData
265 266

    on_FlightModeChanged: {
267 268 269 270
        _vehiclePaused =        activeVehicle ? _flightMode === activeVehicle.pauseFlightMode : false
        _vehicleInRTLMode =     activeVehicle ? _flightMode === activeVehicle.rtlFlightMode || _flightMode === activeVehicle.smartRTLFlightMode : false
        _vehicleInLandMode =    activeVehicle ? _flightMode === activeVehicle.landFlightMode : false
        _vehicleInMissionMode = activeVehicle ? _flightMode === activeVehicle.missionFlightMode : false // Must be last to get correct signalling for showStartMission popups
271
    }
272

273 274 275 276 277 278 279 280
    Connections {
        target:                     missionController
        onResumeMissionUploadFail:  confirmAction(actionResumeMissionUploadFail)
    }

    Connections {
        target:                             mainWindow
        onArmVehicleRequest:                armVehicleRequest()
281
        onForceArmVehicleRequest:           forceArmVehicleRequest()
282 283 284 285 286 287 288 289 290
        onDisarmVehicleRequest:             disarmVehicleRequest()
        onVtolTransitionToFwdFlightRequest: vtolTransitionToFwdFlightRequest()
        onVtolTransitionToMRFlightRequest:  vtolTransitionToMRFlightRequest()
    }

    function armVehicleRequest() {
        confirmAction(actionArm)
    }

291 292 293 294
    function forceArmVehicleRequest() {
        confirmAction(actionForceArm)
    }

295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
    function disarmVehicleRequest() {
        if (showEmergenyStop) {
            confirmAction(actionEmergencyStop)
        } else {
            confirmAction(actionDisarm)
        }

    }

    function vtolTransitionToFwdFlightRequest() {
        confirmAction(actionVtolTransitionToFwdFlight)
    }

    function vtolTransitionToMRFlightRequest() {
        confirmAction(actionVtolTransitionToMRFlight)
    }

312 313 314 315 316 317
    function closeAll() {
        confirmDialog.visible =     false
        actionList.visible =        false
        altitudeSlider.visible =    false
    }

318
    // Called when an action is about to be executed in order to confirm
319
    function confirmAction(actionCode, actionData, mapIndicator) {
320
        var showImmediate = true
321
        closeAll()
322 323
        confirmDialog.action = actionCode
        confirmDialog.actionData = actionData
324
        confirmDialog.hideTrigger = true
325
        confirmDialog.mapIndicator = mapIndicator
DonLakeFlyer's avatar
DonLakeFlyer committed
326
        confirmDialog.optionText = ""
327 328 329
        _actionData = actionData
        switch (actionCode) {
        case actionArm:
330
            if (_vehicleFlying || !_guidedActionsEnabled) {
331 332
                return
            }
333 334 335
            confirmDialog.title = armTitle
            confirmDialog.message = armMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showArm })
336
            break;
337 338 339 340 341
        case actionForceArm:
            confirmDialog.title = forceArmTitle
            confirmDialog.message = forceArmMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showForceArm })
            break;
342
        case actionDisarm:
343
            if (_vehicleFlying) {
344 345
                return
            }
346 347 348
            confirmDialog.title = disarmTitle
            confirmDialog.message = disarmMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showDisarm })
349 350
            break;
        case actionEmergencyStop:
351 352 353
            confirmDialog.title = emergencyStopTitle
            confirmDialog.message = emergencyStopMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showEmergenyStop })
354 355
            break;
        case actionTakeoff:
356 357 358
            confirmDialog.title = takeoffTitle
            confirmDialog.message = takeoffMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showTakeoff })
359
            altitudeSlider.setToMinimumTakeoff()
360
            altitudeSlider.visible = true
361 362
            break;
        case actionStartMission:
363
            showImmediate = false
364 365 366
            confirmDialog.title = startMissionTitle
            confirmDialog.message = startMissionMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showStartMission })
367
            break;
368
        case actionMVStartMission:
369
            confirmDialog.title = mvStartMissionTitle
370 371 372
            confirmDialog.message = startMissionMessage
            confirmDialog.hideTrigger = true
            break;
373
        case actionContinueMission:
374
            showImmediate = false
375 376 377 378
            confirmDialog.title = continueMissionTitle
            confirmDialog.message = continueMissionMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showContinueMission })
            break;
379
        case actionResumeMission:
Don Gagne's avatar
Don Gagne committed
380 381
            // Resume Mission is handled in mission end dialog
            return
382 383 384 385 386
        case actionResumeMissionUploadFail:
            confirmDialog.title = resumeMissionUploadFailTitle
            confirmDialog.message = resumeMissionUploadFailMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showResumeMission })
            break;
387
        case actionLand:
388 389 390
            confirmDialog.title = landTitle
            confirmDialog.message = landMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showLand })
391 392
            break;
        case actionRTL:
393 394
            confirmDialog.title = rtlTitle
            confirmDialog.message = rtlMessage
395
            if (activeVehicle.supportsSmartRTL) {
DonLakeFlyer's avatar
DonLakeFlyer committed
396 397 398
                confirmDialog.optionText = qsTr("Smart RTL")
                confirmDialog.optionChecked = false
            }
399
            confirmDialog.hideTrigger = Qt.binding(function() { return !showRTL })
400 401
            break;
        case actionChangeAlt:
402 403 404
            confirmDialog.title = changeAltTitle
            confirmDialog.message = changeAltMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showChangeAlt })
Don Gagne's avatar
Don Gagne committed
405 406
            altitudeSlider.reset()
            altitudeSlider.visible = true
407 408
            break;
        case actionGoto:
409 410 411
            confirmDialog.title = gotoTitle
            confirmDialog.message = gotoMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showGotoLocation })
412 413
            break;
        case actionSetWaypoint:
414 415
            confirmDialog.title = setWaypointTitle
            confirmDialog.message = setWaypointMessage
416 417
            break;
        case actionOrbit:
418 419 420
            confirmDialog.title = orbitTitle
            confirmDialog.message = orbitMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showOrbit })
DonLakeFlyer's avatar
DonLakeFlyer committed
421 422
            altitudeSlider.reset()
            altitudeSlider.visible = true
423 424
            break;
        case actionLandAbort:
425 426 427
            confirmDialog.title = landAbortTitle
            confirmDialog.message = landAbortMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showLandAbort })
428 429
            break;
        case actionPause:
430 431 432
            confirmDialog.title = pauseTitle
            confirmDialog.message = pauseMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showPause })
433 434
            altitudeSlider.reset()
            altitudeSlider.visible = true
435
            break;
436
        case actionMVPause:
437
            confirmDialog.title = mvPauseTitle
438 439 440
            confirmDialog.message = mvPauseMessage
            confirmDialog.hideTrigger = true
            break;
441 442 443 444 445 446 447 448 449 450
        case actionVtolTransitionToFwdFlight:
            confirmDialog.title = vtolTransitionTitle
            confirmDialog.message = vtolTransitionFwdMessage
            confirmDialog.hideTrigger = true
            break
        case actionVtolTransitionToMRFlight:
            confirmDialog.title = vtolTransitionTitle
            confirmDialog.message = vtolTransitionMRMessage
            confirmDialog.hideTrigger = true
            break
Gus Grubba's avatar
Gus Grubba committed
451 452 453 454 455
        case actionROI:
            confirmDialog.title = roiTitle
            confirmDialog.message = roiMessage
            confirmDialog.hideTrigger = Qt.binding(function() { return !showROI })
            break;
456 457 458
        case actionActionList:
            actionList.show()
            return
459 460 461
        default:
            console.warn("Unknown actionCode", actionCode)
            return
462
        }
463
        confirmDialog.show(showImmediate)
464 465 466
    }

    // Executes the specified action
DonLakeFlyer's avatar
DonLakeFlyer committed
467
    function executeAction(actionCode, actionData, actionAltitudeChange, optionChecked) {
468 469
        var i;
        var rgVehicle;
470 471
        switch (actionCode) {
        case actionRTL:
472
            activeVehicle.guidedModeRTL(optionChecked)
473 474
            break
        case actionLand:
475
            activeVehicle.guidedModeLand()
476 477
            break
        case actionTakeoff:
478
            activeVehicle.guidedModeTakeoff(actionAltitudeChange)
479 480
            break
        case actionResumeMission:
481
        case actionResumeMissionUploadFail:
482
            missionController.resumeMission(missionController.resumeMissionIndex)
483 484
            break
        case actionStartMission:
485
        case actionContinueMission:
486
            activeVehicle.startMission()
487
            break
488
        case actionMVStartMission:
489 490 491
            rgVehicle = QGroundControl.multiVehicleManager.vehicles
            for (i = 0; i < rgVehicle.count; i++) {
                rgVehicle.get(i).startMission()
492 493
            }
            break
494
        case actionArm:
495
            activeVehicle.armed = true
496
            break
497 498 499
        case actionForceArm:
            activeVehicle.forceArm()
            break
500
        case actionDisarm:
501
            activeVehicle.armed = false
502 503
            break
        case actionEmergencyStop:
504
            activeVehicle.emergencyStop()
505 506
            break
        case actionChangeAlt:
507
            activeVehicle.guidedModeChangeAltitude(actionAltitudeChange)
508 509
            break
        case actionGoto:
510
            activeVehicle.guidedModeGotoLocation(actionData)
511 512
            break
        case actionSetWaypoint:
513
            activeVehicle.setCurrentMissionSequence(actionData)
514 515
            break
        case actionOrbit:
516
            activeVehicle.guidedModeOrbit(orbitMapCircle.center, orbitMapCircle.radius() * (orbitMapCircle.clockwiseRotation ? 1 : -1), activeVehicle.altitudeAMSL.rawValue + actionAltitudeChange)
517 518
            break
        case actionLandAbort:
519
            activeVehicle.abortLanding(50)     // hardcoded value for climbOutAltitude that is currently ignored
520 521
            break
        case actionPause:
522 523
            activeVehicle.pauseVehicle()
            activeVehicle.guidedModeChangeAltitude(actionAltitudeChange)
524
            break
525
        case actionMVPause:
526 527 528
            rgVehicle = QGroundControl.multiVehicleManager.vehicles
            for (i = 0; i < rgVehicle.count; i++) {
                rgVehicle.get(i).pauseVehicle()
529 530
            }
            break
531
        case actionVtolTransitionToFwdFlight:
532
            activeVehicle.vtolInFwdFlight = true
533 534
            break
        case actionVtolTransitionToMRFlight:
535
            activeVehicle.vtolInFwdFlight = false
536
            break
Gus Grubba's avatar
Gus Grubba committed
537 538 539
        case actionROI:
            activeVehicle.guidedModeROI(actionData)
            break
540 541 542 543 544 545
        default:
            console.warn(qsTr("Internal error: unknown actionCode"), actionCode)
            break
        }
    }
}