Skip to content

Commit

Permalink
Change plan drawing in Fly View to match Plan View
Browse files Browse the repository at this point in the history
Updated the Fly View's flight plan drawing to match the Plan View,
enabling support for discontinuities in missions (unconnected flight
legs) in the former.

Key changes:
- Fly View now uses simpleFlightPathSegments, the same model used by
  Plan View, to draw flight paths. This enables proper handling of
  disconnected mission legs, which the previous _waypointPath approach
  did not support.
- Flight plan arrows now appear in the same places between the Fly and
  the Plan Views.
- Removed the old Fly View drawing logic and related members and
  properties.
  • Loading branch information
rubenp02 committed Jan 9, 2025
1 parent 93e7e12 commit e2d7ca7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 54 deletions.
11 changes: 0 additions & 11 deletions src/FlightDisplay/FlyViewMap.qml
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,6 @@ FlightMap {
}
}

MapItemView {
model: pipMode ? undefined : _missionController.directionArrows

delegate: MapLineArrow {
fromCoord: object ? object.coordinate1 : undefined
toCoord: object ? object.coordinate2 : undefined
arrowPosition: 2
z: QGroundControl.zOrderWaypointLines
}
}

// Allow custom builds to add map items
CustomMapItems {
map: _root
Expand Down
28 changes: 21 additions & 7 deletions src/FlightMap/MapItems/PlanMapItems.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,35 @@ Item {
_missionLineViewComponent = missionLineViewComponent.createObject(map)
if (_missionLineViewComponent.status === Component.Error)
console.log(_missionLineViewComponent.errorString())
map.addMapItem(_missionLineViewComponent)
map.addMapItemGroup(_missionLineViewComponent)
}

Component.onDestruction: {
_missionLineViewComponent.destroy()
if (_missionLineViewComponent) {
// Must remove MapItemGroup before destruction, otherwise we crash on quit
map.removeMapItemGroup(_missionLineViewComponent)
_missionLineViewComponent.destroy()
}
}

Component {
id: missionLineViewComponent

MapPolyline {
line.width: 3
line.color: "#be781c" // Hack, can't get palette to work in here
z: QGroundControl.zOrderWaypointLines
path: _missionController.waypointPath
MapItemGroup {
MissionLineView {
model: _missionController.simpleFlightPathSegments
}

MapItemView {
model: _missionController.directionArrows

delegate: MapLineArrow {
fromCoord: object ? object.coordinate1 : undefined
toCoord: object ? object.coordinate2 : undefined
arrowPosition: 3
z: QGroundControl.zOrderWaypointLines + 1
}
}
}
}
}
44 changes: 12 additions & 32 deletions src/MissionManager/MissionController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,6 @@ void MissionController::_recalcFlightPathSegments(void)

_missionContainsVTOLTakeoff = false;
_flightPathSegmentHashTable.clear();
_waypointPath.clear();

// Note: Although visual support for _incompleteComplexItemLines is still in the codebase. The support for populating the list is not.
// This is due to the initial implementation being buggy and incomplete with respect to correctly generating the line set.
Expand Down Expand Up @@ -1358,38 +1357,28 @@ void MissionController::_recalcFlightPathSegments(void)
}

lastSegmentVisualItemPair = VisualItemPair(lastFlyThroughVI, visualItem);
if (!_flyView || addDirectionArrow) {
SimpleMissionItem* simpleItem = qobject_cast<SimpleMissionItem*>(lastFlyThroughVI);
bool mavlinkTerrainFrame = simpleItem ? simpleItem->missionItem().frame() == MAV_FRAME_GLOBAL_TERRAIN_ALT : false;
FlightPathSegment* segment = _addFlightPathSegment(oldSegmentTable, lastSegmentVisualItemPair, mavlinkTerrainFrame);
segment->setSpecialVisual(roiActive);
if (addDirectionArrow) {
_directionArrows.append(segment);
}
if (visualItem->isCurrentItem() && _delayedSplitSegmentUpdate) {
_splitSegment = segment;
_delayedSplitSegmentUpdate = false;
signalSplitSegmentChanged = true;
}
lastFlyThroughVI->setSimpleFlighPathSegment(segment);
SimpleMissionItem* simpleItem = qobject_cast<SimpleMissionItem*>(lastFlyThroughVI);
bool mavlinkTerrainFrame = simpleItem ? simpleItem->missionItem().frame() == MAV_FRAME_GLOBAL_TERRAIN_ALT : false;
FlightPathSegment* segment = _addFlightPathSegment(oldSegmentTable, lastSegmentVisualItemPair, mavlinkTerrainFrame);
segment->setSpecialVisual(roiActive);
if (addDirectionArrow) {
_directionArrows.append(segment);
}
if (visualItem->isCurrentItem() && _delayedSplitSegmentUpdate) {
_splitSegment = segment;
_delayedSplitSegmentUpdate = false;
signalSplitSegmentChanged = true;
}
lastFlyThroughVI->setSimpleFlighPathSegment(segment);
}
firstCoordinateNotFound = false;
_waypointPath.append(QVariant::fromValue(visualItem->coordinate()));
lastFlyThroughVI = visualItem;
}
}
}

if (linkStartToHome && homePositionValid) {
_waypointPath.prepend(QVariant::fromValue(_settingsItem->coordinate()));
}

if (linkEndToHome && lastFlyThroughVI != _settingsItem && homePositionValid) {
lastSegmentVisualItemPair = VisualItemPair(lastFlyThroughVI, _settingsItem);
if (_flyView) {
_waypointPath.append(QVariant::fromValue(_settingsItem->coordinate()));
}
FlightPathSegment* segment = _addFlightPathSegment(oldSegmentTable, lastSegmentVisualItemPair, false /* mavlinkTerrainFrame */);
segment->setSpecialVisual(roiActive);
lastFlyThroughVI->setSimpleFlighPathSegment(segment);
Expand Down Expand Up @@ -1433,15 +1422,6 @@ void MissionController::_recalcFlightPathSegments(void)

emit _recalcMissionFlightStatusSignal();

if (_waypointPath.count() == 0) {
// MapPolyLine has a bug where if you change from a path which has elements to an empty path the line drawn
// is not cleared from the map. This hack works around that since it causes the previous lines to be remove
// as then doesn't draw anything on the map.
_waypointPath.append(QVariant::fromValue(QGeoCoordinate(0, 0)));
_waypointPath.append(QVariant::fromValue(QGeoCoordinate(0, 0)));
}

emit waypointPathChanged();
emit recalcTerrainProfile();
if (signalSplitSegmentChanged) {
emit splitSegmentChanged();
Expand Down
4 changes: 0 additions & 4 deletions src/MissionManager/MissionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class MissionController : public PlanElementController

Q_PROPERTY(QmlObjectListModel* visualItems READ visualItems NOTIFY visualItemsChanged)
Q_PROPERTY(QmlObjectListModel* simpleFlightPathSegments READ simpleFlightPathSegments CONSTANT) ///< Used by Plan view only for interactive editing
Q_PROPERTY(QVariantList waypointPath READ waypointPath NOTIFY waypointPathChanged) ///< Used by Fly view only for static display
Q_PROPERTY(QmlObjectListModel* directionArrows READ directionArrows CONSTANT)
Q_PROPERTY(QmlObjectListModel* incompleteComplexItemLines READ incompleteComplexItemLines CONSTANT) ///< Segments which are not yet completed.
Q_PROPERTY(QStringList complexMissionItemNames READ complexMissionItemNames NOTIFY complexMissionItemNamesChanged)
Expand Down Expand Up @@ -226,7 +225,6 @@ class MissionController : public PlanElementController
QmlObjectListModel* simpleFlightPathSegments (void) { return &_simpleFlightPathSegments; }
QmlObjectListModel* directionArrows (void) { return &_directionArrows; }
QmlObjectListModel* incompleteComplexItemLines (void) { return &_incompleteComplexItemLines; }
QVariantList waypointPath (void) { return _waypointPath; }
QStringList complexMissionItemNames (void) const;
QGeoCoordinate plannedHomePosition (void) const;
VisualMissionItem* currentPlanViewItem (void) const { return _currentPlanViewItem; }
Expand Down Expand Up @@ -264,7 +262,6 @@ class MissionController : public PlanElementController

signals:
void visualItemsChanged (void);
void waypointPathChanged (void);
void splitSegmentChanged (void);
void newItemsFromVehicle (void);
void missionDistanceChanged (double missionDistance);
Expand Down Expand Up @@ -373,7 +370,6 @@ private slots:
MissionSettingsItem* _settingsItem = nullptr;
PlanViewSettings* _planViewSettings = nullptr;
QmlObjectListModel _simpleFlightPathSegments;
QVariantList _waypointPath;
QmlObjectListModel _directionArrows;
QmlObjectListModel _incompleteComplexItemLines;
FlightPathSegmentHashTable _flightPathSegmentHashTable;
Expand Down

0 comments on commit e2d7ca7

Please sign in to comment.