mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 18:35:35 +08:00
@@ -50,90 +50,133 @@ namespace BlackCore
|
|||||||
return remoteAircraft.getModel();
|
return remoteAircraft.getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAircraftModel matchedModel(remoteAircraft.getModel());
|
||||||
|
if (matchedModels.isEmpty())
|
||||||
|
{
|
||||||
|
logDetails(log, remoteAircraft, "No models for matching, using default", CStatusMessage::SeverityError);
|
||||||
|
matchedModel = this->getDefaultModel();
|
||||||
|
matchedModel.setCallsign(remoteAircraft.getCallsign());
|
||||||
|
return matchedModel;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
if (matchedModels.isEmpty())
|
||||||
|
{
|
||||||
|
logDetails(log, remoteAircraft, "No models for matching, using default", CStatusMessage::SeverityWarning);
|
||||||
|
matchedModel = this->getDefaultModel();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// try to find in installed models by model string
|
// try to find in installed models by model string
|
||||||
if (mode.testFlag(ByModelString))
|
if (mode.testFlag(ByModelString))
|
||||||
{
|
{
|
||||||
aircraftModel = matchByExactModelString(remoteAircraft, matchModels, log);
|
matchedModel = matchByExactModelString(remoteAircraft, matchedModels, log);
|
||||||
if (aircraftModel.hasModelString()) { break; }
|
if (matchedModel.hasModelString()) { break; }
|
||||||
}
|
}
|
||||||
else if (log)
|
else if (log)
|
||||||
{
|
{
|
||||||
logDetails(log, remoteAircraft, "Skipping model string match");
|
logDetails(log, remoteAircraft, "Skipping model string match");
|
||||||
}
|
}
|
||||||
|
|
||||||
// by livery, then by ICAO
|
// primary reduction
|
||||||
if (mode.testFlag(ByLivery))
|
bool reduced = false;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
aircraftModel = matchByLiveryAndIcaoCode(remoteAircraft, matchModels, log);
|
// by livery, then by ICAO
|
||||||
if (aircraftModel.hasModelString()) { break; }
|
if (mode.testFlag(ByLivery))
|
||||||
}
|
{
|
||||||
else if (log)
|
matchedModels = ifPossibleReduceByLiveryAndIcaoCode(remoteAircraft, matchedModels, reduced, log);
|
||||||
{
|
if (reduced) { break; }
|
||||||
logDetails(log, remoteAircraft, "Skipping livery match");
|
}
|
||||||
}
|
else if (log)
|
||||||
|
{
|
||||||
|
logDetails(log, remoteAircraft, "Skipping livery reduction");
|
||||||
|
}
|
||||||
|
|
||||||
// by ICAO data from set
|
// by ICAO data from set
|
||||||
aircraftModel = matchModelsByIcaoData(remoteAircraft, matchModels, false, log);
|
if (mode.testFlag(ByIcaoData))
|
||||||
if (aircraftModel.hasModelString()) { break; }
|
{
|
||||||
|
// if already matched by livery skip
|
||||||
|
matchedModels = ifPossibleReduceByIcaoData(remoteAircraft, matchedModels, false, reduced, log);
|
||||||
|
if (reduced) { break; }
|
||||||
|
}
|
||||||
|
else if (log)
|
||||||
|
{
|
||||||
|
logDetails(log, remoteAircraft, "Skipping ICAO reduction");
|
||||||
|
}
|
||||||
|
|
||||||
// family
|
// family
|
||||||
if (mode.testFlag(ByFamily))
|
if (mode.testFlag(ByFamily))
|
||||||
{
|
{
|
||||||
QString family = remoteAircraft.getAircraftIcaoCode().getFamily();
|
QString family = remoteAircraft.getAircraftIcaoCode().getFamily();
|
||||||
aircraftModel = matchByFamily(remoteAircraft, family, matchModels, "real family", log);
|
matchedModels = ifPossibleReduceByFamily(remoteAircraft, family, matchedModels, "real family", reduced, log);
|
||||||
if (aircraftModel.hasModelString()) { break; }
|
if (reduced) { break; }
|
||||||
|
|
||||||
// scenario: the ICAO actually is the family
|
// scenario: the ICAO actually is the family
|
||||||
family = remoteAircraft.getAircraftIcaoCodeDesignator();
|
family = remoteAircraft.getAircraftIcaoCodeDesignator();
|
||||||
aircraftModel = matchByFamily(remoteAircraft, family, matchModels, "ICAO treated as family", log);
|
matchedModels = ifPossibleReduceByFamily(remoteAircraft, family, matchedModels, "ICAO treated as family", reduced, log);
|
||||||
if (aircraftModel.hasModelString()) { break; }
|
if (reduced) { break; }
|
||||||
}
|
}
|
||||||
else if (log)
|
else if (log)
|
||||||
{
|
{
|
||||||
logDetails(log, remoteAircraft, "Skipping family match");
|
logDetails(log, remoteAircraft, "Skipping family match");
|
||||||
}
|
}
|
||||||
|
|
||||||
// combined code
|
// combined code
|
||||||
if (mode.testFlag(ByCombinedCode))
|
if (mode.testFlag(ByCombinedCode))
|
||||||
{
|
{
|
||||||
aircraftModel = matchByCombinedCode(remoteAircraft, matchModels, true, log);
|
matchedModels = ifPossibleReduceByCombinedCode(remoteAircraft, matchedModels, true, reduced, log);
|
||||||
if (aircraftModel.hasModelString()) { break; }
|
if (reduced) { break; }
|
||||||
}
|
}
|
||||||
else if (log)
|
else if (log)
|
||||||
{
|
{
|
||||||
logDetails(log, remoteAircraft, "Skipping combined code match");
|
logDetails(log, remoteAircraft, "Skipping combined code match");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (false);
|
||||||
|
|
||||||
aircraftModel = getDefaultModel();
|
// here we have a list of possible models, we reduce/refine further
|
||||||
logDetails(log, remoteAircraft, "Using default model " + aircraftModel.getModelString());
|
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();
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
||||||
// copy over callsign and other data
|
// copy over callsign and other data
|
||||||
aircraftModel.setCallsign(remoteAircraft.getCallsign());
|
matchedModel.setCallsign(remoteAircraft.getCallsign());
|
||||||
|
|
||||||
Q_ASSERT_X(!aircraftModel.getCallsign().isEmpty(), Q_FUNC_INFO, "Missing callsign");
|
Q_ASSERT_X(!matchedModel.getCallsign().isEmpty(), Q_FUNC_INFO, "Missing callsign");
|
||||||
Q_ASSERT_X(aircraftModel.hasModelString(), Q_FUNC_INFO, "Missing model string");
|
Q_ASSERT_X(matchedModel.hasModelString(), Q_FUNC_INFO, "Missing model string");
|
||||||
Q_ASSERT_X(aircraftModel.getModelType() != CAircraftModel::TypeUnknown, Q_FUNC_INFO, "Missing model type");
|
Q_ASSERT_X(matchedModel.getModelType() != CAircraftModel::TypeUnknown, Q_FUNC_INFO, "Missing model type");
|
||||||
|
|
||||||
return aircraftModel;
|
return matchedModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftModel CAircraftMatcher::reverseLookup(const CAircraftModel &modelToLookup, const QString &liveryInfo, CStatusMessageList *log)
|
CAircraftModel CAircraftMatcher::reverseLookup(const CAircraftModel &modelToLookup, const QString &liveryInfo, CStatusMessageList *log)
|
||||||
{
|
{
|
||||||
CAircraftModel model(modelToLookup);
|
CAircraftModel model(modelToLookup);
|
||||||
const CCallsign callsign(model.getCallsign());
|
const CCallsign callsign(model.getCallsign());
|
||||||
if (model.hasModelString())
|
const QStringList liveryModelStrings = CAircraftModel::splitNetworkLiveryString(liveryInfo);
|
||||||
|
const QString modelString(modelToLookup.hasModelString() ? modelToLookup.getModelString() : liveryModelStrings[1]);
|
||||||
|
QString liveryCode(liveryModelStrings[0]);
|
||||||
|
|
||||||
|
if (!modelString.isEmpty())
|
||||||
{
|
{
|
||||||
// if we find the model here we have a fully defined DB model
|
// if we find the model here we have a fully defined DB model
|
||||||
const CAircraftModel modelFromDb(sApp->getWebDataServices()->getModelForModelString(model.getModelString()));
|
const CAircraftModel modelFromDb(sApp->getWebDataServices()->getModelForModelString(modelString));
|
||||||
if (modelFromDb.hasValidDbKey())
|
if (modelFromDb.hasValidDbKey())
|
||||||
{
|
{
|
||||||
model = modelFromDb;
|
model = modelFromDb;
|
||||||
if (log) { logDetails(log, callsign, QString("Reverse looked up DB model `%1` for %2").arg(modelFromDb.getDbKey()).arg(callsign.toQString())); }
|
if (log) { logDetails(log, callsign, QString("Reverse looked up DB model `%1` for %2").arg(modelFromDb.getDbKey()).arg(callsign.toQString())); }
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (log) { logDetails(log, callsign, QString("Reverse looked, not found model for `%1`").arg(modelString)); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// only if not yet matched with DB
|
// only if not yet matched with DB
|
||||||
|
|||||||
Reference in New Issue
Block a user