AirspaceController.cc 2.01 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (c) 2009-2016 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
10
#include "AirMapManager.h"
11 12
#include "AirspaceController.h"
#include "AirspaceManagement.h"
13 14 15
#include "QGCApplication.h"
#include "QGCQGeoCoordinate.h"

Gus Grubba's avatar
Gus Grubba committed
16 17 18
#define WEATHER_UPDATE_DISTANCE 50000                   //-- 50km threshold for weather updates
#define WEATHER_UPDATE_TIME     30 * 60 * 60 * 1000     //-- 30 minutes threshold for weather updates

19
AirspaceController::AirspaceController(QObject* parent)
20
    : QObject(parent)
21
    , _manager(qgcApp()->toolbox()->airspaceManager())
Gus Grubba's avatar
Gus Grubba committed
22 23 24 25 26 27 28
    , _weatherTemp(0)
    , _hasWeather(false)
{
    connect(_manager, &AirspaceManager::weatherUpdate, this, &AirspaceController::_weatherUpdate);
}

void AirspaceController::setROI(QGeoCoordinate center, double radius)
29
{
Gus Grubba's avatar
Gus Grubba committed
30 31 32 33 34 35 36 37 38 39 40 41 42
    _manager->setROI(center, radius);
    //-- If first time or we've moved more than WEATHER_UPDATE_DISTANCE, ask for weather updates.
    if(!_lastRoiCenter.isValid() || _lastRoiCenter.distanceTo(center) > WEATHER_UPDATE_DISTANCE) {
        _lastRoiCenter = center;
        _manager->requestWeatherUpdate(center);
        _weatherTime.start();
    } else {
        //-- Check weather once every WEATHER_UPDATE_TIME
        if(_weatherTime.elapsed() > WEATHER_UPDATE_TIME) {
            _manager->requestWeatherUpdate(center);
            _weatherTime.start();
        }
    }
43 44
}

Gus Grubba's avatar
Gus Grubba committed
45 46 47 48 49 50 51 52
void AirspaceController::_weatherUpdate(bool success, QGeoCoordinate, WeatherInformation weather)
{
    qCDebug(AirMapManagerLog)<<"Weather Info:"<< success << weather.condition << weather.temperature;
    _hasWeather     = success;
    _weatherIcon    = QStringLiteral("qrc:/airmapweather/") + weather.condition + QStringLiteral(".svg");
    _weatherTemp    = weather.temperature;
    emit weatherChanged();
}