Commit eb341a6e authored by Gus Grubba's avatar Gus Grubba

Update airmapd (fixes airspace crashes)

Added some basic color management for airspaces
parent 6c1fb389
...@@ -48,7 +48,9 @@ class Airspace { ...@@ -48,7 +48,9 @@ class Airspace {
/// ControlledAirspace bundles up properties describing /// ControlledAirspace bundles up properties describing
/// a controlled airspace. /// a controlled airspace.
struct ControlledAirspace {}; struct ControlledAirspace {
std::string airspace_classification; ///< The classification of the ControlledAirspace.
};
/// SpecialUseAirspace bundles up properties describing /// SpecialUseAirspace bundles up properties describing
/// a special use airspace. /// a special use airspace.
......
...@@ -24,7 +24,7 @@ class Airspaces : DoNotCopyOrMove { ...@@ -24,7 +24,7 @@ class Airspaces : DoNotCopyOrMove {
}; };
/// Result models the outcome of calling Airspaces::for_id. /// Result models the outcome of calling Airspaces::for_id.
using Result = Outcome<std::vector<Airspace>, Error>; using Result = Outcome<Airspace, Error>;
/// Callback describes the function signature of the callback that is /// Callback describes the function signature of the callback that is
/// invoked when a call to Airspaces::for_id finishes. /// invoked when a call to Airspaces::for_id finishes.
using Callback = std::function<void(const Result&)>; using Callback = std::function<void(const Result&)>;
......
...@@ -43,9 +43,9 @@ AirMapManager::AirMapManager(QGCApplication* app, QGCToolbox* toolbox) ...@@ -43,9 +43,9 @@ 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, true); _logger->logging_category().setEnabled(QtDebugMsg, false);
_logger->logging_category().setEnabled(QtInfoMsg, true); _logger->logging_category().setEnabled(QtInfoMsg, false);
_logger->logging_category().setEnabled(QtWarningMsg, true); _logger->logging_category().setEnabled(QtWarningMsg, false);
_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);
connect(&_shared, &AirMapSharedState::authStatus, this, &AirMapManager::_authStatusChanged); connect(&_shared, &AirMapSharedState::authStatus, this, &AirMapManager::_authStatusChanged);
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#include "AirMapManager.h" #include "AirMapManager.h"
#include "AirspaceRestriction.h" #include "AirspaceRestriction.h"
#include "airmap/airspaces.h"
#define RESTRICTION_UPDATE_DISTANCE 500 //-- 500m threshold for updates #define RESTRICTION_UPDATE_DISTANCE 500 //-- 500m threshold for updates
using namespace airmap; using namespace airmap;
...@@ -37,6 +35,40 @@ AirMapRestrictionManager::setROI(const QGCGeoBoundingCube& roi, bool reset) ...@@ -37,6 +35,40 @@ AirMapRestrictionManager::setROI(const QGCGeoBoundingCube& roi, bool reset)
} }
} }
//-----------------------------------------------------------------------------
QColor
AirMapRestrictionManager::_getColor(const Airspace::Type type)
{
if(type == Airspace::Type::airport)
return QColor(254,65,65,30);
if(type == Airspace::Type::controlled_airspace)
return QColor(254,158,65,60);
if(type == Airspace::Type::special_use_airspace)
return QColor(65,230,254,30);
if(type == Airspace::Type::tfr)
return QColor(95,230,254,30);
if(type == Airspace::Type::wildfire)
return QColor(254,120,0,30);
if(type == Airspace::Type::park)
return QColor(7,165,22,30);
if(type == Airspace::Type::power_plant)
return QColor(11,7,165,30);
if(type == Airspace::Type::heliport)
return QColor(233,57,57,30);
if(type == Airspace::Type::prison)
return QColor(100,100,100,30);
if(type == Airspace::Type::school)
return QColor(56,224,190,30);
if(type == Airspace::Type::hospital)
return QColor(56,159,224,30);
if(type == Airspace::Type::fire)
return QColor(223,83,10,30);
if(type == Airspace::Type::emergency)
return QColor(255,0,0,30);
return QColor(255,0,255,30);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi) AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi)
...@@ -54,7 +86,7 @@ AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi) ...@@ -54,7 +86,7 @@ AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi)
_circles.clear(); _circles.clear();
_state = State::RetrieveItems; _state = State::RetrieveItems;
Airspaces::Search::Parameters params; Airspaces::Search::Parameters params;
params.full = true; params.full = false;
params.date_time = Clock::universal_time(); params.date_time = Clock::universal_time();
//-- Geometry: Polygon //-- Geometry: Polygon
Geometry::Polygon polygon; Geometry::Polygon polygon;
...@@ -74,23 +106,24 @@ AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi) ...@@ -74,23 +106,24 @@ AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi)
const std::vector<Airspace>& airspaces = result.value(); const std::vector<Airspace>& airspaces = result.value();
qCDebug(AirMapManagerLog)<<"Successful search. Items:" << airspaces.size(); qCDebug(AirMapManagerLog)<<"Successful search. Items:" << airspaces.size();
for (const auto& airspace : airspaces) { for (const auto& airspace : airspaces) {
QColor color = _getColor(airspace.type());
const Geometry& geometry = airspace.geometry(); const Geometry& geometry = airspace.geometry();
switch(geometry.type()) { switch(geometry.type()) {
case Geometry::Type::polygon: { case Geometry::Type::polygon: {
const Geometry::Polygon& polygon = geometry.details_for_polygon(); const Geometry::Polygon& polygon = geometry.details_for_polygon();
_addPolygonToList(polygon); _addPolygonToList(polygon, color);
} }
break; break;
case Geometry::Type::multi_polygon: { case Geometry::Type::multi_polygon: {
const Geometry::MultiPolygon& multiPolygon = geometry.details_for_multi_polygon(); const Geometry::MultiPolygon& multiPolygon = geometry.details_for_multi_polygon();
for (const auto& polygon : multiPolygon) { for (const auto& polygon : multiPolygon) {
_addPolygonToList(polygon); _addPolygonToList(polygon, color);
} }
} }
break; break;
case Geometry::Type::point: { case Geometry::Type::point: {
const Geometry::Point& point = geometry.details_for_point(); const Geometry::Point& point = geometry.details_for_point();
_circles.append(new AirspaceCircularRestriction(QGeoCoordinate(point.latitude, point.longitude), 0.)); _circles.append(new AirspaceCircularRestriction(QGeoCoordinate(point.latitude, point.longitude), 0., color));
// TODO: radius??? // TODO: radius???
} }
break; break;
...@@ -114,7 +147,7 @@ AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi) ...@@ -114,7 +147,7 @@ AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
AirMapRestrictionManager::_addPolygonToList(const airmap::Geometry::Polygon& polygon) AirMapRestrictionManager::_addPolygonToList(const airmap::Geometry::Polygon& polygon, const QColor color)
{ {
QVariantList polygonArray; QVariantList polygonArray;
for (const auto& vertex : polygon.outer_ring.coordinates) { for (const auto& vertex : polygon.outer_ring.coordinates) {
...@@ -126,7 +159,7 @@ AirMapRestrictionManager::_addPolygonToList(const airmap::Geometry::Polygon& pol ...@@ -126,7 +159,7 @@ AirMapRestrictionManager::_addPolygonToList(const airmap::Geometry::Polygon& pol
} }
polygonArray.append(QVariant::fromValue(coord)); polygonArray.append(QVariant::fromValue(coord));
} }
_polygons.append(new AirspacePolygonRestriction(polygonArray)); _polygons.append(new AirspacePolygonRestriction(polygonArray, color));
if (polygon.inner_rings.size() > 0) { if (polygon.inner_rings.size() > 0) {
// no need to support those (they are rare, and in most cases, there's a more restrictive polygon filling the hole) // no need to support those (they are rare, and in most cases, there's a more restrictive polygon filling the hole)
qCDebug(AirMapManagerLog) << "Polygon with holes. Size: "<<polygon.inner_rings.size(); qCDebug(AirMapManagerLog) << "Polygon with holes. Size: "<<polygon.inner_rings.size();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <QGeoCoordinate> #include <QGeoCoordinate>
#include "airmap/geometry.h" #include "airmap/geometry.h"
#include "airmap/airspaces.h"
/** /**
* @file AirMapRestrictionManager.h * @file AirMapRestrictionManager.h
...@@ -38,7 +39,8 @@ signals: ...@@ -38,7 +39,8 @@ signals:
private: private:
void _requestRestrictions(const QGCGeoBoundingCube& roi); void _requestRestrictions(const QGCGeoBoundingCube& roi);
void _addPolygonToList (const airmap::Geometry::Polygon& polygon); void _addPolygonToList (const airmap::Geometry::Polygon& polygon, const QColor color);
QColor _getColor (const airmap::Airspace::Type type);
enum class State { enum class State {
Idle, Idle,
......
...@@ -117,7 +117,7 @@ AirspaceManager::_setROI(const QGCGeoBoundingCube& roi) ...@@ -117,7 +117,7 @@ AirspaceManager::_setROI(const QGCGeoBoundingCube& roi)
{ {
if(_roi != roi) { if(_roi != roi) {
_roi = roi; _roi = roi;
_ruleUpdateTimer.start(); _updateTimer.start();
} }
} }
......
...@@ -9,20 +9,21 @@ ...@@ -9,20 +9,21 @@
#include "AirspaceRestriction.h" #include "AirspaceRestriction.h"
AirspaceRestriction::AirspaceRestriction(QObject* parent) AirspaceRestriction::AirspaceRestriction(QColor color, QObject* parent)
: QObject(parent) : QObject(parent)
, _color(color)
{ {
} }
AirspacePolygonRestriction::AirspacePolygonRestriction(const QVariantList& polygon, QObject* parent) AirspacePolygonRestriction::AirspacePolygonRestriction(const QVariantList& polygon, QColor color, QObject* parent)
: AirspaceRestriction(parent) : AirspaceRestriction(color, parent)
, _polygon(polygon) , _polygon(polygon)
{ {
} }
AirspaceCircularRestriction::AirspaceCircularRestriction(const QGeoCoordinate& center, double radius, QObject* parent) AirspaceCircularRestriction::AirspaceCircularRestriction(const QGeoCoordinate& center, double radius, QColor color, QObject* parent)
: AirspaceRestriction(parent) : AirspaceRestriction(color, parent)
, _center(center) , _center(center)
, _radius(radius) , _radius(radius)
{ {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <QObject> #include <QObject>
#include <QGeoCoordinate> #include <QGeoCoordinate>
#include <QVariantList> #include <QVariantList>
#include <QColor>
/** /**
* @class AirspaceRestriction * @class AirspaceRestriction
...@@ -22,7 +23,11 @@ class AirspaceRestriction : public QObject ...@@ -22,7 +23,11 @@ class AirspaceRestriction : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
AirspaceRestriction(QObject* parent = nullptr); AirspaceRestriction(QColor color, QObject* parent = nullptr);
Q_PROPERTY(QColor color READ color CONSTANT)
QColor color() { return _color; }
protected:
QColor _color;
}; };
/** /**
...@@ -34,12 +39,9 @@ class AirspacePolygonRestriction : public AirspaceRestriction ...@@ -34,12 +39,9 @@ class AirspacePolygonRestriction : public AirspaceRestriction
{ {
Q_OBJECT Q_OBJECT
public: public:
AirspacePolygonRestriction(const QVariantList& polygon, QObject* parent = nullptr); AirspacePolygonRestriction(const QVariantList& polygon, QColor color, QObject* parent = nullptr);
Q_PROPERTY(QVariantList polygon READ polygon CONSTANT)
Q_PROPERTY(QVariantList polygon MEMBER _polygon CONSTANT) QVariantList polygon() { return _polygon; }
const QVariantList& getPolygon() const { return _polygon; }
private: private:
QVariantList _polygon; QVariantList _polygon;
}; };
...@@ -53,11 +55,11 @@ class AirspaceCircularRestriction : public AirspaceRestriction ...@@ -53,11 +55,11 @@ class AirspaceCircularRestriction : public AirspaceRestriction
{ {
Q_OBJECT Q_OBJECT
public: public:
AirspaceCircularRestriction(const QGeoCoordinate& center, double radius, QObject* parent = nullptr); AirspaceCircularRestriction(const QGeoCoordinate& center, double radius, QColor color, QObject* parent = nullptr);
Q_PROPERTY(QGeoCoordinate center READ center CONSTANT)
Q_PROPERTY(QGeoCoordinate center MEMBER _center CONSTANT) Q_PROPERTY(double radius READ radius CONSTANT)
Q_PROPERTY(double radius MEMBER _radius CONSTANT) QGeoCoordinate center () { return _center; }
double radius () { return _radius; }
private: private:
QGeoCoordinate _center; QGeoCoordinate _center;
double _radius; double _radius;
......
...@@ -438,7 +438,7 @@ FlightMap { ...@@ -438,7 +438,7 @@ FlightMap {
delegate: MapCircle { delegate: MapCircle {
center: object.center center: object.center
radius: object.radius radius: object.radius
color: Qt.rgba(0.94, 0.87, 0, 0.15) color: object.color
border.color: Qt.rgba(1,1,1,0.85) border.color: Qt.rgba(1,1,1,0.85)
} }
} }
...@@ -447,7 +447,7 @@ FlightMap { ...@@ -447,7 +447,7 @@ FlightMap {
model: _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : [] model: _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : []
delegate: MapPolygon { delegate: MapPolygon {
path: object.polygon path: object.polygon
color: Qt.rgba(0.94, 0.87, 0, 0.15) color: object.color
border.color: Qt.rgba(1,1,1,0.85) border.color: Qt.rgba(1,1,1,0.85)
} }
} }
......
...@@ -560,7 +560,7 @@ QGCView { ...@@ -560,7 +560,7 @@ QGCView {
delegate: MapCircle { delegate: MapCircle {
center: object.center center: object.center
radius: object.radius radius: object.radius
color: Qt.rgba(0.94, 0.87, 0, 0.1) color: object.color
border.color: Qt.rgba(1,1,1,0.65) border.color: Qt.rgba(1,1,1,0.65)
} }
} }
...@@ -569,7 +569,7 @@ QGCView { ...@@ -569,7 +569,7 @@ QGCView {
model: _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : [] model: _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : []
delegate: MapPolygon { delegate: MapPolygon {
path: object.polygon path: object.polygon
color: Qt.rgba(0.94, 0.87, 0, 0.1) color: object.color
border.color: Qt.rgba(1,1,1,0.65) border.color: Qt.rgba(1,1,1,0.65)
} }
} }
......
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