diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index 25bc39b25..5707f935c 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -242,8 +242,11 @@ namespace BlackCore //! 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; + //! Repeat all mappings + virtual int doMatchingsAgain() = 0; + //! Repeat the mapping - virtual bool doMappingAgain(const BlackMisc::Aviation::CCallsign &callsign) = 0; + virtual bool doMatchingAgain(const BlackMisc::Aviation::CCallsign &callsign) = 0; //! Current matching statistics virtual BlackMisc::Simulation::CMatchingStatistics getCurrentMatchingStatistics(bool missingOnly) const = 0; diff --git a/src/blackcore/context/contextsimulatorempty.h b/src/blackcore/context/contextsimulatorempty.h index ecbff8e41..044b17174 100644 --- a/src/blackcore/context/contextsimulatorempty.h +++ b/src/blackcore/context/contextsimulatorempty.h @@ -238,8 +238,15 @@ namespace BlackCore return false; } - //! \copydoc IContextSimulator::doMappingAgain - virtual bool doMappingAgain(const BlackMisc::Aviation::CCallsign &callsign) override + + //! \copydoc IContextSimulator::doMatchingsAgain + virtual int doMatchingsAgain() override + { + return 0; + } + + //! \copydoc IContextSimulator::doMatchingAgain + virtual bool doMatchingAgain(const BlackMisc::Aviation::CCallsign &callsign) override { Q_UNUSED(callsign); return false; diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index 8b00001fe..3c55c3f5a 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -863,7 +863,26 @@ namespace BlackCore m_weatherManager.requestWeatherGrid(weatherGrid, identifier); } - bool CContextSimulator::doMappingAgain(const CCallsign &callsign) + int CContextSimulator::doMatchingsAgain() + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + const CCallsignSet callsigns = this->getAircraftInRangeCallsigns(); + if (callsigns.isEmpty()) { return 0; } + int delayMs = 25; + QPointer myself(this); + for (const CCallsign &cs : callsigns) + { + QTimer::singleShot(delayMs, this, [ = ] + { + if (!sApp || sApp->isShuttingDown() || !myself) { return; } + this->doMatchingAgain(cs); + }); + delayMs += 25; + } + return callsigns.size(); + } + + bool CContextSimulator::doMatchingAgain(const CCallsign &callsign) { if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign.asString(); } if (!this->isAircraftInRange(callsign)) { return false; } @@ -872,10 +891,12 @@ namespace BlackCore QPointer myself(this); QTimer::singleShot(2500, this, [ = ] { - if (!myself) { return; } + if (!sApp || sApp->isShuttingDown() || !myself) { return; } const CSimulatedAircraft aircraft = this->getAircraftInRangeForCallsign(callsign); if (!aircraft.hasCallsign()) { return; } // no longer valid - this->xCtxAddedRemoteAircraftReadyForModelMatching(aircraft); + CSimulatedAircraft resetAircraft(aircraft); + resetAircraft.resetToNetworkModel(); + this->xCtxAddedRemoteAircraftReadyForModelMatching(resetAircraft); }); return false; } diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index ea866def5..ffc008d75 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -101,7 +101,8 @@ namespace BlackCore 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 bool doMappingAgain(const BlackMisc::Aviation::CCallsign &callsign) override; + virtual int doMatchingsAgain() override; + virtual bool doMatchingAgain(const BlackMisc::Aviation::CCallsign &callsign) override; virtual BlackMisc::CStatusMessageList getMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual bool isMatchingMessagesEnabled() const override; virtual void enableMatchingMessages(bool enabled) override; diff --git a/src/blackcore/context/contextsimulatorproxy.cpp b/src/blackcore/context/contextsimulatorproxy.cpp index 01553e515..e944dc847 100644 --- a/src/blackcore/context/contextsimulatorproxy.cpp +++ b/src/blackcore/context/contextsimulatorproxy.cpp @@ -261,9 +261,14 @@ namespace BlackCore return m_dBusInterface->callDBusRet(QLatin1String("parseCommandLine"), commandLine, originator); } - bool CContextSimulatorProxy::doMappingAgain(const CCallsign &callsign) + int CContextSimulatorProxy::doMatchingsAgain() { - return m_dBusInterface->callDBusRet(QLatin1String("doMappingAgain"), callsign); + return m_dBusInterface->callDBusRet(QLatin1String("doMatchingsAgain")); + } + + bool CContextSimulatorProxy::doMatchingAgain(const CCallsign &callsign) + { + return m_dBusInterface->callDBusRet(QLatin1String("doMatchingAgain"), callsign); } CMatchingStatistics CContextSimulatorProxy::getCurrentMatchingStatistics(bool missingOnly) const diff --git a/src/blackcore/context/contextsimulatorproxy.h b/src/blackcore/context/contextsimulatorproxy.h index 90b4a111c..56bf6a6fd 100644 --- a/src/blackcore/context/contextsimulatorproxy.h +++ b/src/blackcore/context/contextsimulatorproxy.h @@ -91,7 +91,8 @@ namespace BlackCore virtual bool isMatchingMessagesEnabled() const override; virtual void enableMatchingMessages(bool enabled) override; virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; - virtual bool doMappingAgain(const BlackMisc::Aviation::CCallsign &callsign) override; + virtual int doMatchingsAgain() override; + virtual bool doMatchingAgain(const BlackMisc::Aviation::CCallsign &callsign) override; virtual BlackMisc::Simulation::CMatchingStatistics getCurrentMatchingStatistics(bool missingOnly) const override; virtual void setMatchingSetup(const BlackMisc::Simulation::CAircraftMatcherSetup &setup) override; virtual BlackMisc::Simulation::CAircraftMatcherSetup getMatchingSetup() const override; diff --git a/src/blackmisc/simulation/simulatedaircraft.cpp b/src/blackmisc/simulation/simulatedaircraft.cpp index dba8a958d..44ff6363b 100644 --- a/src/blackmisc/simulation/simulatedaircraft.cpp +++ b/src/blackmisc/simulation/simulatedaircraft.cpp @@ -491,6 +491,14 @@ namespace BlackMisc m_models[NetworkModel] = model; } + bool CSimulatedAircraft::resetToNetworkModel() + { + Q_ASSERT_X(m_models.size() == 2, Q_FUNC_INFO, "Wrong model size"); + const CAircraftModel nwModel = m_models[NetworkModel]; + m_models[CurrentModel] = nwModel; + return true; + } + bool CSimulatedAircraft::setCG(const CLength &cg) { if (cg.isNull()) { return false; } diff --git a/src/blackmisc/simulation/simulatedaircraft.h b/src/blackmisc/simulation/simulatedaircraft.h index 8ec3ff019..613bf347b 100644 --- a/src/blackmisc/simulation/simulatedaircraft.h +++ b/src/blackmisc/simulation/simulatedaircraft.h @@ -390,6 +390,9 @@ namespace BlackMisc //! Set network model void setNetworkModel(const CAircraftModel &model); + //! Reset to the newtork model + bool resetToNetworkModel(); + //! Set the center of gravity bool setCG(const PhysicalQuantities::CLength &cg);