From 7aa5d4f690787f0437de29938e6563c08ce21b7f Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Fri, 16 Feb 2018 22:30:38 -0500 Subject: [PATCH] Collecting briefing advisories --- src/Airmap/AirMapAdvisoryManager.cc | 10 ++--- src/Airmap/AirMapAdvisoryManager.h | 5 ++- src/Airmap/AirMapFlightPlanManager.cc | 40 +++++++++++++++++-- src/Airmap/AirMapFlightPlanManager.h | 14 +++++-- src/Airmap/AirspaceControl.qml | 4 +- .../AirspaceAdvisoryProvider.h | 4 +- .../AirspaceFlightPlanProvider.h | 39 +++++++++++------- 7 files changed, 83 insertions(+), 33 deletions(-) diff --git a/src/Airmap/AirMapAdvisoryManager.cc b/src/Airmap/AirMapAdvisoryManager.cc index eef4f9bb9..c2f6e59ea 100644 --- a/src/Airmap/AirMapAdvisoryManager.cc +++ b/src/Airmap/AirMapAdvisoryManager.cc @@ -69,7 +69,7 @@ AirMapAdvisoryManager::_requestAdvisories() return; } _valid = false; - _airspaces.clearAndDeleteContents(); + _advisories.clearAndDeleteContents(); Status::GetStatus::Parameters params; params.longitude = _lastRoiCenter.longitude(); params.latitude = _lastRoiCenter.latitude(); @@ -89,13 +89,13 @@ AirMapAdvisoryManager::_requestAdvisories() pAdvisory->_name = QString::fromStdString(advisory.airspace.name()); pAdvisory->_type = (AirspaceAdvisory::AdvisoryType)(int)advisory.airspace.type(); pAdvisory->_color = (AirspaceAdvisoryProvider::AdvisoryColor)(int)advisory.color; - _airspaces.append(pAdvisory); + _advisories.append(pAdvisory); qCDebug(AirMapManagerLog) << "Adding advisory" << pAdvisory->name(); } //-- Sort in order of color (priority) - _airspaces.beginReset(); - std::sort(_airspaces.objectList()->begin(), _airspaces.objectList()->end(), adv_sort); - _airspaces.endReset(); + _advisories.beginReset(); + std::sort(_advisories.objectList()->begin(), _advisories.objectList()->end(), adv_sort); + _advisories.endReset(); _valid = true; } else { qCDebug(AirMapManagerLog) << "Advisories Request Failed"; diff --git a/src/Airmap/AirMapAdvisoryManager.h b/src/Airmap/AirMapAdvisoryManager.h index 37af8400c..4e668f4fd 100644 --- a/src/Airmap/AirMapAdvisoryManager.h +++ b/src/Airmap/AirMapAdvisoryManager.h @@ -30,6 +30,7 @@ class AirMapAdvisory : public AirspaceAdvisory { Q_OBJECT friend class AirMapAdvisoryManager; + friend class AirMapFlightPlanManager; public: AirMapAdvisory (QObject* parent = NULL); QString id () override { return _id; } @@ -55,7 +56,7 @@ public: AirMapAdvisoryManager (AirMapSharedState &shared, QObject *parent = nullptr); bool valid () override { return _valid; } AdvisoryColor airspaceColor () override { return _airspaceColor; } - QmlObjectListModel* airspaces () override { return &_airspaces; } + QmlObjectListModel* advisories () override { return &_advisories; } void setROI (const QGeoCoordinate& center, double radiusMeters) override; signals: void error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails); @@ -66,6 +67,6 @@ private: double _lastRadius; AirMapSharedState& _shared; QGeoCoordinate _lastRoiCenter; - QmlObjectListModel _airspaces; + QmlObjectListModel _advisories; AdvisoryColor _airspaceColor; }; diff --git a/src/Airmap/AirMapFlightPlanManager.cc b/src/Airmap/AirMapFlightPlanManager.cc index b76d443bf..0bab02cde 100644 --- a/src/Airmap/AirMapFlightPlanManager.cc +++ b/src/Airmap/AirMapFlightPlanManager.cc @@ -10,6 +10,7 @@ #include "AirMapFlightPlanManager.h" #include "AirMapManager.h" #include "AirMapRulesetsManager.h" +#include "AirMapAdvisoryManager.h" #include "QGCApplication.h" #include "MissionController.h" @@ -76,7 +77,7 @@ AirMapFlightPlanManager::createFlightPlan(MissionController* missionController) return; } - //-- TODO: Check if there is an ongoing flight plan and do something about it + //-- TODO: Check if there is an ongoing flight plan and do something about it (Delete it?) _createPlan = true; if(!_controller) { _controller = missionController; @@ -120,6 +121,7 @@ AirMapFlightPlanManager::_createFlightPlan() qCDebug(AirMapManagerLog) << "Flight Start:" << _flightStartTime; qCDebug(AirMapManagerLog) << "Flight End: " << _flightEndTime; + //-- Not Yet return; if (_pilotID == "") { @@ -220,6 +222,9 @@ AirMapFlightPlanManager::_uploadFlightPlan() void AirMapFlightPlanManager::_updateFlightPlan() { + //-- TODO: This is broken as the parameters for updating the plan have + // little to do with those used when creating it. + qCDebug(AirMapManagerLog) << "Updating flight plan"; _state = State::FlightUpdate; std::weak_ptr isAlive(_instance); @@ -230,8 +235,6 @@ AirMapFlightPlanManager::_updateFlightPlan() params.authorization = login_token.toStdString(); params.flight_plan.id = _flightPlan.toStdString(); params.flight_plan.pilot.id = _pilotID.toStdString(); - //-- TODO: This is broken as the parameters for updating the plan have - // little to do with those used when creating it. params.flight_plan.altitude_agl.max = _flight.maxAltitude; params.flight_plan.buffer = 2.f; params.flight_plan.takeoff.latitude = _flight.takeoffCoord.latitude(); @@ -280,6 +283,16 @@ AirMapFlightPlanManager::_updateFlightPlan() }); } +//----------------------------------------------------------------------------- +static bool +adv_sort(QObject* a, QObject* b) +{ + AirMapAdvisory* aa = qobject_cast(a); + AirMapAdvisory* bb = qobject_cast(b); + if(!aa || !bb) return false; + return (int)aa->color() > (int)bb->color(); +} + //----------------------------------------------------------------------------- void AirMapFlightPlanManager::_pollBriefing() @@ -298,6 +311,27 @@ AirMapFlightPlanManager::_pollBriefing() if (result) { const FlightPlan::Briefing& briefing = result.value(); qCDebug(AirMapManagerLog) << "Flight polling/briefing response"; + //-- Collect advisories + _valid = false; + _advisories.clearAndDeleteContents(); + const std::vector advisories = briefing.airspace.advisories; + _airspaceColor = (AirspaceAdvisoryProvider::AdvisoryColor)(int)briefing.airspace.color; + for (const auto& advisory : advisories) { + AirMapAdvisory* pAdvisory = new AirMapAdvisory(this); + pAdvisory->_id = QString::fromStdString(advisory.airspace.id()); + pAdvisory->_name = QString::fromStdString(advisory.airspace.name()); + pAdvisory->_type = (AirspaceAdvisory::AdvisoryType)(int)advisory.airspace.type(); + pAdvisory->_color = (AirspaceAdvisoryProvider::AdvisoryColor)(int)advisory.color; + _advisories.append(pAdvisory); + qCDebug(AirMapManagerLog) << "Adding briefing advisory" << pAdvisory->name(); + } + //-- Sort in order of color (priority) + _advisories.beginReset(); + std::sort(_advisories.objectList()->begin(), _advisories.objectList()->end(), adv_sort); + _advisories.endReset(); + _valid = true; + emit advisoryChanged(); + //-- Evaluate briefing status bool rejected = false; bool accepted = false; bool pending = false; diff --git a/src/Airmap/AirMapFlightPlanManager.h b/src/Airmap/AirMapFlightPlanManager.h index 2ae9adc43..5afbcaa60 100644 --- a/src/Airmap/AirMapFlightPlanManager.h +++ b/src/Airmap/AirMapFlightPlanManager.h @@ -26,10 +26,13 @@ class AirMapFlightPlanManager : public AirspaceFlightPlanProvider, public Lifeti public: AirMapFlightPlanManager(AirMapSharedState& shared, QObject *parent = nullptr); - PermitStatus flightPermitStatus () const override { return _flightPermitStatus; } - QString flightID () { return _flightPlan; } - QDateTime flightStartTime () const override { return _flightStartTime; } - QDateTime flightEndTime () const override { return _flightEndTime; } + PermitStatus flightPermitStatus () const override { return _flightPermitStatus; } + QString flightID () { return _flightPlan; } + QDateTime flightStartTime () const override { return _flightStartTime; } + QDateTime flightEndTime () const override { return _flightEndTime; } + bool valid () override { return _valid; } + QmlObjectListModel* advisories () override { return &_advisories; } + AirspaceAdvisoryProvider::AdvisoryColor airspaceColor () override { return _airspaceColor; } void createFlightPlan (MissionController* missionController) override; void setFlightStartTime (QDateTime start) override; @@ -76,9 +79,12 @@ private: QString _pilotID; ///< Pilot ID in the form "auth0|abc123" MissionController* _controller = nullptr; bool _createPlan = true; + bool _valid = false; QDateTime _flightStartTime; QDateTime _flightEndTime; + QmlObjectListModel _advisories; + AirspaceAdvisoryProvider::AdvisoryColor _airspaceColor; AirspaceFlightPlanProvider::PermitStatus _flightPermitStatus = AirspaceFlightPlanProvider::PermitUnknown; }; diff --git a/src/Airmap/AirspaceControl.qml b/src/Airmap/AirspaceControl.qml index b5e4a0d5c..7643c2fb9 100644 --- a/src/Airmap/AirspaceControl.qml +++ b/src/Airmap/AirspaceControl.qml @@ -166,7 +166,7 @@ Item { color: _textColor } QGCLabel { - text: _validAdvisories ? QGroundControl.airspaceManager.advisories.airspaces.count + qsTr(" Advisories") : "" + text: _validAdvisories ? QGroundControl.airspaceManager.advisories.advisories.count + qsTr(" Advisories") : "" color: _textColor visible: _validAdvisories font.pointSize: ScreenTools.smallFontPointSize @@ -317,7 +317,7 @@ Item { anchors.right: parent.right anchors.left: parent.left Repeater { - model: _validAdvisories ? QGroundControl.airspaceManager.advisories.airspaces : [] + model: _validAdvisories ? QGroundControl.airspaceManager.advisories.advisories : [] delegate: AirspaceRegulation { regTitle: object.typeStr regText: object.name diff --git a/src/AirspaceManagement/AirspaceAdvisoryProvider.h b/src/AirspaceManagement/AirspaceAdvisoryProvider.h index 68be491b4..4946a4c0e 100644 --- a/src/AirspaceManagement/AirspaceAdvisoryProvider.h +++ b/src/AirspaceManagement/AirspaceAdvisoryProvider.h @@ -39,11 +39,11 @@ public: Q_PROPERTY(bool valid READ valid NOTIFY advisoryChanged) Q_PROPERTY(AdvisoryColor airspaceColor READ airspaceColor NOTIFY advisoryChanged) - Q_PROPERTY(QmlObjectListModel* airspaces READ airspaces NOTIFY advisoryChanged) + Q_PROPERTY(QmlObjectListModel* advisories READ advisories NOTIFY advisoryChanged) virtual bool valid () = 0; ///< Current data is valid virtual AdvisoryColor airspaceColor () = 0; ///< Aispace overall color - virtual QmlObjectListModel* airspaces () = 0; ///< List of AirspaceAdvisory + virtual QmlObjectListModel* advisories () = 0; ///< List of AirspaceAdvisory /** * Set region of interest that should be queried. When finished, the advisoryChanged() signal will be emmited. diff --git a/src/AirspaceManagement/AirspaceFlightPlanProvider.h b/src/AirspaceManagement/AirspaceFlightPlanProvider.h index 2d11d7037..1462e4192 100644 --- a/src/AirspaceManagement/AirspaceFlightPlanProvider.h +++ b/src/AirspaceManagement/AirspaceFlightPlanProvider.h @@ -14,6 +14,9 @@ * Create and maintain a flight plan */ +#include "AirspaceAdvisoryProvider.h" +#include "QmlObjectListModel.h" + #include #include @@ -34,24 +37,30 @@ public: Q_ENUM(PermitStatus) - AirspaceFlightPlanProvider (QObject *parent = nullptr); - virtual ~AirspaceFlightPlanProvider () {} - - Q_PROPERTY(PermitStatus flightPermitStatus READ flightPermitStatus NOTIFY flightPermitStatusChanged) ///< State of flight permission - Q_PROPERTY(QDateTime flightStartTime READ flightStartTime WRITE setFlightStartTime NOTIFY flightStartTimeChanged) ///< Start of flight - Q_PROPERTY(QDateTime flightEndTime READ flightEndTime WRITE setFlightEndTime NOTIFY flightEndTimeChanged) ///< End of flight + AirspaceFlightPlanProvider (QObject *parent = nullptr); + virtual ~AirspaceFlightPlanProvider () {} - virtual PermitStatus flightPermitStatus () const { return PermitUnknown; } - virtual QDateTime flightStartTime () const = 0; - virtual QDateTime flightEndTime () const = 0; + Q_PROPERTY(PermitStatus flightPermitStatus READ flightPermitStatus NOTIFY flightPermitStatusChanged) ///< State of flight permission + Q_PROPERTY(QDateTime flightStartTime READ flightStartTime WRITE setFlightStartTime NOTIFY flightStartTimeChanged) ///< Start of flight + Q_PROPERTY(QDateTime flightEndTime READ flightEndTime WRITE setFlightEndTime NOTIFY flightEndTimeChanged) ///< End of flight + Q_PROPERTY(bool valid READ valid NOTIFY advisoryChanged) + Q_PROPERTY(QmlObjectListModel* advisories READ advisories NOTIFY advisoryChanged) + Q_PROPERTY(AirspaceAdvisoryProvider::AdvisoryColor airspaceColor READ airspaceColor NOTIFY advisoryChanged) - virtual void setFlightStartTime (QDateTime start) = 0; - virtual void setFlightEndTime (QDateTime end) = 0; - virtual void createFlightPlan (MissionController* missionController) = 0; + virtual PermitStatus flightPermitStatus () const { return PermitUnknown; } + virtual QDateTime flightStartTime () const = 0; + virtual QDateTime flightEndTime () const = 0; + virtual bool valid () = 0; ///< Current advisory list is valid + virtual QmlObjectListModel* advisories () = 0; ///< List of AirspaceAdvisory + virtual AirspaceAdvisoryProvider::AdvisoryColor airspaceColor () = 0; ///< Aispace overall color + virtual void setFlightStartTime (QDateTime start) = 0; + virtual void setFlightEndTime (QDateTime end) = 0; + virtual void createFlightPlan (MissionController* missionController) = 0; signals: - void flightPermitStatusChanged (); - void flightStartTimeChanged (); - void flightEndTimeChanged (); + void flightPermitStatusChanged (); + void flightStartTimeChanged (); + void flightEndTimeChanged (); + void advisoryChanged (); }; -- 2.22.0