AirspaceManager.cc 3.8 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)
74
{
75
    _setROI(QGCGeoBoundingCube(pointNW, pointSE));
76 77
}

78
void AirspaceManager::_setROI(const QGCGeoBoundingCube& roi)
79
{
80
    _roi = roi;
81 82 83 84 85
    _roiUpdateTimer.start();
}

void AirspaceManager::_updateToROI()
{
86
    if(_airspaces) {
87
        _airspaces->setROI(_roi);
88
    }
89
    if(_ruleSetsProvider) {
90
        _ruleSetsProvider->setROI(_roi);
Gus Grubba's avatar
Gus Grubba committed
91
    }
92
    if(_weatherProvider) {
93
        _weatherProvider->setROI(_roi);
94
    }
Gus Grubba's avatar
Gus Grubba committed
95
    if (_advisories) {
96
        _advisories->setROI(_roi);
Gus Grubba's avatar
Gus Grubba committed
97
    }
98
}