AirspaceManager.cc 4.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/****************************************************************************
 *
 *   (c) 2017 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.
 *
 ****************************************************************************/


Gus Grubba's avatar
Gus Grubba committed
11
#include "AirspaceAdvisoryProvider.h"
Gus Grubba's avatar
Gus Grubba committed
12 13
#include "AirspaceFlightPlanProvider.h"
#include "AirspaceManager.h"
Gus Grubba's avatar
Gus Grubba committed
14
#include "AirspaceRestriction.h"
15
#include "AirspaceRestrictionProvider.h"
Gus Grubba's avatar
Gus Grubba committed
16
#include "AirspaceRulesetsProvider.h"
Gus Grubba's avatar
Gus Grubba committed
17
#include "AirspaceVehicleManager.h"
Gus Grubba's avatar
Gus Grubba committed
18
#include "AirspaceWeatherInfoProvider.h"
Gus Grubba's avatar
Gus Grubba committed
19 20 21

#include "Vehicle.h"
#include "QGCApplication.h"
22 23 24 25 26

QGC_LOGGING_CATEGORY(AirspaceManagementLog, "AirspaceManagementLog")

AirspaceManager::AirspaceManager(QGCApplication* app, QGCToolbox* toolbox)
    : QGCTool(app, toolbox)
27
    , _airspaceVisible(false)
28 29 30 31
{
    _roiUpdateTimer.setInterval(2000);
    _roiUpdateTimer.setSingleShot(true);
    connect(&_roiUpdateTimer, &QTimer::timeout, this, &AirspaceManager::_updateToROI);
32
    qmlRegisterUncreatableType<AirspaceAdvisoryProvider>    ("QGroundControl.Airspace",      1, 0, "AirspaceAdvisoryProvider",       "Reference only");
Gus Grubba's avatar
Gus Grubba committed
33
    qmlRegisterUncreatableType<AirspaceFlightPlanProvider>  ("QGroundControl.Airspace",      1, 0, "AirspaceFlightPlanProvider",     "Reference only");
34 35 36 37 38 39 40
    qmlRegisterUncreatableType<AirspaceManager>             ("QGroundControl.Airspace",      1, 0, "AirspaceManager",                "Reference only");
    qmlRegisterUncreatableType<AirspaceRestrictionProvider> ("QGroundControl.Airspace",      1, 0, "AirspaceRestrictionProvider",    "Reference only");
    qmlRegisterUncreatableType<AirspaceRule>                ("QGroundControl.Airspace",      1, 0, "AirspaceRule",                   "Reference only");
    qmlRegisterUncreatableType<AirspaceRuleFeature>         ("QGroundControl.Airspace",      1, 0, "AirspaceRuleFeature",            "Reference only");
    qmlRegisterUncreatableType<AirspaceRuleSet>             ("QGroundControl.Airspace",      1, 0, "AirspaceRuleSet",                "Reference only");
    qmlRegisterUncreatableType<AirspaceRulesetsProvider>    ("QGroundControl.Airspace",      1, 0, "AirspaceRulesetsProvider",       "Reference only");
    qmlRegisterUncreatableType<AirspaceWeatherInfoProvider> ("QGroundControl.Airspace",      1, 0, "AirspaceWeatherInfoProvider",    "Reference only");
Gus Grubba's avatar
Gus Grubba committed
41 42
    qmlRegisterUncreatableType<AirspaceFlightAuthorization> ("QGroundControl.Airspace",      1, 0, "AirspaceFlightAuthorization",    "Reference only");
    qmlRegisterUncreatableType<AirspaceFlightInfo>          ("QGroundControl.Airspace",      1, 0, "AirspaceFlightInfo",             "Reference only");
43 44 45 46
}

AirspaceManager::~AirspaceManager()
{
Gus Grubba's avatar
Gus Grubba committed
47 48 49 50 51
    if(_advisories) {
        delete _advisories;
    }
    if(_weatherProvider) {
        delete _weatherProvider;
52
    }
53 54
    if(_ruleSetsProvider) {
        delete _ruleSetsProvider;
Gus Grubba's avatar
Gus Grubba committed
55
    }
56 57
    if(_airspaces) {
        delete _airspaces;
Gus Grubba's avatar
Gus Grubba committed
58
    }
Gus Grubba's avatar
Gus Grubba committed
59 60 61
    if(_flightPlan) {
        delete _flightPlan;
    }
62 63 64 65 66
}

void AirspaceManager::setToolbox(QGCToolbox* toolbox)
{
    QGCTool::setToolbox(toolbox);
67
    // We should not call virtual methods in the constructor, so we instantiate the restriction provider here
68 69 70 71
    _ruleSetsProvider   = _instantiateRulesetsProvider();
    _weatherProvider    = _instatiateAirspaceWeatherInfoProvider();
    _advisories         = _instatiateAirspaceAdvisoryProvider();
    _airspaces          = _instantiateAirspaceRestrictionProvider();
Gus Grubba's avatar
Gus Grubba committed
72
    _flightPlan         = _instantiateAirspaceFlightPlanProvider();
73 74
}

75
void AirspaceManager::setROI(const QGeoCoordinate& pointNW, const QGeoCoordinate& pointSE, bool planView)
76
{
77 78 79 80 81 82 83 84 85 86 87
    if(planView) {
        //-- Is there a mission?
        if(_flightPlan->flightPermitStatus() != AirspaceFlightPlanProvider::PermitNone) {
            //-- Is there a polygon to work with?
            if(_flightPlan->missionArea()->isValid() && _flightPlan->missionArea()->area() > 0.0) {
                _setROI(*_flightPlan->missionArea());
                return;
            }
        }
    }
    //-- Use screen coordinates (what you see is what you get)
88
    _setROI(QGCGeoBoundingCube(pointNW, pointSE));
89 90
}

91
void AirspaceManager::_setROI(const QGCGeoBoundingCube& roi)
92
{
93 94 95 96
    if(_roi != roi) {
        _roi = roi;
        _roiUpdateTimer.start();
    }
97 98 99 100
}

void AirspaceManager::_updateToROI()
{
101
    if(_airspaces) {
102
        _airspaces->setROI(_roi);
103
    }
104
    if(_ruleSetsProvider) {
105
        _ruleSetsProvider->setROI(_roi);
Gus Grubba's avatar
Gus Grubba committed
106
    }
107
    if(_weatherProvider) {
108
        _weatherProvider->setROI(_roi);
109
    }
Gus Grubba's avatar
Gus Grubba committed
110
    if (_advisories) {
111
        _advisories->setROI(_roi);
Gus Grubba's avatar
Gus Grubba committed
112
    }
113
}