AirspaceManager.cc 6.05 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

QGC_LOGGING_CATEGORY(AirspaceManagementLog, "AirspaceManagementLog")

25
//-----------------------------------------------------------------------------
26 27
AirspaceManager::AirspaceManager(QGCApplication* app, QGCToolbox* toolbox)
    : QGCTool(app, toolbox)
28
    , _airspaceVisible(false)
29 30 31
{
    _roiUpdateTimer.setInterval(2000);
    _roiUpdateTimer.setSingleShot(true);
32 33 34 35
    _updateTimer.setInterval(1000);
    _updateTimer.setSingleShot(true);
    connect(&_roiUpdateTimer, &QTimer::timeout, this, &AirspaceManager::_updateToROITimeout);
    connect(&_updateTimer,    &QTimer::timeout, this, &AirspaceManager::_updateTimeout);
36
    qmlRegisterUncreatableType<AirspaceAdvisoryProvider>    ("QGroundControl.Airspace",      1, 0, "AirspaceAdvisoryProvider",       "Reference only");
Gus Grubba's avatar
Gus Grubba committed
37
    qmlRegisterUncreatableType<AirspaceFlightPlanProvider>  ("QGroundControl.Airspace",      1, 0, "AirspaceFlightPlanProvider",     "Reference only");
38 39 40 41 42 43 44
    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
45 46
    qmlRegisterUncreatableType<AirspaceFlightAuthorization> ("QGroundControl.Airspace",      1, 0, "AirspaceFlightAuthorization",    "Reference only");
    qmlRegisterUncreatableType<AirspaceFlightInfo>          ("QGroundControl.Airspace",      1, 0, "AirspaceFlightInfo",             "Reference only");
47 48
}

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

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

82 83 84
//-----------------------------------------------------------------------------
void
AirspaceManager::setROI(const QGeoCoordinate& pointNW, const QGeoCoordinate& pointSE, bool planView, bool reset)
85
{
86 87 88 89 90
    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) {
91 92 93 94 95 96
                if(reset) {
                    _roi = *_flightPlan->missionArea();
                    _updateToROI(true);
                } else {
                    _setROI(*_flightPlan->missionArea());
                }
97 98 99 100 101
                return;
            }
        }
    }
    //-- Use screen coordinates (what you see is what you get)
102 103 104 105 106 107 108 109 110 111 112 113 114 115
    if(reset) {
        _roi = QGCGeoBoundingCube(pointNW, pointSE);
        _updateToROI(true);
    } else {
        _setROI(QGCGeoBoundingCube(pointNW, pointSE));
    }
}


//-----------------------------------------------------------------------------
void
AirspaceManager::setUpdate()
{
    _updateTimer.start();
116 117
}

118 119 120
//-----------------------------------------------------------------------------
void
AirspaceManager::_setROI(const QGCGeoBoundingCube& roi)
121
{
122 123 124 125
    if(_roi != roi) {
        _roi = roi;
        _roiUpdateTimer.start();
    }
126 127
}

128 129 130
//-----------------------------------------------------------------------------
void
AirspaceManager::_updateToROI(bool reset)
131
{
132 133 134
    if(reset) {
        _updateTimer.stop();
    }
135
    if(_airspaces) {
136
        _airspaces->setROI(_roi, reset);
137
    }
138
    if(_ruleSetsProvider) {
139
        _ruleSetsProvider->setROI(_roi, reset);
Gus Grubba's avatar
Gus Grubba committed
140
    }
141
    if(_weatherProvider) {
142
        _weatherProvider->setROI(_roi, reset);
143
    }
Gus Grubba's avatar
Gus Grubba committed
144
    if (_advisories) {
145
        _advisories->setROI(_roi, reset);
Gus Grubba's avatar
Gus Grubba committed
146
    }
147
}
148 149 150 151 152 153 154 155 156 157 158 159 160 161

//-----------------------------------------------------------------------------
void
AirspaceManager::_updateToROITimeout()
{
    _updateToROI(false);
}

//-----------------------------------------------------------------------------
void
AirspaceManager::_updateTimeout()
{
    emit update();
}