mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
* added functions to callsign / callsign list * used in aircraft matcher * also resolve std.livery in matcher * also allow to find aircraft ICAO designator ending with string (e.g. 737 for B737) * renamed CAircraftMatcher::reverseLookup -> CAircraftMatcher::reverselLookupModel * threadsafe isInRange (CAIrspaceMonitor)
This commit is contained in:
@@ -52,6 +52,26 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftIcaoCodeList CAircraftIcaoCodeList::findEndingWith(const QString &icaoEnding) const
|
||||
{
|
||||
QString ends = icaoEnding.trimmed().toUpper();
|
||||
if (ends.isEmpty()) { return CAircraftIcaoCodeList(); }
|
||||
CAircraftIcaoCodeList icaosDesignator;
|
||||
CAircraftIcaoCodeList icaosFamily;
|
||||
for (const CAircraftIcaoCode &icao : *this)
|
||||
{
|
||||
if (icao.getDesignator().endsWith(ends))
|
||||
{
|
||||
icaosDesignator.push_back(icao);
|
||||
}
|
||||
else if (icao.getFamily().endsWith(ends))
|
||||
{
|
||||
icaosFamily.push_back(icao);
|
||||
}
|
||||
}
|
||||
return icaosDesignator.isEmpty() ? icaosFamily : icaosDesignator;
|
||||
}
|
||||
|
||||
CAircraftIcaoCodeList CAircraftIcaoCodeList::findByIataCode(const QString &iata) const
|
||||
{
|
||||
if (iata.isEmpty()) { return CAircraftIcaoCodeList(); }
|
||||
@@ -221,6 +241,10 @@ namespace BlackMisc
|
||||
// we have one exact match
|
||||
if (codes.size() == 1) { return codes.front(); }
|
||||
|
||||
// now try to find as ending
|
||||
codes = this->findEndingWith(d);
|
||||
if (codes.size() == 1) { return codes.front(); }
|
||||
|
||||
// still empty, hopeless
|
||||
if (codes.isEmpty()) { return icaoPattern; }
|
||||
|
||||
|
||||
@@ -60,6 +60,10 @@ namespace BlackMisc
|
||||
//! Find by ICAO/IATA code or family
|
||||
CAircraftIcaoCodeList findByDesignatorIataOrFamily(const QString &icaoIataOrFamily) const;
|
||||
|
||||
//! Find code ending with string, e.g. "738" finds "B738"
|
||||
//! \remark many users use wrong ICAO designators, one typical mistake is "738" for "B737"
|
||||
CAircraftIcaoCodeList findEndingWith(const QString &icaoEnding) const;
|
||||
|
||||
//! Find by manufacturer
|
||||
CAircraftIcaoCodeList findByManufacturer(const QString &manufacturer) const;
|
||||
|
||||
|
||||
@@ -119,12 +119,23 @@ namespace BlackMisc
|
||||
return icaoPattern;
|
||||
}
|
||||
|
||||
CAirlineIcaoCode CAirlineIcaoCodeList::findBestMatchByCallsign(const CCallsign &callsign) const
|
||||
{
|
||||
if (this->isEmpty() || callsign.isEmpty()) { return CAirlineIcaoCode(); }
|
||||
const QString airline = callsign.getAirlineSuffix().toUpper();
|
||||
if (airline.isEmpty()) { return CAirlineIcaoCode(); }
|
||||
const CAirlineIcaoCode airlineCode = (airline.length() == 3) ?
|
||||
this->findFirstByOrDefault(&CAirlineIcaoCode::getDesignator, airline) :
|
||||
this->findFirstByOrDefault(&CAirlineIcaoCode::getVDesignator, airline);
|
||||
return airlineCode;
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::fromDatabaseJson(const QJsonArray &array, bool ignoreIncomplete)
|
||||
{
|
||||
CAirlineIcaoCodeList codes;
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
CAirlineIcaoCode icao(CAirlineIcaoCode::fromDatabaseJson(value.toObject()));
|
||||
const CAirlineIcaoCode icao(CAirlineIcaoCode::fromDatabaseJson(value.toObject()));
|
||||
if (ignoreIncomplete && !icao.hasCompleteData()) { continue; }
|
||||
codes.push_back(icao);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#define BLACKMISC_AVIATION_AIRLINEICAOCODELIST_H
|
||||
|
||||
#include "airlineicaocode.h"
|
||||
#include "blackmisc/aviation/airlineicaocode.h"
|
||||
#include "callsign.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/collection.h"
|
||||
#include "blackmisc/db/datastoreobjectlist.h"
|
||||
@@ -72,6 +72,9 @@ namespace BlackMisc
|
||||
//! Best selection by given pattern
|
||||
CAirlineIcaoCode smartAirlineIcaoSelector(const CAirlineIcaoCode &icaoPattern) const;
|
||||
|
||||
//! Use callsign to conclude airline
|
||||
CAirlineIcaoCode findBestMatchByCallsign(const CCallsign &callsign) const;
|
||||
|
||||
//! String list for completion by ICAO designator
|
||||
QStringList toIcaoDesignatorCompleterStrings(bool combinedString = true, bool sort = true) const;
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace BlackMisc
|
||||
if ("CTR" == sfx) { return CIconList::iconByIndex(CIcons::NetworkRoleCenter); }
|
||||
if ("SUP" == sfx) { return CIconList::iconByIndex(CIcons::NetworkRoleSup); }
|
||||
if ("OBS" == sfx) { return CIconList::iconByIndex(CIcons::NetworkRoleObs); }
|
||||
if ("INS" == sfx) { return CIconList::iconByIndex(CIcons::NetworkRoleMnt); }
|
||||
if ("FSS" == sfx) { return CIconList::iconByIndex(CIcons::NetworkRoleFss); }
|
||||
if ("ATIS" == sfx) { return CIconList::iconByIndex(CIcons::AviationAtis); }
|
||||
if ("EXAM" == sfx) { return CIconList::iconByIndex(CIcons::NetworkRoleMnt); }
|
||||
@@ -125,6 +126,20 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
QString CCallsign::getAirlineSuffix() const
|
||||
{
|
||||
if (this->m_callsign.length() < 3) { return ""; }
|
||||
if (this->isAtcCallsign()) { return ""; }
|
||||
|
||||
static const QRegExp regExp("^[A-Z]{3,}");
|
||||
const int pos = regExp.indexIn(this->m_callsign);
|
||||
if (pos < 0) { return ""; }
|
||||
const QString airline = regExp.cap(0);
|
||||
if (airline.length() == 3) { return airline; } // we allow 3 letters
|
||||
if (airline.length() == 4 && airline.startsWith('V')) { return airline; } // we allow virtual 4 letter codes, e.g. VDLD
|
||||
return ""; // invalid
|
||||
}
|
||||
|
||||
bool CCallsign::hasSuffix() const
|
||||
{
|
||||
return this->getStringAsSet().contains('_');
|
||||
@@ -187,6 +202,8 @@ namespace BlackMisc
|
||||
return this->m_callsignAsSet.compare(compareValue.m_callsignAsSet, Qt::CaseInsensitive);
|
||||
case IndexTelephonyDesignator:
|
||||
return this->m_telephonyDesignator.compare(compareValue.m_telephonyDesignator, Qt::CaseInsensitive);
|
||||
case IndexSuffix:
|
||||
return this->getSuffix().compare(compareValue.getSuffix(), Qt::CaseInsensitive);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -247,9 +264,8 @@ namespace BlackMisc
|
||||
|
||||
const QStringList &CCallsign::atcAlikeCallsignSuffixes()
|
||||
{
|
||||
static const QStringList a({ "ATIS", "APP", "GND", "OBS", "TWR", "DEL", "CTR", "SUP", "FSS" });
|
||||
static const QStringList a({ "ATIS", "APP", "GND", "OBS", "TWR", "DEL", "CTR", "SUP", "FSS", "INS" });
|
||||
return a;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -110,6 +110,9 @@ namespace BlackMisc
|
||||
//! Get the callsign suffix ("TWR", "ATIS" ...) if any ("_" is removed)
|
||||
QString getSuffix() const;
|
||||
|
||||
//! Airline suffix (e.g. DLH1234 -> DLH) if applicable
|
||||
QString getAirlineSuffix() const;
|
||||
|
||||
//! Suffix such as "_TWR"?
|
||||
bool hasSuffix() const;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace BlackMisc
|
||||
if (liveryPattern.hasValidDbKey())
|
||||
{
|
||||
int k = liveryPattern.getDbKey();
|
||||
CLivery l(this->findByKey(k));
|
||||
const CLivery l(this->findByKey(k));
|
||||
if (l.hasCompleteData()) { return l; }
|
||||
}
|
||||
|
||||
@@ -93,14 +93,14 @@ namespace BlackMisc
|
||||
if (liveryPattern.hasCombinedCode())
|
||||
{
|
||||
QString cc(liveryPattern.getCombinedCode());
|
||||
CLivery l(this->findByCombinedCode(cc));
|
||||
const CLivery l(this->findByCombinedCode(cc));
|
||||
if (l.hasCompleteData()) { return l; }
|
||||
}
|
||||
|
||||
if (liveryPattern.hasValidAirlineDesignator())
|
||||
{
|
||||
QString icao(liveryPattern.getAirlineIcaoCodeDesignator());
|
||||
CLivery l(this->findStdLiveryByAirlineIcaoDesignator(icao));
|
||||
const QString icao(liveryPattern.getAirlineIcaoCodeDesignator());
|
||||
const CLivery l(this->findStdLiveryByAirlineIcaoDesignator(icao));
|
||||
if (l.hasCompleteData()) { return l; }
|
||||
}
|
||||
return CLivery();
|
||||
|
||||
@@ -334,7 +334,7 @@ namespace BlackMisc
|
||||
//! From swift DB JSON
|
||||
static CAircraftModel fromDatabaseJson(const QJsonObject &json, const QString prefix = QString("mod_"));
|
||||
|
||||
//! Split swift network string "DLH._STD" [modelname]"
|
||||
//! Split swift network string "DLH._STD [modelname]"
|
||||
//! \return QStringList [0] livery code , [1] model string
|
||||
//! \sa getSwiftLiveryString
|
||||
static QStringList splitNetworkLiveryString(const QString &liveryString);
|
||||
|
||||
Reference in New Issue
Block a user