Commit 32ed1ec0 authored by Gus Grubba's avatar Gus Grubba

Make all argument to AirMap queries based on what the screen shows (bounding...

Make all argument to AirMap queries based on what the screen shows (bounding rectangle and/or radius), respecting the limits imposed by AirMap.
parent 60bc4330
...@@ -573,6 +573,7 @@ HEADERS += \ ...@@ -573,6 +573,7 @@ HEADERS += \
src/QmlControls/QGCImageProvider.h \ src/QmlControls/QGCImageProvider.h \
src/QmlControls/QGroundControlQmlGlobal.h \ src/QmlControls/QGroundControlQmlGlobal.h \
src/QmlControls/QmlObjectListModel.h \ src/QmlControls/QmlObjectListModel.h \
src/QmlControls/QGCGeoBoundingCube.h \
src/QmlControls/RCChannelMonitorController.h \ src/QmlControls/RCChannelMonitorController.h \
src/QmlControls/ScreenToolsController.h \ src/QmlControls/ScreenToolsController.h \
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h \ src/QtLocationPlugin/QMLControl/QGCMapEngineManager.h \
...@@ -766,6 +767,7 @@ SOURCES += \ ...@@ -766,6 +767,7 @@ SOURCES += \
src/QmlControls/QGCImageProvider.cc \ src/QmlControls/QGCImageProvider.cc \
src/QmlControls/QGroundControlQmlGlobal.cc \ src/QmlControls/QGroundControlQmlGlobal.cc \
src/QmlControls/QmlObjectListModel.cc \ src/QmlControls/QmlObjectListModel.cc \
src/QmlControls/QGCGeoBoundingCube.cc \
src/QmlControls/RCChannelMonitorController.cc \ src/QmlControls/RCChannelMonitorController.cc \
src/QmlControls/ScreenToolsController.cc \ src/QmlControls/ScreenToolsController.cc \
src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc \ src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc \
......
...@@ -22,7 +22,6 @@ using namespace airmap; ...@@ -22,7 +22,6 @@ using namespace airmap;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
AirMapAdvisory::AirMapAdvisory(QObject* parent) AirMapAdvisory::AirMapAdvisory(QObject* parent)
: AirspaceAdvisory(parent) : AirspaceAdvisory(parent)
, _radius(0.0)
{ {
} }
...@@ -30,19 +29,17 @@ AirMapAdvisory::AirMapAdvisory(QObject* parent) ...@@ -30,19 +29,17 @@ AirMapAdvisory::AirMapAdvisory(QObject* parent)
AirMapAdvisoryManager::AirMapAdvisoryManager(AirMapSharedState& shared, QObject *parent) AirMapAdvisoryManager::AirMapAdvisoryManager(AirMapSharedState& shared, QObject *parent)
: AirspaceAdvisoryProvider(parent) : AirspaceAdvisoryProvider(parent)
, _valid(false) , _valid(false)
, _lastRadius(0.0)
, _shared(shared) , _shared(shared)
{ {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapAdvisoryManager::setROI(const QGeoCoordinate& center, double radiusMeters) AirMapAdvisoryManager::setROI(const QGCGeoBoundingCube& roi)
{ {
//-- If first time or we've moved more than ADVISORY_UPDATE_DISTANCE, ask for updates. //-- If first time or we've moved more than ADVISORY_UPDATE_DISTANCE, ask for updates.
if(!_lastRoiCenter.isValid() || _lastRoiCenter.distanceTo(center) > ADVISORY_UPDATE_DISTANCE || _lastRadius != radiusMeters) { if(!_lastROI.isValid() || _lastROI.pointNW.distanceTo(roi.pointNW) > ADVISORY_UPDATE_DISTANCE || _lastROI.pointSE.distanceTo(roi.pointSE) > ADVISORY_UPDATE_DISTANCE) {
_lastRadius = radiusMeters; _lastROI = roi;
_lastRoiCenter = center;
_requestAdvisories(); _requestAdvisories();
} }
} }
...@@ -71,11 +68,13 @@ AirMapAdvisoryManager::_requestAdvisories() ...@@ -71,11 +68,13 @@ AirMapAdvisoryManager::_requestAdvisories()
_valid = false; _valid = false;
_advisories.clearAndDeleteContents(); _advisories.clearAndDeleteContents();
Status::GetStatus::Parameters params; Status::GetStatus::Parameters params;
params.longitude = _lastRoiCenter.longitude(); params.longitude = _lastROI.center().longitude();
params.latitude = _lastRoiCenter.latitude(); params.latitude = _lastROI.center().latitude();
params.types = Airspace::Type::all; params.types = Airspace::Type::all;
params.weather = false; params.weather = false;
params.buffer = _lastRadius; double diagonal = _lastROI.pointNW.distanceTo(_lastROI.pointSE);
params.buffer = fmax(fmin(diagonal, 10000.0), 500.0);
params.flight_date_time = Clock::universal_time();
std::weak_ptr<LifetimeChecker> isAlive(_instance); std::weak_ptr<LifetimeChecker> isAlive(_instance);
_shared.client()->status().get_status_by_point(params, [this, isAlive](const Status::GetStatus::Result& result) { _shared.client()->status().get_status_by_point(params, [this, isAlive](const Status::GetStatus::Result& result) {
if (!isAlive.lock()) return; if (!isAlive.lock()) return;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "AirspaceAdvisoryProvider.h" #include "AirspaceAdvisoryProvider.h"
#include "AirMapSharedState.h" #include "AirMapSharedState.h"
#include <QGeoCoordinate> #include "QGCGeoBoundingCube.h"
#include "airmap/status.h" #include "airmap/status.h"
...@@ -53,20 +53,19 @@ class AirMapAdvisoryManager : public AirspaceAdvisoryProvider, public LifetimeCh ...@@ -53,20 +53,19 @@ class AirMapAdvisoryManager : public AirspaceAdvisoryProvider, public LifetimeCh
{ {
Q_OBJECT Q_OBJECT
public: 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* advisories () override { return &_advisories; } QmlObjectListModel* advisories () override { return &_advisories; }
void setROI (const QGeoCoordinate& center, double radiusMeters) override; void setROI (const QGCGeoBoundingCube& roi) 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);
private: private:
void _requestAdvisories(); void _requestAdvisories ();
private: private:
bool _valid; bool _valid;
double _lastRadius;
AirMapSharedState& _shared; AirMapSharedState& _shared;
QGeoCoordinate _lastRoiCenter; QGCGeoBoundingCube _lastROI;
QmlObjectListModel _advisories; QmlObjectListModel _advisories;
AdvisoryColor _airspaceColor; AdvisoryColor _airspaceColor;
}; };
...@@ -106,12 +106,7 @@ AirMapFlightPlanManager::_createFlightPlan() ...@@ -106,12 +106,7 @@ AirMapFlightPlanManager::_createFlightPlan()
QGCGeoBoundingCube bc = _controller->travelBoundingCube(); QGCGeoBoundingCube bc = _controller->travelBoundingCube();
_flight.maxAltitude = fmax(bc.pointNW.altitude(), bc.pointSE.altitude()); _flight.maxAltitude = fmax(bc.pointNW.altitude(), bc.pointSE.altitude());
_flight.takeoffCoord = _controller->takeoffCoordinate(); _flight.takeoffCoord = _controller->takeoffCoordinate();
_flight.coords.append(QGeoCoordinate(bc.pointNW.latitude(), bc.pointNW.longitude(), _flight.maxAltitude)); _flight.coords = bc.polygon2D();
_flight.coords.append(QGeoCoordinate(bc.pointNW.latitude(), bc.pointSE.longitude(), _flight.maxAltitude));
_flight.coords.append(QGeoCoordinate(bc.pointSE.latitude(), bc.pointSE.longitude(), _flight.maxAltitude));
_flight.coords.append(QGeoCoordinate(bc.pointSE.latitude(), bc.pointNW.longitude(), _flight.maxAltitude));
_flight.coords.append(QGeoCoordinate(bc.pointNW.latitude(), bc.pointNW.longitude(), _flight.maxAltitude));
if(_flightStartTime.isNull() || _flightStartTime < QDateTime::currentDateTime()) { if(_flightStartTime.isNull() || _flightStartTime < QDateTime::currentDateTime()) {
_flightStartTime = QDateTime::currentDateTime().addSecs(5 * 60); _flightStartTime = QDateTime::currentDateTime().addSecs(5 * 60);
emit flightStartTimeChanged(); emit flightStartTimeChanged();
...@@ -382,6 +377,11 @@ AirMapFlightPlanManager::_pollBriefing() ...@@ -382,6 +377,11 @@ AirMapFlightPlanManager::_pollBriefing()
//-- Iterate Rules //-- Iterate Rules
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
for (const auto& feature : rule.features) {
AirMapRuleFeature* pFeature = new AirMapRuleFeature(feature, this);
pRule->_features.append(pFeature);
}
pRuleSet->_rules.append(pRule); pRuleSet->_rules.append(pRule);
} }
//-- Sort rules by relevance order //-- Sort rules by relevance order
......
...@@ -37,8 +37,8 @@ AirMapManager::AirMapManager(QGCApplication* app, QGCToolbox* toolbox) ...@@ -37,8 +37,8 @@ AirMapManager::AirMapManager(QGCApplication* app, QGCToolbox* toolbox)
{ {
_logger = std::make_shared<qt::Logger>(); _logger = std::make_shared<qt::Logger>();
qt::register_types(); // TODO: still needed? qt::register_types(); // TODO: still needed?
_logger->logging_category().setEnabled(QtDebugMsg, false); _logger->logging_category().setEnabled(QtDebugMsg, false);
_logger->logging_category().setEnabled(QtInfoMsg, false); _logger->logging_category().setEnabled(QtInfoMsg, false);
_logger->logging_category().setEnabled(QtWarningMsg, true); _logger->logging_category().setEnabled(QtWarningMsg, true);
_dispatchingLogger = std::make_shared<qt::DispatchingLogger>(_logger); _dispatchingLogger = std::make_shared<qt::DispatchingLogger>(_logger);
connect(&_shared, &AirMapSharedState::error, this, &AirMapManager::_error); connect(&_shared, &AirMapSharedState::error, this, &AirMapManager::_error);
......
...@@ -20,25 +20,26 @@ using namespace airmap; ...@@ -20,25 +20,26 @@ using namespace airmap;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
AirMapRestrictionManager::AirMapRestrictionManager(AirMapSharedState& shared) AirMapRestrictionManager::AirMapRestrictionManager(AirMapSharedState& shared)
: _shared(shared) : _shared(shared)
, _lastRadius(0.0)
{ {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapRestrictionManager::setROI(const QGeoCoordinate& center, double radiusMeters) AirMapRestrictionManager::setROI(const QGCGeoBoundingCube& roi)
{ {
//-- If first time or we've moved more than ADVISORY_UPDATE_DISTANCE, ask for updates. //-- If first time or we've moved more than RESTRICTION_UPDATE_DISTANCE, ask for updates.
if(!_lastRoiCenter.isValid() || _lastRoiCenter.distanceTo(center) > RESTRICTION_UPDATE_DISTANCE || _lastRadius != radiusMeters) { if(!_lastROI.isValid() || _lastROI.pointNW.distanceTo(roi.pointNW) > RESTRICTION_UPDATE_DISTANCE || _lastROI.pointSE.distanceTo(roi.pointSE) > RESTRICTION_UPDATE_DISTANCE) {
_lastRadius = radiusMeters; //-- No more than 40000 km^2
_lastRoiCenter = center; if(roi.area() < 40000.0) {
_requestRestrictions(center, radiusMeters); _lastROI = roi;
_requestRestrictions(roi);
}
} }
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapRestrictionManager::_requestRestrictions(const QGeoCoordinate& center, double radiusMeters) AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi)
{ {
if (!_shared.client()) { if (!_shared.client()) {
qCDebug(AirMapManagerLog) << "No AirMap client instance. Not updating Airspace"; qCDebug(AirMapManagerLog) << "No AirMap client instance. Not updating Airspace";
...@@ -48,14 +49,22 @@ AirMapRestrictionManager::_requestRestrictions(const QGeoCoordinate& center, dou ...@@ -48,14 +49,22 @@ AirMapRestrictionManager::_requestRestrictions(const QGeoCoordinate& center, dou
qCWarning(AirMapManagerLog) << "AirMapRestrictionManager::updateROI: state not idle"; qCWarning(AirMapManagerLog) << "AirMapRestrictionManager::updateROI: state not idle";
return; return;
} }
qCDebug(AirMapManagerLog) << "setting ROI"; qCDebug(AirMapManagerLog) << "Setting Restriction Manager ROI";
_polygons.clear(); _polygons.clear();
_circles.clear(); _circles.clear();
_state = State::RetrieveItems; _state = State::RetrieveItems;
Airspaces::Search::Parameters params; Airspaces::Search::Parameters params;
params.geometry = Geometry::point(center.latitude(), center.longitude());
params.buffer = radiusMeters;
params.full = true; params.full = true;
params.date_time = Clock::universal_time();
//-- Geometry: Polygon
Geometry::Polygon polygon;
for (const auto& qcoord : roi.polygon2D()) {
Geometry::Coordinate coord;
coord.latitude = qcoord.latitude();
coord.longitude = qcoord.longitude();
polygon.outer_ring.coordinates.push_back(coord);
}
params.geometry = Geometry(polygon);
std::weak_ptr<LifetimeChecker> isAlive(_instance); std::weak_ptr<LifetimeChecker> isAlive(_instance);
_shared.client()->airspaces().search(params, _shared.client()->airspaces().search(params,
[this, isAlive](const Airspaces::Search::Result& result) { [this, isAlive](const Airspaces::Search::Result& result) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "LifetimeChecker.h" #include "LifetimeChecker.h"
#include "AirspaceRestrictionProvider.h" #include "AirspaceRestrictionProvider.h"
#include "AirMapSharedState.h" #include "AirMapSharedState.h"
#include "QGCGeoBoundingCube.h"
#include <QList> #include <QList>
#include <QGeoCoordinate> #include <QGeoCoordinate>
...@@ -30,13 +31,13 @@ public: ...@@ -30,13 +31,13 @@ public:
AirMapRestrictionManager (AirMapSharedState& shared); AirMapRestrictionManager (AirMapSharedState& shared);
QmlObjectListModel* polygons () override { return &_polygons; } QmlObjectListModel* polygons () override { return &_polygons; }
QmlObjectListModel* circles () override { return &_circles; } QmlObjectListModel* circles () override { return &_circles; }
void setROI (const QGeoCoordinate& center, double radiusMeters) override; void setROI (const QGCGeoBoundingCube &roi) 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);
private: private:
void _requestRestrictions(const QGeoCoordinate& center, double radiusMeters); void _requestRestrictions(const QGCGeoBoundingCube& roi);
void _addPolygonToList (const airmap::Geometry::Polygon& polygon); void _addPolygonToList (const airmap::Geometry::Polygon& polygon);
enum class State { enum class State {
...@@ -45,8 +46,7 @@ private: ...@@ -45,8 +46,7 @@ private:
}; };
AirMapSharedState& _shared; AirMapSharedState& _shared;
double _lastRadius; QGCGeoBoundingCube _lastROI;
QGeoCoordinate _lastRoiCenter;
State _state = State::Idle; State _state = State::Idle;
QmlObjectListModel _polygons; QmlObjectListModel _polygons;
QmlObjectListModel _circles; QmlObjectListModel _circles;
......
...@@ -177,7 +177,7 @@ rules_sort(QObject* a, QObject* b) ...@@ -177,7 +177,7 @@ rules_sort(QObject* a, QObject* b)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void AirMapRulesetsManager::setROI(const QGeoCoordinate& center) void AirMapRulesetsManager::setROI(const QGCGeoBoundingCube& roi)
{ {
if (!_shared.client()) { if (!_shared.client()) {
qCDebug(AirMapManagerLog) << "No AirMap client instance. Not updating Airspace"; qCDebug(AirMapManagerLog) << "No AirMap client instance. Not updating Airspace";
...@@ -192,7 +192,15 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center) ...@@ -192,7 +192,15 @@ void AirMapRulesetsManager::setROI(const QGeoCoordinate& center)
_ruleSets.clearAndDeleteContents(); _ruleSets.clearAndDeleteContents();
_state = State::RetrieveItems; _state = State::RetrieveItems;
RuleSets::Search::Parameters params; RuleSets::Search::Parameters params;
params.geometry = Geometry::point(center.latitude(), center.longitude()); //-- Geometry: Polygon
Geometry::Polygon polygon;
for (const auto& qcoord : roi.polygon2D()) {
Geometry::Coordinate coord;
coord.latitude = qcoord.latitude();
coord.longitude = qcoord.longitude();
polygon.outer_ring.coordinates.push_back(coord);
}
params.geometry = Geometry(polygon);
std::weak_ptr<LifetimeChecker> isAlive(_instance); std::weak_ptr<LifetimeChecker> isAlive(_instance);
_shared.client()->rulesets().search(params, _shared.client()->rulesets().search(params,
[this, isAlive](const RuleSets::Search::Result& result) { [this, isAlive](const RuleSets::Search::Result& result) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "LifetimeChecker.h" #include "LifetimeChecker.h"
#include "AirspaceRulesetsProvider.h" #include "AirspaceRulesetsProvider.h"
#include "AirMapSharedState.h" #include "AirMapSharedState.h"
#include "QGCGeoBoundingCube.h"
#include <QGeoCoordinate> #include <QGeoCoordinate>
#include <QStringList> #include <QStringList>
...@@ -50,6 +51,7 @@ class AirMapRule : public AirspaceRule ...@@ -50,6 +51,7 @@ class AirMapRule : public AirspaceRule
{ {
Q_OBJECT Q_OBJECT
friend class AirMapRulesetsManager; friend class AirMapRulesetsManager;
friend class AirMapFlightPlanManager;
public: public:
AirMapRule (QObject* parent = NULL); AirMapRule (QObject* parent = NULL);
...@@ -107,7 +109,7 @@ public: ...@@ -107,7 +109,7 @@ public:
QmlObjectListModel* ruleSets () override { return &_ruleSets; } QmlObjectListModel* ruleSets () override { return &_ruleSets; }
QString selectedRuleSets() override; QString selectedRuleSets() override;
void setROI (const QGeoCoordinate& center) override; void setROI (const QGCGeoBoundingCube& roi) 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);
......
...@@ -23,17 +23,17 @@ AirMapWeatherInfoManager::AirMapWeatherInfoManager(AirMapSharedState& shared, QO ...@@ -23,17 +23,17 @@ AirMapWeatherInfoManager::AirMapWeatherInfoManager(AirMapSharedState& shared, QO
} }
void void
AirMapWeatherInfoManager::setROI(const QGeoCoordinate& center) AirMapWeatherInfoManager::setROI(const QGCGeoBoundingCube& roi)
{ {
//-- If first time or we've moved more than WEATHER_UPDATE_DISTANCE, ask for weather updates. //-- If first time or we've moved more than WEATHER_UPDATE_DISTANCE, ask for weather updates.
if(!_lastRoiCenter.isValid() || _lastRoiCenter.distanceTo(center) > WEATHER_UPDATE_DISTANCE) { if(!_lastRoiCenter.isValid() || _lastRoiCenter.distanceTo(roi.center()) > WEATHER_UPDATE_DISTANCE) {
_lastRoiCenter = center; _lastRoiCenter = roi.center();
_requestWeatherUpdate(center); _requestWeatherUpdate(_lastRoiCenter);
_weatherTime.start(); _weatherTime.start();
} else { } else {
//-- Check weather once every WEATHER_UPDATE_TIME //-- Check weather once every WEATHER_UPDATE_TIME
if(_weatherTime.elapsed() > WEATHER_UPDATE_TIME) { if(_weatherTime.elapsed() > WEATHER_UPDATE_TIME) {
_requestWeatherUpdate(center); _requestWeatherUpdate(roi.center());
_weatherTime.start(); _weatherTime.start();
} }
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "AirspaceWeatherInfoProvider.h" #include "AirspaceWeatherInfoProvider.h"
#include "AirMapSharedState.h" #include "AirMapSharedState.h"
#include "QGCGeoBoundingCube.h"
#include <QGeoCoordinate> #include <QGeoCoordinate>
#include <QTime> #include <QTime>
...@@ -41,7 +42,7 @@ public: ...@@ -41,7 +42,7 @@ public:
quint32 visibility () override { return _weather.visibility; } quint32 visibility () override { return _weather.visibility; }
quint32 precipitation () override { return _weather.precipitation; } quint32 precipitation () override { return _weather.precipitation; }
void setROI (const QGeoCoordinate& center) override; void setROI (const QGCGeoBoundingCube& roi) 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);
......
...@@ -86,10 +86,19 @@ Item { ...@@ -86,10 +86,19 @@ Item {
color: _textColor color: _textColor
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
QGCLabel { Column {
text: qsTr("Airspace") spacing: 0
color: _textColor
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
QGCLabel {
text: qsTr("Airspace")
color: _textColor
}
QGCLabel {
text: _validAdvisories ? QGroundControl.airspaceManager.advisories.advisories.count + qsTr(" Advisories") : ""
color: _textColor
visible: _validAdvisories
font.pointSize: ScreenTools.smallFontPointSize
}
} }
Item { Item {
width: ScreenTools.defaultFontPixelWidth width: ScreenTools.defaultFontPixelWidth
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
#include "QmlObjectListModel.h" #include "QmlObjectListModel.h"
#include "QGCGeoBoundingCube.h"
#include <QObject> #include <QObject>
#include <QGeoCoordinate> #include <QGeoCoordinate>
...@@ -49,7 +50,7 @@ public: ...@@ -49,7 +50,7 @@ public:
* 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.
* @param center Center coordinate for ROI * @param center Center coordinate for ROI
*/ */
virtual void setROI (const QGeoCoordinate& center, double radiusMeters) = 0; virtual void setROI (const QGCGeoBoundingCube& roi) = 0;
signals: signals:
void advisoryChanged (); void advisoryChanged ();
......
...@@ -70,30 +70,29 @@ void AirspaceManager::setToolbox(QGCToolbox* toolbox) ...@@ -70,30 +70,29 @@ void AirspaceManager::setToolbox(QGCToolbox* toolbox)
_flightPlan = _instantiateAirspaceFlightPlanProvider(); _flightPlan = _instantiateAirspaceFlightPlanProvider();
} }
void AirspaceManager::setROI(QGeoCoordinate center, double radiusMeters) void AirspaceManager::setROI(const QGeoCoordinate& pointNW, const QGeoCoordinate& pointSE)
{ {
_setROI(center, radiusMeters); _setROI(QGCGeoBoundingCube(pointNW, pointSE));
} }
void AirspaceManager::_setROI(const QGeoCoordinate& center, double radiusMeters) void AirspaceManager::_setROI(const QGCGeoBoundingCube& roi)
{ {
_roiCenter = center; _roi = roi;
_roiRadius = radiusMeters;
_roiUpdateTimer.start(); _roiUpdateTimer.start();
} }
void AirspaceManager::_updateToROI() void AirspaceManager::_updateToROI()
{ {
if(_airspaces) { if(_airspaces) {
_airspaces->setROI(_roiCenter, _roiRadius); _airspaces->setROI(_roi);
} }
if(_ruleSetsProvider) { if(_ruleSetsProvider) {
_ruleSetsProvider->setROI(_roiCenter); _ruleSetsProvider->setROI(_roi);
} }
if(_weatherProvider) { if(_weatherProvider) {
_weatherProvider->setROI(_roiCenter); _weatherProvider->setROI(_roi);
} }
if (_advisories) { if (_advisories) {
_advisories->setROI(_roiCenter, _roiRadius); _advisories->setROI(_roi);
} }
} }
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "QGCToolbox.h" #include "QGCToolbox.h"
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "QmlObjectListModel.h" #include "QmlObjectListModel.h"
#include "QGCGeoBoundingCube.h"
#include <QGeoCoordinate> #include <QGeoCoordinate>
#include <QObject> #include <QObject>
...@@ -63,7 +64,7 @@ public: ...@@ -63,7 +64,7 @@ public:
Q_PROPERTY(AirspaceFlightPlanProvider* flightPlan READ flightPlan CONSTANT) Q_PROPERTY(AirspaceFlightPlanProvider* flightPlan READ flightPlan CONSTANT)
Q_PROPERTY(bool airspaceVisible READ airspaceVisible WRITE setAirspaceVisible NOTIFY airspaceVisibleChanged) Q_PROPERTY(bool airspaceVisible READ airspaceVisible WRITE setAirspaceVisible NOTIFY airspaceVisibleChanged)
Q_INVOKABLE void setROI (QGeoCoordinate center, double radius); Q_INVOKABLE void setROI (const QGeoCoordinate& pointNW, const QGeoCoordinate& pointSE);
AirspaceWeatherInfoProvider* weatherInfo () { return _weatherProvider; } AirspaceWeatherInfoProvider* weatherInfo () { return _weatherProvider; }
AirspaceAdvisoryProvider* advisories () { return _advisories; } AirspaceAdvisoryProvider* advisories () { return _advisories; }
...@@ -92,7 +93,7 @@ protected: ...@@ -92,7 +93,7 @@ protected:
* @param center Center coordinate for ROI * @param center Center coordinate for ROI
* @param radiusMeters Radius in meters around center which is of interest * @param radiusMeters Radius in meters around center which is of interest
*/ */
virtual void _setROI (const QGeoCoordinate& center, double radiusMeters); virtual void _setROI (const QGCGeoBoundingCube& roi);
/** /**
* Factory methods * Factory methods
...@@ -111,8 +112,7 @@ protected: ...@@ -111,8 +112,7 @@ protected:
AirspaceRestrictionProvider* _airspaces = nullptr; ///< Airspace info AirspaceRestrictionProvider* _airspaces = nullptr; ///< Airspace info
AirspaceFlightPlanProvider* _flightPlan = nullptr; ///< Flight plan management AirspaceFlightPlanProvider* _flightPlan = nullptr; ///< Flight plan management
QTimer _roiUpdateTimer; QTimer _roiUpdateTimer;
QGeoCoordinate _roiCenter; QGCGeoBoundingCube _roi;
double _roiRadius;
private: private:
void _updateToROI (); void _updateToROI ();
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
#include "QmlObjectListModel.h" #include "QmlObjectListModel.h"
#include "QGCGeoBoundingCube.h"
#include <QObject> #include <QObject>
#include <QList> #include <QList>
...@@ -37,7 +38,7 @@ public: ...@@ -37,7 +38,7 @@ public:
* @param center Center coordinate for ROI * @param center Center coordinate for ROI
* @param radiusMeters Radius in meters around center which is of interest * @param radiusMeters Radius in meters around center which is of interest
*/ */
virtual void setROI (const QGeoCoordinate& center, double radiusMeters) = 0; virtual void setROI (const QGCGeoBoundingCube& roi) = 0;
virtual QmlObjectListModel* polygons () = 0; ///< List of AirspacePolygonRestriction objects virtual QmlObjectListModel* polygons () = 0; ///< List of AirspacePolygonRestriction objects
virtual QmlObjectListModel* circles () = 0; ///< List of AirspaceCircularRestriction objects virtual QmlObjectListModel* circles () = 0; ///< List of AirspaceCircularRestriction objects
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*/ */
#include "QmlObjectListModel.h" #include "QmlObjectListModel.h"
#include "QGCGeoBoundingCube.h"
#include <QObject> #include <QObject>
#include <QGeoCoordinate> #include <QGeoCoordinate>
...@@ -161,7 +162,7 @@ public: ...@@ -161,7 +162,7 @@ public:
* 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.
* @param center Center coordinate for ROI * @param center Center coordinate for ROI
*/ */
virtual void setROI (const QGeoCoordinate& center) = 0; virtual void setROI (const QGCGeoBoundingCube& roi) = 0;
signals: signals:
void ruleSetsChanged (); void ruleSetsChanged ();
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* Weather information provided by the Airspace Managemement * Weather information provided by the Airspace Managemement
*/ */
#include "QGCGeoBoundingCube.h"
#include <QObject> #include <QObject>
#include <QGeoCoordinate> #include <QGeoCoordinate>
...@@ -50,7 +51,7 @@ public: ...@@ -50,7 +51,7 @@ public:
* Set region of interest that should be queried. When finished, the weatherChanged() signal will be emmited. * Set region of interest that should be queried. When finished, the weatherChanged() signal will be emmited.
* @param center Center coordinate for ROI * @param center Center coordinate for ROI
*/ */
virtual void setROI (const QGeoCoordinate& center) = 0; virtual void setROI (const QGCGeoBoundingCube& roi) = 0;
signals: signals:
void weatherChanged (); void weatherChanged ();
......
...@@ -57,13 +57,25 @@ FlightMap { ...@@ -57,13 +57,25 @@ FlightMap {
property bool _disableVehicleTracking: false property bool _disableVehicleTracking: false
property bool _keepVehicleCentered: _mainIsMap ? false : true property bool _keepVehicleCentered: _mainIsMap ? false : true
// Track last known map position and zoom from Fly view in settings function updateAirspace() {
onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
onCenterChanged: {
if(_airspaceEnabled) { if(_airspaceEnabled) {
QGroundControl.airspaceManager.setROI(center, 1000) var coordinateNW = flightMap.toCoordinate(Qt.point(0,0), false /* clipToViewPort */)
var coordinateSE = flightMap.toCoordinate(Qt.point(width,height), false /* clipToViewPort */)
if(coordinateNW.isValid && coordinateSE.isValid) {
QGroundControl.airspaceManager.setROI(coordinateNW, coordinateSE)
}
} }
}
// Track last known map position and zoom from Fly view in settings
onZoomLevelChanged: {
QGroundControl.flightMapZoom = zoomLevel
updateAirspace()
}
onCenterChanged: {
QGroundControl.flightMapPosition = center QGroundControl.flightMapPosition = center
updateAirspace()
} }
// When the user pans the map we stop responding to vehicle coordinate updates until the panRecenterTimer fires // When the user pans the map we stop responding to vehicle coordinate updates until the panRecenterTimer fires
......
...@@ -30,7 +30,7 @@ Item { ...@@ -30,7 +30,7 @@ Item {
property var qgcView property var qgcView
property bool useLightColors property bool useLightColors
property var missionController property var missionController
property bool showValues: QGroundControl.airspaceManager.airspaceVisible property bool showValues: !QGroundControl.airspaceManager.airspaceVisible
property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property bool _isSatellite: _mainIsMap ? (_flightMap ? _flightMap.isSatelliteMap : true) : true property bool _isSatellite: _mainIsMap ? (_flightMap ? _flightMap.isSatelliteMap : true) : true
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "Vehicle.h" #include "Vehicle.h"
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "MavlinkQmlSingleton.h" #include "MavlinkQmlSingleton.h"
#include "QGCGeo.h" #include "QGCGeoBoundingCube.h"
#include <QHash> #include <QHash>
......
...@@ -84,6 +84,16 @@ QGCView { ...@@ -84,6 +84,16 @@ QGCView {
_missionController.setCurrentPlanViewIndex(sequenceNumber, true) _missionController.setCurrentPlanViewIndex(sequenceNumber, true)
} }
function updateAirspace() {
if(_airspaceEnabled) {
var coordinateNW = editorMap.toCoordinate(Qt.point(0,0), false /* clipToViewPort */)
var coordinateSE = editorMap.toCoordinate(Qt.point(width,height), false /* clipToViewPort */)
if(coordinateNW.isValid && coordinateSE.isValid) {
QGroundControl.airspaceManager.setROI(coordinateNW, coordinateSE)
}
}
}
property bool _firstMissionLoadComplete: false property bool _firstMissionLoadComplete: false
property bool _firstFenceLoadComplete: false property bool _firstFenceLoadComplete: false
property bool _firstRallyLoadComplete: false property bool _firstRallyLoadComplete: false
...@@ -347,11 +357,8 @@ QGCView { ...@@ -347,11 +357,8 @@ QGCView {
QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap } QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }
onCenterChanged: { onZoomLevelChanged: updateAirspace()
if(_airspaceEnabled) { onCenterChanged: updateAirspace()
QGroundControl.airspaceManager.setROI(center, 5000)
}
}
MouseArea { MouseArea {
//-- It's a whole lot faster to just fill parent and deal with top offset below //-- It's a whole lot faster to just fill parent and deal with top offset below
...@@ -542,7 +549,7 @@ QGCView { ...@@ -542,7 +549,7 @@ QGCView {
height: ScreenTools.availableHeight height: ScreenTools.availableHeight
width: _rightPanelWidth width: _rightPanelWidth
color: qgcPal.window color: qgcPal.window
opacity: 0.2 opacity: planExpanded.visible ? 0.2 : 0
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: ScreenTools.defaultFontPixelWidth anchors.rightMargin: ScreenTools.defaultFontPixelWidth
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include "JoystickConfigController.h" #include "JoystickConfigController.h"
#include "JoystickManager.h" #include "JoystickManager.h"
#include "QmlObjectListModel.h" #include "QmlObjectListModel.h"
#include "QGCGeoBoundingCube.h"
#include "MissionManager.h" #include "MissionManager.h"
#include "QGroundControlQmlGlobal.h" #include "QGroundControlQmlGlobal.h"
#include "FlightMapSettings.h" #include "FlightMapSettings.h"
...@@ -381,6 +382,8 @@ void QGCApplication::_initCommon(void) ...@@ -381,6 +382,8 @@ void QGCApplication::_initCommon(void)
qmlRegisterUncreatableType<RallyPointController>("QGroundControl.Controllers", 1, 0, "RallyPointController", "Reference only"); qmlRegisterUncreatableType<RallyPointController>("QGroundControl.Controllers", 1, 0, "RallyPointController", "Reference only");
qmlRegisterUncreatableType<VisualMissionItem> ("QGroundControl.Controllers", 1, 0, "VisualMissionItem", "Reference only"); qmlRegisterUncreatableType<VisualMissionItem> ("QGroundControl.Controllers", 1, 0, "VisualMissionItem", "Reference only");
qmlRegisterType<QGCGeoBoundingCube> ("QGroundControl", 1, 0, "QGCGeoBoundingCube");
qmlRegisterType<ParameterEditorController> ("QGroundControl.Controllers", 1, 0, "ParameterEditorController"); qmlRegisterType<ParameterEditorController> ("QGroundControl.Controllers", 1, 0, "ParameterEditorController");
qmlRegisterType<ESP8266ComponentController> ("QGroundControl.Controllers", 1, 0, "ESP8266ComponentController"); qmlRegisterType<ESP8266ComponentController> ("QGroundControl.Controllers", 1, 0, "ESP8266ComponentController");
qmlRegisterType<ScreenToolsController> ("QGroundControl.Controllers", 1, 0, "ScreenToolsController"); qmlRegisterType<ScreenToolsController> ("QGroundControl.Controllers", 1, 0, "ScreenToolsController");
......
...@@ -102,10 +102,3 @@ void convertUTMToGeo(double easting, double northing, int zone, bool southhemi, ...@@ -102,10 +102,3 @@ void convertUTMToGeo(double easting, double northing, int zone, bool southhemi,
coord.setLatitude(RadToDeg(latRadians)); coord.setLatitude(RadToDeg(latRadians));
coord.setLongitude(RadToDeg(lonRadians)); coord.setLongitude(RadToDeg(lonRadians));
} }
double QGCGeoBoundingCube::MaxAlt = 1000000.0;
double QGCGeoBoundingCube::MinAlt = -1000000.0;
double QGCGeoBoundingCube::MaxNorth = 90.0;
double QGCGeoBoundingCube::MaxSouth = -90.0;
double QGCGeoBoundingCube::MaxWest = -180.0;
double QGCGeoBoundingCube::MaxEast = 180.0;
...@@ -81,46 +81,4 @@ int convertGeoToUTM(const QGeoCoordinate& coord, double& easting, double& northi ...@@ -81,46 +81,4 @@ int convertGeoToUTM(const QGeoCoordinate& coord, double& easting, double& northi
// The function does not return a value. // The function does not return a value.
void convertUTMToGeo(double easting, double northing, int zone, bool southhemi, QGeoCoordinate& coord); void convertUTMToGeo(double easting, double northing, int zone, bool southhemi, QGeoCoordinate& coord);
// A bounding cube
class QGCGeoBoundingCube {
public:
QGCGeoBoundingCube()
: pointNW(QGeoCoordinate(MaxSouth, MaxEast, MaxAlt))
, pointSE(QGeoCoordinate(MaxNorth, MaxWest, MinAlt))
{
}
QGCGeoBoundingCube(QGeoCoordinate p1, QGeoCoordinate p2)
: pointNW(p1)
, pointSE(p2)
{
}
QGeoCoordinate pointNW;
QGeoCoordinate pointSE;
inline bool operator ==(const QGCGeoBoundingCube& other)
{
return pointNW == other.pointNW && pointSE == other.pointSE;
}
inline bool operator !=(const QGCGeoBoundingCube& other)
{
return !(*this == other);
}
inline QGCGeoBoundingCube operator =(const QGCGeoBoundingCube& other)
{
pointNW = other.pointNW;
pointSE = other.pointSE;
return *this;
}
inline bool isValid()
{
return pointNW.isValid() && pointSE.isValid() && pointNW.latitude() != MaxSouth && pointSE.latitude() != MaxNorth && \
pointNW.longitude() != MaxEast && pointSE.longitude() != MaxWest && pointNW.altitude() < MaxAlt and pointSE.altitude() > MinAlt;
}
static double MaxAlt;
static double MinAlt;
static double MaxNorth;
static double MaxSouth;
static double MaxWest;
static double MaxEast;
};
#endif // QGCGEO_H #endif // QGCGEO_H
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include "QGCGeoBoundingCube.h"
#include <QDebug>
double QGCGeoBoundingCube::MaxAlt = 1000000.0;
double QGCGeoBoundingCube::MinAlt = -1000000.0;
double QGCGeoBoundingCube::MaxNorth = 90.0;
double QGCGeoBoundingCube::MaxSouth = -90.0;
double QGCGeoBoundingCube::MaxWest = -180.0;
double QGCGeoBoundingCube::MaxEast = 180.0;
//-----------------------------------------------------------------------------
bool
QGCGeoBoundingCube::isValid() const
{
return pointNW.isValid() && pointSE.isValid() && pointNW.latitude() != MaxSouth && pointSE.latitude() != MaxNorth && \
pointNW.longitude() != MaxEast && pointSE.longitude() != MaxWest && pointNW.altitude() < MaxAlt and pointSE.altitude() > MinAlt;
}
//-----------------------------------------------------------------------------
QGeoCoordinate
QGCGeoBoundingCube::center() const
{
double lat = (((pointNW.latitude() + 90.0) + (pointSE.latitude() + 90.0)) / 2.0) - 90.0;
double lon = (((pointNW.longitude() + 180.0) + (pointSE.longitude() + 180.0)) / 2.0) - 180.0;
double alt = (pointNW.altitude() + pointSE.altitude()) / 2.0;
//qDebug() << pointNW << pointSE << QGeoCoordinate(lat, lon, alt);
return QGeoCoordinate(lat, lon, alt);
}
//-----------------------------------------------------------------------------
QList<QGeoCoordinate>
QGCGeoBoundingCube::polygon2D() const
{
QList<QGeoCoordinate> coords;
coords.append(QGeoCoordinate(pointNW.latitude(), pointNW.longitude(), pointSE.altitude()));
coords.append(QGeoCoordinate(pointNW.latitude(), pointSE.longitude(), pointSE.altitude()));
coords.append(QGeoCoordinate(pointSE.latitude(), pointSE.longitude(), pointSE.altitude()));
coords.append(QGeoCoordinate(pointSE.latitude(), pointNW.longitude(), pointSE.altitude()));
coords.append(QGeoCoordinate(pointNW.latitude(), pointNW.longitude(), pointSE.altitude()));
return coords;
}
//-----------------------------------------------------------------------------
double
QGCGeoBoundingCube::width() const
{
QGeoCoordinate ne = QGeoCoordinate(pointNW.latitude(), pointSE.longitude());
return pointNW.distanceTo(ne);
}
//-----------------------------------------------------------------------------
double
QGCGeoBoundingCube::height() const
{
QGeoCoordinate sw = QGeoCoordinate(pointSE.latitude(), pointNW.longitude());
return pointNW.distanceTo(sw);
}
//-----------------------------------------------------------------------------
double
QGCGeoBoundingCube::area() const
{
// Area in km^2
double a = (height() / 1000.0) * (width() / 1000.0);
//qDebug() << "Area:" << a;
return a;
}
//-----------------------------------------------------------------------------
double
QGCGeoBoundingCube::radius() const
{
return pointNW.distanceTo(pointSE) / 2.0;
}
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#pragma once
#include <QObject>
#include <QGeoCoordinate>
// A bounding "cube" for small surface areas (doesn't take in consideration earth's curvature)
// Coordinate system makes NW Up Left Bottom (0,0,0) and SE Bottom Right Top (y,x,z)
class QGCGeoBoundingCube : public QObject {
Q_OBJECT
public:
QGCGeoBoundingCube(const QGCGeoBoundingCube& other)
{
pointNW = other.pointNW;
pointSE = other.pointSE;
}
QGCGeoBoundingCube()
: pointNW(QGeoCoordinate(MaxSouth, MaxEast, MaxAlt))
, pointSE(QGeoCoordinate(MaxNorth, MaxWest, MinAlt))
{
}
QGCGeoBoundingCube(QGeoCoordinate p1, QGeoCoordinate p2)
: pointNW(p1)
, pointSE(p2)
{
}
Q_PROPERTY(QGeoCoordinate pointNW MEMBER pointNW CONSTANT)
Q_PROPERTY(QGeoCoordinate pointSE MEMBER pointNW CONSTANT)
Q_INVOKABLE bool isValid() const;
Q_INVOKABLE QGeoCoordinate center() const;
inline bool operator ==(const QGCGeoBoundingCube& other)
{
return pointNW == other.pointNW && pointSE == other.pointSE;
}
inline bool operator !=(const QGCGeoBoundingCube& other)
{
return !(*this == other);
}
inline const QGCGeoBoundingCube& operator =(const QGCGeoBoundingCube& other)
{
pointNW = other.pointNW;
pointSE = other.pointSE;
return *this;
}
//-- 2D
QList<QGeoCoordinate> polygon2D() const;
double width () const;
double height () const;
double area () const;
double radius () const;
QGeoCoordinate pointNW;
QGeoCoordinate pointSE;
static double MaxAlt;
static double MinAlt;
static double MaxNorth;
static double MaxSouth;
static double MaxWest;
static double MaxEast;
};
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