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

View File

@@ -487,7 +487,8 @@ namespace BlackCore
{
const CCallsign cs(parser.part(2));
const bool changed = this->setInterpolationMode(part1, cs);
CLogMessage(this).info(changed ? QStringLiteral("Changed interpolation mode for '%1'")
CLogMessage(this).info(changed
? QStringLiteral("Changed interpolation mode for '%1'")
: QStringLiteral("Unchanged interpolation mode for '%1'")) << cs.asString();
return true;
}
@@ -496,7 +497,8 @@ namespace BlackCore
CInterpolationAndRenderingSetupGlobal setup = this->getInterpolationSetupGlobal();
const bool changed = setup.setInterpolatorMode(part1);
if (changed) { this->setInterpolationSetupGlobal(setup); }
CLogMessage(this).info(changed ? QStringLiteral("Changed interpolation mode globally")
CLogMessage(this).info(changed
? QStringLiteral("Changed interpolation mode globally")
: QStringLiteral("Unchanged interpolation mode"));
return true;
}
@@ -566,17 +568,47 @@ namespace BlackCore
}
// CG override
if (part1 == QStringView(u"cg") && parser.hasPart(3))
if (part1 == QStringView(u"cg"))
{
// ms can be a string like "B773 B773_RR SDM"
const QString ms = parser.partAndRemainingStringAfter(3).toUpper();
CLength cg;
cg.parseFromString(parser.part(2), CPqString::SeparatorBestGuess);
if (!ms.isEmpty())
if (parser.part(2).startsWith("clear", Qt::CaseInsensitive))
{
CLogMessage(this).info(u"Setting CG for '%1': %2") << ms << cg.valueRoundedWithUnit();
this->insertCGForModelStringOverridden(cg, ms);
CLogMessage(this).info(u"Clear all overridden CGs");
const CLengthPerCallsign cgsPerCallsign = this->clearCGOverrides();
// restore all CGs
for (const CCallsign &cs : this->getAircraftInRangeCallsigns())
{
// reset CGs per callsign
const CLength cg = cgsPerCallsign.contains(cs) ? cgsPerCallsign[cs] : CLength::null();
this->updateCG(cs, cg);
}
return true;
}
if (parser.hasPart(3))
{
// ms can be a string like "B773 B773_RR SDM"
const QString ms = parser.partAndRemainingStringAfter(3).toUpper();
CLength cg;
cg.parseFromString(parser.part(2), CPqString::SeparatorBestGuess);
if (!ms.isEmpty())
{
CLogMessage(this).info(u"Setting CG for '%1': %2") << ms << cg.valueRoundedWithUnit();
const bool set = this->insertCGForModelStringOverridden(cg, ms);
if (set)
{
const CCallsignSet callsigns = this->updateCGForModel(ms, cg);
if (!callsigns.isEmpty())
{
this->insertCGOverridden(cg, callsigns);
CLogMessage(this).info(u"Setting CG for '%1': %2") << callsigns.getCallsignsAsString(true) << cg.valueRoundedWithUnit();
}
return true;
} // set
} // model string
} // 3 parts
}
// driver specific cmd line arguments
@@ -588,7 +620,7 @@ namespace BlackCore
if (CSimpleCommandParser::registered("BlackCore::ISimulator")) { return; }
CSimpleCommandParser::registerCommand({".drv", "alias: .driver .plugin"});
CSimpleCommandParser::registerCommand({".drv unload", "unload driver"});
CSimpleCommandParser::registerCommand({".drv cg length modelstring", "override CG"});
CSimpleCommandParser::registerCommand({".drv cg length clear|modelstr.", "override CG"});
CSimpleCommandParser::registerCommand({".drv limit number/secs.", "limit updates to number per second (0..off)"});
CSimpleCommandParser::registerCommand({".drv logint callsign", "log interpolator for callsign"});
CSimpleCommandParser::registerCommand({".drv logint off", "no log information for interpolator"});
@@ -884,9 +916,12 @@ namespace BlackCore
const QString modelString = model.getModelString();
if (modelString.isEmpty()) { return; }
// this value now is the simulator or overridden value
const CLength cgOvr = this->overriddenCGorDefault(simulatorCG, modelString);
if (!cgOvr.isNull() && !this->hasSameSimulatorCG(cgOvr, callsign))
{
// the value did change
const CSimulatorSettings::CGSource source = this->getSimulatorSettings().getSimulatorSettings().getCGSource();
if (source != CSimulatorSettings::CGFromDBOnly)
{

View File

@@ -285,19 +285,19 @@ namespace BlackCore
//! \addtogroup swiftdotcommands
//! @{
//! <pre>
//! .drv cg length modelstring set overridden CG for model string BlackCore::ISimulator
//! .drv unload unload plugin BlackCore::ISimulator
//! .drv limit number limit the number of updates BlackCore::ISimulator
//! .drv logint callsign log interpolator for callsign BlackCore::ISimulator
//! .drv logint off no log information for interpolator BlackCore::ISimulator
//! .drv logint write write interpolator log to file BlackCore::ISimulator
//! .drv logint clear clear current log BlackCore::ISimulator
//! .drv pos callsign shows current position in simulator BlackCore::ISimulator
//! .drv spline|linear callsign interpolator spline or linear BlackCore::ISimulator
//! .drv aircraft readd callsign re-add (add again) aircraft BlackCore::ISimulator
//! .drv aircraft readd all re-add all aircraft BlackCore::ISimulator
//! .drv aircraft rm callsign remove aircraft BlackCore::ISimulator
//! .drv fsuipc on|off enable/disable FSUIPC (if applicable) BlackSimPlugin::FsCommon::CSimulatorFsCommon
//! .drv cg length clear|modelstring set overridden CG for model string BlackCore::ISimulator
//! .drv unload unload plugin BlackCore::ISimulator
//! .drv limit number limit the number of updates BlackCore::ISimulator
//! .drv logint callsign log interpolator for callsign BlackCore::ISimulator
//! .drv logint off no log information for interpolator BlackCore::ISimulator
//! .drv logint write write interpolator log to file BlackCore::ISimulator
//! .drv logint clear clear current log BlackCore::ISimulator
//! .drv pos callsign shows current position in simulator BlackCore::ISimulator
//! .drv spline|linear callsign interpolator spline or linear BlackCore::ISimulator
//! .drv aircraft readd callsign re-add (add again) aircraft BlackCore::ISimulator
//! .drv aircraft readd all re-add all aircraft BlackCore::ISimulator
//! .drv aircraft rm callsign remove aircraft BlackCore::ISimulator
//! .drv fsuipc on|off enable/disable FSUIPC (if applicable) BlackSimPlugin::FsCommon::CSimulatorFsCommon
//! </pre>
//! @}
//! Parse command line for simulator drivers, derived classes can add specific parsing by overriding ISimulator::parseDetails