Commit 60bb6cbc authored by Don Gagne's avatar Don Gagne

parent ca4d085e
...@@ -349,7 +349,7 @@ int MissionController::_nextSequenceNumber(void) ...@@ -349,7 +349,7 @@ int MissionController::_nextSequenceNumber(void)
} }
} }
int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i) int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int visualItemIndex)
{ {
int sequenceNumber = _nextSequenceNumber(); int sequenceNumber = _nextSequenceNumber();
SimpleMissionItem * newItem = new SimpleMissionItem(_controllerVehicle, _flyView, this); SimpleMissionItem * newItem = new SimpleMissionItem(_controllerVehicle, _flyView, this);
...@@ -367,13 +367,13 @@ int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i) ...@@ -367,13 +367,13 @@ int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i)
double prevAltitude; double prevAltitude;
int prevAltitudeMode; int prevAltitudeMode;
if (_findPreviousAltitude(i, &prevAltitude, &prevAltitudeMode)) { if (_findPreviousAltitude(visualItemIndex, &prevAltitude, &prevAltitudeMode)) {
newItem->altitude()->setRawValue(prevAltitude); newItem->altitude()->setRawValue(prevAltitude);
newItem->setAltitudeMode(static_cast<QGroundControlQmlGlobal::AltitudeMode>(prevAltitudeMode)); newItem->setAltitudeMode(static_cast<QGroundControlQmlGlobal::AltitudeMode>(prevAltitudeMode));
} }
} }
newItem->setMissionFlightStatus(_missionFlightStatus); newItem->setMissionFlightStatus(_missionFlightStatus);
_visualItems->insert(i, newItem); _visualItems->insert(visualItemIndex, newItem);
// We send the click coordinate through here to be able to set the planned home position from the user click location if needed // We send the click coordinate through here to be able to set the planned home position from the user click location if needed
_recalcAllWithClickCoordinate(coordinate); _recalcAllWithClickCoordinate(coordinate);
...@@ -381,7 +381,7 @@ int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i) ...@@ -381,7 +381,7 @@ int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i)
return newItem->sequenceNumber(); return newItem->sequenceNumber();
} }
int MissionController::insertROIMissionItem(QGeoCoordinate coordinate, int i) int MissionController::insertROIMissionItem(QGeoCoordinate coordinate, int visualItemIndex)
{ {
int sequenceNumber = _nextSequenceNumber(); int sequenceNumber = _nextSequenceNumber();
SimpleMissionItem * newItem = new SimpleMissionItem(_controllerVehicle, _flyView, this); SimpleMissionItem * newItem = new SimpleMissionItem(_controllerVehicle, _flyView, this);
...@@ -395,18 +395,18 @@ int MissionController::insertROIMissionItem(QGeoCoordinate coordinate, int i) ...@@ -395,18 +395,18 @@ int MissionController::insertROIMissionItem(QGeoCoordinate coordinate, int i)
double prevAltitude; double prevAltitude;
int prevAltitudeMode; int prevAltitudeMode;
if (_findPreviousAltitude(i, &prevAltitude, &prevAltitudeMode)) { if (_findPreviousAltitude(visualItemIndex, &prevAltitude, &prevAltitudeMode)) {
newItem->altitude()->setRawValue(prevAltitude); newItem->altitude()->setRawValue(prevAltitude);
newItem->setAltitudeMode(static_cast<QGroundControlQmlGlobal::AltitudeMode>(prevAltitudeMode)); newItem->setAltitudeMode(static_cast<QGroundControlQmlGlobal::AltitudeMode>(prevAltitudeMode));
} }
_visualItems->insert(i, newItem); _visualItems->insert(visualItemIndex, newItem);
_recalcAll(); _recalcAll();
return newItem->sequenceNumber(); return newItem->sequenceNumber();
} }
int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate mapCenterCoordinate, int i) int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate mapCenterCoordinate, int visualItemIndex)
{ {
ComplexMissionItem* newItem; ComplexMissionItem* newItem;
...@@ -425,10 +425,10 @@ int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate ...@@ -425,10 +425,10 @@ int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate
return sequenceNumber; return sequenceNumber;
} }
return _insertComplexMissionItemWorker(newItem, i); return _insertComplexMissionItemWorker(newItem, visualItemIndex);
} }
int MissionController::insertComplexMissionItemFromKMLOrSHP(QString itemName, QString file, int i) int MissionController::insertComplexMissionItemFromKMLOrSHP(QString itemName, QString file, int visualItemIndex)
{ {
ComplexMissionItem* newItem; ComplexMissionItem* newItem;
...@@ -443,10 +443,10 @@ int MissionController::insertComplexMissionItemFromKMLOrSHP(QString itemName, QS ...@@ -443,10 +443,10 @@ int MissionController::insertComplexMissionItemFromKMLOrSHP(QString itemName, QS
return _nextSequenceNumber(); return _nextSequenceNumber();
} }
return _insertComplexMissionItemWorker(newItem, i); return _insertComplexMissionItemWorker(newItem, visualItemIndex);
} }
int MissionController::_insertComplexMissionItemWorker(ComplexMissionItem* complexItem, int i) int MissionController::_insertComplexMissionItemWorker(ComplexMissionItem* complexItem, int visualItemIndex)
{ {
int sequenceNumber = _nextSequenceNumber(); int sequenceNumber = _nextSequenceNumber();
bool surveyStyleItem = qobject_cast<SurveyComplexItem*>(complexItem) || bool surveyStyleItem = qobject_cast<SurveyComplexItem*>(complexItem) ||
...@@ -482,10 +482,10 @@ int MissionController::_insertComplexMissionItemWorker(ComplexMissionItem* compl ...@@ -482,10 +482,10 @@ int MissionController::_insertComplexMissionItemWorker(ComplexMissionItem* compl
complexItem->setSequenceNumber(sequenceNumber); complexItem->setSequenceNumber(sequenceNumber);
_initVisualItem(complexItem); _initVisualItem(complexItem);
if (i == -1) { if (visualItemIndex == -1) {
_visualItems->append(complexItem); _visualItems->append(complexItem);
} else { } else {
_visualItems->insert(i, complexItem); _visualItems->insert(visualItemIndex, complexItem);
} }
//-- Keep track of bounding box changes in complex items //-- Keep track of bounding box changes in complex items
...@@ -2227,3 +2227,16 @@ bool MissionController::isEmpty(void) const ...@@ -2227,3 +2227,16 @@ bool MissionController::isEmpty(void) const
{ {
return _visualItems->count() <= 1; return _visualItems->count() <= 1;
} }
int MissionController::visualItemIndexFromSequenceNumber(int sequenceNumber) const
{
for (int i=0; i<_visualItems->count(); i++) {
const VisualMissionItem* vi = _visualItems->value<VisualMissionItem*>(i);
if (vi->sequenceNumber() == sequenceNumber) {
return i;
}
}
qWarning() << "MissionController::getVisualItemIndex visual item not found";
return 0;
}
...@@ -103,28 +103,28 @@ public: ...@@ -103,28 +103,28 @@ public:
Q_INVOKABLE void removeMissionItem(int index); Q_INVOKABLE void removeMissionItem(int index);
/// Add a new simple mission item to the list /// Add a new simple mission item to the list
/// @param i: index to insert at /// @param visualItemIndex: index to insert at
/// @return Sequence number for new item /// @return Sequence number for new item
Q_INVOKABLE int insertSimpleMissionItem(QGeoCoordinate coordinate, int i); Q_INVOKABLE int insertSimpleMissionItem(QGeoCoordinate coordinate, int visualItemIndex);
/// Add a new ROI mission item to the list /// Add a new ROI mission item to the list
/// @param i: index to insert at /// @param visualItemIndex: index to insert at
/// @return Sequence number for new item /// @return Sequence number for new item
Q_INVOKABLE int insertROIMissionItem(QGeoCoordinate coordinate, int i); Q_INVOKABLE int insertROIMissionItem(QGeoCoordinate coordinate, int visualItemIndex);
/// Add a new complex mission item to the list /// Add a new complex mission item to the list
/// @param itemName: Name of complex item to create (from complexMissionItemNames) /// @param itemName: Name of complex item to create (from complexMissionItemNames)
/// @param mapCenterCoordinate: coordinate for current center of map /// @param mapCenterCoordinate: coordinate for current center of map
/// @param i: index to insert at /// @param visualItemIndex: index to insert at
/// @return Sequence number for new item /// @return Sequence number for new item
Q_INVOKABLE int insertComplexMissionItem(QString itemName, QGeoCoordinate mapCenterCoordinate, int i); Q_INVOKABLE int insertComplexMissionItem(QString itemName, QGeoCoordinate mapCenterCoordinate, int visualItemIndex);
/// Add a new complex mission item to the list /// Add a new complex mission item to the list
/// @param itemName: Name of complex item to create (from complexMissionItemNames) /// @param itemName: Name of complex item to create (from complexMissionItemNames)
/// @param file: kml or shp file to load from shape from /// @param file: kml or shp file to load from shape from
/// @param i: index to insert at, -1 for end /// @param visualItemIndex: index to insert at, -1 for end
/// @return Sequence number for new item /// @return Sequence number for new item
Q_INVOKABLE int insertComplexMissionItemFromKMLOrSHP(QString itemName, QString file, int i); Q_INVOKABLE int insertComplexMissionItemFromKMLOrSHP(QString itemName, QString file, int visualItemIndex);
Q_INVOKABLE void resumeMission(int resumeIndex); Q_INVOKABLE void resumeMission(int resumeIndex);
...@@ -135,6 +135,9 @@ public: ...@@ -135,6 +135,9 @@ public:
/// @param sequenceNumber - index for new item, -1 to clear current item /// @param sequenceNumber - index for new item, -1 to clear current item
Q_INVOKABLE void setCurrentPlanViewIndex(int sequenceNumber, bool force); 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;
/// Determines if the mission has all data needed to be saved or sent to the vehicle. Currently the only case where this /// Determines if the mission has all data needed to be saved or sent to the vehicle. Currently the only case where this
/// would return false is when it is still waiting on terrain data to determine correct altitudes. /// would return false is when it is still waiting on terrain data to determine correct altitudes.
bool readyForSaveSend(void) const; bool readyForSaveSend(void) const;
...@@ -280,7 +283,7 @@ private: ...@@ -280,7 +283,7 @@ private:
void _initLoadedVisualItems(QmlObjectListModel* loadedVisualItems); void _initLoadedVisualItems(QmlObjectListModel* loadedVisualItems);
CoordinateVector* _addWaypointLineSegment(CoordVectHashTable& prevItemPairHashTable, VisualItemPair& pair); CoordinateVector* _addWaypointLineSegment(CoordVectHashTable& prevItemPairHashTable, VisualItemPair& pair);
void _addTimeDistance(bool vtolInHover, double hoverTime, double cruiseTime, double extraTime, double distance, int seqNum); void _addTimeDistance(bool vtolInHover, double hoverTime, double cruiseTime, double extraTime, double distance, int seqNum);
int _insertComplexMissionItemWorker(ComplexMissionItem* complexItem, int i); int _insertComplexMissionItemWorker(ComplexMissionItem* complexItem, int visualItemIndex);
void _warnIfTerrainFrameUsed(void); void _warnIfTerrainFrameUsed(void);
private: private:
......
...@@ -489,7 +489,7 @@ Item { ...@@ -489,7 +489,7 @@ Item {
z: QGroundControl.zOrderWaypointLines + 1 z: QGroundControl.zOrderWaypointLines + 1
sourceItem: SplitIndicator { sourceItem: SplitIndicator {
onClicked: insertSimpleMissionItem(splitSegmentItem.coordinate, _missionController.currentPlanViewIndex) onClicked: insertSimpleMissionItem(splitSegmentItem.coordinate, _missionController.visualItemIndexFromSequenceNumber(_missionController.currentPlanViewIndex))
} }
function _updateSplitCoord() { function _updateSplitCoord() {
......
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