Ref T773, allow to update CG per model string

* needed if CG is overridden by "dot command"
* update all existing aircraft (in range) if changing CG per modelstring
* made "overriddenCGorDefault" public so it can be checked if overridden
* use overridden value in CContextSimulator::xCtxAddedRemoteAircraftReadyForModelMatching
* allow to clear overridden values
This commit is contained in:
Klaus Basan
2020-03-05 00:19:33 +01:00
committed by Mat Sutcliffe
parent 93652ccd43
commit 2999aebf37
10 changed files with 252 additions and 43 deletions

View File

@@ -1109,6 +1109,13 @@ namespace BlackCore
return c;
}
CCallsignSet CContextNetwork::updateCGForModel(const QString &modelString, const CLength &cg)
{
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << modelString << cg.valueRoundedWithUnit(1); }
const CCallsignSet set = m_airspace->updateCGForModel(modelString, cg);
return set;
}
bool CContextNetwork::updateCGAndModelString(const CCallsign &callsign, const CLength &cg, const QString &modelString)
{
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign << cg.valueRoundedWithUnit(1) << modelString; }

View File

@@ -178,6 +178,7 @@ namespace BlackCore
virtual bool setAircraftEnabledFlag(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRendering) override;
virtual int reInitializeAllAircraft() override;
virtual bool updateCG(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CLength &cg) override;
virtual BlackMisc::Aviation::CCallsignSet updateCGForModel(const QString &modelString, const BlackMisc::PhysicalQuantities::CLength &cg) override;
virtual bool updateCGAndModelString(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CLength &cg, const QString &modelString) override;
virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const override;
virtual BlackMisc::Aviation::CCallsignSet getAircraftInRangeCallsigns() const override;

View File

@@ -124,6 +124,11 @@ namespace BlackCore
return this;
}
bool CContextSimulator::isSimulatorPluginAvailable() const
{
return m_simulatorPlugin.second && IContextSimulator::isSimulatorAvailable();
}
CContextSimulator::~CContextSimulator()
{
this->gracefulShutdown();
@@ -525,7 +530,7 @@ namespace BlackCore
Q_ASSERT(c);
c = connect(CLogHandler::instance(), &CLogHandler::remoteMessageLogged, this, &CContextSimulator::relayStatusMessageToSimulator);
Q_ASSERT(c);
Q_UNUSED(c);
Q_UNUSED(c)
// Once the simulator signaled it is ready to simulate, add all known aircraft
m_initallyAddAircraft = true;
@@ -603,7 +608,7 @@ namespace BlackCore
{
const bool s = QMetaObject::invokeMethod(listener, &ISimulatorListener::start, Qt::QueuedConnection);
Q_ASSERT_X(s, Q_FUNC_INFO, "cannot invoke method");
Q_UNUSED(s);
Q_UNUSED(s)
}
CLogMessage(this).info(u"Listening for simulator '%1'") << simulatorInfo.getIdentifier();
return true;
@@ -658,7 +663,8 @@ namespace BlackCore
void CContextSimulator::xCtxAddedRemoteAircraftReadyForModelMatching(const CSimulatedAircraft &remoteAircraft)
{
if (!this->isSimulatorAvailable()) { return; }
if (!this->isSimulatorPluginAvailable()) { return; }
const CCallsign callsign = remoteAircraft.getCallsign();
BLACK_VERIFY_X(!callsign.isEmpty(), Q_FUNC_INFO, "Remote aircraft with empty callsign");
if (callsign.isEmpty()) { return; }
@@ -692,6 +698,9 @@ namespace BlackCore
break; // leave CG from model alone
}
const CLength overriddenCG = m_simulatorPlugin.second->overriddenCGorDefault(CLength::null(), aircraftModel.getModelString());
if (!overriddenCG.isNull()) { aircraftModel.setCG(overriddenCG); }
// model in provider
this->updateAircraftModel(callsign, aircraftModel, this->identifier());

View File

@@ -181,6 +181,9 @@ namespace BlackCore
//! Register myself in DBus
CContextSimulator *registerWithDBus(BlackMisc::CDBusServer *server);
//! Simulator plugin available?
bool isSimulatorPluginAvailable() const;
private:
static constexpr int MatchingLogMaxModelSetSize = 250; //!< default value for switching matching log on
static constexpr int MaxModelAddedFailoverTrials = 3; //!< if model cannot be added, try again max <n> times