Commit 7aa5d4f6 authored by Gus Grubba's avatar Gus Grubba

Collecting briefing advisories

parent f4731132
...@@ -69,7 +69,7 @@ AirMapAdvisoryManager::_requestAdvisories() ...@@ -69,7 +69,7 @@ AirMapAdvisoryManager::_requestAdvisories()
return; return;
} }
_valid = false; _valid = false;
_airspaces.clearAndDeleteContents(); _advisories.clearAndDeleteContents();
Status::GetStatus::Parameters params; Status::GetStatus::Parameters params;
params.longitude = _lastRoiCenter.longitude(); params.longitude = _lastRoiCenter.longitude();
params.latitude = _lastRoiCenter.latitude(); params.latitude = _lastRoiCenter.latitude();
...@@ -89,13 +89,13 @@ AirMapAdvisoryManager::_requestAdvisories() ...@@ -89,13 +89,13 @@ AirMapAdvisoryManager::_requestAdvisories()
pAdvisory->_name = QString::fromStdString(advisory.airspace.name()); pAdvisory->_name = QString::fromStdString(advisory.airspace.name());
pAdvisory->_type = (AirspaceAdvisory::AdvisoryType)(int)advisory.airspace.type(); pAdvisory->_type = (AirspaceAdvisory::AdvisoryType)(int)advisory.airspace.type();
pAdvisory->_color = (AirspaceAdvisoryProvider::AdvisoryColor)(int)advisory.color; pAdvisory->_color = (AirspaceAdvisoryProvider::AdvisoryColor)(int)advisory.color;
_airspaces.append(pAdvisory); _advisories.append(pAdvisory);
qCDebug(AirMapManagerLog) << "Adding advisory" << pAdvisory->name(); qCDebug(AirMapManagerLog) << "Adding advisory" << pAdvisory->name();
} }
//-- Sort in order of color (priority) //-- Sort in order of color (priority)
_airspaces.beginReset(); _advisories.beginReset();
std::sort(_airspaces.objectList()->begin(), _airspaces.objectList()->end(), adv_sort); std::sort(_advisories.objectList()->begin(), _advisories.objectList()->end(), adv_sort);
_airspaces.endReset(); _advisories.endReset();
_valid = true; _valid = true;
} else { } else {
qCDebug(AirMapManagerLog) << "Advisories Request Failed"; qCDebug(AirMapManagerLog) << "Advisories Request Failed";
......
...@@ -30,6 +30,7 @@ class AirMapAdvisory : public AirspaceAdvisory ...@@ -30,6 +30,7 @@ class AirMapAdvisory : public AirspaceAdvisory
{ {
Q_OBJECT Q_OBJECT
friend class AirMapAdvisoryManager; friend class AirMapAdvisoryManager;
friend class AirMapFlightPlanManager;
public: public:
AirMapAdvisory (QObject* parent = NULL); AirMapAdvisory (QObject* parent = NULL);
QString id () override { return _id; } QString id () override { return _id; }
...@@ -55,7 +56,7 @@ public: ...@@ -55,7 +56,7 @@ public:
AirMapAdvisoryManager (AirMapSharedState &shared, QObject *parent = nullptr); AirMapAdvisoryManager (AirMapSharedState &shared, QObject *parent = nullptr);
bool valid () override { return _valid; } bool valid () override { return _valid; }
AdvisoryColor airspaceColor () override { return _airspaceColor; } AdvisoryColor airspaceColor () override { return _airspaceColor; }
QmlObjectListModel* airspaces () override { return &_airspaces; } QmlObjectListModel* advisories () override { return &_advisories; }
void setROI (const QGeoCoordinate& center, double radiusMeters) override; void setROI (const QGeoCoordinate& center, double radiusMeters) override;
signals: signals:
void error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails); void error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);
...@@ -66,6 +67,6 @@ private: ...@@ -66,6 +67,6 @@ private:
double _lastRadius; double _lastRadius;
AirMapSharedState& _shared; AirMapSharedState& _shared;
QGeoCoordinate _lastRoiCenter; QGeoCoordinate _lastRoiCenter;
QmlObjectListModel _airspaces; QmlObjectListModel _advisories;
AdvisoryColor _airspaceColor; AdvisoryColor _airspaceColor;
}; };
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "AirMapFlightPlanManager.h" #include "AirMapFlightPlanManager.h"
#include "AirMapManager.h" #include "AirMapManager.h"
#include "AirMapRulesetsManager.h" #include "AirMapRulesetsManager.h"
#include "AirMapAdvisoryManager.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "MissionController.h" #include "MissionController.h"
...@@ -76,7 +77,7 @@ AirMapFlightPlanManager::createFlightPlan(MissionController* missionController) ...@@ -76,7 +77,7 @@ AirMapFlightPlanManager::createFlightPlan(MissionController* missionController)
return; 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; _createPlan = true;
if(!_controller) { if(!_controller) {
_controller = missionController; _controller = missionController;
...@@ -120,6 +121,7 @@ AirMapFlightPlanManager::_createFlightPlan() ...@@ -120,6 +121,7 @@ AirMapFlightPlanManager::_createFlightPlan()
qCDebug(AirMapManagerLog) << "Flight Start:" << _flightStartTime; qCDebug(AirMapManagerLog) << "Flight Start:" << _flightStartTime;
qCDebug(AirMapManagerLog) << "Flight End: " << _flightEndTime; qCDebug(AirMapManagerLog) << "Flight End: " << _flightEndTime;
//-- Not Yet
return; return;
if (_pilotID == "") { if (_pilotID == "") {
...@@ -220,6 +222,9 @@ AirMapFlightPlanManager::_uploadFlightPlan() ...@@ -220,6 +222,9 @@ AirMapFlightPlanManager::_uploadFlightPlan()
void void
AirMapFlightPlanManager::_updateFlightPlan() 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"; qCDebug(AirMapManagerLog) << "Updating flight plan";
_state = State::FlightUpdate; _state = State::FlightUpdate;
std::weak_ptr<LifetimeChecker> isAlive(_instance); std::weak_ptr<LifetimeChecker> isAlive(_instance);
...@@ -230,8 +235,6 @@ AirMapFlightPlanManager::_updateFlightPlan() ...@@ -230,8 +235,6 @@ AirMapFlightPlanManager::_updateFlightPlan()
params.authorization = login_token.toStdString(); params.authorization = login_token.toStdString();
params.flight_plan.id = _flightPlan.toStdString(); params.flight_plan.id = _flightPlan.toStdString();
params.flight_plan.pilot.id = _pilotID.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.altitude_agl.max = _flight.maxAltitude;
params.flight_plan.buffer = 2.f; params.flight_plan.buffer = 2.f;
params.flight_plan.takeoff.latitude = _flight.takeoffCoord.latitude(); params.flight_plan.takeoff.latitude = _flight.takeoffCoord.latitude();
...@@ -280,6 +283,16 @@ AirMapFlightPlanManager::_updateFlightPlan() ...@@ -280,6 +283,16 @@ AirMapFlightPlanManager::_updateFlightPlan()
}); });
} }
//-----------------------------------------------------------------------------
static bool
adv_sort(QObject* a, QObject* b)
{
AirMapAdvisory* aa = qobject_cast<AirMapAdvisory*>(a);
AirMapAdvisory* bb = qobject_cast<AirMapAdvisory*>(b);
if(!aa || !bb) return false;
return (int)aa->color() > (int)bb->color();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapFlightPlanManager::_pollBriefing() AirMapFlightPlanManager::_pollBriefing()
...@@ -298,6 +311,27 @@ AirMapFlightPlanManager::_pollBriefing() ...@@ -298,6 +311,27 @@ AirMapFlightPlanManager::_pollBriefing()
if (result) { if (result) {
const FlightPlan::Briefing& briefing = result.value(); const FlightPlan::Briefing& briefing = result.value();
qCDebug(AirMapManagerLog) << "Flight polling/briefing response"; qCDebug(AirMapManagerLog) << "Flight polling/briefing response";
//-- Collect advisories
_valid = false;
_advisories.clearAndDeleteContents();
const std::vector<Status::Advisory> 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 rejected = false;
bool accepted = false; bool accepted = false;
bool pending = false; bool pending = false;
......
...@@ -26,10 +26,13 @@ class AirMapFlightPlanManager : public AirspaceFlightPlanProvider, public Lifeti ...@@ -26,10 +26,13 @@ class AirMapFlightPlanManager : public AirspaceFlightPlanProvider, public Lifeti
public: public:
AirMapFlightPlanManager(AirMapSharedState& shared, QObject *parent = nullptr); AirMapFlightPlanManager(AirMapSharedState& shared, QObject *parent = nullptr);
PermitStatus flightPermitStatus () const override { return _flightPermitStatus; } PermitStatus flightPermitStatus () const override { return _flightPermitStatus; }
QString flightID () { return _flightPlan; } QString flightID () { return _flightPlan; }
QDateTime flightStartTime () const override { return _flightStartTime; } QDateTime flightStartTime () const override { return _flightStartTime; }
QDateTime flightEndTime () const override { return _flightEndTime; } 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 createFlightPlan (MissionController* missionController) override;
void setFlightStartTime (QDateTime start) override; void setFlightStartTime (QDateTime start) override;
...@@ -76,9 +79,12 @@ private: ...@@ -76,9 +79,12 @@ private:
QString _pilotID; ///< Pilot ID in the form "auth0|abc123" QString _pilotID; ///< Pilot ID in the form "auth0|abc123"
MissionController* _controller = nullptr; MissionController* _controller = nullptr;
bool _createPlan = true; bool _createPlan = true;
bool _valid = false;
QDateTime _flightStartTime; QDateTime _flightStartTime;
QDateTime _flightEndTime; QDateTime _flightEndTime;
QmlObjectListModel _advisories;
AirspaceAdvisoryProvider::AdvisoryColor _airspaceColor;
AirspaceFlightPlanProvider::PermitStatus _flightPermitStatus = AirspaceFlightPlanProvider::PermitUnknown; AirspaceFlightPlanProvider::PermitStatus _flightPermitStatus = AirspaceFlightPlanProvider::PermitUnknown;
}; };
......
...@@ -166,7 +166,7 @@ Item { ...@@ -166,7 +166,7 @@ Item {
color: _textColor color: _textColor
} }
QGCLabel { QGCLabel {
text: _validAdvisories ? QGroundControl.airspaceManager.advisories.airspaces.count + qsTr(" Advisories") : "" text: _validAdvisories ? QGroundControl.airspaceManager.advisories.advisories.count + qsTr(" Advisories") : ""
color: _textColor color: _textColor
visible: _validAdvisories visible: _validAdvisories
font.pointSize: ScreenTools.smallFontPointSize font.pointSize: ScreenTools.smallFontPointSize
...@@ -317,7 +317,7 @@ Item { ...@@ -317,7 +317,7 @@ Item {
anchors.right: parent.right anchors.right: parent.right
anchors.left: parent.left anchors.left: parent.left
Repeater { Repeater {
model: _validAdvisories ? QGroundControl.airspaceManager.advisories.airspaces : [] model: _validAdvisories ? QGroundControl.airspaceManager.advisories.advisories : []
delegate: AirspaceRegulation { delegate: AirspaceRegulation {
regTitle: object.typeStr regTitle: object.typeStr
regText: object.name regText: object.name
......
...@@ -39,11 +39,11 @@ public: ...@@ -39,11 +39,11 @@ public:
Q_PROPERTY(bool valid READ valid NOTIFY advisoryChanged) Q_PROPERTY(bool valid READ valid NOTIFY advisoryChanged)
Q_PROPERTY(AdvisoryColor airspaceColor READ airspaceColor 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 bool valid () = 0; ///< Current data is valid
virtual AdvisoryColor airspaceColor () = 0; ///< Aispace overall color 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. * Set region of interest that should be queried. When finished, the advisoryChanged() signal will be emmited.
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
* Create and maintain a flight plan * Create and maintain a flight plan
*/ */
#include "AirspaceAdvisoryProvider.h"
#include "QmlObjectListModel.h"
#include <QObject> #include <QObject>
#include <QDateTime> #include <QDateTime>
...@@ -34,24 +37,30 @@ public: ...@@ -34,24 +37,30 @@ public:
Q_ENUM(PermitStatus) Q_ENUM(PermitStatus)
AirspaceFlightPlanProvider (QObject *parent = nullptr); AirspaceFlightPlanProvider (QObject *parent = nullptr);
virtual ~AirspaceFlightPlanProvider () {} 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
virtual PermitStatus flightPermitStatus () const { return PermitUnknown; } Q_PROPERTY(PermitStatus flightPermitStatus READ flightPermitStatus NOTIFY flightPermitStatusChanged) ///< State of flight permission
virtual QDateTime flightStartTime () const = 0; Q_PROPERTY(QDateTime flightStartTime READ flightStartTime WRITE setFlightStartTime NOTIFY flightStartTimeChanged) ///< Start of flight
virtual QDateTime flightEndTime () const = 0; 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 PermitStatus flightPermitStatus () const { return PermitUnknown; }
virtual void setFlightEndTime (QDateTime end) = 0; virtual QDateTime flightStartTime () const = 0;
virtual void createFlightPlan (MissionController* missionController) = 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: signals:
void flightPermitStatusChanged (); void flightPermitStatusChanged ();
void flightStartTimeChanged (); void flightStartTimeChanged ();
void flightEndTimeChanged (); void flightEndTimeChanged ();
void advisoryChanged ();
}; };
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