You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.7 KiB
115 lines
3.7 KiB
8 years ago
|
/****************************************************************************
|
||
|
*
|
||
|
* (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.
|
||
|
*
|
||
|
****************************************************************************/
|
||
|
|
||
|
|
||
|
#include "AirspaceManagement.h"
|
||
|
#include <Vehicle.h>
|
||
|
|
||
|
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);
|
||
|
qmlRegisterUncreatableType<AirspaceAuthorization>("QGroundControl", 1, 0, "AirspaceAuthorization", "Reference only");
|
||
|
}
|
||
|
|
||
|
AirspaceManager::~AirspaceManager()
|
||
|
{
|
||
|
if (_restrictionsProvider) {
|
||
|
delete _restrictionsProvider;
|
||
|
}
|
||
7 years ago
|
if(_rulesetsProvider) {
|
||
|
delete _rulesetsProvider;
|
||
|
}
|
||
8 years ago
|
_polygonRestrictions.clearAndDeleteContents();
|
||
|
_circleRestrictions.clearAndDeleteContents();
|
||
|
}
|
||
|
|
||
|
void AirspaceManager::setToolbox(QGCToolbox* toolbox)
|
||
|
{
|
||
|
QGCTool::setToolbox(toolbox);
|
||
7 years ago
|
// We should not call virtual methods in the constructor, so we instantiate the restriction provider here
|
||
8 years ago
|
_restrictionsProvider = instantiateRestrictionProvider();
|
||
|
if (_restrictionsProvider) {
|
||
7 years ago
|
connect(_restrictionsProvider, &AirspaceRestrictionProvider::requestDone, this, &AirspaceManager::_restrictionsUpdated);
|
||
8 years ago
|
}
|
||
7 years ago
|
_rulesetsProvider = instantiateRulesetsProvider();
|
||
|
if (_rulesetsProvider) {
|
||
7 years ago
|
connect(_rulesetsProvider, &AirspaceRulesetsProvider::requestDone, this, &AirspaceManager::_rulessetsUpdated);
|
||
7 years ago
|
}
|
||
7 years ago
|
_weatherProvider = instatiateAirspaceWeatherInfoProvider();
|
||
8 years ago
|
}
|
||
|
|
||
|
void AirspaceManager::setROI(const QGeoCoordinate& center, double radiusMeters)
|
||
|
{
|
||
|
_roiCenter = center;
|
||
|
_roiRadius = radiusMeters;
|
||
|
_roiUpdateTimer.start();
|
||
|
}
|
||
|
|
||
|
void AirspaceManager::_updateToROI()
|
||
|
{
|
||
|
if (_restrictionsProvider) {
|
||
|
_restrictionsProvider->setROI(_roiCenter, _roiRadius);
|
||
|
}
|
||
7 years ago
|
if(_rulesetsProvider) {
|
||
|
_rulesetsProvider->setROI(_roiCenter);
|
||
|
}
|
||
7 years ago
|
if(_weatherProvider) {
|
||
|
_weatherProvider->setROI(_roiCenter);
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
|
void AirspaceManager::_restrictionsUpdated(bool success)
|
||
|
{
|
||
|
_polygonRestrictions.clearAndDeleteContents();
|
||
|
_circleRestrictions.clearAndDeleteContents();
|
||
|
if (success) {
|
||
|
for (const auto& circle : _restrictionsProvider->circles()) {
|
||
|
_circleRestrictions.append(circle);
|
||
|
}
|
||
|
for (const auto& polygon : _restrictionsProvider->polygons()) {
|
||
|
_polygonRestrictions.append(polygon);
|
||
|
}
|
||
|
} else {
|
||
|
// TODO: show error?
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
void AirspaceManager::_rulessetsUpdated(bool)
|
||
|
{
|
||
|
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
AirspaceVehicleManager::AirspaceVehicleManager(const Vehicle& vehicle)
|
||
8 years ago
|
: _vehicle(vehicle)
|
||
|
{
|
||
7 years ago
|
connect(&_vehicle, &Vehicle::armedChanged, this, &AirspaceVehicleManager::_vehicleArmedChanged);
|
||
|
connect(&_vehicle, &Vehicle::mavlinkMessageReceived, this, &AirspaceVehicleManager::vehicleMavlinkMessageReceived);
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
void AirspaceVehicleManager::_vehicleArmedChanged(bool armed)
|
||
8 years ago
|
{
|
||
|
if (armed) {
|
||
|
startTelemetryStream();
|
||
|
_vehicleWasInMissionMode = _vehicle.flightMode() == _vehicle.missionFlightMode();
|
||
|
} else {
|
||
|
stopTelemetryStream();
|
||
|
// end the flight if we were in mission mode during arming or disarming
|
||
|
// TODO: needs to be improved. for instance if we do RTL and then want to continue the mission...
|
||
|
if (_vehicleWasInMissionMode || _vehicle.flightMode() == _vehicle.missionFlightMode()) {
|
||
|
endFlight();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|