mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
Introduced hint for callsign to specify callsign type (aircraft? ATC?) by context.
Background: Pilots can login in with virtually any callsign like XXX_OBS, resulting in wrong interpretations (as OBS here is no ATC station).
This commit is contained in:
committed by
Mathew Sutcliffe
parent
acec379151
commit
7b1beaf02d
@@ -24,6 +24,7 @@ namespace BlackMisc
|
||||
: m_callsign(callsign), m_pilot(user), m_situation(situation)
|
||||
{
|
||||
// sync callsigns
|
||||
this->m_callsign.setTypeHint(CCallsign::Aircraft);
|
||||
if (!callsign.isEmpty())
|
||||
{
|
||||
this->setCallsign(callsign);
|
||||
@@ -37,9 +38,10 @@ namespace BlackMisc
|
||||
void CAircraft::setCallsign(const CCallsign &callsign)
|
||||
{
|
||||
this->m_callsign = callsign;
|
||||
this->m_pilot.setCallsign(callsign);
|
||||
this->m_situation.setCallsign(callsign);
|
||||
this->m_parts.setCallsign(callsign);
|
||||
this->m_callsign.setTypeHint(CCallsign::Aircraft);
|
||||
this->m_pilot.setCallsign(this->m_callsign);
|
||||
this->m_situation.setCallsign(this->m_callsign);
|
||||
this->m_parts.setCallsign(this->m_callsign);
|
||||
}
|
||||
|
||||
QString CAircraft::convertToQString(bool i18n) const
|
||||
|
||||
@@ -21,6 +21,18 @@ namespace BlackMisc
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
CAircraftSituation::CAircraftSituation(const CCoordinateGeodetic &position, const CAltitude &altitude, const CHeading &heading, const CAngle &pitch, const CAngle &bank, const CSpeed &gs)
|
||||
: m_position(position), m_altitude(altitude), m_heading(heading), m_pitch(pitch),
|
||||
m_bank(bank), m_groundspeed(gs) {}
|
||||
|
||||
CAircraftSituation::CAircraftSituation(const CCallsign &correspondingCallsign, const CCoordinateGeodetic &position, const CAltitude &altitude, const CHeading &heading, const CAngle &pitch, const CAngle &bank, const CSpeed &gs)
|
||||
: m_correspondingCallsign(correspondingCallsign),
|
||||
m_position(position), m_altitude(altitude), m_heading(heading), m_pitch(pitch),
|
||||
m_bank(bank), m_groundspeed(gs)
|
||||
{
|
||||
m_correspondingCallsign.setTypeHint(CCallsign::Aircraft);
|
||||
}
|
||||
|
||||
QString CAircraftSituation::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s(this->m_position.toQString(i18n));
|
||||
@@ -140,5 +152,11 @@ namespace BlackMisc
|
||||
return notAvialable;
|
||||
}
|
||||
|
||||
void CAircraftSituation::setCallsign(const CCallsign &callsign)
|
||||
{
|
||||
this->m_correspondingCallsign = callsign;
|
||||
this->m_correspondingCallsign.setTypeHint(CCallsign::Aircraft);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -54,9 +54,7 @@ namespace BlackMisc
|
||||
const BlackMisc::Aviation::CHeading &heading = {},
|
||||
const BlackMisc::PhysicalQuantities::CAngle &pitch = {},
|
||||
const BlackMisc::PhysicalQuantities::CAngle &bank = {},
|
||||
const BlackMisc::PhysicalQuantities::CSpeed &gs = {})
|
||||
: m_position(position), m_altitude(altitude), m_heading(heading), m_pitch(pitch),
|
||||
m_bank(bank), m_groundspeed(gs) {}
|
||||
const BlackMisc::PhysicalQuantities::CSpeed &gs = {});
|
||||
|
||||
//! Comprehensive constructor
|
||||
CAircraftSituation(const BlackMisc::Aviation::CCallsign &correspondingCallsign,
|
||||
@@ -64,11 +62,7 @@ namespace BlackMisc
|
||||
const BlackMisc::Aviation::CHeading &heading = {},
|
||||
const BlackMisc::PhysicalQuantities::CAngle &pitch = {},
|
||||
const BlackMisc::PhysicalQuantities::CAngle &bank = {},
|
||||
const BlackMisc::PhysicalQuantities::CSpeed &gs = {})
|
||||
: m_correspondingCallsign(correspondingCallsign),
|
||||
m_position(position), m_altitude(altitude), m_heading(heading), m_pitch(pitch),
|
||||
m_bank(bank), m_groundspeed(gs) {}
|
||||
|
||||
const BlackMisc::PhysicalQuantities::CSpeed &gs = {});
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
@@ -141,7 +135,7 @@ namespace BlackMisc
|
||||
const BlackMisc::Aviation::CCallsign &getCallsign() const { return this->m_correspondingCallsign; }
|
||||
|
||||
//! Corresponding callsign
|
||||
void setCallsign(const BlackMisc::Aviation::CCallsign &callsign) { this->m_correspondingCallsign = callsign; }
|
||||
void setCallsign(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
@@ -29,16 +29,24 @@ namespace BlackMisc
|
||||
{ }
|
||||
|
||||
CAtcStation::CAtcStation(const QString &callsign) : m_callsign(callsign)
|
||||
{ }
|
||||
{
|
||||
this->m_callsign.setTypeHint(CCallsign::Atc);
|
||||
}
|
||||
|
||||
CAtcStation::CAtcStation(const CCallsign &callsign, const CUser &controller, const CFrequency &frequency, const CCoordinateGeodetic &pos, const CLength &range, bool isOnline,
|
||||
const QDateTime &bookedFromUtc, const QDateTime &bookedUntilUtc, const CInformationMessage &atis, const CInformationMessage &metar) :
|
||||
CAtcStation::CAtcStation(const CCallsign &callsign, const CUser &controller, const CFrequency &frequency,
|
||||
const CCoordinateGeodetic &pos, const CLength &range, bool isOnline,
|
||||
const QDateTime &bookedFromUtc, const QDateTime &bookedUntilUtc,
|
||||
const CInformationMessage &atis, const CInformationMessage &metar) :
|
||||
m_callsign(callsign), m_controller(controller), m_frequency(frequency), m_position(pos),
|
||||
m_range(range), m_isOnline(isOnline), m_bookedFromUtc(bookedFromUtc), m_bookedUntilUtc(bookedUntilUtc), m_atis(atis), m_metar(metar)
|
||||
m_range(range), m_isOnline(isOnline), m_bookedFromUtc(bookedFromUtc), m_bookedUntilUtc(bookedUntilUtc),
|
||||
m_atis(atis), m_metar(metar)
|
||||
{
|
||||
// sync callsigns
|
||||
this->m_callsign.setTypeHint(CCallsign::Atc);
|
||||
if (!this->m_controller.hasValidCallsign() && !callsign.isEmpty())
|
||||
this->m_controller.setCallsign(callsign);
|
||||
{
|
||||
this->m_controller.setCallsign(m_callsign);
|
||||
}
|
||||
}
|
||||
|
||||
bool CAtcStation::hasMetar() const
|
||||
|
||||
@@ -30,17 +30,17 @@ namespace BlackMisc
|
||||
|
||||
const CIcon &CCallsign::convertToIcon(const CCallsign &callsign)
|
||||
{
|
||||
if (callsign.hasSuffix())
|
||||
{
|
||||
return suffixToIcon(callsign.getSuffix());
|
||||
}
|
||||
else
|
||||
if (callsign.getTypeHint() == CCallsign::Aircraft || !callsign.hasSuffix())
|
||||
{
|
||||
return CIconList::iconByIndex(CIcons::NetworkRolePilot);
|
||||
}
|
||||
else
|
||||
{
|
||||
return atcSuffixToIcon(callsign.getSuffix());
|
||||
}
|
||||
}
|
||||
|
||||
const CIcon &CCallsign::suffixToIcon(const QString &suffix)
|
||||
const CIcon &CCallsign::atcSuffixToIcon(const QString &suffix)
|
||||
{
|
||||
if (suffix.length() < 3) { return CIconList::iconByIndex(CIcons::NetworkRoleUnknown); }
|
||||
QString sfx = suffix.toUpper();
|
||||
@@ -60,23 +60,39 @@ namespace BlackMisc
|
||||
|
||||
bool CCallsign::isAtcCallsign() const
|
||||
{
|
||||
if (this->getTypeHint() == Atc) { return true; }
|
||||
if (!this->hasSuffix()) { return false; }
|
||||
return atcCallsignSuffixes().contains(this->getSuffix(), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
bool CCallsign::isSupervisorCallsign() const
|
||||
{
|
||||
if (this->getTypeHint() == Aircraft) { return false; }
|
||||
return this->m_callsign.endsWith("SUP");
|
||||
}
|
||||
|
||||
QString CCallsign::getIcaoCode() const
|
||||
{
|
||||
if (this->isAtcCallsign())
|
||||
{
|
||||
if (m_callsign.length() >= 4)
|
||||
{
|
||||
return m_callsign.left(4).toUpper();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool CCallsign::isAtcAlikeCallsign() const
|
||||
{
|
||||
if (this->getTypeHint() == Aircraft) { return false; }
|
||||
if (!this->hasSuffix()) { return false; }
|
||||
return atcAlikeCallsignSuffixes().contains(this->getSuffix(), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
bool CCallsign::isObserverCallsign() const
|
||||
{
|
||||
if (this->getTypeHint() == Aircraft) { return false; }
|
||||
return m_callsignAsSet.endsWith("_OBS", Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,17 +35,30 @@ namespace BlackMisc
|
||||
IndexSuffix
|
||||
};
|
||||
|
||||
//! Representing what
|
||||
enum TypeHint
|
||||
{
|
||||
NoHint,
|
||||
Aircraft,
|
||||
Atc
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
CCallsign() = default;
|
||||
|
||||
//! Constructor
|
||||
CCallsign(const QString &callsign, const QString &telephonyDesignator = "")
|
||||
: m_callsignAsSet(callsign.trimmed()), m_callsign(CCallsign::unifyCallsign(callsign.trimmed())), m_telephonyDesignator(telephonyDesignator.trimmed())
|
||||
CCallsign(const QString &callsign, TypeHint hint = NoHint)
|
||||
: m_callsignAsSet(callsign.trimmed()), m_callsign(CCallsign::unifyCallsign(callsign.trimmed())), m_typeHint(hint)
|
||||
{}
|
||||
|
||||
//! Constructor
|
||||
CCallsign(const QString &callsign, const QString &telephonyDesignator, TypeHint hint = NoHint)
|
||||
: m_callsignAsSet(callsign.trimmed()), m_callsign(CCallsign::unifyCallsign(callsign.trimmed())), m_telephonyDesignator(telephonyDesignator.trimmed()), m_typeHint(hint)
|
||||
{}
|
||||
|
||||
//! Constructor, needed to disambiguate implicit conversion from string literal.
|
||||
CCallsign(const char *callsign)
|
||||
: m_callsignAsSet(callsign), m_callsign(CCallsign::unifyCallsign(callsign))
|
||||
CCallsign(const char *callsign, TypeHint hint = NoHint)
|
||||
: m_callsignAsSet(callsign), m_callsign(CCallsign::unifyCallsign(callsign)), m_typeHint(hint)
|
||||
{}
|
||||
|
||||
//! Is empty?
|
||||
@@ -74,8 +87,14 @@ namespace BlackMisc
|
||||
//! Get callsign telephony designator (how callsign is pronounced)
|
||||
const QString &getTelephonyDesignator() const { return this->m_telephonyDesignator; }
|
||||
|
||||
//! Type hint
|
||||
TypeHint getTypeHint() const { return m_typeHint; }
|
||||
|
||||
//! Type hint
|
||||
void setTypeHint(TypeHint hint) { this->m_typeHint = hint; }
|
||||
|
||||
//! Get ICAO code, if this makes sense (EDDF_TWR -> EDDF)
|
||||
QString getIcaoCode() const { return m_callsign.left(4).toUpper(); }
|
||||
QString getIcaoCode() const;
|
||||
|
||||
//! Makes this callsign looking like an observer callsign (DAMBZ -> DAMBZ_OBS)
|
||||
QString getAsObserverCallsignString() const;
|
||||
@@ -108,7 +127,7 @@ namespace BlackMisc
|
||||
static const QStringList &atcAlikeCallsignSuffixes();
|
||||
|
||||
//! Suffix to icon
|
||||
static const BlackMisc::CIcon &suffixToIcon(const QString &suffix);
|
||||
static const BlackMisc::CIcon &atcSuffixToIcon(const QString &suffix);
|
||||
|
||||
//! Representing icon
|
||||
static const CIcon &convertToIcon(const CCallsign &callsign);
|
||||
@@ -122,9 +141,10 @@ namespace BlackMisc
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CCallsign)
|
||||
QString m_callsignAsSet;
|
||||
QString m_callsign;
|
||||
QString m_telephonyDesignator;
|
||||
QString m_callsignAsSet;
|
||||
QString m_callsign;
|
||||
QString m_telephonyDesignator;
|
||||
TypeHint m_typeHint = NoHint;
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -132,7 +152,8 @@ namespace BlackMisc
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CCallsign, (
|
||||
attr(o.m_callsign, flags<CaseInsensitiveComparison>()),
|
||||
attr(o.m_callsignAsSet, flags<DisabledForComparison>()),
|
||||
attr(o.m_telephonyDesignator, flags<DisabledForComparison>())
|
||||
attr(o.m_telephonyDesignator, flags<DisabledForComparison>()),
|
||||
attr(o.m_typeHint, flags<DisabledForComparison>())
|
||||
))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CCallsign)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user