AirspaceManager.cc 4.3 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");
41 42 43 44
}

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

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

73
void AirspaceManager::setROI(const QGeoCoordinate& pointNW, const QGeoCoordinate& pointSE, bool planView)
74
{
75 76 77 78 79 80 81 82 83 84 85
    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)
86
    _setROI(QGCGeoBoundingCube(pointNW, pointSE));
87 88
}

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

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