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 {
/// ControlledAirspace bundles up properties describing
/// a controlled airspace.
struct ControlledAirspace {};
struct ControlledAirspace {
std::string airspace_classification; ///< The classification of the ControlledAirspace.
};
/// SpecialUseAirspace bundles up properties describing
/// a special use airspace.
......
......@@ -24,7 +24,7 @@ class Airspaces : DoNotCopyOrMove {
};
/// 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
/// invoked when a call to Airspaces::for_id finishes.
using Callback = std::function<void(const Result&)>;
......
......@@ -43,9 +43,9 @@ AirMapManager::AirMapManager(QGCApplication* app, QGCToolbox* toolbox)
{
_logger = std::make_shared<qt::Logger>();
qt::register_types(); // TODO: still needed?
_logger->logging_category().setEnabled(QtDebugMsg, true);
_logger->logging_category().setEnabled(QtInfoMsg, true);
_logger->logging_category().setEnabled(QtWarningMsg, true);
_logger->logging_category().setEnabled(QtDebugMsg, false);
_logger->logging_category().setEnabled(QtInfoMsg, false);
_logger->logging_category().setEnabled(QtWarningMsg, false);
_dispatchingLogger = std::make_shared<qt::DispatchingLogger>(_logger);
connect(&_shared, &AirMapSharedState::error, this, &AirMapManager::_error);
connect(&_shared, &AirMapSharedState::authStatus, this, &AirMapManager::_authStatusChanged);
......
......@@ -11,8 +11,6 @@
#include "AirMapManager.h"
#include "AirspaceRestriction.h"
#include "airmap/airspaces.h"
#define RESTRICTION_UPDATE_DISTANCE 500 //-- 500m threshold for updates
using namespace airmap;
......@@ -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
AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi)
......@@ -54,7 +86,7 @@ AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi)
_circles.clear();
_state = State::RetrieveItems;
Airspaces::Search::Parameters params;
params.full = true;
params.full = false;
params.date_time = Clock::universal_time();
//-- Geometry: Polygon
Geometry::Polygon polygon;
......@@ -74,23 +106,24 @@ AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi)
const std::vector<Airspace>& airspaces = result.value();
qCDebug(AirMapManagerLog)<<"Successful search. Items:" << airspaces.size();
for (const auto& airspace : airspaces) {
QColor color = _getColor(airspace.type());
const Geometry& geometry = airspace.geometry();
switch(geometry.type()) {
case Geometry::Type::polygon: {
const Geometry::Polygon& polygon = geometry.details_for_polygon();
_addPolygonToList(polygon);
_addPolygonToList(polygon, color);
}
break;
case Geometry::Type::multi_polygon: {
const Geometry::MultiPolygon& multiPolygon = geometry.details_for_multi_polygon();
for (const auto& polygon : multiPolygon) {
_addPolygonToList(polygon);
_addPolygonToList(polygon, color);
}
}
break;
case Geometry::Type::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???
}
break;
......@@ -114,7 +147,7 @@ AirMapRestrictionManager::_requestRestrictions(const QGCGeoBoundingCube& roi)
//-----------------------------------------------------------------------------
void
AirMapRestrictionManager::_addPolygonToList(const airmap::Geometry::Polygon& polygon)
AirMapRestrictionManager::_addPolygonToList(const airmap::Geometry::Polygon& polygon, const QColor color)
{
QVariantList polygonArray;
for (const auto& vertex : polygon.outer_ring.coordinates) {
......@@ -126,7 +159,7 @@ AirMapRestrictionManager::_addPolygonToList(const airmap::Geometry::Polygon& pol
}
polygonArray.append(QVariant::fromValue(coord));
}
_polygons.append(new AirspacePolygonRestriction(polygonArray));
_polygons.append(new AirspacePolygonRestriction(polygonArray, color));
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)
qCDebug(AirMapManagerLog) << "Polygon with holes. Size: "<<polygon.inner_rings.size();
......
......@@ -18,6 +18,7 @@
#include <QGeoCoordinate>
#include "airmap/geometry.h"
#include "airmap/airspaces.h"
/**
* @file AirMapRestrictionManager.h
......@@ -38,7 +39,8 @@ signals:
private:
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 {
Idle,
......
......@@ -117,7 +117,7 @@ AirspaceManager::_setROI(const QGCGeoBoundingCube& roi)
{
if(_roi != roi) {
_roi = roi;
_ruleUpdateTimer.start();
_updateTimer.start();
}
}
......
......@@ -9,20 +9,21 @@
#include "AirspaceRestriction.h"
AirspaceRestriction::AirspaceRestriction(QObject* parent)
AirspaceRestriction::AirspaceRestriction(QColor color, QObject* parent)
: QObject(parent)
, _color(color)
{
}
AirspacePolygonRestriction::AirspacePolygonRestriction(const QVariantList& polygon, QObject* parent)
: AirspaceRestriction(parent)
AirspacePolygonRestriction::AirspacePolygonRestriction(const QVariantList& polygon, QColor color, QObject* parent)
: AirspaceRestriction(color, parent)
, _polygon(polygon)
{
}
AirspaceCircularRestriction::AirspaceCircularRestriction(const QGeoCoordinate& center, double radius, QObject* parent)
: AirspaceRestriction(parent)
AirspaceCircularRestriction::AirspaceCircularRestriction(const QGeoCoordinate& center, double radius, QColor color, QObject* parent)
: AirspaceRestriction(color, parent)
, _center(center)
, _radius(radius)
{
......
......@@ -12,6 +12,7 @@
#include <QObject>
#include <QGeoCoordinate>
#include <QVariantList>
#include <QColor>
/**
* @class AirspaceRestriction
......@@ -22,7 +23,11 @@ class AirspaceRestriction : public QObject
{
Q_OBJECT
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
{
Q_OBJECT
public:
AirspacePolygonRestriction(const QVariantList& polygon, QObject* parent = nullptr);
Q_PROPERTY(QVariantList polygon MEMBER _polygon CONSTANT)
const QVariantList& getPolygon() const { return _polygon; }
AirspacePolygonRestriction(const QVariantList& polygon, QColor color, QObject* parent = nullptr);
Q_PROPERTY(QVariantList polygon READ polygon CONSTANT)
QVariantList polygon() { return _polygon; }
private:
QVariantList _polygon;
};
......@@ -53,11 +55,11 @@ class AirspaceCircularRestriction : public AirspaceRestriction
{
Q_OBJECT
public:
AirspaceCircularRestriction(const QGeoCoordinate& center, double radius, QObject* parent = nullptr);
Q_PROPERTY(QGeoCoordinate center MEMBER _center CONSTANT)
Q_PROPERTY(double radius MEMBER _radius CONSTANT)
AirspaceCircularRestriction(const QGeoCoordinate& center, double radius, QColor color, QObject* parent = nullptr);
Q_PROPERTY(QGeoCoordinate center READ center CONSTANT)
Q_PROPERTY(double radius READ radius CONSTANT)
QGeoCoordinate center () { return _center; }
double radius () { return _radius; }
private:
QGeoCoordinate _center;
double _radius;
......
......@@ -438,7 +438,7 @@ FlightMap {
delegate: MapCircle {
center: object.center
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)
}
}
......@@ -447,7 +447,7 @@ FlightMap {
model: _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : []
delegate: MapPolygon {
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)
}
}
......
......@@ -560,7 +560,7 @@ QGCView {
delegate: MapCircle {
center: object.center
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)
}
}
......@@ -569,7 +569,7 @@ QGCView {
model: _airspaceEnabled && QGroundControl.airspaceManager.airspaceVisible ? QGroundControl.airspaceManager.airspaces.polygons : []
delegate: MapPolygon {
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)
}
}
......
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