Unverified Commit 42f2098b authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #8368 from DonLakeFlyer/TakeoffLand

Plan: Takeoff/Land insertion fixes, fix current item update after delete, fix crash
parents 28546b72 153a139e
......@@ -598,6 +598,16 @@ void MissionController::removeMissionItem(int viIndex)
}
_recalcAll();
// Adjust current item
int newVIIndex;
if (viIndex >= _visualItems->count()) {
newVIIndex = _visualItems->count() - 1;
} else {
newVIIndex = viIndex;
}
setCurrentPlanViewSeqNum(_visualItems->value<VisualMissionItem*>(newVIIndex)->sequenceNumber(), true);
setDirty(true);
}
......@@ -2278,9 +2288,10 @@ bool MissionController::_isROICancelItem(SimpleMissionItem* simpleItem)
void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
{
if (_visualItems && (force || sequenceNumber != _currentPlanViewSeqNum)) {
bool foundLand = false;
int takeoffIndex = -1;
int landIndex = -1;
bool foundLand = false;
int takeoffSeqNum = -1;
int landSeqNum = -1;
int lastFlyThroughSeqNum = -1;
_splitSegment = nullptr;
_currentPlanViewItem = nullptr;
......@@ -2294,10 +2305,11 @@ void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
_previousCoordinate = QGeoCoordinate();
for (int viIndex=0; viIndex<_visualItems->count(); viIndex++) {
VisualMissionItem* pVI = qobject_cast<VisualMissionItem*>(_visualItems->get(viIndex));
SimpleMissionItem* simpleItem = qobject_cast<SimpleMissionItem*>(pVI);
VisualMissionItem* pVI = qobject_cast<VisualMissionItem*>(_visualItems->get(viIndex));
SimpleMissionItem* simpleItem = qobject_cast<SimpleMissionItem*>(pVI);
int currentSeqNumber = pVI->sequenceNumber();
if (sequenceNumber != 0 && pVI->sequenceNumber() <= sequenceNumber) {
if (sequenceNumber != 0 && currentSeqNumber <= sequenceNumber) {
if (pVI->specifiesCoordinate() && !pVI->isStandaloneCoordinate()) {
// Coordinate based flight commands prior to where the takeoff would be inserted
_isInsertTakeoffValid = false;
......@@ -2305,7 +2317,7 @@ void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
}
if (qobject_cast<TakeoffMissionItem*>(pVI)) {
takeoffIndex = viIndex;
takeoffSeqNum = currentSeqNumber;
_isInsertTakeoffValid = false;
}
......@@ -2317,7 +2329,7 @@ void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
case MAV_CMD_DO_LAND_START:
case MAV_CMD_NAV_RETURN_TO_LAUNCH:
foundLand = true;
landIndex = viIndex;
landSeqNum = currentSeqNumber;
break;
default:
break;
......@@ -2326,19 +2338,19 @@ void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
FixedWingLandingComplexItem* fwLanding = qobject_cast<FixedWingLandingComplexItem*>(pVI);
if (fwLanding) {
foundLand = true;
landIndex = viIndex;
landSeqNum = currentSeqNumber;
}
}
}
if (simpleItem) {
// Remember previous coordinate
if (pVI->sequenceNumber() < sequenceNumber && simpleItem->specifiesCoordinate() && !simpleItem->isStandaloneCoordinate()) {
if (currentSeqNumber < sequenceNumber && simpleItem->specifiesCoordinate() && !simpleItem->isStandaloneCoordinate()) {
_previousCoordinate = simpleItem->coordinate();
}
// ROI state handling
if (pVI->sequenceNumber() <= sequenceNumber) {
if (currentSeqNumber <= sequenceNumber) {
if (_isROIActive) {
if (_isROICancelItem(simpleItem)) {
_isROIActive = false;
......@@ -2349,12 +2361,17 @@ void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
}
}
}
if (pVI->sequenceNumber() == sequenceNumber && _isROIBeginItem(simpleItem)) {
if (currentSeqNumber == sequenceNumber && _isROIBeginItem(simpleItem)) {
_isROIBeginCurrentItem = true;
}
if (simpleItem->specifiesCoordinate() && !simpleItem->isStandaloneCoordinate()) {
lastFlyThroughSeqNum = currentSeqNumber;
}
}
if (pVI->sequenceNumber() == sequenceNumber) {
if (currentSeqNumber == sequenceNumber) {
pVI->setIsCurrentItem(true);
pVI->setHasCurrentChildItem(false);
......@@ -2383,9 +2400,9 @@ void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
}
}
if (takeoffIndex != -1) {
if (takeoffSeqNum != -1) {
// Takeoff item was found which means mission starts from ground
if (sequenceNumber < takeoffIndex) {
if (sequenceNumber < takeoffSeqNum) {
// Land is only valid after the takeoff item.
_isInsertLandValid = false;
// Fly through commands are not allowed prior to the takeoff command
......@@ -2393,10 +2410,17 @@ void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
}
}
if (lastFlyThroughSeqNum != -1) {
// Land item must be after any fly through coordinates
if (sequenceNumber < lastFlyThroughSeqNum) {
_isInsertLandValid = false;
}
}
if (foundLand) {
// Can't have more than one land sequence
_isInsertLandValid = false;
if (sequenceNumber >= landIndex) {
if (sequenceNumber >= landSeqNum) {
// Can't have fly through commands after a land item
_flyThroughCommandsAllowed = false;
}
......
......@@ -31,6 +31,7 @@ MissionSettingsItem::MissionSettingsItem(Vehicle* vehicle, bool flyView, QObject
, _cameraSection (vehicle)
, _speedSection (vehicle)
{
_isIncomplete = false;
_editorQml = "qrc:/qml/MissionSettingsEditor.qml";
if (_metaDataMap.isEmpty()) {
......
......@@ -291,6 +291,17 @@ Item {
_missionController.insertComplexMissionItem(complexItemName, mapCenter(), nextIndex, true /* makeCurrentItem */)
}
function insertTakeItemAfterCurrent() {
var nextIndex = _missionController.currentPlanViewVIIndex + 1
_missionController.insertTakeoffItem(mapCenter(), nextIndex, true /* makeCurrentItem */)
}
function insertLandItemAfterCurrent() {
var nextIndex = _missionController.currentPlanViewVIIndex + 1
_missionController.insertLandItem(mapCenter(), nextIndex, true /* makeCurrentItem */)
}
function selectNextNotReady() {
var foundCurrent = false
for (var i=0; i<_missionController.visualItems.count; i++) {
......@@ -643,7 +654,7 @@ Item {
break*/
case takeoffButtonIndex:
allAddClickBoolsOff()
_missionController.insertTakeoffItem(mapCenter(), _missionController.currentMissionIndex, true /* makeCurrentItem */)
insertTakeItemAfterCurrent()
break
case waypointButtonIndex:
if (_addWaypointOnClick) {
......@@ -675,7 +686,7 @@ Item {
break
case landButtonIndex:
allAddClickBoolsOff()
_missionController.insertLandItem(mapCenter(), _missionController.currentMissionIndex, true /* makeCurrentItem */)
insertLandItemAfterCurrent()
break
}
}
......@@ -835,12 +846,11 @@ Item {
readOnly: false
onClicked: _missionController.setCurrentPlanViewSeqNum(object.sequenceNumber, false)
onRemove: {
var removeIndex = index
_missionController.removeMissionItem(removeIndex)
if (removeIndex >= _missionController.visualItems.count) {
removeIndex--
var removeVIIndex = index
_missionController.removeMissionItem(removeVIIndex)
if (removeVIIndex >= _missionController.visualItems.count) {
removeVIIndex--
}
_missionController.setCurrentPlanViewSeqNum(removeIndex, true)
}
onSelectNextNotReadyItem: selectNextNotReady()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment