From 69049001d1a93f407cb2153e70f0eedd87a3d440 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 9 Apr 2016 23:10:00 +0200 Subject: [PATCH] refs #638, reverse lookup in model matching --- src/blackcore/aircraftmatcher.cpp | 29 +++- .../components/modelmatchercomponent.cpp | 48 ++++-- .../components/modelmatchercomponent.h | 5 +- .../components/modelmatchercomponent.ui | 137 ++++++++++++------ 4 files changed, 152 insertions(+), 67 deletions(-) diff --git a/src/blackcore/aircraftmatcher.cpp b/src/blackcore/aircraftmatcher.cpp index 92bd94260..1891305e8 100644 --- a/src/blackcore/aircraftmatcher.cpp +++ b/src/blackcore/aircraftmatcher.cpp @@ -138,29 +138,36 @@ namespace BlackCore // only if not yet matched with DB const QString aircraftIcaoDesignator(model.getAircraftIcaoCodeDesignator()); - const QString airlineIcaoDesignator(model.getAircraftIcaoCodeDesignator()); + const QString airlineIcaoDesignator(model.getAirlineIcaoCodeDesignator()); if (!model.hasValidDbKey()) { // try to match by livery - const QString livery(liveryInfo); - if (CLivery::isValidCombinedCode(livery)) + if (liveryCode.isEmpty() && !airlineIcaoDesignator.isEmpty()) + { + // we create a standard livery code, then we try to find based on this + liveryCode = CLivery::getStandardCode(model.getAirlineIcaoCode()); + } + + if (CLivery::isValidCombinedCode(liveryCode)) { // search DB model by livery - const CAircraftModelList models(sApp->getWebDataServices()->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftIcaoDesignator, livery)); + const CAircraftModelList models(sApp->getWebDataServices()->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftIcaoDesignator, liveryCode)); if (models.isEmpty()) { // no models for that livery, search for livery only - const CLivery databaseLivery(sApp->getWebDataServices()->getLiveryForCombinedCode(livery)); + const CLivery databaseLivery(sApp->getWebDataServices()->getLiveryForCombinedCode(liveryCode)); if (databaseLivery.hasValidDbKey()) { // we have found a livery in the DB model.setLivery(databaseLivery); + if (log) { logDetails(log, callsign, QString("Reverse lookup, set livery `%1`").arg(databaseLivery.getCombinedCodePlusInfo())); } } } else { // model by livery data found model = models.front(); + if (log) { logDetails(log, callsign, QString("Reverse lookup, DB model `%1` for %2/%3, found %4").arg(model.getDbKey()).arg(aircraftIcaoDesignator).arg(liveryCode).arg(models.size())); } } } @@ -175,8 +182,12 @@ namespace BlackCore airlineIcao = model.getAirlineIcaoCode(); airlineIcao.updateMissingParts(CAirlineIcaoCode(airlineIcaoDesignator)); } - const CLivery liveryDummy(livery, airlineIcao, "Generated"); - model.setLivery(liveryDummy); + if (!airlineIcaoDesignator.isEmpty()) + { + const CLivery liveryDummy(CLivery::getStandardCode(airlineIcao), airlineIcao, "Generated"); + model.setLivery(liveryDummy); + if (log) { logDetails(log, callsign, QString("Reverse lookup, set dummy livery `%1`").arg(liveryDummy.getCombinedCodePlusInfo())); } + } } if (!model.getAircraftIcaoCode().hasValidDbKey()) @@ -187,11 +198,15 @@ namespace BlackCore // no DB data, we update as much as possible aircraftIcao = model.getAircraftIcaoCode(); aircraftIcao.updateMissingParts(CAircraftIcaoCode(aircraftIcaoDesignator)); + if (log) { logDetails(log, callsign, QString("Reverse lookup, aircraft `%1` not found in DB").arg(aircraftIcaoDesignator)); } } model.setAircraftIcaoCode(aircraftIcao); + if (log) { logDetails(log, callsign, QString("Reverse lookup, set aircraft `%1`").arg(aircraftIcao.getCombinedIcaoStringWithKey())); } } } // model from DB + if (model.getModelType() != CAircraftModel::TypeUnknown) { model.setModelType(modelToLookup.getModelType()); } + model.setCallsign(modelToLookup.getCallsign()); return model; } diff --git a/src/blackgui/components/modelmatchercomponent.cpp b/src/blackgui/components/modelmatchercomponent.cpp index d1eb21ce8..b6dd4e295 100644 --- a/src/blackgui/components/modelmatchercomponent.cpp +++ b/src/blackgui/components/modelmatchercomponent.cpp @@ -43,7 +43,8 @@ namespace BlackGui ui->le_Manufacturer->setValidator(validator); connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CModelMatcherComponent::ps_simulatorChanged); - connect(ui->pb_Test, &QPushButton::pressed, this, &CModelMatcherComponent::ps_test); + connect(ui->pb_ModelMatching, &QPushButton::pressed, this, &CModelMatcherComponent::ps_testModelMatching); + connect(ui->pb_ReverseLookup, &QPushButton::pressed, this, &CModelMatcherComponent::ps_reverseLookup); connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CModelMatcherComponent::ps_webDataRed); const CSimulatorInfo sim(ui->comp_SimulatorSelector->getValue()); @@ -79,15 +80,33 @@ namespace BlackGui this->redisplay(); } - void CModelMatcherComponent::ps_test() + void CModelMatcherComponent::ps_testModelMatching() + { + ui->te_Results->clear(); + CStatusMessageList msgs; + CSimulatedAircraft remoteAircraft(createAircraft()); + if (this->ui->cb_withReverseLookup->isChecked()) + { + const QString liveryString(ui->comp_LiverySelector->getRawCombinedCode()); + const CAircraftModel reverseModel = CAircraftMatcher::reverseLookup(remoteAircraft.getModel(), liveryString, &msgs); + remoteAircraft.setModel(reverseModel); + } + + this->m_matcher.setDefaultModel(CModelMatcherComponent::defaultModel()); + const CAircraftModel matched = this->m_matcher.getClosestMatch(remoteAircraft, &msgs); + ui->te_Results->setText(matched.toQString(true)); + ui->tvp_ResultMessages->updateContainer(msgs); + } + + void CModelMatcherComponent::ps_reverseLookup() { ui->te_Results->clear(); CStatusMessageList msgs; this->m_matcher.setDefaultModel(CModelMatcherComponent::defaultModel()); - CSimulatedAircraft remoteAircraft(createAircraft()); - const CAircraftModel matched = this->m_matcher.getClosestMatch(remoteAircraft, &msgs); - remoteAircraft.setModel(matched); - ui->te_Results->setText(remoteAircraft.toQString(true)); + const CSimulatedAircraft remoteAircraft(createAircraft()); + const QString livery(ui->comp_LiverySelector->getRawCombinedCode()); + const CAircraftModel matched = CAircraftMatcher::reverseLookup(remoteAircraft.getModel(), livery, &msgs); + ui->te_Results->setText(matched.toQString(true)); ui->tvp_ResultMessages->updateContainer(msgs); } @@ -111,31 +130,28 @@ namespace BlackGui { const QString airline(ui->comp_AirlineSelector->getRawDesignator()); const QString aircraft(ui->comp_AircraftSelector->getRawDesignator()); - const QString model(ui->le_ModelString->text().trimmed().toUpper()); + const QString modelString(ui->le_ModelString->text().trimmed().toUpper()); const QString combined(ui->comp_CombinedCode->getCombinedType()); const QString manufacturer(ui->le_Manufacturer->text().trimmed().toUpper()); const QString liveryCombinedCode(ui->comp_LiverySelector->getRawCombinedCode()); static const CCallsign cs("SWIFT"); static const CUser pilot("123456", "swift Test", cs); - CSimulatedAircraft sa; - if (!model.isEmpty()) - { - const CAircraftModel m(model, CAircraftModel::TypeFsdData); - sa = CSimulatedAircraft(m); - } - sa.setCallsign(cs); CAircraftIcaoCode icao(aircraft, combined); icao.setManufacturer(manufacturer); - sa.setAircraftIcaoCode(icao); const CAirlineIcaoCode al(airline); const CLivery l(liveryCombinedCode.isEmpty() ? CLivery::getStandardCode(al) : liveryCombinedCode, al, "Standard"); - sa.setLivery(l); + CAircraftModel m(modelString, CAircraftModel::TypeFsdData); + m.setLivery(l); + m.setCallsign(cs); + m.setModelType(CAircraftModel::TypeFsdData); + CSimulatedAircraft sa(m); sa.setPilot(pilot); + sa.setAircraftIcaoCode(icao); return sa; } diff --git a/src/blackgui/components/modelmatchercomponent.h b/src/blackgui/components/modelmatchercomponent.h index 789a855c3..3a938b09d 100644 --- a/src/blackgui/components/modelmatchercomponent.h +++ b/src/blackgui/components/modelmatchercomponent.h @@ -53,7 +53,10 @@ namespace BlackGui void ps_cacheChanged(BlackMisc::Simulation::CSimulatorInfo &simulator); //! Run the matcher - void ps_test(); + void ps_testModelMatching(); + + //! Reverse lookup + void ps_reverseLookup(); //! Web data have been read void ps_webDataRed(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); diff --git a/src/blackgui/components/modelmatchercomponent.ui b/src/blackgui/components/modelmatchercomponent.ui index e2f3a6026..e348f6314 100644 --- a/src/blackgui/components/modelmatchercomponent.ui +++ b/src/blackgui/components/modelmatchercomponent.ui @@ -6,8 +6,8 @@ 0 0 - 324 - 318 + 356 + 340 @@ -32,6 +32,26 @@ 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -106,24 +126,62 @@ - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - + + + + + 0 + 0 + + QFrame::StyledPanel QFrame::Raised + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + reverse + + + + + + + matching + + + + + + + use reverse lookup for model matching + + + with lookup + + + true + + + + @@ -147,20 +205,6 @@ - - - - model string - - - - - - - Simulator: - - - @@ -175,17 +219,27 @@ - - - - Run + + + + model string - - - - true + + + + Simulator: + + + + + + + + + + Manufacturer: @@ -196,16 +250,13 @@ - - - - Manufacturer: + + + + true - - -