mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
This should be further improved with #417
This commit is contained in:
@@ -93,19 +93,11 @@ namespace BlackCore
|
||||
//! Return list of available simulator plugins
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const = 0;
|
||||
|
||||
//! Returns true when simulator is connected
|
||||
//! \sa isSimulating
|
||||
virtual bool isConnected() const = 0;
|
||||
|
||||
//! Can we connect?
|
||||
//! \todo Remove?
|
||||
virtual bool canConnect() const = 0;
|
||||
|
||||
//! Disconnect from simulator
|
||||
virtual bool disconnectFromSimulator() = 0;
|
||||
|
||||
//! Returns true when simulator is running / simulating
|
||||
virtual bool isSimulating() const = 0;
|
||||
//! Simulator combined status
|
||||
virtual int getSimulatorStatus() const = 0;
|
||||
|
||||
//! Simulator info
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const = 0;
|
||||
@@ -189,9 +181,6 @@ namespace BlackCore
|
||||
//! Simulator avialable (driver available)?
|
||||
bool isSimulatorAvailable() const { return BlackMisc::CProject::isCompiledWithFlightSimulatorSupport() && !getSimulatorPluginInfo().isUnspecified(); }
|
||||
|
||||
//! Simulator paused?
|
||||
virtual bool isPaused() const = 0;
|
||||
|
||||
//! Settings have been changed
|
||||
virtual void settingsChanged(uint type) = 0;
|
||||
|
||||
|
||||
@@ -86,29 +86,14 @@ namespace BlackCore
|
||||
return list;
|
||||
}
|
||||
|
||||
bool CContextSimulator::isConnected() const
|
||||
int CContextSimulator::getSimulatorStatus() const
|
||||
{
|
||||
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulatorPlugin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!m_simulatorPlugin) { return 0; }
|
||||
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
return m_simulatorPlugin->simulator->isConnected();
|
||||
}
|
||||
|
||||
bool CContextSimulator::canConnect() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulatorPlugin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
return m_simulatorPlugin->simulator->canConnect();
|
||||
Q_ASSERT_X(m_simulatorPlugin->simulator, Q_FUNC_INFO, "Missing simulator");
|
||||
return m_simulatorPlugin->simulator->getSimulatorStatus();
|
||||
}
|
||||
|
||||
bool CContextSimulator::disconnectFromSimulator()
|
||||
@@ -722,28 +707,6 @@ namespace BlackCore
|
||||
this->m_simulatorPlugin->simulator->highlightAircraft(aircraftToHighlight, enableHighlight, displayTime);
|
||||
}
|
||||
|
||||
bool CContextSimulator::isPaused() const
|
||||
{
|
||||
if (!this->m_simulatorPlugin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
return m_simulatorPlugin->simulator->isPaused();
|
||||
}
|
||||
|
||||
bool CContextSimulator::isSimulating() const
|
||||
{
|
||||
if (!this->m_simulatorPlugin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
return m_simulatorPlugin->simulator->isSimulating();
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_simulatorStarted(QObject *listener)
|
||||
{
|
||||
Q_ASSERT(listener);
|
||||
|
||||
@@ -49,21 +49,12 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginList()
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::isConnected()
|
||||
virtual bool isConnected() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::canConnect
|
||||
virtual bool canConnect() const override;
|
||||
//! \copydoc IContextSimulator::getSimulatorStatus()
|
||||
virtual int getSimulatorStatus() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::disconnectFrom
|
||||
virtual bool disconnectFromSimulator() override;
|
||||
|
||||
//! \copydoc IContextSimulator::isPaused
|
||||
virtual bool isPaused() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::isSimulating
|
||||
virtual bool isSimulating() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginInfo()
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override;
|
||||
|
||||
|
||||
@@ -61,14 +61,9 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<CSimulatorPluginInfoList>(QLatin1Literal("getAvailableSimulatorPlugins"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::isConnected() const
|
||||
int CContextSimulatorProxy::getSimulatorStatus() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("isConnected"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::canConnect() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("canConnect"));
|
||||
return m_dBusInterface->callDBusRet<int>(QLatin1Literal("getSimulatorStatus"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::disconnectFromSimulator()
|
||||
@@ -226,14 +221,4 @@ namespace BlackCore
|
||||
m_dBusInterface->callDBus(QLatin1Literal("enableDebugMessages"), driver, interpolator);
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::isPaused() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("isPaused"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::isSimulating() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("isRunning"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -45,21 +45,12 @@ namespace BlackCore
|
||||
|
||||
public slots:
|
||||
|
||||
//! \copydoc IContextSimulator::isConnected()
|
||||
virtual bool isConnected() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::canConnect
|
||||
virtual bool canConnect() const override;
|
||||
//! \copydoc IContextSimulator::getSimualtorStatus()
|
||||
virtual int getSimulatorStatus() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::disconnectFrom
|
||||
virtual bool disconnectFromSimulator() override;
|
||||
|
||||
//! \copydoc IContextSimulator::isSimulating
|
||||
virtual bool isSimulating() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::isPaused
|
||||
virtual bool isPaused() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getAirportsInRange()
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
|
||||
@@ -128,13 +119,13 @@ namespace BlackCore
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPluginFromSettings()
|
||||
virtual bool loadSimulatorPluginFromSettings();
|
||||
|
||||
|
||||
//! \copydoc IContextSimulator::listenForSimulator()
|
||||
virtual void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
|
||||
//! \copydoc IContextSimulator::listenForAllSimulators()
|
||||
virtual void listenForAllSimulators() override;
|
||||
|
||||
|
||||
//! \copydoc IContextSimulator::listenForSimulatorFromSettings()
|
||||
virtual void listenForSimulatorFromSettings() override;
|
||||
|
||||
|
||||
@@ -20,6 +20,15 @@ using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
int ISimulator::getSimulatorStatus() const
|
||||
{
|
||||
int status =
|
||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isSimulating() ? Simulating : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0));
|
||||
return status;
|
||||
}
|
||||
|
||||
const QString &ISimulator::simulatorOriginator()
|
||||
{
|
||||
// string is generated once, the timestamp allows to use multiple
|
||||
@@ -34,7 +43,7 @@ namespace BlackCore
|
||||
{
|
||||
QString s;
|
||||
if (status & Connected) { s.append("Connected"); }
|
||||
if (status & Running) { if (!s.isEmpty()) { s.append(", "); } s.append("Simulating"); }
|
||||
if (status & Simulating) { if (!s.isEmpty()) { s.append(", "); } s.append("Simulating"); }
|
||||
if (status & Paused) { if (!s.isEmpty()) { s.append(", "); } s.append("Paused"); }
|
||||
return s;
|
||||
}
|
||||
@@ -46,11 +55,7 @@ namespace BlackCore
|
||||
|
||||
void ISimulator::emitSimulatorCombinedStatus()
|
||||
{
|
||||
int status =
|
||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0))
|
||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0));
|
||||
emit simulatorStatusChanged(status);
|
||||
emit simulatorStatusChanged(getSimulatorStatus());
|
||||
}
|
||||
|
||||
ISimulatorListener::ISimulatorListener(QObject *parent) : QObject(parent)
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace BlackCore
|
||||
{
|
||||
Disconnected = 0,
|
||||
Connected = 1 << 0, //!< Is the plugin connected to the simulator?
|
||||
Running = 1 << 1, //!< Is the simulator actually simulating?
|
||||
Simulating = 1 << 1, //!< Is the simulator actually simulating?
|
||||
Paused = 1 << 2, //!< Is the simulator paused?
|
||||
};
|
||||
|
||||
@@ -54,18 +54,18 @@ namespace BlackCore
|
||||
//! Are we connected to the simulator?
|
||||
virtual bool isConnected() const = 0;
|
||||
|
||||
//! Can we connect?
|
||||
virtual bool canConnect() const = 0;
|
||||
|
||||
//! Is time synchronization on?
|
||||
virtual bool isTimeSynchronized() const = 0;
|
||||
|
||||
//! Simulator paused?
|
||||
virtual bool isPaused() const = 0;
|
||||
|
||||
//! Simulator running?
|
||||
virtual bool isSimulating() const = 0;
|
||||
|
||||
//! Combined status
|
||||
virtual int getSimulatorStatus() const;
|
||||
|
||||
//! Is time synchronization on?
|
||||
virtual bool isTimeSynchronized() const = 0;
|
||||
|
||||
//! Get the simulator info (metadata of plugin)
|
||||
virtual const BlackMisc::Simulation::CSimulatorPluginInfo &getSimulatorPluginInfo() const = 0;
|
||||
|
||||
@@ -219,6 +219,10 @@ namespace BlackCore
|
||||
//! Remove all remote aircraft
|
||||
virtual void physicallyRemoveAllRemoteAircraft() = 0;
|
||||
|
||||
//! Can we connect?
|
||||
//! \todo Do we really need this function? Currently made protected, as
|
||||
virtual bool canConnect() const = 0;
|
||||
|
||||
//! Emit the combined status
|
||||
//! \sa simulatorStatusChanged;
|
||||
void emitSimulatorCombinedStatus();
|
||||
@@ -249,7 +253,6 @@ namespace BlackCore
|
||||
virtual void stop() = 0;
|
||||
|
||||
signals:
|
||||
|
||||
//! Emitted when the listener discovers the simulator running.
|
||||
void simulatorStarted();
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace BlackGui
|
||||
this->ui->tvp_AircraftInRange->updateContainer(this->getIContextNetwork()->getAircraftInRange());
|
||||
}
|
||||
}
|
||||
if (this->getIContextSimulator()->isConnected())
|
||||
if (this->getIContextSimulator()->getSimulatorStatus() > 0)
|
||||
{
|
||||
bool visible = (this->isVisibleWidget() && this->currentWidget() == this->ui->tb_AirportsInRange);
|
||||
if (this->countAirportsInRange() < 1 || visible)
|
||||
|
||||
@@ -81,8 +81,7 @@ namespace BlackGui
|
||||
|
||||
// initial values
|
||||
this->ps_onMapperReady();
|
||||
bool connected = this->getIContextSimulator()->isConnected();
|
||||
this->ps_onSimulatorStatusChanged(connected ? ISimulator::Connected : ISimulator::Disconnected);
|
||||
this->ps_onSimulatorStatusChanged(this->getIContextSimulator()->getSimulatorStatus());
|
||||
}
|
||||
|
||||
if (this->getIContextNetwork())
|
||||
@@ -116,7 +115,7 @@ namespace BlackGui
|
||||
this->ui->led_Simulator->setTriState();
|
||||
this->ui->led_Simulator->setTriStateToolTip(s);
|
||||
}
|
||||
else if (status & ISimulator::Running)
|
||||
else if (status & ISimulator::Simulating)
|
||||
{
|
||||
this->ui->led_Simulator->setOn(true);
|
||||
this->ui->led_Simulator->setOnToolTip(s);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "blackcore/context_audio.h"
|
||||
#include "blackcore/context_simulator.h"
|
||||
#include "blackcore/network.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/aviation/aircrafticaodata.h"
|
||||
#include "../uppercasevalidator.h"
|
||||
@@ -355,8 +356,9 @@ namespace BlackGui
|
||||
|
||||
CAircraftIcaoData icao;
|
||||
|
||||
bool simConnected = this->getIContextSimulator() && this->getIContextSimulator()->isSimulating();
|
||||
if (simConnected)
|
||||
bool simulating = this->getIContextSimulator() &&
|
||||
(this->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating);
|
||||
if (simulating)
|
||||
{
|
||||
CAircraftModel model = this->getIContextOwnAircraft()->getOwnAircraft().getModel();
|
||||
this->ui->le_SimulatorModel->setText(model.getModelString());
|
||||
@@ -381,7 +383,6 @@ namespace BlackGui
|
||||
{
|
||||
this->setGuiIcaoValues(icao, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CLoginComponent::setGuiIcaoValues(const CAircraftIcaoData &icao, bool onlyIfEmpty)
|
||||
|
||||
@@ -386,7 +386,7 @@ namespace BlackGui
|
||||
Q_ASSERT_X(getIContextNetwork(), Q_FUNC_INFO, "missing network context");
|
||||
Q_ASSERT_X(getIContextSimulator(), Q_FUNC_INFO, "missing simulator context");
|
||||
if (this->isVisibleWidget()) { return; }
|
||||
if (getIContextSimulator()->isConnected())
|
||||
if (getIContextSimulator()->getSimulatorStatus() > 0)
|
||||
{
|
||||
const CSimulatedAircraftList aircraft(getIContextNetwork()->getAircraftInRange());
|
||||
this->ui->tvp_SimulatedAircraft->updateContainer(aircraft);
|
||||
|
||||
@@ -62,17 +62,20 @@ namespace BlackGui
|
||||
|
||||
void CSimulatorComponent::update()
|
||||
{
|
||||
Q_ASSERT(getIContextSimulator());
|
||||
Q_ASSERT_X(getIContextSimulator(), Q_FUNC_INFO, "No simulator context");
|
||||
|
||||
if (!this->isVisibleWidget()) return; // no updates on invisible widgets
|
||||
if (!this->getIContextOwnAircraft()) return;
|
||||
|
||||
if (!this->getIContextSimulator()->isConnected()) {
|
||||
int simualtorStatus = this->getIContextSimulator()->getSimulatorStatus();
|
||||
if (simualtorStatus == 0)
|
||||
{
|
||||
addOrUpdateByName("info", tr("No simulator available"), CIcons::StandardIconWarning16);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->getIContextSimulator()->isSimulating()) {
|
||||
if (!(simualtorStatus & ISimulator::Simulating))
|
||||
{
|
||||
this->addOrUpdateByName("info",
|
||||
tr("Simulator (%1) not yet running").arg(
|
||||
getIContextSimulator()->getSimulatorPluginInfo().getSimulator()
|
||||
@@ -109,12 +112,12 @@ namespace BlackGui
|
||||
|
||||
void CSimulatorComponent::runtimeHasBeenSet()
|
||||
{
|
||||
Q_ASSERT(this->getIContextSimulator());
|
||||
if (!this->getIContextSimulator()) return;
|
||||
Q_ASSERT_X(this->getIContextSimulator(), Q_FUNC_INFO, "Missing simulator context");
|
||||
if (!this->getIContextSimulator()) { return; }
|
||||
QObject::connect(this->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CSimulatorComponent::ps_onSimulatorStatusChanged);
|
||||
|
||||
this->setUpdateInterval(getUpdateIntervalMs());
|
||||
if (!getIContextSimulator()->isConnected())
|
||||
if (getIContextSimulator()->getSimulatorStatus() == 0)
|
||||
{
|
||||
this->stopTimer();
|
||||
}
|
||||
@@ -122,10 +125,13 @@ namespace BlackGui
|
||||
|
||||
void CSimulatorComponent::ps_onSimulatorStatusChanged(int status)
|
||||
{
|
||||
if (status & ISimulator::Connected) {
|
||||
if (status & ISimulator::Connected)
|
||||
{
|
||||
int intervalMs = getUpdateIntervalMs();
|
||||
this->m_updateTimer->startTimer(intervalMs);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
this->stopTimer();
|
||||
clear();
|
||||
update();
|
||||
|
||||
Reference in New Issue
Block a user