From 6befaa32d578df0ad16114e9246353e224eb2f23 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 29 Nov 2016 23:13:30 +0100 Subject: [PATCH] refs #797, added support for combined type * adjusted log messages * aligned name to combined type --- src/blackcore/aircraftmatcher.cpp | 51 +++++++++++++++---- .../context/contextsimulatorimpl.cpp | 4 +- src/blackmisc/aviation/aircrafticaocode.cpp | 12 ++--- src/blackmisc/aviation/aircrafticaocode.h | 2 +- .../simulation/aircraftmodellist.cpp | 8 +-- src/blackmisc/simulation/aircraftmodellist.h | 2 +- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/src/blackcore/aircraftmatcher.cpp b/src/blackcore/aircraftmatcher.cpp index dadf61a36..b824cb3e3 100644 --- a/src/blackcore/aircraftmatcher.cpp +++ b/src/blackcore/aircraftmatcher.cpp @@ -53,7 +53,7 @@ namespace BlackCore const MatchingMode mode = this->m_matchingMode; CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "Matching uses model set of " + QString::number(matchedModels.size()) + " models", getLogCategories()); - CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "Input model: " + remoteAircraft.toQString(), getLogCategories()); + CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "Input model: " + remoteAircraft.getModel().toQString(), getLogCategories()); // Manually set string? if (remoteAircraft.getModel().hasManuallySetString()) @@ -150,13 +150,37 @@ namespace BlackCore } while (false); + // the last resort is to use the combined type + if (matchedModels.isEmpty() && remoteAircraft.getModel().getAircraftIcaoCode().hasValidCombinedType()) + { + const QString combinedType(remoteAircraft.getModel().getAircraftIcaoCode().getCombinedType()); + CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "Searching by combined type '" + combinedType + "'", getLogCategories()); + matchedModels = matchedModels.findByCombinedType(combinedType); + if (!matchedModels.isEmpty()) + { + CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "Found " + QString::number(matchedModels.size()) + " by combined type '" + combinedType + "'", getLogCategories()); + } + } + // here we have a list of possible models, we reduce/refine further - bool military = remoteAircraft.getModel().isMilitary(); - matchedModels = ifPossibleReduceByManufacturer(remoteAircraft, matchedModels, "2nd pass", reduced, log); - matchedModels = ifPossibleReduceByMilitaryFlag(remoteAircraft, military, matchedModels, reduced, log); + if (!matchedModels.isEmpty()) + { + bool military = remoteAircraft.getModel().isMilitary(); + matchedModels = ifPossibleReduceByManufacturer(remoteAircraft, matchedModels, "2nd pass", reduced, log); + matchedModels = ifPossibleReduceByMilitaryFlag(remoteAircraft, military, matchedModels, reduced, log); + } // expect first to be the right one in order - matchedModel = matchedModels.isEmpty() ? getDefaultModel() : matchedModels.front(); + if (matchedModels.isEmpty()) + { + matchedModel = getDefaultModel(); + CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "Using default model (nothing else found)", getLogCategories()); + } + else + { + matchedModel = matchedModels.front(); + CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "Using first of " + QString::number(matchedModels.size()) + " models", getLogCategories()); + } } while (false); @@ -451,6 +475,12 @@ namespace BlackCore CAircraftModelList CAircraftMatcher::ifPossibleReduceByIcaoData(const CSimulatedAircraft &remoteAircraft, const CAircraftModelList &inList, bool ignoreAirline, bool &reduced, CStatusMessageList *log) { reduced = false; + if (inList.isEmpty()) + { + if (log) { CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "Empty list, skipping step", getLogCategories()); } + return inList; + } + if (!remoteAircraft.hasAircraftDesignator()) { if (log) { CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "No aircraft designator, skipping step", getLogCategories()); } @@ -461,7 +491,8 @@ namespace BlackCore remoteAircraft.getAircraftIcaoCode(), ignoreAirline ? CAirlineIcaoCode() : remoteAircraft.getAirlineIcaoCode())); - if (!searchModels.isEmpty()) + const bool searchModelsEmpty = searchModels.isEmpty(); + if (!searchModelsEmpty) { if (log) { @@ -481,9 +512,9 @@ namespace BlackCore if (log) { CMatchingUtils::addLogDetailsToList(log, remoteAircraft, - "Not found by ICAO " + - remoteAircraft.getAircraftIcaoCodeDesignator() + " " + remoteAircraft.getAirlineIcaoCodeDesignator() + - " relaxing to only ICAO " + remoteAircraft.getAircraftIcaoCodeDesignator()); + "Not found by ICAO '" + + remoteAircraft.getAircraftIcaoCodeDesignator() + "' '" + remoteAircraft.getAirlineIcaoCodeDesignator() + + "', relaxing to only ICAO " + remoteAircraft.getAircraftIcaoCodeDesignator()); } // recursive lookup by ignoring airline return ifPossibleReduceByIcaoData(remoteAircraft, inList, true, reduced, log); @@ -585,7 +616,7 @@ namespace BlackCore } const QString cc = remoteAircraft.getAircraftIcaoCode().getCombinedType(); - CAircraftModelList byCombinedCode(inList.findByCombinedCode(cc)); + CAircraftModelList byCombinedCode(inList.findByCombinedType(cc)); if (byCombinedCode.isEmpty()) { if (log) { CMatchingUtils::addLogDetailsToList(log, remoteAircraft, "Not found by combined code " + cc, getLogCategories()); } diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index c40c3379c..2ce1b7164 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -420,13 +420,13 @@ namespace BlackCore { if (!isSimulatorSimulating()) { return; } const CCallsign callsign = remoteAircraft.getCallsign(); - BLACK_VERIFY_X(!callsign.isEmpty(), Q_FUNC_INFO, "Remote aircrft with empty callsign"); + BLACK_VERIFY_X(!callsign.isEmpty(), Q_FUNC_INFO, "Remote aircraft with empty callsign"); if (callsign.isEmpty()) { return; } CStatusMessageList matchingMessages; CStatusMessageList *pMatchingMessages = m_enableMatchingMessages ? &matchingMessages : nullptr; const CAircraftModel aircraftModel = m_modelMatcher.getClosestMatch(remoteAircraft, pMatchingMessages); - Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "mismatching callsigns"); + Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "Mismatching callsigns"); updateAircraftModel(callsign, aircraftModel, identifier()); const CSimulatedAircraft aircraftAfterModelApplied = getAircraftInRangeForCallsign(remoteAircraft.getCallsign()); m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraftAfterModelApplied); diff --git a/src/blackmisc/aviation/aircrafticaocode.cpp b/src/blackmisc/aviation/aircrafticaocode.cpp index 6eee138af..0deb35415 100644 --- a/src/blackmisc/aviation/aircrafticaocode.cpp +++ b/src/blackmisc/aviation/aircrafticaocode.cpp @@ -175,17 +175,17 @@ namespace BlackMisc return c; } - bool CAircraftIcaoCode::matchesCombinedCode(const QString &combinedCode) const + bool CAircraftIcaoCode::matchesCombinedType(const QString &combinedType) const { - const QString cc(combinedCode.toUpper().trimmed().replace(' ', '*').replace('-', '*')); - if (combinedCode.length() != 3) { return false; } + const QString cc(combinedType.toUpper().trimmed().replace(' ', '*').replace('-', '*')); + if (combinedType.length() != 3) { return false; } if (cc == this->getCombinedType()) { return true; } const bool wildcard = cc.contains('*'); if (!wildcard) { return false; } - QChar at = cc.at(0); - QChar c = cc.at(1); - QChar et = cc.at(2); + const QChar at = cc.at(0); + const QChar c = cc.at(1); + const QChar et = cc.at(2); if (at != '*') { const QString cat = getAircraftType(); diff --git a/src/blackmisc/aviation/aircrafticaocode.h b/src/blackmisc/aviation/aircrafticaocode.h index 098bcfb2c..9a74dd7f0 100644 --- a/src/blackmisc/aviation/aircrafticaocode.h +++ b/src/blackmisc/aviation/aircrafticaocode.h @@ -139,7 +139,7 @@ namespace BlackMisc //! Matches given combined code //! \remark * can be used as wildcard, e.g. L*J, L** - bool matchesCombinedCode(const QString &combinedCode) const; + bool matchesCombinedType(const QString &combinedType) const; //! Designator + Manufacturer QString getDesignatorManufacturer() const; diff --git a/src/blackmisc/simulation/aircraftmodellist.cpp b/src/blackmisc/simulation/aircraftmodellist.cpp index 59a3a1064..a1f90aa74 100644 --- a/src/blackmisc/simulation/aircraftmodellist.cpp +++ b/src/blackmisc/simulation/aircraftmodellist.cpp @@ -191,14 +191,14 @@ namespace BlackMisc }); } - CAircraftModelList CAircraftModelList::findByCombinedCode(const QString &combinedCode) const + CAircraftModelList CAircraftModelList::findByCombinedType(const QString &combinedType) const { - const QString cc(combinedCode.trimmed().toUpper()); - if (combinedCode.length() != 3) { return CAircraftModelList(); } + const QString cc(combinedType.trimmed().toUpper()); + if (combinedType.length() != 3) { return CAircraftModelList(); } return this->findBy([ & ](const CAircraftModel & model) { const CAircraftIcaoCode icao(model.getAircraftIcaoCode()); - return icao.matchesCombinedCode(cc); + return icao.matchesCombinedType(cc); }); } diff --git a/src/blackmisc/simulation/aircraftmodellist.h b/src/blackmisc/simulation/aircraftmodellist.h index 245a6959e..fc6a65192 100644 --- a/src/blackmisc/simulation/aircraftmodellist.h +++ b/src/blackmisc/simulation/aircraftmodellist.h @@ -121,7 +121,7 @@ namespace BlackMisc CAircraftModelList findByFamily(const QString &family) const; //! Find by combined code, wildcards possible e.g. L*P, *2J - CAircraftModelList findByCombinedCode(const QString &combinedCode) const; + CAircraftModelList findByCombinedType(const QString &combinedType) const; //! Find by military flag CAircraftModelList findByMilitaryFlag(bool military) const;