diff --git a/src/Airmap/AirMapManager.cc b/src/Airmap/AirMapManager.cc index c6df502a46b42286aef7b291a3075c8aded680d3..7b41ea3da1574e8560b4380276e2051d067842dc 100644 --- a/src/Airmap/AirMapManager.cc +++ b/src/Airmap/AirMapManager.cc @@ -36,7 +36,7 @@ AirMapManager::AirMapManager(QGCApplication* app, QGCToolbox* toolbox) _logger = std::make_shared(); qt::register_types(); // TODO: still needed?s _logger->logging_category().setEnabled(QtDebugMsg, true); - _logger->logging_category().setEnabled(QtInfoMsg, true); + _logger->logging_category().setEnabled(QtInfoMsg, true); _logger->logging_category().setEnabled(QtWarningMsg, true); _dispatchingLogger = std::make_shared(_logger); connect(&_shared, &AirMapSharedState::error, this, &AirMapManager::_error); diff --git a/src/Airmap/AirMapRulesetsManager.cc b/src/Airmap/AirMapRulesetsManager.cc index cb98e88bf94ed4925cb133e7f008a21ea52045db..10d5c189cec77d686f9f57c147de68f06fd4cf95 100644 --- a/src/Airmap/AirMapRulesetsManager.cc +++ b/src/Airmap/AirMapRulesetsManager.cc @@ -37,6 +37,9 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center) return; } qCDebug(AirMapManagerLog) << "Setting ROI for Rulesets"; + _defaultIndex = 0; + _currentIndex = 0; + _valid = false; _rules.clearAndDeleteContents(); _state = State::RetrieveItems; RuleSets::Search::Parameters params; @@ -48,14 +51,33 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center) if (_state != State::RetrieveItems) return; if (result) { const std::vector rules = result.value(); - qCDebug(AirMapManagerLog)<<"Successful rulesets search. Items:" << rules.size(); + qCDebug(AirMapManagerLog) << "Successful rulesets search. Items:" << rules.size(); for (const auto& ruleset : rules) { AirMapRule* pRule = new AirMapRule(this); pRule->_id = QString::fromStdString(ruleset.id); pRule->_name = QString::fromStdString(ruleset.short_name); pRule->_description = QString::fromStdString(ruleset.description); pRule->_isDefault = ruleset.is_default; + if(pRule->_isDefault) { + _defaultIndex = _rules.count(); + //-- TODO: This should be persistent and if the new incoming set has this + // rule, it should point to it. + _currentIndex = _defaultIndex; + } + switch(ruleset.selection_type) { + case RuleSet::SelectionType::pickone: + pRule->_selectionType = AirspaceRule::pickone; + break; + case RuleSet::SelectionType::required: + pRule->_selectionType = AirspaceRule::required; + break; + default: + case RuleSet::SelectionType::optional: + pRule->_selectionType = AirspaceRule::optional; + break; + } _rules.append(pRule); + qCDebug(AirMapManagerLog) << "Adding rule" << pRule->name(); /* qDebug() << "------------------------------------------"; qDebug() << "Jurisdiction:" << ruleset.jurisdiction.name.data() << (int)ruleset.jurisdiction.region; @@ -83,12 +105,36 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center) } */ } + _valid = true; } 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 error("Failed to retrieve RuleSets", QString::fromStdString(result.error().message()), description); } _state = State::Idle; emit rulesChanged(); }); } + +//----------------------------------------------------------------------------- +QString +AirMapRulesetsManager::defaultRule() +{ + if(_defaultIndex < _rules.count()) { + AirMapRule* rule = qobject_cast(_rules.get(_defaultIndex)); + if(rule) { + return rule->name(); + } + } + return QString(); +} + +//----------------------------------------------------------------------------- +void +AirMapRulesetsManager::setCurrentIndex(int index) +{ + _currentIndex = index; + //-- TODO: Do whatever it is you do to select a rule + + + emit currentIndexChanged(); +} diff --git a/src/Airmap/AirMapRulesetsManager.h b/src/Airmap/AirMapRulesetsManager.h index a25458fb35e000d282149eba86030e427be4bde0..565d13d54b7b5f4c1de1ae7006a251ac8144d802 100644 --- a/src/Airmap/AirMapRulesetsManager.h +++ b/src/Airmap/AirMapRulesetsManager.h @@ -29,15 +29,17 @@ class AirMapRule : public AirspaceRule friend class AirMapRulesetsManager; public: AirMapRule (QObject* parent = NULL); - QString id () override { return _id; } - QString description () override { return _description; } - bool isDefault () override { return _isDefault; } - QString name () override { return _name; } + QString id () override { return _id; } + QString description () override { return _description; } + bool isDefault () override { return _isDefault; } + QString name () override { return _name; } + SelectionType selectionType () override { return _selectionType; } private: - QString _id; - QString _description; - bool _isDefault; - QString _name; + QString _id; + QString _description; + bool _isDefault; + QString _name; + SelectionType _selectionType; }; //----------------------------------------------------------------------------- @@ -47,9 +49,14 @@ class AirMapRulesetsManager : public AirspaceRulesetsProvider, public LifetimeCh public: AirMapRulesetsManager (AirMapSharedState& shared); - bool valid () override { return _valid; } - QmlObjectListModel* rules () override { return &_rules; } - void setROI (const QGeoCoordinate& center) override; + bool valid () override { return _valid; } + QmlObjectListModel* rules () override { return &_rules; } + QString defaultRule () override; + int defaultIndex() override { return _defaultIndex; } + int currentIndex() override { return _currentIndex; } + void setCurrentIndex(int index) override; + + void setROI (const QGeoCoordinate& center) override; signals: void error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails); @@ -59,6 +66,8 @@ private: Idle, RetrieveItems, }; + int _defaultIndex; + int _currentIndex; bool _valid; State _state = State::Idle; AirMapSharedState& _shared; diff --git a/src/Airmap/AirMapWeatherInformation.cc b/src/Airmap/AirMapWeatherInformation.cc index 4c6fdc978d0d28da9578e79042233b561b580107..90f7e77d4da63f3352d71251946ab1ad527751f5 100644 --- a/src/Airmap/AirMapWeatherInformation.cc +++ b/src/Airmap/AirMapWeatherInformation.cc @@ -58,7 +58,7 @@ AirMapWeatherInformation::_requestWeatherUpdate(const QGeoCoordinate& coordinate const Status::Weather& weather = result.value().weather; _valid = true; _icon = QStringLiteral("qrc:/airmapweather/") + QString::fromStdString(weather.icon) + QStringLiteral(".svg"); - qCDebug(AirMapManagerLog) << "Weather Info: " << _valid << _icon; + qCDebug(AirMapManagerLog) << "Weather Info: " << _valid << "Icon:" << QString::fromStdString(weather.icon) << "Condition:" << QString::fromStdString(weather.condition) << "Temp:" << weather.temperature; } else { _valid = false; qCDebug(AirMapManagerLog) << "Request Weather Failed"; diff --git a/src/Airmap/AirspaceControl.qml b/src/Airmap/AirspaceControl.qml index df936210b8c79efee6b7dff8f932228cfff440a9..5446cf6d3a27feb5f84deb073efd88dc4967a456 100644 --- a/src/Airmap/AirspaceControl.qml +++ b/src/Airmap/AirspaceControl.qml @@ -4,6 +4,7 @@ import QtQuick.Controls.Styles 1.4 import QtQuick.Dialogs 1.2 import QtQuick.Layouts 1.2 import QtQml 2.2 +import QtGraphicalEffects 1.0 import QGroundControl 1.0 import QGroundControl.ScreenTools 1.0 @@ -22,6 +23,7 @@ Item { property bool showColapse: true property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle + property bool validRules: _activeVehicle ? _activeVehicle.airspaceController.rulesets.valid : false readonly property real _radius: ScreenTools.defaultFontPixelWidth * 0.5 readonly property color _colorOrange: "#d75e0d" @@ -232,6 +234,13 @@ Item { source: "qrc:/airmap/pencil.svg" color: _colorWhite anchors.centerIn: parent + MouseArea { + anchors.fill: parent + onClicked: { + rootLoader.sourceComponent = ruleSelector + mainWindow.disableToolbar() + } + } } } Rectangle { @@ -242,9 +251,10 @@ Item { Layout.fillWidth: true QGCLabel { id: regLabel - text: qsTr("FAA-107, Airmap") + text: validRules ? _activeVehicle.airspaceController.rulesets.rules.get(currentIndex).name : qsTr("None") color: _colorWhite anchors.centerIn: parent + property int currentIndex: validRules ? _activeVehicle.airspaceController.rulesets.currentIndex : 0 } } } @@ -281,4 +291,106 @@ Item { } } } + //--------------------------------------------------------------- + //-- Rule Selector + Component { + id: ruleSelector + Rectangle { + width: mainWindow.width + height: mainWindow.height + color: Qt.rgba(0,0,0,0.1) + MouseArea { + anchors.fill: parent + onClicked: { + mainWindow.enableToolbar() + rootLoader.sourceComponent = null + } + } + Rectangle { + id: ruleSelectorShadow + anchors.fill: ruleSelectorRect + radius: ruleSelectorRect.radius + color: qgcPal.window + visible: false + } + DropShadow { + anchors.fill: ruleSelectorShadow + visible: ruleSelectorRect.visible + horizontalOffset: 4 + verticalOffset: 4 + radius: 32.0 + samples: 65 + color: Qt.rgba(0,0,0,0.75) + source: ruleSelectorShadow + } + Rectangle { + id: ruleSelectorRect + color: qgcPal.window + width: rulesCol.width + ScreenTools.defaultFontPixelWidth + height: rulesCol.height + ScreenTools.defaultFontPixelHeight + radius: ScreenTools.defaultFontPixelWidth + anchors.centerIn: parent + Column { + id: rulesCol + spacing: ScreenTools.defaultFontPixelHeight * 0.5 + anchors.centerIn: parent + //-- Regulations + Rectangle { + color: qgcPal.windowShade + height: rulesTitle.height + ScreenTools.defaultFontPixelHeight + width: parent.width * 0.95 + radius: _radius + anchors.horizontalCenter: parent.horizontalCenter + QGCLabel { + id: rulesTitle + text: qsTr("Airspace Regulation Options") + anchors.centerIn: parent + } + } + Flickable { + clip: true + width: ScreenTools.defaultFontPixelWidth * 30 + height: ScreenTools.defaultFontPixelHeight * 14 + contentHeight: rulesetCol.height + flickableDirection: Flickable.VerticalFlick + Column { + id: rulesetCol + spacing: ScreenTools.defaultFontPixelHeight * 0.5 + anchors.right: parent.right + anchors.left: parent.left + QGCLabel { + text: qsTr("PICK ONE REGULATION") + font.pointSize: ScreenTools.smallFontPointSize + anchors.horizontalCenter: parent.horizontalCenter + } + Repeater { + model: validRules ? _activeVehicle.airspaceController.rulesets.rules : [] + delegate: Row { + spacing: ScreenTools.defaultFontPixelWidth + anchors.right: parent.right + anchors.rightMargin: ScreenTools.defaultFontPixelWidth + anchors.left: parent.left + anchors.leftMargin: ScreenTools.defaultFontPixelWidth + Rectangle { + width: ScreenTools.defaultFontPixelWidth * 0.75 + height: ScreenTools.defaultFontPixelHeight + color: qgcPal.colorGreen + anchors.verticalCenter: parent.verticalCenter + } + QGCLabel { + text: object.name + font.pointSize: ScreenTools.smallFontPointSize + anchors.verticalCenter: parent.verticalCenter + } + } + } + } + } + } + } + Component.onCompleted: { + mainWindow.disableToolbar() + } + } + } } diff --git a/src/AirspaceManagement/AirspaceController.cc b/src/AirspaceManagement/AirspaceController.cc index fe8230453aff95e7b5e060e7a30f0ed8b5bf3993..02648932db3e30c15789ed5c4958e74e1e9bd980 100644 --- a/src/AirspaceManagement/AirspaceController.cc +++ b/src/AirspaceManagement/AirspaceController.cc @@ -59,7 +59,7 @@ AirspaceController::advisories() } AirspaceRulesetsProvider* -AirspaceController::rules() +AirspaceController::rulesets() { - return _manager->rules(); + return _manager->rulesets(); } diff --git a/src/AirspaceManagement/AirspaceController.h b/src/AirspaceManagement/AirspaceController.h index a892f20a3e031376c1ecb5523b2af7e6d18bc39b..8e6d6a43999601e88c9eb8e30c4acd1454ebc20a 100644 --- a/src/AirspaceManagement/AirspaceController.h +++ b/src/AirspaceManagement/AirspaceController.h @@ -30,7 +30,7 @@ public: Q_PROPERTY(QString providerName READ providerName CONSTANT) Q_PROPERTY(AirspaceWeatherInfoProvider* weatherInfo READ weatherInfo CONSTANT) Q_PROPERTY(AirspaceAdvisoryProvider* advisories READ advisories CONSTANT) - Q_PROPERTY(AirspaceRulesetsProvider* rules READ rules CONSTANT) + Q_PROPERTY(AirspaceRulesetsProvider* rulesets READ rulesets CONSTANT) Q_INVOKABLE void setROI (QGeoCoordinate center, double radius); @@ -39,7 +39,7 @@ public: QString providerName(); AirspaceWeatherInfoProvider* weatherInfo (); AirspaceAdvisoryProvider* advisories (); - AirspaceRulesetsProvider* rules (); + AirspaceRulesetsProvider* rulesets (); private: AirspaceManager* _manager; diff --git a/src/AirspaceManagement/AirspaceManager.cc b/src/AirspaceManagement/AirspaceManager.cc index 3b9a5c0c098d3d17faba5b5873516984553811a1..1a94762e94c206c2966988c14bd11dd12919b415 100644 --- a/src/AirspaceManagement/AirspaceManager.cc +++ b/src/AirspaceManagement/AirspaceManager.cc @@ -76,14 +76,12 @@ void AirspaceManager::setROI(const QGeoCoordinate& center, double radiusMeters) void AirspaceManager::_updateToROI() { - /* if (_restrictionsProvider) { _restrictionsProvider->setROI(_roiCenter, _roiRadius); } if(_rulesetsProvider) { _rulesetsProvider->setROI(_roiCenter); } - */ if(_weatherProvider) { _weatherProvider->setROI(_roiCenter); } diff --git a/src/AirspaceManagement/AirspaceManager.h b/src/AirspaceManagement/AirspaceManager.h index fe12bec820f9fa4a804bef2ed694548c610048a9..349298402773332ca41addd10adef35e73d189e5 100644 --- a/src/AirspaceManagement/AirspaceManager.h +++ b/src/AirspaceManagement/AirspaceManager.h @@ -90,7 +90,7 @@ public: QmlObjectListModel* circularRestrictions () { return &_circleRestrictions; } AirspaceWeatherInfoProvider* weatherInfo () { return _weatherProvider; } AirspaceAdvisoryProvider* advisories () { return _advisories; } - AirspaceRulesetsProvider* rules () { return _rulesetsProvider; } + AirspaceRulesetsProvider* rulesets () { return _rulesetsProvider; } void setToolbox(QGCToolbox* toolbox) override; diff --git a/src/AirspaceManagement/AirspaceRulesetsProvider.h b/src/AirspaceManagement/AirspaceRulesetsProvider.h index 3d5aac35762b6b8955c00ea5ff5b8c0d213552f2..6ddd4c2700963b3b9d108dc600595730de33c761 100644 --- a/src/AirspaceManagement/AirspaceRulesetsProvider.h +++ b/src/AirspaceManagement/AirspaceRulesetsProvider.h @@ -25,17 +25,28 @@ class AirspaceRule : public QObject { Q_OBJECT public: + + enum SelectionType { + pickone, ///< One rule from the overall set needs to be picked. + required, ///< Satisfying the RuleSet is required. + optional ///< Satisfying the RuleSet is not required. + }; + + Q_ENUM(SelectionType) + AirspaceRule(QObject* parent = NULL); - Q_PROPERTY(QString id READ id CONSTANT) - Q_PROPERTY(QString name READ name CONSTANT) - Q_PROPERTY(QString description READ description CONSTANT) - Q_PROPERTY(bool isDefault READ isDefault CONSTANT) + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QString description READ description CONSTANT) + Q_PROPERTY(bool isDefault READ isDefault CONSTANT) + Q_PROPERTY(SelectionType selectionType READ selectionType CONSTANT) - virtual QString id () = 0; - virtual QString description () = 0; - virtual bool isDefault () = 0; - virtual QString name () = 0; + virtual QString id () = 0; + virtual QString description () = 0; + virtual bool isDefault () = 0; + virtual QString name () = 0; + virtual SelectionType selectionType () = 0; }; //----------------------------------------------------------------------------- @@ -45,12 +56,18 @@ public: AirspaceRulesetsProvider (QObject* parent = NULL); ~AirspaceRulesetsProvider () = default; - Q_PROPERTY(bool valid READ valid NOTIFY rulesChanged) - Q_PROPERTY(QmlObjectListModel* rules READ rules NOTIFY rulesChanged) - - virtual bool valid () = 0; ///< Current ruleset is valid - virtual QmlObjectListModel* rules () = 0; ///< List of AirspaceRule + Q_PROPERTY(bool valid READ valid NOTIFY rulesChanged) + Q_PROPERTY(QString defaultRule READ defaultRule NOTIFY rulesChanged) + Q_PROPERTY(int defaultIndex READ defaultIndex NOTIFY rulesChanged) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_PROPERTY(QmlObjectListModel* rules READ rules NOTIFY rulesChanged) + virtual bool valid () = 0; ///< Current ruleset is valid + virtual QmlObjectListModel* rules () = 0; ///< List of AirspaceRule + virtual QString defaultRule () = 0; ///< AirspaceRule::name + virtual int defaultIndex() = 0; ///< Index into rules (QmlObjectListModel) + virtual int currentIndex() = 0; ///< User selected index into rules (QmlObjectListModel) + virtual void setCurrentIndex(int index) = 0; ///< Select a rule /** * Set region of interest that should be queried. When finished, the rulesChanged() signal will be emmited. * @param center Center coordinate for ROI @@ -59,5 +76,6 @@ public: signals: void rulesChanged (); + void currentIndexChanged (); };