diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index c096a9efe..bf76e452c 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -864,7 +864,11 @@ namespace BlackCore const CLength cgOvr = this->overriddenCGorDefault(simulatorCG, modelString); if (!cgOvr.isNull() && !this->hasSameSimulatorCG(cgOvr, callsign)) { - this->insertCG(cgOvr, modelString, callsign); // per model string and CG + const CSimulatorSettings::CGSource source = this->getSimulatorSettings().getSimulatorSettings().getCGSource(); + if (source != CSimulatorSettings::CGFromDBOnly) + { + this->insertCG(cgOvr, modelString, callsign); // per model string and CG + } // here we know we have a valid model and CG did change const CSimulatorInfo sim = this->getSimulatorInfo(); diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index db99d3858..9ca509859 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -56,10 +56,22 @@ namespace BlackMisc } template - CLength CInterpolator::getAndFetchModelCG() + CLength CInterpolator::getAndFetchModelCG(const CLength &dbCG) { - const CLength cgDB = this->getRemoteAircraftProvider() ? this->getRemoteAircraftProvider()->getCGFromDB(m_callsign) : CLength::null(); - const CLength cg = this->getSimulatorOrDbCG(m_callsign, cgDB); // simulation environment + CLength cgDb = dbCG; + if (cgDb.isNull()) + { + // no input DB value, try to find one + cgDb = this->getRemoteAircraftProvider() ? this->getRemoteAircraftProvider()->getCGFromDB(m_callsign) : CLength::null(); + } + else if (this->getRemoteAircraftProvider()) + { + // if a value has been passed, remember it + if (m_model.hasModelString()) { this->getRemoteAircraftProvider()->rememberCGFromDB(cgDb, m_model.getModelString()); } + if (!m_model.getCallsign().isEmpty()) { this->getRemoteAircraftProvider()->rememberCGFromDB(cgDb, m_model.getCallsign()); } + } + + const CLength cg = this->getSimulatorOrDbCG(m_callsign, cgDb); // simulation environment m_model.setCG(cg); m_model.setCallsign(m_callsign); return cg; @@ -511,7 +523,7 @@ namespace BlackMisc if (!m_model.hasCG() || slowUpdateStep) { - this->getAndFetchModelCG(); // update CG + this->getAndFetchModelCG(CLength::null()); // update CG } bool success = false; @@ -584,7 +596,7 @@ namespace BlackMisc m_model = model; } } - this->getAndFetchModelCG(); + this->getAndFetchModelCG(model.getCG()); } template diff --git a/src/blackmisc/simulation/interpolator.h b/src/blackmisc/simulation/interpolator.h index 2165a9487..199b79a33 100644 --- a/src/blackmisc/simulation/interpolator.h +++ b/src/blackmisc/simulation/interpolator.h @@ -316,7 +316,7 @@ namespace BlackMisc Aviation::CAircraftSituationList remoteAircraftSituationsAndChange(const CInterpolationAndRenderingSetupPerCallsign &setup); //! Center of gravity, fetched from provider in case needed - PhysicalQuantities::CLength getAndFetchModelCG(); + PhysicalQuantities::CLength getAndFetchModelCG(const PhysicalQuantities::CLength &dbCG); //! Deferred init void deferredInit();