diff --git a/src/blackmisc/aviation/aircraftsituation.cpp b/src/blackmisc/aviation/aircraftsituation.cpp index a1b0781a4..9d94fa303 100644 --- a/src/blackmisc/aviation/aircraftsituation.cpp +++ b/src/blackmisc/aviation/aircraftsituation.cpp @@ -11,9 +11,10 @@ #include "blackmisc/pq/physicalquantity.h" #include "blackmisc/pq/units.h" #include "blackmisc/propertyindex.h" +#include "blackmisc/comparefunctions.h" #include "blackmisc/variant.h" #include "blackmisc/verify.h" - +#include "QStringBuilder" #include using namespace BlackMisc; @@ -41,16 +42,52 @@ namespace BlackMisc QString CAircraftSituation::convertToQString(bool i18n) const { - QString s(this->m_position.toQString(i18n)); - s.append(" bank: ").append(this->m_bank.toQString(i18n)); - s.append(" pitch: ").append(this->m_pitch.toQString(i18n)); - s.append(" gs: ").append(this->m_groundSpeed.toQString(i18n)); - s.append(" elevation: ").append(this->m_groundElevation.toQString(i18n)); - s.append(" heading: ").append(this->m_heading.toQString(i18n)); - s.append(" timestamp: ").append(this->getFormattedUtcTimestampDhms()); + const QString s = (this->m_position.toQString(i18n)) % + QLatin1Literal(" bank: ") % (this->m_bank.toQString(i18n)) % + QLatin1Literal(" pitch: ") % (this->m_pitch.toQString(i18n)) % + QLatin1Literal(" gs: ") % (this->m_groundSpeed.toQString(i18n)) % + QLatin1Literal(" elevation: ") % (this->m_groundElevation.toQString(i18n)) % + QLatin1Literal(" heading: ") % (this->m_heading.toQString(i18n)) % + QLatin1Literal(" timestamp: ") % (this->getFormattedUtcTimestampDhms()); return s; } + const QString &CAircraftSituation::isOnGroundToString(CAircraftSituation::IsOnGround onGround) + { + static const QString notog("not on ground"); + static const QString og("on ground"); + static const QString unknown("unknown"); + + switch (onGround) + { + case CAircraftSituation::NotOnGround: return notog; + case CAircraftSituation::OnGround: return og; + case CAircraftSituation::OnGroundSituationUnknown: + default: + return unknown; + } + } + + const QString &CAircraftSituation::onGroundReliabilityToString(CAircraftSituation::OnGroundReliability reliability) + { + static const QString elv("by elevation"); + static const QString elvCg("by elevation/CG"); + static const QString inter("by interpolation"); + static const QString guess("guessing"); + static const QString unknown("unknown"); + + switch (reliability) + { + case CAircraftSituation::OnGroundByElevation: return elv; + case CAircraftSituation::OnGroundByElevationAndCG: return elvCg; + case CAircraftSituation::OnGroundByGuessing: return guess; + case CAircraftSituation::OnGroundByInterpolation: return inter; + case CAircraftSituation::OnGroundReliabilityNoSet: + default: + return unknown; + } + } + CVariant CAircraftSituation::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } @@ -80,6 +117,14 @@ namespace BlackMisc return this->m_groundElevation.propertyByIndex(index.copyFrontRemoved()); case IndexCallsign: return this->m_correspondingCallsign.propertyByIndex(index.copyFrontRemoved()); + case IndexIsOnGround: + return CVariant::fromValue(m_isOnGround); + case IndexIsOnGroundString: + return CVariant::fromValue(this->isOnGroundAsString()); + case IndexOnGroundReliability: + return CVariant::fromValue(m_onGroundReliability); + case IndexOnGroundReliabilityString: + return CVariant::fromValue(this->getOnGroundReliabilityAsString()); default: return CValueObject::propertyByIndex(index); } @@ -115,6 +160,12 @@ namespace BlackMisc case IndexCallsign: this->m_correspondingCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break; + case IndexIsOnGround: + this->m_isOnGround = variant.toInt(); + break; + case IndexOnGroundReliability: + this->m_onGroundReliability = variant.toInt(); + break; default: CValueObject::setPropertyByIndex(index, variant); break; @@ -130,25 +181,24 @@ namespace BlackMisc { case IndexPosition: return this->m_position.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPosition()); - break; case IndexAltitude: return this->getAltitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getAltitude()); - break; case IndexPitch: return this->m_pitch.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPitch()); - break; case IndexBank: return this->m_bank.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getBank()); - break; case IndexGroundSpeed: return this->m_groundSpeed.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getGroundSpeed()); - break; case IndexGroundElevation: return this->m_groundElevation.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getGroundElevation()); - break; case IndexCallsign: return this->m_correspondingCallsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); - break; + case IndexIsOnGround: + case IndexIsOnGroundString: + return Compare::compare(this->m_isOnGround, compareValue.m_isOnGround); + case IndexOnGroundReliability: + case IndexOnGroundReliabilityString: + return Compare::compare(this->m_onGroundReliability, compareValue.m_onGroundReliability); default: break; } @@ -157,6 +207,11 @@ namespace BlackMisc return 0; } + const QString &CAircraftSituation::isOnGroundAsString() const + { + return CAircraftSituation::isOnGroundToString(this->isOnGround()); + } + bool CAircraftSituation::isOnGroundInfoAvailable() const { return this->isOnGround() != CAircraftSituation::OnGroundSituationUnknown && @@ -169,6 +224,16 @@ namespace BlackMisc this->setOnGroundReliabiliy(reliability); } + const QString &CAircraftSituation::getOnGroundReliabilityAsString() const + { + return CAircraftSituation::onGroundReliabilityToString(this->getOnGroundReliability()); + } + + QString CAircraftSituation::getOnGroundInfo() const + { + return this->isOnGroundAsString() % QLatin1Char(' ') % this->getOnGroundReliabilityAsString(); + } + bool CAircraftSituation::hasGroundElevation() const { return !this->getGroundElevation().isNull(); diff --git a/src/blackmisc/aviation/aircraftsituation.h b/src/blackmisc/aviation/aircraftsituation.h index dcba6879e..c5ceffa78 100644 --- a/src/blackmisc/aviation/aircraftsituation.h +++ b/src/blackmisc/aviation/aircraftsituation.h @@ -52,6 +52,10 @@ namespace BlackMisc IndexAltitude, IndexHeading, IndexBank, + IndexIsOnGround, + IndexIsOnGroundString, + IndexOnGroundReliability, + IndexOnGroundReliabilityString, IndexPitch, IndexGroundSpeed, IndexGroundElevation, @@ -119,6 +123,9 @@ namespace BlackMisc //! On ground? IsOnGround isOnGround() const { return static_cast(m_isOnGround); } + //! On ground? + const QString &isOnGroundAsString() const; + //! On ground info available? bool isOnGroundInfoAvailable() const; @@ -131,9 +138,15 @@ namespace BlackMisc //! On ground reliability OnGroundReliability getOnGroundReliability() const { return static_cast(m_onGroundReliability); } + //! On ground reliability as string + const QString &getOnGroundReliabilityAsString() const; + //! Reliability void setOnGroundReliabiliy(CAircraftSituation::OnGroundReliability onGroundReliability) { m_onGroundReliability = static_cast(onGroundReliability); } + //! On ground info as string + QString getOnGroundInfo() const; + //! \copydoc Geo::ICoordinateGeodetic::geodeticHeight const BlackMisc::Aviation::CAltitude &geodeticHeight() const override { return this->m_position.geodeticHeight(); } @@ -212,6 +225,12 @@ namespace BlackMisc //! \copydoc BlackMisc::Mixin::String::toQString QString convertToQString(bool i18n = false) const; + //! Enum to string + static const QString &isOnGroundToString(IsOnGround onGround); + + //! Enum to string + static const QString &onGroundReliabilityToString(OnGroundReliability reliability); + private: CCallsign m_correspondingCallsign; BlackMisc::Geo::CCoordinateGeodetic m_position; @@ -219,7 +238,7 @@ namespace BlackMisc BlackMisc::PhysicalQuantities::CAngle m_pitch; BlackMisc::PhysicalQuantities::CAngle m_bank; BlackMisc::PhysicalQuantities::CSpeed m_groundSpeed; - BlackMisc::Aviation::CAltitude m_groundElevation; + BlackMisc::Aviation::CAltitude m_groundElevation{0, BlackMisc::Aviation::CAltitude::MeanSeaLevel, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()}; int m_isOnGround = static_cast(CAircraftSituation::OnGroundSituationUnknown); int m_onGroundReliability = static_cast(CAircraftSituation::OnGroundReliabilityNoSet); qint64 m_timeOffsetMs = 0;