refs #797, added support for combined type

* adjusted log messages
* aligned name to combined type
This commit is contained in:
Klaus Basan
2016-11-29 23:13:30 +01:00
parent fc3ac8b323
commit 6befaa32d5
6 changed files with 55 additions and 24 deletions

View File

@@ -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()); }

View File

@@ -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);

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);
});
}

View File

@@ -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;