Commit f3253d42 authored by Gus Grubba's avatar Gus Grubba

Figuring out rulesets

parent be0901cc
......@@ -24,6 +24,7 @@
#include <airmap/flights.h>
#include <airmap/pilots.h>
#include <airmap/telemetry.h>
#include <airmap/rulesets.h>
using namespace airmap;
......@@ -979,3 +980,74 @@ AirspaceRestrictionProvider* AirMapManager::instantiateRestrictionProvider()
return restrictionManager;
}
AirspaceRulesetsProvider* AirMapManager::instantiateRulesetsProvider()
{
AirMapRulesetsManager* rulesetsManager = new AirMapRulesetsManager(_shared);
connect(rulesetsManager, &AirMapRulesetsManager::error, this, &AirMapManager::_error);
return rulesetsManager;
}
//-----------------------------------------------------------------------------
AirMapRulesetsManager::AirMapRulesetsManager(AirMapSharedState& shared)
: _shared(shared)
{
}
//-----------------------------------------------------------------------------
void AirMapRulesetsManager::setROI(const QGeoCoordinate& center)
{
if (!_shared.client()) {
qCDebug(AirMapManagerLog) << "No AirMap client instance. Not updating Airspace";
return;
}
if (_state != State::Idle) {
qCWarning(AirMapManagerLog) << "AirMapRestrictionManager::updateROI: state not idle";
return;
}
qCDebug(AirMapManagerLog) << "Setting ROI for Rulesets";
_state = State::RetrieveItems;
RuleSets::Search::Parameters params;
params.geometry = Geometry::point(center.latitude(), center.longitude());
std::weak_ptr<LifetimeChecker> isAlive(_instance);
_shared.client()->rulesets().search(params,
[this, isAlive](const RuleSets::Search::Result& result) {
if (!isAlive.lock()) return;
if (_state != State::RetrieveItems) return;
if (result) {
const std::vector<RuleSet>& rulesets = result.value();
qCDebug(AirMapManagerLog)<<"Successful rulesets search. Items:" << rulesets.size();
for (const auto& ruleset : rulesets) {
qDebug() << "------------------------------------------";
qDebug() << "Jurisdiction:" << ruleset.jurisdiction.name.data() << (int)ruleset.jurisdiction.region;
qDebug() << "Name: " << ruleset.name.data();
qDebug() << "Short Name: " << ruleset.short_name.data();
qDebug() << "Description: " << ruleset.description.data();
qDebug() << "Is default: " << ruleset.is_default;
qDebug() << "Applicable to these airspace types:";
for (const auto& airspaceType : ruleset.airspace_types) {
qDebug() << airspaceType.data();
}
qDebug() << "Rules:";
for (const auto& rule : ruleset.rules) {
qDebug() << " --------------------------------------";
qDebug() << " " << rule.short_text.data();
qDebug() << " " << rule.description.data();
qDebug() << " " << rule.display_order;
qDebug() << " " << (int)rule.status;
qDebug() << " Features:";
for (const auto& feature : rule.features) {
qDebug() << " " << feature.name.data();
qDebug() << " " << feature.description.data();
qDebug() << " " << (int)feature.status;
}
}
}
} else {
QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
emit error("Failed to retrieve RuleSets",
QString::fromStdString(result.error().message()), description);
}
emit requestDone(true);
_state = State::Idle;
});
}
......@@ -136,6 +136,27 @@ private:
AirMapSharedState& _shared;
};
/// class to download rulesets from AirMap
class AirMapRulesetsManager : public AirspaceRulesetsProvider, public LifetimeChecker
{
Q_OBJECT
public:
AirMapRulesetsManager (AirMapSharedState& shared);
void setROI (const QGeoCoordinate& center) override;
signals:
void error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);
private:
enum class State {
Idle,
RetrieveItems,
};
State _state = State::Idle;
AirMapSharedState& _shared;
};
/// class to upload a flight
class AirMapFlightManager : public QObject, public LifetimeChecker
......@@ -343,9 +364,9 @@ public:
void setToolbox(QGCToolbox* toolbox) override;
AirspaceManagerPerVehicle* instantiateVehicle(const Vehicle& vehicle) override;
AirspaceRestrictionProvider* instantiateRestrictionProvider() override;
AirspaceManagerPerVehicle* instantiateVehicle (const Vehicle& vehicle) override;
AirspaceRestrictionProvider* instantiateRestrictionProvider () override;
AirspaceRulesetsProvider* instantiateRulesetsProvider () override;
QString name() const override { return "AirMap"; }
......
......@@ -50,6 +50,9 @@ AirspaceManager::~AirspaceManager()
if (_restrictionsProvider) {
delete _restrictionsProvider;
}
if(_rulesetsProvider) {
delete _rulesetsProvider;
}
_polygonRestrictions.clearAndDeleteContents();
_circleRestrictions.clearAndDeleteContents();
}
......@@ -64,6 +67,13 @@ void AirspaceManager::setToolbox(QGCToolbox* toolbox)
connect(_restrictionsProvider, &AirspaceRestrictionProvider::requestDone, this,
&AirspaceManager::_restrictionsUpdated);
}
_rulesetsProvider = instantiateRulesetsProvider();
/*
if (_rulesetsProvider) {
connect(_rulesetsProvider, &AirspaceRulesetsProvider::requestDone, this,
&AirspaceManager::_rulesetsUpdated);
}
*/
}
void AirspaceManager::setROI(const QGeoCoordinate& center, double radiusMeters)
......@@ -78,6 +88,11 @@ void AirspaceManager::_updateToROI()
if (_restrictionsProvider) {
_restrictionsProvider->setROI(_roiCenter, _roiRadius);
}
//-- TODO: We may want to check the distance between this ROI and the last
// to see if we really need to update it.
if(_rulesetsProvider) {
_rulesetsProvider->setROI(_roiCenter);
}
}
void AirspaceManager::_restrictionsUpdated(bool success)
......
......@@ -120,6 +120,24 @@ protected:
QList<CircularAirspaceRestriction*> _circleList;
};
/**
* @class AirspaceRulesetsProvider
* Base class that queries for airspace rulesets
*/
class AirspaceRulesetsProvider : public QObject {
Q_OBJECT
public:
AirspaceRulesetsProvider () = default;
~AirspaceRulesetsProvider () = default;
/**
* Set region of interest that should be queried. When finished, the requestDone() signal will be emmited.
* @param center Center coordinate for ROI
*/
virtual void setROI (const QGeoCoordinate& center) = 0;
signals:
void requestDone(bool success);
};
class AirspaceManagerPerVehicle;
class Vehicle;
......@@ -153,11 +171,15 @@ public:
virtual AirspaceManagerPerVehicle* instantiateVehicle(const Vehicle& vehicle) = 0;
/**
*
* Factory method to create an AirspaceRestrictionProvider object
*/
virtual AirspaceRestrictionProvider* instantiateRestrictionProvider() = 0;
/**
* Factory method to create an AirspaceRulesetsProvider object
*/
virtual AirspaceRulesetsProvider* instantiateRulesetsProvider() = 0;
/**
* Set the ROI for airspace information (restrictions shown in UI)
* @param center Center coordinate for ROI
......@@ -190,10 +212,11 @@ private slots:
private:
void _updateToROI();
AirspaceRestrictionProvider* _restrictionsProvider = nullptr; ///< restrictions that are shown in the UI
AirspaceRestrictionProvider* _restrictionsProvider = nullptr; ///< restrictions that are shown in the UI
AirspaceRulesetsProvider* _rulesetsProvider = nullptr; ///< restrictions that are shown in the UI
QmlObjectListModel _polygonRestrictions; ///< current polygon restrictions
QmlObjectListModel _circleRestrictions; ///< current circle restrictions
QmlObjectListModel _polygonRestrictions; ///< current polygon restrictions
QmlObjectListModel _circleRestrictions; ///< current circle restrictions
QTimer _roiUpdateTimer;
QGeoCoordinate _roiCenter;
......
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