From f9fed02a176cd4d80424ec78534aecf530b4bd2d Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Tue, 10 Dec 2019 18:18:43 +0300 Subject: [PATCH] Cancel ROI support plus many big fixes --- src/MissionManager/CorridorScanPlanCreator.cc | 2 +- src/MissionManager/MissionController.cc | 111 +++++++----- src/MissionManager/MissionController.h | 28 ++- .../StructureScanPlanCreator.cc | 2 +- src/MissionManager/SurveyPlanCreator.cc | 2 +- src/PlanView/MissionItemEditor.qml | 2 - src/PlanView/MissionItemStatus.qml | 2 +- src/PlanView/PlanView.qml | 162 +++++------------- 8 files changed, 129 insertions(+), 182 deletions(-) diff --git a/src/MissionManager/CorridorScanPlanCreator.cc b/src/MissionManager/CorridorScanPlanCreator.cc index d08d642b7..9eac0b780 100644 --- a/src/MissionManager/CorridorScanPlanCreator.cc +++ b/src/MissionManager/CorridorScanPlanCreator.cc @@ -24,5 +24,5 @@ void CorridorScanPlanCreator::createPlan(const QGeoCoordinate& mapCenterCoord) VisualMissionItem* takeoffItem = _missionController->insertTakeoffItem(mapCenterCoord, -1); _missionController->insertComplexMissionItem(MissionController::patternCorridorScanName, mapCenterCoord, -1); _missionController->insertLandItem(mapCenterCoord, -1); - _missionController->setCurrentPlanViewIndex(takeoffItem->sequenceNumber(), true); + _missionController->setCurrentPlanViewSeqNum(takeoffItem->sequenceNumber(), true); } diff --git a/src/MissionManager/MissionController.cc b/src/MissionManager/MissionController.cc index c1a72429a..ca905f40b 100644 --- a/src/MissionManager/MissionController.cc +++ b/src/MissionManager/MissionController.cc @@ -68,7 +68,8 @@ MissionController::MissionController(PlanMasterController* masterController, QOb , _inRecalcSequence (false) , _appSettings (qgcApp()->toolbox()->settingsManager()->appSettings()) , _progressPct (0) - , _currentPlanViewIndex (-1) + , _currentPlanViewSeqNum (-1) + , _currentPlanViewVIIndex (-1) , _currentPlanViewItem (nullptr) , _splitSegment (nullptr) { @@ -380,7 +381,7 @@ VisualMissionItem* MissionController::_insertSimpleMissionItemWorker(QGeoCoordin _recalcAllWithCoordinate(coordinate); if (makeCurrentItem) { - setCurrentPlanViewIndex(newItem->sequenceNumber(), true); + setCurrentPlanViewSeqNum(newItem->sequenceNumber(), true); } return newItem; @@ -418,7 +419,7 @@ VisualMissionItem* MissionController::insertTakeoffItem(QGeoCoordinate /*coordin _recalcAll(); if (makeCurrentItem) { - setCurrentPlanViewIndex(newItem->sequenceNumber(), true); + setCurrentPlanViewSeqNum(newItem->sequenceNumber(), true); } return newItem; @@ -437,10 +438,24 @@ VisualMissionItem* MissionController::insertLandItem(QGeoCoordinate coordinate, VisualMissionItem* MissionController::insertROIMissionItem(QGeoCoordinate coordinate, int visualItemIndex, bool makeCurrentItem) { - MAV_CMD command = _controllerVehicle->firmwarePlugin()->supportedMissionCommands().contains(MAV_CMD_DO_SET_ROI_LOCATION) ? - MAV_CMD_DO_SET_ROI_LOCATION : - MAV_CMD_DO_SET_ROI; - return _insertSimpleMissionItemWorker(coordinate, command, visualItemIndex, makeCurrentItem); + SimpleMissionItem* simpleItem = qobject_cast(_insertSimpleMissionItemWorker(coordinate, MAV_CMD_DO_SET_ROI_LOCATION, visualItemIndex, makeCurrentItem)); + + if (!_controllerVehicle->firmwarePlugin()->supportedMissionCommands().contains(MAV_CMD_DO_SET_ROI_LOCATION)) { + simpleItem->setCommand(MAV_CMD_DO_SET_ROI) ; + simpleItem->missionItem().setParam1(MAV_ROI_LOCATION); + } + return simpleItem; +} + +VisualMissionItem* MissionController::insertCancelROIMissionItem(int visualItemIndex, bool makeCurrentItem) +{ + SimpleMissionItem* simpleItem = qobject_cast(_insertSimpleMissionItemWorker(QGeoCoordinate(), MAV_CMD_DO_SET_ROI_NONE, visualItemIndex, makeCurrentItem)); + + if (!_controllerVehicle->firmwarePlugin()->supportedMissionCommands().contains(MAV_CMD_DO_SET_ROI_NONE)) { + simpleItem->setCommand(MAV_CMD_DO_SET_ROI) ; + simpleItem->missionItem().setParam1(MAV_ROI_NONE); + } + return simpleItem; } VisualMissionItem* MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate mapCenterCoordinate, int visualItemIndex, bool makeCurrentItem) @@ -536,7 +551,7 @@ void MissionController::_insertComplexMissionItemWorker(const QGeoCoordinate& ma _recalcAllWithCoordinate(mapCenterCoordinate); if (makeCurrentItem) { - setCurrentPlanViewIndex(complexItem->sequenceNumber(), true); + setCurrentPlanViewSeqNum(complexItem->sequenceNumber(), true); } } @@ -1736,7 +1751,7 @@ void MissionController::_initAllVisualItems(void) emit plannedHomePositionChanged(plannedHomePosition()); if (!_flyView) { - setCurrentPlanViewIndex(0, true); + setCurrentPlanViewSeqNum(0, true); } setDirty(false); @@ -2149,32 +2164,25 @@ void MissionController::_managerRemoveAllComplete(bool error) } } -int MissionController::currentPlanViewIndex(void) const -{ - return _currentPlanViewIndex; -} - -VisualMissionItem* MissionController::currentPlanViewItem(void) const -{ - return _currentPlanViewItem; -} - -void MissionController::setCurrentPlanViewIndex(int sequenceNumber, bool force) +void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force) { - if (_visualItems && (force || sequenceNumber != _currentPlanViewIndex)) { - bool foundLand = false; - int takeoffIndex = -1; - int landIndex = -1; + if (_visualItems && (force || sequenceNumber != _currentPlanViewSeqNum)) { + bool foundLand = false; + int takeoffIndex = -1; + int landIndex = -1; _splitSegment = nullptr; _currentPlanViewItem = nullptr; - _currentPlanViewIndex = -1; + _currentPlanViewSeqNum = -1; + _currentPlanViewVIIndex = -1; _isInsertTakeoffValid = true; _isInsertLandValid = true; + _isROIActive = false; _flyThroughCommandsAllowed = true; - for (int i = 0; i < _visualItems->count(); i++) { - VisualMissionItem* pVI = qobject_cast(_visualItems->get(i)); + for (int viIndex=0; viIndex<_visualItems->count(); viIndex++) { + VisualMissionItem* pVI = qobject_cast(_visualItems->get(viIndex)); + SimpleMissionItem* simpleItem = qobject_cast(pVI); if (sequenceNumber != 0 && pVI->sequenceNumber() <= sequenceNumber) { if (pVI->specifiesCoordinate() && !pVI->isStandaloneCoordinate()) { @@ -2184,12 +2192,11 @@ void MissionController::setCurrentPlanViewIndex(int sequenceNumber, bool force) } if (qobject_cast(pVI)) { - takeoffIndex = i; + takeoffIndex = viIndex; _isInsertTakeoffValid = false; } if (!foundLand) { - SimpleMissionItem* simpleItem = qobject_cast(pVI); if (simpleItem) { switch (simpleItem->mavCommand()) { case MAV_CMD_NAV_LAND: @@ -2197,7 +2204,7 @@ void MissionController::setCurrentPlanViewIndex(int sequenceNumber, bool force) case MAV_CMD_DO_LAND_START: case MAV_CMD_NAV_RETURN_TO_LAUNCH: foundLand = true; - landIndex = i; + landIndex = viIndex; break; default: break; @@ -2206,7 +2213,27 @@ void MissionController::setCurrentPlanViewIndex(int sequenceNumber, bool force) FixedWingLandingComplexItem* fwLanding = qobject_cast(pVI); if (fwLanding) { foundLand = true; - landIndex = i; + landIndex = viIndex; + } + } + } + + // ROI state handling + if (simpleItem) { + if (pVI->sequenceNumber() <= sequenceNumber) { + if (_isROIActive) { + if (simpleItem->mavCommand() == MAV_CMD_DO_SET_ROI_NONE || + (simpleItem->mavCommand() == MAV_CMD_DO_SET_ROI && + simpleItem->missionItem().param1() == MAV_ROI_NONE)) { + _isROIActive = false; + } + } else { + if (simpleItem->mavCommand() == MAV_CMD_DO_SET_ROI_LOCATION || + simpleItem->mavCommand() == MAV_CMD_DO_SET_ROI_WPNEXT_OFFSET || + (simpleItem->mavCommand() == MAV_CMD_DO_SET_ROI && + simpleItem->missionItem().param1() == MAV_ROI_LOCATION)) { + _isROIActive = true; + } } } } @@ -2214,11 +2241,12 @@ void MissionController::setCurrentPlanViewIndex(int sequenceNumber, bool force) if (pVI->sequenceNumber() == sequenceNumber) { pVI->setIsCurrentItem(true); _currentPlanViewItem = pVI; - _currentPlanViewIndex = sequenceNumber; + _currentPlanViewSeqNum = sequenceNumber; + _currentPlanViewVIIndex = viIndex; if (pVI->specifiesCoordinate() && !pVI->isStandaloneCoordinate()) { // Determine split segment used to display line split editing ui. - for (int j=i-1; j>0; j--) { + for (int j=viIndex-1; j>0; j--) { VisualMissionItem* pPrev = qobject_cast(_visualItems->get(j)); if (pPrev->specifiesCoordinate() && !pPrev->isStandaloneCoordinate()) { VisualItemPair splitPair(pPrev, pVI); @@ -2252,11 +2280,13 @@ void MissionController::setCurrentPlanViewIndex(int sequenceNumber, bool force) } } - emit currentPlanViewIndexChanged(); + emit currentPlanViewSeqNumChanged(); + emit currentPlanViewVIIndexChanged(); emit currentPlanViewItemChanged(); emit splitSegmentChanged(); emit isInsertTakeoffValidChanged(); emit isInsertLandValidChanged(); + emit isROIActiveChanged(); emit flyThroughCommandsAllowedChanged(); } } @@ -2349,16 +2379,3 @@ bool MissionController::isEmpty(void) const { return _visualItems->count() <= 1; } - -int MissionController::visualItemIndexFromSequenceNumber(int sequenceNumber) const -{ - for (int i=0; i<_visualItems->count(); i++) { - const VisualMissionItem* vi = _visualItems->value(i); - if (vi->sequenceNumber() == sequenceNumber) { - return i; - } - } - - qWarning() << "MissionController::getVisualItemIndex visual item not found"; - return 0; -} diff --git a/src/MissionManager/MissionController.h b/src/MissionManager/MissionController.h index 310372060..1e6643c08 100644 --- a/src/MissionManager/MissionController.h +++ b/src/MissionManager/MissionController.h @@ -77,7 +77,8 @@ public: Q_PROPERTY(int missionItemCount READ missionItemCount NOTIFY missionItemCountChanged) ///< True mission item command count (only valid in Fly View) Q_PROPERTY(int currentMissionIndex READ currentMissionIndex NOTIFY currentMissionIndexChanged) Q_PROPERTY(int resumeMissionIndex READ resumeMissionIndex NOTIFY resumeMissionIndexChanged) ///< Returns the item index two which a mission should be resumed. -1 indicates resume mission not available. - Q_PROPERTY(int currentPlanViewIndex READ currentPlanViewIndex NOTIFY currentPlanViewIndexChanged) + Q_PROPERTY(int currentPlanViewSeqNum READ currentPlanViewSeqNum NOTIFY currentPlanViewSeqNumChanged) + Q_PROPERTY(int currentPlanViewVIIndex READ currentPlanViewVIIndex NOTIFY currentPlanViewVIIndexChanged) Q_PROPERTY(VisualMissionItem* currentPlanViewItem READ currentPlanViewItem NOTIFY currentPlanViewItemChanged) Q_PROPERTY(double missionDistance READ missionDistance NOTIFY missionDistanceChanged) Q_PROPERTY(double missionTime READ missionTime NOTIFY missionTimeChanged) @@ -94,6 +95,7 @@ public: Q_PROPERTY(QString structureScanComplexItemName READ structureScanComplexItemName CONSTANT) Q_PROPERTY(bool isInsertTakeoffValid MEMBER _isInsertTakeoffValid NOTIFY isInsertTakeoffValidChanged) Q_PROPERTY(bool isInsertLandValid MEMBER _isInsertLandValid NOTIFY isInsertLandValidChanged) + Q_PROPERTY(bool isROIActive MEMBER _isROIActive NOTIFY isROIActiveChanged) Q_PROPERTY(bool flyThroughCommandsAllowed MEMBER _flyThroughCommandsAllowed NOTIFY flyThroughCommandsAllowedChanged) Q_INVOKABLE void removeMissionItem(int index); @@ -126,6 +128,12 @@ public: /// @return Newly created item Q_INVOKABLE VisualMissionItem* insertROIMissionItem(QGeoCoordinate coordinate, int visualItemIndex, bool makeCurrentItem = false); + /// Add a new Cancel ROI mission item to the list + /// @param visualItemIndex: index to insert at, -1 for end of list + /// @param makeCurrentItem: true: Make this item the current item + /// @return Newly created item + Q_INVOKABLE VisualMissionItem* insertCancelROIMissionItem(int visualItemIndex, bool makeCurrentItem = false); + /// Add a new complex mission item to the list /// @param itemName: Name of complex item to create (from complexMissionItemNames) /// @param mapCenterCoordinate: coordinate for current center of map @@ -150,10 +158,7 @@ public: /// Sets a new current mission item (PlanView). /// @param sequenceNumber - index for new item, -1 to clear current item - Q_INVOKABLE void setCurrentPlanViewIndex(int sequenceNumber, bool force); - - /// Returns the index of this item in the visual item list - Q_INVOKABLE int visualItemIndexFromSequenceNumber(int sequenceNumber) const; + Q_INVOKABLE void setCurrentPlanViewSeqNum(int sequenceNumber, bool force); /// Determines if the mission has all data needed to be saved or sent to the vehicle. /// IMPORTANT NOTE: The return value is a VisualMissionItem::ReadForSaveState value. It is an int here to work around @@ -196,7 +201,7 @@ public: QVariantList waypointPath (void) { return _waypointPath; } QStringList complexMissionItemNames (void) const; QGeoCoordinate plannedHomePosition (void) const; - VisualMissionItem* currentPlanViewItem (void) const; + VisualMissionItem* currentPlanViewItem (void) const { return _currentPlanViewItem; } double progressPct (void) const { return _progressPct; } QString surveyComplexItemName (void) const { return patternSurveyName; } QString corridorScanComplexItemName (void) const { return patternCorridorScanName; } @@ -206,7 +211,8 @@ public: int missionItemCount (void) const { return _missionItemCount; } int currentMissionIndex (void) const; int resumeMissionIndex (void) const; - int currentPlanViewIndex (void) const; + int currentPlanViewSeqNum (void) const { return _currentPlanViewSeqNum; } + int currentPlanViewVIIndex (void) const { return _currentPlanViewVIIndex; } double missionDistance (void) const { return _missionFlightStatus.totalDistance; } double missionTime (void) const { return _missionFlightStatus.totalTime; } @@ -249,12 +255,14 @@ signals: void plannedHomePositionChanged (QGeoCoordinate plannedHomePosition); void progressPctChanged (double progressPct); void currentMissionIndexChanged (int currentMissionIndex); - void currentPlanViewIndexChanged (void); + void currentPlanViewSeqNumChanged (void); + void currentPlanViewVIIndexChanged (void); void currentPlanViewItemChanged (void); void missionBoundingCubeChanged (void); void missionItemCountChanged (int missionItemCount); void isInsertTakeoffValidChanged (void); void isInsertLandValidChanged (void); + void isROIActiveChanged (void); void flyThroughCommandsAllowedChanged (void); private slots: @@ -325,7 +333,8 @@ private: MissionFlightStatus_t _missionFlightStatus; AppSettings* _appSettings; double _progressPct; - int _currentPlanViewIndex; + int _currentPlanViewSeqNum; + int _currentPlanViewVIIndex; VisualMissionItem* _currentPlanViewItem; QTimer _updateTimer; QGCGeoBoundingCube _travelBoundingCube; @@ -333,6 +342,7 @@ private: CoordinateVector* _splitSegment; bool _isInsertTakeoffValid = true; bool _isInsertLandValid = true; + bool _isROIActive = false; bool _flyThroughCommandsAllowed = true; static const char* _settingsGroup; diff --git a/src/MissionManager/StructureScanPlanCreator.cc b/src/MissionManager/StructureScanPlanCreator.cc index 25c02615d..9629b8363 100644 --- a/src/MissionManager/StructureScanPlanCreator.cc +++ b/src/MissionManager/StructureScanPlanCreator.cc @@ -24,5 +24,5 @@ void StructureScanPlanCreator::createPlan(const QGeoCoordinate& mapCenterCoord) VisualMissionItem* takeoffItem = _missionController->insertTakeoffItem(mapCenterCoord, -1); _missionController->insertComplexMissionItem(MissionController::patternStructureScanName, mapCenterCoord, -1)->setWizardMode(true); _missionController->insertLandItem(mapCenterCoord, -1); - _missionController->setCurrentPlanViewIndex(takeoffItem->sequenceNumber(), true); + _missionController->setCurrentPlanViewSeqNum(takeoffItem->sequenceNumber(), true); } diff --git a/src/MissionManager/SurveyPlanCreator.cc b/src/MissionManager/SurveyPlanCreator.cc index b4cc2cbfa..2afa81ef8 100644 --- a/src/MissionManager/SurveyPlanCreator.cc +++ b/src/MissionManager/SurveyPlanCreator.cc @@ -25,5 +25,5 @@ void SurveyPlanCreator::createPlan(const QGeoCoordinate& mapCenterCoord) VisualMissionItem* takeoffItem = _missionController->insertTakeoffItem(mapCenterCoord, -1); _missionController->insertComplexMissionItem(MissionController::patternSurveyName, mapCenterCoord, -1); _missionController->insertLandItem(mapCenterCoord, -1); - _missionController->setCurrentPlanViewIndex(takeoffItem->sequenceNumber(), true); + _missionController->setCurrentPlanViewSeqNum(takeoffItem->sequenceNumber(), true); } diff --git a/src/PlanView/MissionItemEditor.qml b/src/PlanView/MissionItemEditor.qml index 870edd678..592280a4d 100644 --- a/src/PlanView/MissionItemEditor.qml +++ b/src/PlanView/MissionItemEditor.qml @@ -30,8 +30,6 @@ Rectangle { signal clicked signal remove - signal insertWaypoint - signal insertComplexItem(string complexItemName) signal selectNextNotReadyItem property var _masterController: masterController diff --git a/src/PlanView/MissionItemStatus.qml b/src/PlanView/MissionItemStatus.qml index 150be13b3..37d5d9fba 100644 --- a/src/PlanView/MissionItemStatus.qml +++ b/src/PlanView/MissionItemStatus.qml @@ -60,7 +60,7 @@ Rectangle { orientation: ListView.Horizontal spacing: 0 clip: true - currentIndex: _missionController.currentPlanViewIndex + currentIndex: _missionController.currentPlanViewSeqNum onCountChanged: { var calcLength = (statusListView.count + 1) * (statusListView.count ? statusListView.contentItem.children[0].width : 1) diff --git a/src/PlanView/PlanView.qml b/src/PlanView/PlanView.qml index 76bfd9fa6..981f6848b 100644 --- a/src/PlanView/PlanView.qml +++ b/src/PlanView/PlanView.qml @@ -68,25 +68,6 @@ Item { return coordinate } - function addComplexItem(complexItemName) { - var next_index = _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex)+1 - if(next_index ==1 && _missionController.visualItems.count >1){ - console.log(next_index, _missionController.visualItems.count) - insertComplexMissionItem(complexItemName, mapCenter(), next_index+1) - } - else if(next_index <= _missionController.visualItems.count){ - insertComplexMissionItem(complexItemName, mapCenter(), next_index) - } - } - - function insertComplexMissionItem(complexItemName, coordinate, index) { - _missionController.insertComplexMissionItem(complexItemName, coordinate, index, true /* makeCurrentItem */) - } - - function insertComplexMissionItemFromKMLOrSHP(complexItemName, file, index) { - _missionController.insertComplexMissionItemFromKMLOrSHP(complexItemName, file, index, true /* makeCurrentItem */) - } - function updateAirspace(reset) { if(_airspaceEnabled) { var coordinateNW = editorMap.toCoordinate(Qt.point(0,0), false /* clipToViewPort */) @@ -195,7 +176,7 @@ Item { Component.onCompleted: { _planMasterController.start(false /* flyView */) - _missionController.setCurrentPlanViewIndex(0, true) + _missionController.setCurrentPlanViewSeqNum(0, true) mainWindow.planMasterControllerPlan = _planMasterController } @@ -258,16 +239,6 @@ Item { mapFitFunctions.fitMapViewportToMissionItems() } - function loadShapeFromSelectedFile() { - fileDialog.title = qsTr("Load Shape") - fileDialog.planFiles = false - fileDialog.selectExisting = true - fileDialog.nameFilters = ShapeFileHelper.fileDialogKMLOrSHPFilters - fileDialog.fileExtension = _appSettings.kmlFileExtension - fileDialog.fileExtension2 = _appSettings.shpFileExtension - fileDialog.openForLoad() - } - function saveKmlToSelectedFile() { if (!checkReadyForSaveUpload(true /* save */)) { return @@ -289,31 +260,38 @@ Item { if (_visualItems && _visualItems.count !== 1) { mapFitFunctions.fitMapViewportToMissionItems() } - _missionController.setCurrentPlanViewIndex(0, true) + _missionController.setCurrentPlanViewSeqNum(0, true) } } - /// Inserts a new simple mission item - /// @param coordinate Location to insert item - /// @param index Insert item at this index - function insertSimpleMissionItem(coordinate, index) { - _missionController.insertSimpleMissionItem(coordinate, index, true /* makeCurrentItem */) + function insertSimpleItemAfterCurrent(coordinate) { + var nextIndex = _missionController.currentPlanViewVIIndex + 1 + _missionController.insertSimpleMissionItem(coordinate, nextIndex, true /* makeCurrentItem */) + } + + function insertROIAfterCurrent(coordinate) { + var nextIndex = _missionController.currentPlanViewVIIndex + 1 + _missionController.insertROIMissionItem(coordinate, nextIndex, true /* makeCurrentItem */) + _addROIOnClick = false } - /// Inserts a new ROI mission item - /// @param coordinate Location to insert item - /// @param index Insert item at this index - function insertROIMissionItem(coordinate, index) { - _missionController.insertROIMissionItem(coordinate, index, true /* makeCurrentItem */) + function insertCancelROIAfterCurrent() { + var nextIndex = _missionController.currentPlanViewVIIndex + 1 + _missionController.insertCancelROIMissionItem(nextIndex, true /* makeCurrentItem */) _addROIOnClick = false } + function insertComplexItemAfterCurrent(complexItemName) { + var nextIndex = _missionController.currentPlanViewVIIndex + 1 + _missionController.insertComplexMissionItem(complexItemName, mapCenter(), nextIndex, true /* makeCurrentItem */) + } + function selectNextNotReady() { var foundCurrent = false for (var i=0; i<_missionController.visualItems.count; i++) { var vmi = _missionController.visualItems.get(i) if (vmi.readyForSaveState === VisualMissionItem.NotReadyForSaveData) { - _missionController.setCurrentPlanViewIndex(vmi.sequenceNumber, true) + _missionController.setCurrentPlanViewSeqNum(vmi.sequenceNumber, true) break } } @@ -337,66 +315,13 @@ Item { } onAcceptedForLoad: { - if (planFiles) { - _planMasterController.loadFromFile(file) - _planMasterController.fitViewportToItems() - _missionController.setCurrentPlanViewIndex(0, true) - } else { - var retList = ShapeFileHelper.determineShapeType(file) - if (retList[0] == ShapeFileHelper.Error) { - mainWindow.showMessageDialog("Error", retList[1]) - } else if (retList[0] == ShapeFileHelper.Polygon) { - var editVehicle = activeVehicle ? activeVehicle : QGroundControl.multiVehicleManager.offlineEditingVehicle - if (editVehicle.fixedWing) { - insertComplexMissionItemFromKMLOrSHP(_missionController.surveyComplexItemName, file, -1) - } else { - polygonSelectPatternFile = file - mainWindow.showComponentDialog(patternPolygonSelectDialog, fileDialog.title, mainWindow.showDialogDefaultWidth, StandardButton.Ok | StandardButton.Cancel) - } - } else if (retList[0] == ShapeFileHelper.Polyline) { - insertComplexMissionItemFromKMLOrSHP(_missionController.corridorScanComplexItemName, file, -1) - } - } + _planMasterController.loadFromFile(file) + _planMasterController.fitViewportToItems() + _missionController.setCurrentPlanViewSeqNum(0, true) close() } } - property string polygonSelectPatternFile - Component { - id: patternPolygonSelectDialog - QGCViewDialog { - function accept() { - var complexItemName - if (surveyRadio.checked) { - complexItemName = _missionController.surveyComplexItemName - } else { - complexItemName = _missionController.structureScanComplexItemName - } - insertComplexMissionItemFromKMLOrSHP(complexItemName, polygonSelectPatternFile, -1) - 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 - text: qsTr("Create which pattern type?") - } - QGCRadioButton { - id: surveyRadio - text: qsTr("Survey") - checked: true - } - QGCRadioButton { - text: qsTr("Structure Scan") - } - } - } - } - Component { id: moveDialog QGCViewDialog { @@ -477,17 +402,10 @@ Item { switch (_editingLayer) { case _layerMission: if (_addWaypointOnClick) { - var next_index = _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex)+1 - if(next_index ==1 && _missionController.visualItems.count >1){ - console.log(next_index, _missionController.visualItems.count) - insertSimpleMissionItem(coordinate, next_index+1) - } - else if(next_index <= _missionController.visualItems.count){ - insertSimpleMissionItem(coordinate, next_index) - } + insertSimpleItemAfterCurrent(coordinate) } else if (_addROIOnClick) { _addROIOnClick = false - insertROIMissionItem(coordinate, _missionController.visualItems.count) + insertROIAfterCurrent(coordinate) } break @@ -505,7 +423,7 @@ Item { model: _editingLayer == _layerMission ? _missionController.visualItems : undefined delegate: MissionItemMapVisual { map: editorMap - onClicked: _missionController.setCurrentPlanViewIndex(sequenceNumber, false) + onClicked: _missionController.setCurrentPlanViewSeqNum(sequenceNumber, false) visible: _editingLayer == _layerMission } } @@ -535,7 +453,9 @@ Item { visible: _editingLayer == _layerMission sourceItem: SplitIndicator { - onClicked: insertSimpleMissionItem(splitSegmentItem.coordinate, _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex)) + onClicked: _missionController.insertSimpleMissionItem(splitSegmentItem.coordinate, + _missionController.currentPlanViewVIIndex, + true /* makeCurrentItem */) } function _updateSplitCoord() { @@ -665,11 +585,11 @@ Item { checked: _addWaypointOnClick }, { - name: qsTr("ROI"), + name: _missionController.isROIActive ? qsTr("Cancel ROI") : qsTr("ROI"), iconSource: "/qmlimages/MapAddMission.svg", buttonEnabled: true, buttonVisible: _isMissionLayer, - toggle: true + toggle: !_missionController.isROIActive }, { name: _singleComplexItem ? _missionController.complexMissionItemNames[0] : qsTr("Pattern"), @@ -718,12 +638,16 @@ Item { break case roiButtonIndex: allAddClickBoolsOff() - _addROIOnClick = checked + if (_missionController.isROIActive) { + insertCancelROIAfterCurrent() + } else { + _addROIOnClick = checked + } break case patternButtonIndex: allAddClickBoolsOff() if (_singleComplexItem) { - addComplexItem(_missionController.complexMissionItemNames[0]) + insertComplexItemAfterCurrent(_missionController.complexMissionItemNames[0]) } break case landButtonIndex: @@ -876,7 +800,7 @@ Item { model: _missionController.visualItems cacheBuffer: Math.max(height * 2, 0) clip: true - currentIndex: _missionController.currentPlanViewIndex + currentIndex: _missionController.currentPlanViewSeqNum highlightMoveDuration: 250 visible: _editingLayer == _layerMission && !planControlColapsed //-- List Elements @@ -886,17 +810,15 @@ Item { missionItem: object width: parent.width readOnly: false - onClicked: _missionController.setCurrentPlanViewIndex(object.sequenceNumber, false) + onClicked: _missionController.setCurrentPlanViewSeqNum(object.sequenceNumber, false) onRemove: { var removeIndex = index _missionController.removeMissionItem(removeIndex) if (removeIndex >= _missionController.visualItems.count) { removeIndex-- } - _missionController.setCurrentPlanViewIndex(removeIndex, true) + _missionController.setCurrentPlanViewSeqNum(removeIndex, true) } - onInsertWaypoint: insertSimpleMissionItem(editorMap.center, index) - onInsertComplexItem: insertComplexMissionItem(complexItemName, editorMap.center, index) onSelectNextNotReadyItem: selectNextNotReady() } } @@ -1009,7 +931,7 @@ Item { message: qsTr("Are you sure you want to remove all mission items and clear the mission from the vehicle?") function accept() { _planMasterController.removeAllFromVehicle() - _missionController.setCurrentPlanViewIndex(0, true) + _missionController.setCurrentPlanViewSeqNum(0, true) hideDialog() } } @@ -1042,7 +964,7 @@ Item { Layout.fillWidth: true onClicked: { - addComplexItem(modelData) + insertComplexItemAfterCurrent(modelData) dropPanel.hide() } } -- 2.22.0