From b9366e636ccc9f121dfb85e156dbb694b9edbcff Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 18 May 2019 00:35:31 +0200 Subject: [PATCH] Ref T664, allow hyphen in ATC station callsign --- src/blackgui/components/atcstationcomponent.cpp | 1 + src/blackmisc/aviation/callsign.cpp | 17 ++++++++++++----- src/blackmisc/aviation/callsign.h | 2 +- src/blackmisc/test/testing.cpp | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index 1975ae223..e6b425b76 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -336,6 +336,7 @@ namespace BlackGui void CAtcStationComponent::testCreateDummyOnlineAtcStations(int number) { + if (!sGui || !sGui->getIContextNetwork()) { return; } if (this->canAccessContext()) { sGui->getIContextNetwork()->testCreateDummyOnlineAtcStations(number); diff --git a/src/blackmisc/aviation/callsign.cpp b/src/blackmisc/aviation/callsign.cpp index ead751ec4..7bf2cad67 100644 --- a/src/blackmisc/aviation/callsign.cpp +++ b/src/blackmisc/aviation/callsign.cpp @@ -20,15 +20,15 @@ namespace BlackMisc namespace Aviation { CCallsign::CCallsign(const QString &callsign, CCallsign::TypeHint hint) - : m_callsignAsSet(callsign.trimmed()), m_callsign(CCallsign::unifyCallsign(callsign)), m_typeHint(hint) + : m_callsignAsSet(callsign.trimmed()), m_callsign(CCallsign::unifyCallsign(callsign, hint)), m_typeHint(hint) {} CCallsign::CCallsign(const QString &callsign, const QString &telephonyDesignator, CCallsign::TypeHint hint) - : m_callsignAsSet(callsign.trimmed()), m_callsign(CCallsign::unifyCallsign(callsign)), m_telephonyDesignator(telephonyDesignator.trimmed()), m_typeHint(hint) + : m_callsignAsSet(callsign.trimmed()), m_callsign(CCallsign::unifyCallsign(callsign, hint)), m_telephonyDesignator(telephonyDesignator.trimmed()), m_typeHint(hint) {} CCallsign::CCallsign(const char *callsign, CCallsign::TypeHint hint) - : m_callsignAsSet(callsign), m_callsign(CCallsign::unifyCallsign(callsign)), m_typeHint(hint) + : m_callsignAsSet(callsign), m_callsign(CCallsign::unifyCallsign(callsign, hint)), m_typeHint(hint) {} void CCallsign::registerMetadata() @@ -68,8 +68,14 @@ namespace BlackMisc return std::numeric_limits::max(); } - QString CCallsign::unifyCallsign(const QString &callsign) + QString CCallsign::unifyCallsign(const QString &callsign, TypeHint hint) { + // Ref T664, allow ATC with hyphen, such as Ml-SNO_CTR + switch (hint) + { + case Atc: return removeChars(callsign.toUpper().trimmed(), [](QChar c) { return !c.isLetterOrNumber() && c != '_' && c != '-'; }); + default: break; + } return removeChars(callsign.toUpper().trimmed(), [](QChar c) { return !c.isLetterOrNumber() && c != '_'; }); } @@ -282,8 +288,9 @@ namespace BlackMisc bool CCallsign::isValidAtcCallsign(const QString &callsign) { + // Ref T664, allow ATC with hyphen, such as Ml-SNO_CTR if (callsign.length() < 2 || callsign.length() > 10) { return false; } - return !containsChar(callsign, [](QChar c) { return c != '_' && !c.isUpper() && !c.isDigit(); }); + return !containsChar(callsign, [](QChar c) { return c != '-' && c != '_' && !c.isUpper() && !c.isDigit(); }); } bool CCallsign::isValidAtcCallsign(const CCallsign &callsign) diff --git a/src/blackmisc/aviation/callsign.h b/src/blackmisc/aviation/callsign.h index 75cd69684..105383c7b 100644 --- a/src/blackmisc/aviation/callsign.h +++ b/src/blackmisc/aviation/callsign.h @@ -159,7 +159,7 @@ namespace BlackMisc static bool isValidAtcCallsign(const CCallsign &callsign); //! Unify the callsign by removing illegal characters - static QString unifyCallsign(const QString &callsign); + static QString unifyCallsign(const QString &callsign, TypeHint hint = NoHint); //! List of real ATC suffixes (e.g. TWR); static const QStringList &atcCallsignSuffixes(); diff --git a/src/blackmisc/test/testing.cpp b/src/blackmisc/test/testing.cpp index 69a695b92..86b55d434 100644 --- a/src/blackmisc/test/testing.cpp +++ b/src/blackmisc/test/testing.cpp @@ -50,9 +50,9 @@ namespace BlackMisc // from WGS is slow, so static const (only 1 time init) // https://dev.vatsim-germany.org/issues/322#note-2 static const CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21′ 13″ N", "11° 47′ 09″ E", CAltitude(index, CLengthUnit::ft())); - const QString cs = QStringLiteral("%1_TWR").arg(index); + const QString cs = QStringLiteral("%1MI-SNO_TWR").arg(index); const QString usr = QStringLiteral("Joe %1").arg(index); - const QString id = QStringLiteral("00000%1").arg(index).right(6); + const QString id = QStringLiteral("00000%1").arg(index).right(6); const double f = 118.0 + (index % 30) * 0.25; const QDateTime dtFrom = QDateTime::currentDateTimeUtc(); @@ -78,7 +78,7 @@ namespace BlackMisc } else { - station = CAtcStation(CCallsign(cs), user, + station = CAtcStation(CCallsign(cs, CCallsign::Atc), user, CFrequency(f, CFrequencyUnit::MHz()), geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil); station.setRelativeDistance(CLength(index + 1, CLengthUnit::NM()));