diff --git a/src/blackgui/components/modelmatchercomponent.cpp b/src/blackgui/components/modelmatchercomponent.cpp index 451da4215..a8f417b3c 100644 --- a/src/blackgui/components/modelmatchercomponent.cpp +++ b/src/blackgui/components/modelmatchercomponent.cpp @@ -73,14 +73,17 @@ namespace BlackGui ui->le_Callsign->setValidator(validator); connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CModelMatcherComponent::onSimulatorChanged); - connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CModelMatcherComponent::onWebDataRead, Qt::QueuedConnection); + connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CModelMatcherComponent::onWebDataRead, Qt::QueuedConnection); connect(ui->pb_ModelMatching, &QPushButton::pressed, this, &CModelMatcherComponent::testModelMatching); connect(ui->pb_ReverseLookup, &QPushButton::pressed, this, &CModelMatcherComponent::reverseLookup); - connect(ui->pb_Settings, &QPushButton::pressed, this, &CModelMatcherComponent::displaySettingsDialog); + connect(ui->pb_Settings, &QPushButton::pressed, this, &CModelMatcherComponent::displaySettingsDialog); connect(ui->cb_UseWorkbench, &QCheckBox::toggled, this, &CModelMatcherComponent::onWorkbenchToggled); + // initial settings + m_matcher.setSetup(m_matchingSettings.get()); + this->redisplay(); ui->cb_UseWorkbench->setVisible(false); } @@ -153,18 +156,22 @@ namespace BlackGui void CModelMatcherComponent::testModelMatching() { ui->te_Results->clear(); - CStatusMessageList msgs; this->onSimulatorChanged(ui->comp_SimulatorSelector->getValue()); // update model set to latest version - CSimulatedAircraft remoteAircraft(createAircraft()); + CStatusMessageList msgs; + CSimulatedAircraft remoteAircraft(this->createAircraft()); + m_matcher.setDefaultModel(CModelMatcherComponent::defaultModel()); + if (ui->cb_withReverseLookup->isChecked()) { const QString liveryString(ui->comp_LiverySelector->getRawCombinedCode()); - const CAircraftModel reverseModel = CAircraftMatcher::reverseLookupModel(remoteAircraft.getModel(), liveryString, &msgs); + const CAircraftModel reverseModel = CAircraftMatcher::reverseLookupModel(remoteAircraft.getModel(), liveryString, m_matcher.getSetup(), &msgs); remoteAircraft.setModel(reverseModel); // current model } - m_matcher.setDefaultModel(CModelMatcherComponent::defaultModel()); - const CAircraftModel matched = m_matcher.getClosestMatch(remoteAircraft, MatchingLogAll, &msgs); // test model matching + CStatusMessageList matchingMsgs; + const CAircraftModel matched = m_matcher.getClosestMatch(remoteAircraft, MatchingLogAll, &matchingMsgs, true); // test model matching + msgs.push_back(matchingMsgs); + ui->te_Results->setText(matched.toQString(true)); ui->tvp_ResultMessages->updateContainer(msgs); ui->tvp_ResultMessages->fullResizeToContents(); @@ -180,19 +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, &msgs); - - // Script - CAircraftModel matchedWithScript = matched; - if (setup.doRunMsNetworkEntryScript()) - { - matchedWithScript = CAircraftMatcher::networkEntryScript(matched, setup, &msgs); - } - else - { - CMatchingUtils::addLogDetailsToList(&msgs, remoteAircraft.getCallsign(), QStringLiteral("No entry script used")); - } - + const CAircraftModel matched = CAircraftMatcher::reverseLookupModel(remoteAircraft.getModel(), livery, setup, &msgs); ui->te_Results->setText(matched.toQString(true)); ui->tvp_ResultMessages->updateContainer(msgs); } @@ -276,5 +271,28 @@ namespace BlackGui if (model.getCallsign().isEmpty()) { model.setCallsign("SWIFT"); } return model; } + + MSReturnValues CModelMatcherComponent::matchingScript(const CAircraftModel &inModel, const CAircraftMatcherSetup &setup, CStatusMessageList &msgs) + { + // Script + if (setup.doRunMsReverseLookupScript()) + { + const MSReturnValues rv = CAircraftMatcher::reverseLookupScript(inModel, setup, &msgs); + if (rv.runScriptAndModified()) + { + return rv; + } + else + { + CMatchingUtils::addLogDetailsToList(&msgs, inModel.getCallsign(), QStringLiteral("Matching script, no modification")); + } + } + else + { + CMatchingUtils::addLogDetailsToList(&msgs, inModel.getCallsign(), QStringLiteral("No reverse lookup script used")); + } + + return inModel; + } } // ns } // ns diff --git a/src/blackgui/components/modelmatchercomponent.h b/src/blackgui/components/modelmatchercomponent.h index 977fbeb5f..209a6fac6 100644 --- a/src/blackgui/components/modelmatchercomponent.h +++ b/src/blackgui/components/modelmatchercomponent.h @@ -13,10 +13,12 @@ #include "blackcore/aircraftmatcher.h" #include "blackgui/blackguiexport.h" -#include "blackmisc/network/entityflags.h" +#include "blackmisc/simulation/settings/modelmatchersettings.h" #include "blackmisc/simulation/aircraftmodel.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatorinfo.h" +#include "blackmisc/network/entityflags.h" +#include "blackmisc/settingscache.h" #include #include @@ -91,11 +93,14 @@ namespace BlackGui //! Pseudo default aircraft BlackMisc::Simulation::CAircraftModel defaultModel() const; - QScopedPointer ui; + //! Run matching script + static BlackMisc::Simulation::MSReturnValues matchingScript(const BlackMisc::Simulation::CAircraftModel &inModel, const BlackMisc::Simulation::CAircraftMatcherSetup &setup, BlackMisc::CStatusMessageList &msgs); + QScopedPointer ui; QPointer m_workbenchView; //!< an external workbenc - CSettingsMatchingDialog *m_settingsDialog = nullptr; //!< matching settings as dialog - BlackCore::CAircraftMatcher m_matcher { this }; //!< used matcher + CSettingsMatchingDialog *m_settingsDialog = nullptr; //!< matching settings as dialog + BlackCore::CAircraftMatcher m_matcher { this }; //!< used matcher + BlackMisc::CSettingReadOnly m_matchingSettings { this }; //!< settings }; } // ns } // ns