Add control button to activate and deactivate swift weather

- GUI changes
- Context and ISimulator APIs
- Refactored settings and static weather injection in CSimulatorCommon

refs #807
This commit is contained in:
Roland Winklmeier
2017-01-07 21:06:56 +01:00
committed by Mathew Sutcliffe
parent 2cea07f174
commit 1a6c7fa192
18 changed files with 135 additions and 84 deletions

View File

@@ -199,6 +199,9 @@ namespace BlackCore
//! Reset model by matching it again
virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) = 0;
//! Activates or deactivates simulator weather
virtual void setWeatherActivated(bool activated) = 0;
//! Request weather grid. Argument identifier is past in the signal to identify the requestor
virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) = 0;

View File

@@ -185,6 +185,13 @@ namespace BlackCore
return false;
}
//! \copydoc IContextSimulator::setWeatherActivated
virtual void setWeatherActivated(bool activated) override
{
Q_UNUSED(activated);
logEmptyContextWarning(Q_FUNC_INFO);
}
//! \copydoc IContextSimulator::requestWeatherGrid
virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override
{

View File

@@ -324,6 +324,8 @@ namespace BlackCore
emit simulatorPluginChanged(simulatorPluginInfo);
CLogMessage(this).info("Simulator plugin loaded: %1") << simulatorPluginInfo.toQString(true);
simulator->setWeatherActivated(m_isWeatherActivated);
m_matchingMessages.clear();
return true;
}
@@ -646,6 +648,15 @@ namespace BlackCore
return true;
}
void CContextSimulator::setWeatherActivated(bool activated)
{
m_isWeatherActivated = activated;
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
if (m_simulatorPlugin.first.isUnspecified()) { return; }
m_simulatorPlugin.second->setWeatherActivated(activated);
}
void CContextSimulator::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier)
{
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << identifier; }

View File

@@ -96,6 +96,7 @@ namespace BlackCore
virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override;
virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override;
virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
virtual void setWeatherActivated(bool activated) override;
virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override;
virtual BlackMisc::CStatusMessageList getMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual bool isMatchingMessagesEnabled() const override;
@@ -207,6 +208,7 @@ namespace BlackCore
bool m_initallyAddAircrafts = false;
bool m_enableMatchingMessages = true;
QString m_networkSessionId; //! Network session, if not connected empty
bool m_isWeatherActivated = false;
};
} // namespace
} // namespace

View File

@@ -174,6 +174,11 @@ namespace BlackCore
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("resetToModelMatchingAircraft"), callsign, callsign);
}
void CContextSimulatorProxy::setWeatherActivated(bool activated)
{
m_dBusInterface->callDBus(QLatin1Literal("setWeatherActivated"), activated);
}
void CContextSimulatorProxy::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier)
{
m_dBusInterface->callDBus(QLatin1Literal("requestWeatherGrid"), weatherGrid, identifier);

View File

@@ -74,6 +74,7 @@ namespace BlackCore
virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override;
virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override;
virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
virtual void setWeatherActivated(bool activated) override;
virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override;
virtual BlackMisc::CStatusMessageList getMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual bool isMatchingMessagesEnabled() const override;

View File

@@ -141,6 +141,9 @@ namespace BlackCore
//! Highlight the aircraft for given time (or disable highlight)
virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) = 0;
//! Activates or deactivates simulator weather
virtual void setWeatherActivated(bool activated) = 0;
//! Driver will be unloaded
virtual void unload() = 0;

View File

@@ -194,6 +194,17 @@ namespace BlackCore
}
}
void CSimulatorCommon::reloadWeatherSettings()
{
if (!m_isWeatherActivated) { return; }
const auto selectedWeatherScenario = m_weatherScenarioSettings.get();
if (!CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario))
{
m_lastWeatherPosition = {};
injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario));
}
}
void CSimulatorCommon::reverseLookupAndUpdateOwnAircraftModel(const QString &modelString)
{
CAircraftModel model = getOwnAircraftModel();
@@ -246,6 +257,20 @@ namespace BlackCore
return airports.findClosest(maxAirportsInRange(), ownPosition);
}
void CSimulatorCommon::setWeatherActivated(bool activated)
{
m_isWeatherActivated = activated;
if (m_isWeatherActivated)
{
const auto selectedWeatherScenario = m_weatherScenarioSettings.get();
if (!CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario))
{
m_lastWeatherPosition = {};
injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario));
}
}
}
CAircraftModel CSimulatorCommon::reverseLookupModel(const CAircraftModel &model)
{
bool modified = false;

View File

@@ -27,6 +27,7 @@
#include "blackmisc/simulation/simulatorinfo.h"
#include "blackmisc/simulation/simulatorplugininfo.h"
#include "blackmisc/simulation/simulatorinternals.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/interpolationrenderingsetup.h"
#include "blackmisc/simulation/interpolationhints.h"
#include "blackmisc/weather/weathergridprovider.h"
@@ -79,6 +80,7 @@ namespace BlackCore
virtual const BlackMisc::Simulation::CSimulatorPluginInfo &getSimulatorPluginInfo() const override;
virtual const BlackMisc::Simulation::CSimulatorInternals &getSimulatorInternals() const override;
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
virtual void setWeatherActivated(bool activated) override;
virtual void unload() override;
virtual int physicallyRemoveMultipleRemoteAircraft(const BlackMisc::Aviation::CCallsignSet &callsigns) override;
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override;
@@ -135,6 +137,9 @@ namespace BlackCore
//! Clear all aircraft related data
virtual void clearAllAircraft();
//! Inject weather grid to simulator
virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) { Q_UNUSED(weatherGrid); }
//! Airports from web services
BlackMisc::Aviation::CAirportList getWebServiceAirports() const;
@@ -156,6 +161,9 @@ namespace BlackCore
//! Set own model
void reverseLookupAndUpdateOwnAircraftModel(const QString &modelString);
//! Reload weather settings
void reloadWeatherSettings();
//! Parse driver specific details for ISimulator::parseCommandLine
virtual bool parseDetails(const BlackMisc::CSimpleCommandParser &parser);
@@ -172,6 +180,10 @@ namespace BlackCore
BlackMisc::Simulation::CSimulatedAircraftList m_aircraftToAddAgainWhenRemoved; //!< add this model again when removed, normally used to change model
QHash<BlackMisc::Aviation::CCallsign, BlackMisc::Simulation::CInterpolationHints> m_hints; //!< last ground elevation fetched
bool m_isWeatherActivated = false; //!< Is simulator weather activated?
BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last
BlackMisc::CSetting<BlackMisc::Simulation::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorCommon::reloadWeatherSettings }; //!< Selected weather scenario
//! Lookup against DB data
static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model);