Commit 60bc4330 authored by Gus Grubba's avatar Gus Grubba

Process features

parent 2842dd68
...@@ -186,15 +186,17 @@ void AirMapFlightManager::_uploadFlight() ...@@ -186,15 +186,17 @@ void AirMapFlightManager::_uploadFlight()
params.pilot.id = _pilotID.toStdString(); params.pilot.id = _pilotID.toStdString();
params.start_time = Clock::universal_time() + Minutes{5}; params.start_time = Clock::universal_time() + Minutes{5};
params.end_time = Clock::universal_time() + Hours{2}; // TODO: user-configurable? params.end_time = Clock::universal_time() + Hours{2}; // TODO: user-configurable?
//-- Rules //-- Rules
AirMapRulesetsManager* pRulesMgr = dynamic_cast<AirMapRulesetsManager*>(qgcApp()->toolbox()->airspaceManager()->ruleSets()); AirMapRulesetsManager* pRulesMgr = dynamic_cast<AirMapRulesetsManager*>(qgcApp()->toolbox()->airspaceManager()->ruleSets());
if(pRulesMgr) { if(pRulesMgr) {
foreach(QString ruleset, pRulesMgr->rulesetsIDs()) { for(int rs = 0; rs < pRulesMgr->ruleSets()->count(); rs++) {
params.rulesets.push_back(ruleset.toStdString()); AirMapRuleSet* ruleSet = qobject_cast<AirMapRuleSet*>(pRulesMgr->ruleSets()->get(rs));
//-- If this ruleset is selected
if(ruleSet && ruleSet->selected()) {
params.rulesets.push_back(ruleSet->id().toStdString());
}
} }
} }
// geometry: LineString // geometry: LineString
Geometry::LineString lineString; Geometry::LineString lineString;
for (const auto& qcoord : _flight.coords) { for (const auto& qcoord : _flight.coords) {
......
...@@ -194,8 +194,36 @@ AirMapFlightPlanManager::_uploadFlightPlan() ...@@ -194,8 +194,36 @@ AirMapFlightPlanManager::_uploadFlightPlan()
//-- Rules //-- Rules
AirMapRulesetsManager* pRulesMgr = dynamic_cast<AirMapRulesetsManager*>(qgcApp()->toolbox()->airspaceManager()->ruleSets()); AirMapRulesetsManager* pRulesMgr = dynamic_cast<AirMapRulesetsManager*>(qgcApp()->toolbox()->airspaceManager()->ruleSets());
if(pRulesMgr) { if(pRulesMgr) {
foreach(QString ruleset, pRulesMgr->rulesetsIDs()) { for(int rs = 0; rs < pRulesMgr->ruleSets()->count(); rs++) {
params.rulesets.push_back(ruleset.toStdString()); AirMapRuleSet* ruleSet = qobject_cast<AirMapRuleSet*>(pRulesMgr->ruleSets()->get(rs));
//-- If this ruleset is selected
if(ruleSet && ruleSet->selected()) {
params.rulesets.push_back(ruleSet->id().toStdString());
//-- Features within each rule
for(int r = 0; r < ruleSet->rules()->count(); r++) {
AirMapRule* rule = qobject_cast<AirMapRule*>(ruleSet->rules()->get(r));
if(rule) {
for(int f = 0; f < rule->features()->count(); f++) {
AirMapRuleFeature* feature = qobject_cast<AirMapRuleFeature*>(rule->features()->get(f));
if(feature && feature->value().isValid()) {
switch(feature->type()) {
case AirspaceRuleFeature::Boolean:
params.features[feature->name().toStdString()] = RuleSet::Feature::Value(feature->value().toBool());
break;
case AirspaceRuleFeature::Float:
params.features[feature->name().toStdString()] = RuleSet::Feature::Value(feature->value().toFloat());
break;
case AirspaceRuleFeature::String:
params.features[feature->name().toStdString()] = RuleSet::Feature::Value(feature->value().toString().toStdString());
break;
default:
qCWarning(AirMapManagerLog) << "Unknown type for feature" << feature->name();
}
}
}
}
}
}
} }
} }
//-- Geometry: LineString //-- Geometry: LineString
......
...@@ -9,9 +9,12 @@ ...@@ -9,9 +9,12 @@
#include "AirMapRulesetsManager.h" #include "AirMapRulesetsManager.h"
#include "AirMapManager.h" #include "AirMapManager.h"
#include <QSettings>
using namespace airmap; using namespace airmap;
static const char* kAirMapFeatureGroup = "AirMapFeatureGroup";
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
AirMapRuleFeature::AirMapRuleFeature(QObject* parent) AirMapRuleFeature::AirMapRuleFeature(QObject* parent)
: AirspaceRuleFeature(parent) : AirspaceRuleFeature(parent)
...@@ -23,13 +26,27 @@ AirMapRuleFeature::AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject* ...@@ -23,13 +26,27 @@ AirMapRuleFeature::AirMapRuleFeature(airmap::RuleSet::Feature feature, QObject*
: AirspaceRuleFeature(parent) : AirspaceRuleFeature(parent)
, _feature(feature) , _feature(feature)
{ {
//-- TODO: Read possible saved value from previous runs //-- Restore persisted value (if it exists)
QSettings settings;
settings.beginGroup(kAirMapFeatureGroup);
_value = settings.value(name());
settings.endGroup();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
AirspaceRuleFeature::Type AirspaceRuleFeature::Type
AirMapRuleFeature::type() AirMapRuleFeature::type()
{ {
switch(_feature.type) {
case RuleSet::Feature::Type::boolean:
return AirspaceRuleFeature::Boolean;
case RuleSet::Feature::Type::floating_point:
return AirspaceRuleFeature::Float;
case RuleSet::Feature::Type::string:
return AirspaceRuleFeature::String;
default:
break;
}
return AirspaceRuleFeature::Unknown; return AirspaceRuleFeature::Unknown;
} }
...@@ -37,6 +54,16 @@ AirMapRuleFeature::type() ...@@ -37,6 +54,16 @@ AirMapRuleFeature::type()
AirspaceRuleFeature::Unit AirspaceRuleFeature::Unit
AirMapRuleFeature::unit() AirMapRuleFeature::unit()
{ {
switch(_feature.unit) {
case RuleSet::Feature::Unit::kilograms:
return AirspaceRuleFeature::Kilogram;
case RuleSet::Feature::Unit::meters:
return AirspaceRuleFeature::Meters;
case RuleSet::Feature::Unit::meters_per_sec:
return AirspaceRuleFeature::MetersPerSecond;
default:
break;
}
return AirspaceRuleFeature::UnknownUnit; return AirspaceRuleFeature::UnknownUnit;
} }
...@@ -44,9 +71,32 @@ AirMapRuleFeature::unit() ...@@ -44,9 +71,32 @@ AirMapRuleFeature::unit()
AirspaceRuleFeature::Measurement AirspaceRuleFeature::Measurement
AirMapRuleFeature::measurement() AirMapRuleFeature::measurement()
{ {
switch(_feature.measurement) {
case RuleSet::Feature::Measurement::speed:
return AirspaceRuleFeature::Speed;
case RuleSet::Feature::Measurement::weight:
return AirspaceRuleFeature::Weight;
case RuleSet::Feature::Measurement::distance:
return AirspaceRuleFeature::Distance;
default:
break;
}
return AirspaceRuleFeature::UnknownMeasurement; return AirspaceRuleFeature::UnknownMeasurement;
} }
//-----------------------------------------------------------------------------
void
AirMapRuleFeature::setValue(const QVariant val)
{
_value = val;
//-- Make value persistent
QSettings settings;
settings.beginGroup(kAirMapFeatureGroup);
settings.setValue(name(), _value);
settings.endGroup();
emit valueChanged();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
AirMapRule::AirMapRule(QObject* parent) AirMapRule::AirMapRule(QObject* parent)
: AirspaceRule(parent) : AirspaceRule(parent)
...@@ -98,6 +148,18 @@ AirMapRuleSet::~AirMapRuleSet() ...@@ -98,6 +148,18 @@ AirMapRuleSet::~AirMapRuleSet()
_rules.deleteListAndContents(); _rules.deleteListAndContents();
} }
//-----------------------------------------------------------------------------
void
AirMapRuleSet::setSelected(bool sel)
{
if(_selectionType != AirspaceRuleSet::Required) {
_selected = sel;
} else {
_selected = true;
}
emit selectedChanged();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
AirMapRulesetsManager::AirMapRulesetsManager(AirMapSharedState& shared) AirMapRulesetsManager::AirMapRulesetsManager(AirMapSharedState& shared)
: _shared(shared) : _shared(shared)
...@@ -169,16 +231,17 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center) ...@@ -169,16 +231,17 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center)
for (const auto& rule : ruleset.rules) { for (const auto& rule : ruleset.rules) {
AirMapRule* pRule = new AirMapRule(rule, this); AirMapRule* pRule = new AirMapRule(rule, this);
//-- Iterate Rule Features //-- Iterate Rule Features
for (const auto& feature : rule.features) {
//-- TODO: Rule features don't make sense as they are AirMapRuleFeature* pFeature = new AirMapRuleFeature(feature, this);
pRule->_features.append(pFeature);
}
pRuleSet->_rules.append(pRule); pRuleSet->_rules.append(pRule);
} }
//-- Sort rules by display order //-- Sort rules by display order
std::sort(pRuleSet->_rules.objectList()->begin(), pRuleSet->_rules.objectList()->end(), rules_sort); std::sort(pRuleSet->_rules.objectList()->begin(), pRuleSet->_rules.objectList()->end(), rules_sort);
_ruleSets.append(pRuleSet); _ruleSets.append(pRuleSet);
qCDebug(AirMapManagerLog) << "Adding ruleset" << pRuleSet->name();
/* /*
qCDebug(AirMapManagerLog) << "Adding ruleset" << pRuleSet->name();
qDebug() << "------------------------------------------"; qDebug() << "------------------------------------------";
qDebug() << "Jurisdiction:" << ruleset.jurisdiction.name.data() << (int)ruleset.jurisdiction.region; qDebug() << "Jurisdiction:" << ruleset.jurisdiction.name.data() << (int)ruleset.jurisdiction.region;
qDebug() << "Name: " << ruleset.name.data(); qDebug() << "Name: " << ruleset.name.data();
...@@ -187,20 +250,24 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center) ...@@ -187,20 +250,24 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center)
qDebug() << "Is default: " << ruleset.is_default; qDebug() << "Is default: " << ruleset.is_default;
qDebug() << "Applicable to these airspace types:"; qDebug() << "Applicable to these airspace types:";
for (const auto& airspaceType : ruleset.airspace_types) { for (const auto& airspaceType : ruleset.airspace_types) {
qDebug() << airspaceType.data(); qDebug() << " " << airspaceType.data();
} }
qDebug() << "Rules:"; qDebug() << "Rules:";
for (const auto& rule : ruleset.rules) { for (const auto& rule : ruleset.rules) {
qDebug() << " --------------------------------------"; qDebug() << " --------------------------------------";
qDebug() << " " << rule.short_text.data(); qDebug() << " short_text: " << rule.short_text.data();
qDebug() << " " << rule.description.data(); qDebug() << " description: " << rule.description.data();
qDebug() << " " << rule.display_order; qDebug() << " display_order:" << rule.display_order;
qDebug() << " " << (int)rule.status; qDebug() << " status: " << (int)rule.status;
qDebug() << " ------------------------------";
qDebug() << " Features:"; qDebug() << " Features:";
for (const auto& feature : rule.features) { for (const auto& feature : rule.features) {
qDebug() << " " << feature.name.data(); qDebug() << " name: " << feature.name.data();
qDebug() << " " << feature.description.data(); qDebug() << " description:" << feature.description.data();
qDebug() << " " << (int)feature.status; qDebug() << " status: " << (int)feature.status;
qDebug() << " type: " << (int)feature.type;
qDebug() << " measurement:" << (int)feature.measurement;
qDebug() << " unit: " << (int)feature.unit;
} }
} }
*/ */
...@@ -241,17 +308,3 @@ AirMapRulesetsManager::_selectedChanged() ...@@ -241,17 +308,3 @@ AirMapRulesetsManager::_selectedChanged()
emit selectedRuleSetsChanged(); emit selectedRuleSetsChanged();
//-- TODO: Do whatever it is you do to select a rule //-- TODO: Do whatever it is you do to select a rule
} }
//-----------------------------------------------------------------------------
QStringList
AirMapRulesetsManager::rulesetsIDs()
{
QStringList list;
for(int i = 0; i < _ruleSets.count(); i++) {
AirMapRuleSet* rule = qobject_cast<AirMapRuleSet*>(_ruleSets.get(i));
if(rule && rule->selected()) {
list << rule->id();
}
}
return list;
}
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
QString name () override { return QString::fromStdString(_feature.name); } QString name () override { return QString::fromStdString(_feature.name); }
QString description () override { return QString::fromStdString(_feature.description); } QString description () override { return QString::fromStdString(_feature.description); }
QVariant value () override { return _value; } QVariant value () override { return _value; }
void setValue (const QVariant val) override { _value = val; emit valueChanged(); } void setValue (const QVariant val) override;
private: private:
airmap::RuleSet::Feature _feature; airmap::RuleSet::Feature _feature;
QVariant _value; QVariant _value;
...@@ -49,6 +49,7 @@ private: ...@@ -49,6 +49,7 @@ private:
class AirMapRule : public AirspaceRule class AirMapRule : public AirspaceRule
{ {
Q_OBJECT Q_OBJECT
friend class AirMapRulesetsManager;
public: public:
AirMapRule (QObject* parent = NULL); AirMapRule (QObject* parent = NULL);
...@@ -82,7 +83,7 @@ public: ...@@ -82,7 +83,7 @@ public:
QString shortName () override { return _shortName; } QString shortName () override { return _shortName; }
SelectionType selectionType () override { return _selectionType; } SelectionType selectionType () override { return _selectionType; }
bool selected () override { return _selected; } bool selected () override { return _selected; }
void setSelected (bool sel) override { _selected = sel; emit selectedChanged(); } void setSelected (bool sel) override;
QmlObjectListModel* rules () override { return &_rules; } QmlObjectListModel* rules () override { return &_rules; }
private: private:
QString _id; QString _id;
...@@ -104,14 +105,10 @@ public: ...@@ -104,14 +105,10 @@ public:
bool valid () override { return _valid; } bool valid () override { return _valid; }
QmlObjectListModel* ruleSets () override { return &_ruleSets; } QmlObjectListModel* ruleSets () override { return &_ruleSets; }
QmlObjectListModel* features () override { return &_features; }
QString selectedRuleSets() override; QString selectedRuleSets() override;
void setROI (const QGeoCoordinate& center) override; void setROI (const QGeoCoordinate& center) override;
//-- Selected rules
QStringList rulesetsIDs ();
signals: signals:
void error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails); void error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);
...@@ -127,8 +124,6 @@ private: ...@@ -127,8 +124,6 @@ private:
State _state = State::Idle; State _state = State::Idle;
AirMapSharedState& _shared; AirMapSharedState& _shared;
QmlObjectListModel _ruleSets; QmlObjectListModel _ruleSets;
//-- TODO: Connect to AirMapRuleSet::selectedChanged and rebuild features based on it.
QmlObjectListModel _features;
}; };
...@@ -153,11 +153,9 @@ public: ...@@ -153,11 +153,9 @@ public:
Q_PROPERTY(bool valid READ valid NOTIFY ruleSetsChanged) Q_PROPERTY(bool valid READ valid NOTIFY ruleSetsChanged)
Q_PROPERTY(QString selectedRuleSets READ selectedRuleSets NOTIFY selectedRuleSetsChanged) Q_PROPERTY(QString selectedRuleSets READ selectedRuleSets NOTIFY selectedRuleSetsChanged)
Q_PROPERTY(QmlObjectListModel* ruleSets READ ruleSets NOTIFY ruleSetsChanged) Q_PROPERTY(QmlObjectListModel* ruleSets READ ruleSets NOTIFY ruleSetsChanged)
Q_PROPERTY(QmlObjectListModel* features READ features NOTIFY ruleSetsChanged)
virtual bool valid () = 0; ///< Current ruleset is valid virtual bool valid () = 0; ///< Current ruleset is valid
virtual QmlObjectListModel* ruleSets () = 0; ///< List of AirspaceRuleSet virtual QmlObjectListModel* ruleSets () = 0; ///< List of AirspaceRuleSet
virtual QmlObjectListModel* features () = 0; ///< List of AirspaceRuleFeature (Aggregate of all features of selected rulesets)
virtual QString selectedRuleSets() = 0; ///< All selected rules concatenated into a string virtual QString selectedRuleSets() = 0; ///< All selected rules concatenated into a string
/** /**
* Set region of interest that should be queried. When finished, the rulesChanged() signal will be emmited. * Set region of interest that should be queried. When finished, the rulesChanged() signal will be emmited.
......
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