From 6bc2a15f61a4148c57924adab686d1d00778a13a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 15 Jun 2019 22:55:42 +0200 Subject: [PATCH] Allow to disable reverse lookup for model string and livery ids --- src/blackcore/aircraftmatcher.cpp | 29 +++++++++++++------ src/blackcore/aircraftmatcher.h | 17 ++++++----- src/blackcore/airspacemonitor.cpp | 4 +-- .../components/modelmatchercomponent.cpp | 4 +-- .../simulation/aircraftmatchersetup.cpp | 17 +++++++++++ .../simulation/aircraftmatchersetup.h | 6 ++++ 6 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/blackcore/aircraftmatcher.cpp b/src/blackcore/aircraftmatcher.cpp index fbb42d576..110806dbc 100644 --- a/src/blackcore/aircraftmatcher.cpp +++ b/src/blackcore/aircraftmatcher.cpp @@ -319,7 +319,7 @@ namespace BlackCore CAircraftModel model(networkModelString, type, {}, networkAircraftIcao, livery); model.setCallsign(callsign); - model = CAircraftMatcher::reverseLookupModel(model, networkLiveryInfo, log); + model = CAircraftMatcher::reverseLookupModel(model, networkLiveryInfo, setup, log); model.setModelType(CAircraftModel::TypeReverseLookup); return model; @@ -501,7 +501,7 @@ namespace BlackCore return rv; } - CAircraftModel CAircraftMatcher::reverseLookupModel(const CAircraftModel &modelToLookup, const QString &networkLiveryInfo, CStatusMessageList *log) + CAircraftModel CAircraftMatcher::reverseLookupModel(const CAircraftModel &modelToLookup, const QString &networkLiveryInfo, const CAircraftMatcherSetup &setup, CStatusMessageList *log) { if (!sApp || sApp->isShuttingDown() || !sApp->hasWebDataServices()) { return CAircraftModel(); } @@ -524,7 +524,7 @@ namespace BlackCore if (modelToLookup.hasModelString()) { // if we find the model here we have a fully defined DB model - const CAircraftModel modelFromDb = CAircraftMatcher::reverseLookupModelString(modelToLookup.getModelString(), callsign, log); + const CAircraftModel modelFromDb = CAircraftMatcher::reverseLookupModelString(modelToLookup.getModelString(), callsign, setup.isReverseLookupModelString(), log); if (modelFromDb.hasValidDbKey()) { model = modelFromDb; @@ -536,7 +536,11 @@ namespace BlackCore const DBTripleIds ids = CAircraftModel::parseNetworkLiveryString(networkLiveryInfo); if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Livery string with ids: '%1'").arg(ids.toQString())); } - if (ids.model >= 0 && !modelToLookup.hasModelString()) + if (setup.isReverseLookupSwiftLiveryIds()) + { + if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Ignoring livery ids '%1', because of setup").arg(ids.toQString())); } + } + else if (ids.model >= 0 && !modelToLookup.hasModelString()) { if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Model lookup with id %1 from triple ids '%2'").arg(ids.model).arg(ids.toQString())); } const CAircraftModel modelFromDb = CAircraftMatcher::reverseLookupModelId(ids.model, callsign, log); @@ -663,24 +667,31 @@ namespace BlackCore return model; } - CAircraftModel CAircraftMatcher::reverseLookupModel(const CAircraftModel &modelToLookup, const QString &networkLiveryInfo, const CAircraftMatcherSetup &setup, CStatusMessageList *log) + CAircraftModel CAircraftMatcher::reverseLookupModelMs(const CAircraftModel &modelToLookup, const QString &networkLiveryInfo, const CAircraftMatcherSetup &setup, CStatusMessageList *log) { - CAircraftModel reverseModel = reverseLookupModel(modelToLookup, networkLiveryInfo, log); + CAircraftModel reverseModel = reverseLookupModel(modelToLookup, networkLiveryInfo, setup, log); if (!setup.doRunMsReverseLookupScript()) { return reverseModel; } const CCallsign cs = modelToLookup.getCallsign(); - const MatchingScriptReturnValues rv = reverseLookupScript(reverseModel, setup, log); + const MatchingScriptReturnValues rv = CAircraftMatcher::reverseLookupScript(reverseModel, setup, log); if (rv.runScriptModifiedAndRerun()) { CMatchingUtils::addLogDetailsToList(log, cs, QStringLiteral("Matching script: Modified value and requested rerun")); - reverseModel = reverseLookupModel(rv.model, networkLiveryInfo, log); + CAircraftMatcherSetup setupRerun(setup); + setupRerun.resetReverseLookup(); + reverseModel = CAircraftMatcher::reverseLookupModel(rv.model, networkLiveryInfo, setupRerun, log); return reverseModel; } return (rv.runScriptAndModified() ? rv.model : reverseModel); } - CAircraftModel CAircraftMatcher::reverseLookupModelString(const QString &modelString, const CCallsign &callsign, CStatusMessageList *log) + CAircraftModel CAircraftMatcher::reverseLookupModelString(const QString &modelString, const CCallsign &callsign, bool doLookupString, CStatusMessageList *log) { if (!sApp || sApp->isShuttingDown() || !sApp->hasWebDataServices()) { return CAircraftModel(); } + if (!doLookupString) + { + if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Ignore model string in reverse lookup, ignoring '%1'").arg(modelString)); } + return CAircraftModel(); + } CAircraftModel model = sApp->getWebDataServices()->getModelForModelString(modelString); if (log) { diff --git a/src/blackcore/aircraftmatcher.h b/src/blackcore/aircraftmatcher.h index a1139a4f4..200d75fd6 100644 --- a/src/blackcore/aircraftmatcher.h +++ b/src/blackcore/aircraftmatcher.h @@ -114,7 +114,7 @@ namespace BlackCore const BlackMisc::Aviation::CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString, const BlackMisc::Simulation::CAircraftMatcherSetup &setup, BlackMisc::Simulation::CAircraftModel::ModelType type, - BlackMisc::CStatusMessageList *log = nullptr); + BlackMisc::CStatusMessageList *log); //! Try to find the corresponding data in DB and get best information for following matching //! \threadsafe @@ -122,29 +122,32 @@ namespace BlackCore //! \remark NOT running matching script static BlackMisc::Simulation::CAircraftModel reverseLookupModel( const BlackMisc::Simulation::CAircraftModel &modelToLookup, - const QString &networkLiveryInfo, BlackMisc::CStatusMessageList *log = nullptr); + const QString &networkLiveryInfo, + const BlackMisc::Simulation::CAircraftMatcherSetup &setup, + BlackMisc::CStatusMessageList *log); //! Try to find the corresponding data in DB and get best information for following matching //! \threadsafe //! \ingroup reverselookup //! \remark Running matching script - static BlackMisc::Simulation::CAircraftModel reverseLookupModel( + static BlackMisc::Simulation::CAircraftModel reverseLookupModelMs( const BlackMisc::Simulation::CAircraftModel &modelToLookup, const QString &networkLiveryInfo, const BlackMisc::Simulation::CAircraftMatcherSetup &setup, - BlackMisc::CStatusMessageList *log = nullptr); + BlackMisc::CStatusMessageList *log); //! Try to find model by model string //! \threadsafe //! \ingroup reverselookup static BlackMisc::Simulation::CAircraftModel reverseLookupModelString( - const QString &modelString, const BlackMisc::Aviation::CCallsign &callsign, BlackMisc::CStatusMessageList *log = nullptr); + const QString &modelString, + const BlackMisc::Aviation::CCallsign &callsign, + bool doLookupString, BlackMisc::CStatusMessageList *log); //! Try to find model by id //! \threadsafe //! \ingroup reverselookup - static BlackMisc::Simulation::CAircraftModel reverseLookupModelId( - int id, const BlackMisc::Aviation::CCallsign &callsign, BlackMisc::CStatusMessageList *log = nullptr); + static BlackMisc::Simulation::CAircraftModel reverseLookupModelId(int id, const BlackMisc::Aviation::CCallsign &callsign, BlackMisc::CStatusMessageList *log); //! Try to find the DB corresponding ICAO code //! \threadsafe diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index 8d2cf5be5..2e23a15bb 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -752,7 +752,7 @@ namespace BlackCore // directly check model string if (!modelString.isEmpty()) { - lookupModel = CAircraftMatcher::reverseLookupModelString(modelString, callsign, log); + lookupModel = CAircraftMatcher::reverseLookupModelString(modelString, callsign, setup.isReverseLookupModelString(), log); if (lookupModel.hasValidDbKey()) { break; } // found by model string } @@ -986,7 +986,7 @@ namespace BlackCore const CCallsign callsign(situation.getCallsign()); Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Empty callsign"); - if (isCopilotAircraft(callsign)) { return; } + if (this->isCopilotAircraft(callsign)) { return; } // update client info this->autoAdjustCientGndCapability(situation); diff --git a/src/blackgui/components/modelmatchercomponent.cpp b/src/blackgui/components/modelmatchercomponent.cpp index da589bbc7..252fb8f21 100644 --- a/src/blackgui/components/modelmatchercomponent.cpp +++ b/src/blackgui/components/modelmatchercomponent.cpp @@ -164,7 +164,7 @@ namespace BlackGui if (ui->cb_withReverseLookup->isChecked()) { const QString liveryString(ui->comp_LiverySelector->getRawCombinedCode()); - const CAircraftModel reverseModel = CAircraftMatcher::reverseLookupModel(remoteAircraft.getModel(), liveryString, m_matcher.getSetup(), &msgs); + const CAircraftModel reverseModel = CAircraftMatcher::reverseLookupModelMs(remoteAircraft.getModel(), liveryString, m_matcher.getSetup(), &msgs); remoteAircraft.setModel(reverseModel); // current model } @@ -187,7 +187,7 @@ namespace BlackGui const CAircraftMatcherSetup setup = m_matcher.getSetup(); const CSimulatedAircraft remoteAircraft(createAircraft()); const QString livery(ui->comp_LiverySelector->getRawCombinedCode()); - const CAircraftModel matched = CAircraftMatcher::reverseLookupModel(remoteAircraft.getModel(), livery, setup, &msgs); + const CAircraftModel matched = CAircraftMatcher::reverseLookupModelMs(remoteAircraft.getModel(), livery, setup, &msgs); ui->te_Results->setText(matched.toQString(true)); ui->tvp_ResultMessages->updateContainer(msgs); } diff --git a/src/blackmisc/simulation/aircraftmatchersetup.cpp b/src/blackmisc/simulation/aircraftmatchersetup.cpp index 26e5ff404..37fd3330b 100644 --- a/src/blackmisc/simulation/aircraftmatchersetup.cpp +++ b/src/blackmisc/simulation/aircraftmatchersetup.cpp @@ -44,6 +44,23 @@ namespace BlackMisc return true; } + bool CAircraftMatcherSetup::isReverseLookupModelString() const + { + return this->getMatchingMode().testFlag(ReverseLookupModelString); + } + + bool CAircraftMatcherSetup::isReverseLookupSwiftLiveryIds() const + { + return this->getMatchingMode().testFlag(ReverseLookupSwiftLiveryIds); + } + + void CAircraftMatcherSetup::resetReverseLookup() + { + MatchingMode m = this->getMatchingMode(); + m.setFlag(ReverseLookupDefault); + this->setMatchingMode(m); + } + bool CAircraftMatcherSetup::doRunMsReverseLookupScript() const { return m_msReverseEnabled && !m_msReverseLookupFile.isEmpty(); diff --git a/src/blackmisc/simulation/aircraftmatchersetup.h b/src/blackmisc/simulation/aircraftmatchersetup.h index c40672de0..580aef589 100644 --- a/src/blackmisc/simulation/aircraftmatchersetup.h +++ b/src/blackmisc/simulation/aircraftmatchersetup.h @@ -128,6 +128,12 @@ namespace BlackMisc //! Matching mode MatchingMode getMatchingMode() const { return static_cast(m_mode); } + //! Reverse lookup @{ + bool isReverseLookupModelString() const; + bool isReverseLookupSwiftLiveryIds() const; + void resetReverseLookup(); + //! @} + //! Get matching files @{ const QString &getMsReverseLookupFile() const { return m_msReverseLookupFile; } const QString &getMsMatchingStageFile() const { return m_msMatchingStageFile; }