From e2d7ca727a947b39993808301930b0033f5fedc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20P=C3=A9rez=20Alonso?= Date: Thu, 2 Jan 2025 12:14:46 +0100 Subject: [PATCH] Change plan drawing in Fly View to match Plan View 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. --- src/FlightDisplay/FlyViewMap.qml | 11 ------- src/FlightMap/MapItems/PlanMapItems.qml | 28 ++++++++++++---- src/MissionManager/MissionController.cc | 44 +++++++------------------ src/MissionManager/MissionController.h | 4 --- 4 files changed, 33 insertions(+), 54 deletions(-) diff --git a/src/FlightDisplay/FlyViewMap.qml b/src/FlightDisplay/FlyViewMap.qml index 5aabb6db101..1af4047076d 100644 --- a/src/FlightDisplay/FlyViewMap.qml +++ b/src/FlightDisplay/FlyViewMap.qml @@ -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 diff --git a/src/FlightMap/MapItems/PlanMapItems.qml b/src/FlightMap/MapItems/PlanMapItems.qml index 541ea349bee..03c97084bc6 100644 --- a/src/FlightMap/MapItems/PlanMapItems.qml +++ b/src/FlightMap/MapItems/PlanMapItems.qml @@ -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 + } + } } } } diff --git a/src/MissionManager/MissionController.cc b/src/MissionManager/MissionController.cc index c75b079daec..15c41911bc3 100644 --- a/src/MissionManager/MissionController.cc +++ b/src/MissionManager/MissionController.cc @@ -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. @@ -1358,38 +1357,28 @@ void MissionController::_recalcFlightPathSegments(void) } lastSegmentVisualItemPair = VisualItemPair(lastFlyThroughVI, visualItem); - if (!_flyView || addDirectionArrow) { - SimpleMissionItem* simpleItem = qobject_cast(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(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); @@ -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(); diff --git a/src/MissionManager/MissionController.h b/src/MissionManager/MissionController.h index e1d4917f0a1..ace2ef5d870 100644 --- a/src/MissionManager/MissionController.h +++ b/src/MissionManager/MissionController.h @@ -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) @@ -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; } @@ -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); @@ -373,7 +370,6 @@ private slots: MissionSettingsItem* _settingsItem = nullptr; PlanViewSettings* _planViewSettings = nullptr; QmlObjectListModel _simpleFlightPathSegments; - QVariantList _waypointPath; QmlObjectListModel _directionArrows; QmlObjectListModel _incompleteComplexItemLines; FlightPathSegmentHashTable _flightPathSegmentHashTable;