AirspaceManager.cc 3.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 12
#include "AirspaceManager.h"
#include "AirspaceWeatherInfoProvider.h"
Gus Grubba's avatar
Gus Grubba committed
13
#include "AirspaceAdvisoryProvider.h"
Gus Grubba's avatar
Gus Grubba committed
14
#include "AirspaceRestriction.h"
Gus Grubba's avatar
Gus Grubba committed
15
#include "AirspaceRulesetsProvider.h"
16
#include "AirspaceRestrictionProvider.h"
Gus Grubba's avatar
Gus Grubba committed
17 18
#include "AirspaceVehicleManager.h"
#include "AirspaceController.h"
Gus Grubba's avatar
Gus Grubba committed
19 20 21

#include "Vehicle.h"
#include "QGCApplication.h"
22 23 24 25 26 27 28 29 30

QGC_LOGGING_CATEGORY(AirspaceManagementLog, "AirspaceManagementLog")

AirspaceManager::AirspaceManager(QGCApplication* app, QGCToolbox* toolbox)
    : QGCTool(app, toolbox)
{
    _roiUpdateTimer.setInterval(2000);
    _roiUpdateTimer.setSingleShot(true);
    connect(&_roiUpdateTimer, &QTimer::timeout, this, &AirspaceManager::_updateToROI);
31 32 33 34 35 36 37
    qmlRegisterUncreatableType<AirspaceAuthorization>       ("QGroundControl",              1, 0, "AirspaceAuthorization",          "Reference only");
    qmlRegisterUncreatableType<AirspaceController>          ("QGroundControl.Vehicle",      1, 0, "AirspaceController",             "Reference only");
    qmlRegisterUncreatableType<AirspaceWeatherInfoProvider> ("QGroundControl.Vehicle",      1, 0, "AirspaceWeatherInfoProvider",    "Reference only");
    qmlRegisterUncreatableType<AirspaceAdvisoryProvider>    ("QGroundControl.Vehicle",      1, 0, "AirspaceAdvisoryProvider",       "Reference only");
    qmlRegisterUncreatableType<AirspaceRule>                ("QGroundControl.Vehicle",      1, 0, "AirspaceRule",                   "Reference only");
    qmlRegisterUncreatableType<AirspaceRulesetsProvider>    ("QGroundControl.Vehicle",      1, 0, "AirspaceRulesetsProvider",       "Reference only");
    qmlRegisterUncreatableType<AirspaceRestrictionProvider> ("QGroundControl.Vehicle",      1, 0, "AirspaceRestrictionProvider",    "Reference only");
38 39 40 41
}

AirspaceManager::~AirspaceManager()
{
Gus Grubba's avatar
Gus Grubba committed
42 43 44 45 46
    if(_advisories) {
        delete _advisories;
    }
    if(_weatherProvider) {
        delete _weatherProvider;
47
    }
Gus Grubba's avatar
Gus Grubba committed
48 49 50
    if(_rulesetsProvider) {
        delete _rulesetsProvider;
    }
51 52
    if(_airspaces) {
        delete _airspaces;
Gus Grubba's avatar
Gus Grubba committed
53
    }
54 55 56 57 58
}

void AirspaceManager::setToolbox(QGCToolbox* toolbox)
{
    QGCTool::setToolbox(toolbox);
59
    // We should not call virtual methods in the constructor, so we instantiate the restriction provider here
Gus Grubba's avatar
Gus Grubba committed
60 61 62
    _rulesetsProvider   = instantiateRulesetsProvider();
    _weatherProvider    = instatiateAirspaceWeatherInfoProvider();
    _advisories         = instatiateAirspaceAdvisoryProvider();
63
    _airspaces          = instantiateAirspaceRestrictionProvider();
64 65 66 67 68 69 70 71 72 73 74
}

void AirspaceManager::setROI(const QGeoCoordinate& center, double radiusMeters)
{
    _roiCenter = center;
    _roiRadius = radiusMeters;
    _roiUpdateTimer.start();
}

void AirspaceManager::_updateToROI()
{
75 76
    if(_airspaces) {
        _airspaces->setROI(_roiCenter, _roiRadius);
77
    }
Gus Grubba's avatar
Gus Grubba committed
78 79 80
    if(_rulesetsProvider) {
        _rulesetsProvider->setROI(_roiCenter);
    }
81 82 83
    if(_weatherProvider) {
        _weatherProvider->setROI(_roiCenter);
    }
Gus Grubba's avatar
Gus Grubba committed
84 85 86
    if (_advisories) {
        _advisories->setROI(_roiCenter, _roiRadius);
    }
87
}