From c8fc50e78718c51d1243094e94fa77a23a8c5846 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 30 Jul 2018 15:34:50 +0200 Subject: [PATCH] Ref T296, adding scenery offset as situation member plus utility functions * frontOrNull/backOrNull * added offset in model * style/renaming --- src/blackcore/airspacemonitor.cpp | 4 +-- .../models/aircraftsituationlistmodel.cpp | 1 + .../models/aircraftsituationlistmodel.h | 5 +-- src/blackmisc/aviation/aircraftsituation.cpp | 36 ++++++++++++++----- src/blackmisc/aviation/aircraftsituation.h | 20 +++++++++-- .../aviation/aircraftsituationchange.h | 2 +- .../aviation/aircraftsituationchangelist.cpp | 19 +++++++++- .../aviation/aircraftsituationchangelist.h | 11 ++++-- .../aviation/aircraftsituationlist.cpp | 18 ++++++++++ .../aviation/aircraftsituationlist.h | 9 +++++ src/blackmisc/simulation/interpolator.cpp | 2 +- 11 files changed, 105 insertions(+), 22 deletions(-) diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index f41413127..301001a7f 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -1037,7 +1037,7 @@ namespace BlackCore const CLength cg = this->getCG(callsign); // always x-check against simulator to override guessed values and reflect changed CGs if (!cg.isNull()) { correctedSituation.setCG(cg); } - // store change object + // store corrected situation correctedSituation = CRemoteAircraftProvider::storeAircraftSituation(correctedSituation, false); // we already added offset if any // check if we STILL want to request @@ -1045,7 +1045,7 @@ namespace BlackCore { // we have not requested so far, but we are NEAR ground // we expect at least not transferred cache or we are moving and have no provider elevation yet - if (correctedSituation.isThisElevationInfoBetter(CAircraftSituation::FromCache, false) || (correctedSituation.isMoving() && correctedSituation.isThisElevationInfoBetter(CAircraftSituation::FromProvider, false))) + if (correctedSituation.isOtherElevationInfoBetter(CAircraftSituation::FromCache, false) || (correctedSituation.isMoving() && correctedSituation.isOtherElevationInfoBetter(CAircraftSituation::FromProvider, false))) { haveRequestedElevation = this->requestElevation(correctedSituation); } diff --git a/src/blackgui/models/aircraftsituationlistmodel.cpp b/src/blackgui/models/aircraftsituationlistmodel.cpp index 6d452c766..44d759ea4 100644 --- a/src/blackgui/models/aircraftsituationlistmodel.cpp +++ b/src/blackgui/models/aircraftsituationlistmodel.cpp @@ -32,6 +32,7 @@ namespace BlackGui m_columns.addColumn(CColumn("altitude", CAircraftSituation::IndexAltitude, new CAltitudeFormatter())); m_columns.addColumn(CColumn("CG", CAircraftSituation::IndexCG, new CPhysiqalQuantiyFormatter(CLengthUnit::ft(), 1))); + m_columns.addColumn(CColumn("offset", CAircraftSituation::IndexSceneryOffset, new CPhysiqalQuantiyFormatter(CLengthUnit::ft(), 1))); m_columns.addColumn(CColumn("latitude", CAircraftSituation::IndexLatitude, new CLatLonFormatter())); m_columns.addColumn(CColumn("longitude", CAircraftSituation::IndexLongitude, new CLatLonFormatter())); m_columns.addColumn(CColumn("gs.", CAircraftSituation::IndexGroundSpeed, new CSpeedKtsFormatter())); diff --git a/src/blackgui/models/aircraftsituationlistmodel.h b/src/blackgui/models/aircraftsituationlistmodel.h index 52d3b7eeb..c71a8e5f6 100644 --- a/src/blackgui/models/aircraftsituationlistmodel.h +++ b/src/blackgui/models/aircraftsituationlistmodel.h @@ -12,15 +12,12 @@ #ifndef BLACKGUI_MODELS_AIRCRAFTSITUATIONLISTMODEL_H #define BLACKGUI_MODELS_AIRCRAFTSITUATIONLISTMODEL_H -#include "blackgui/blackguiexport.h" #include "blackgui/models/listmodeltimestampobjects.h" +#include "blackgui/blackguiexport.h" #include "blackmisc/aviation/aircraftsituationlist.h" #include -class QModelIndex; -class QObject; - namespace BlackGui { namespace Models diff --git a/src/blackmisc/aviation/aircraftsituation.cpp b/src/blackmisc/aviation/aircraftsituation.cpp index 4f567807e..5ec94fb68 100644 --- a/src/blackmisc/aviation/aircraftsituation.cpp +++ b/src/blackmisc/aviation/aircraftsituation.cpp @@ -65,6 +65,8 @@ namespace BlackMisc (m_onGroundGuessingDetails.isEmpty() ? QStringLiteral("") : QStringLiteral(" ") % m_onGroundGuessingDetails) % QStringLiteral(" | cg: ") % (m_cg.isNull() ? QStringLiteral("null") : m_cg.valueRoundedWithUnit(CLengthUnit::m(), 1) % QStringLiteral(" ") % m_cg.valueRoundedWithUnit(CLengthUnit::ft(), 1)) % + QStringLiteral(" | offset: ") % + (m_sceneryOffset.isNull() ? QStringLiteral("null") : m_sceneryOffset.valueRoundedWithUnit(CLengthUnit::m(), 1) % QStringLiteral(" ") % m_sceneryOffset.valueRoundedWithUnit(CLengthUnit::ft(), 1)) % QStringLiteral(" | factor [0..1]: ") % QString::number(m_onGroundFactor, 'f', 2) % QStringLiteral(" | skip ng: ") % boolToYesNo(this->canLikelySkipNearGroundInterpolation()) % QStringLiteral(" | bank: ") % m_bank.toQString(i18n) % @@ -303,6 +305,7 @@ namespace BlackMisc case IndexPitch: return m_pitch.propertyByIndex(index.copyFrontRemoved()); case IndexBank: return m_bank.propertyByIndex(index.copyFrontRemoved()); case IndexCG: return m_cg.propertyByIndex(index.copyFrontRemoved()); + case IndexSceneryOffset: return m_sceneryOffset.propertyByIndex(index.copyFrontRemoved()); case IndexGroundSpeed: return m_groundSpeed.propertyByIndex(index.copyFrontRemoved()); case IndexGroundElevationPlane: return m_groundElevationPlane.propertyByIndex(index.copyFrontRemoved()); case IndexCallsign: return m_correspondingCallsign.propertyByIndex(index.copyFrontRemoved()); @@ -331,6 +334,7 @@ namespace BlackMisc case IndexPitch: m_pitch.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexBank: m_bank.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexCG: m_cg.setPropertyByIndex(index.copyFrontRemoved(), variant); break; + case IndexSceneryOffset: m_sceneryOffset.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexGroundSpeed: m_groundSpeed.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexGroundElevationPlane: m_groundElevationPlane.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexCallsign: m_correspondingCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break; @@ -356,6 +360,7 @@ namespace BlackMisc case IndexPitch: return m_pitch.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPitch()); case IndexBank: return m_bank.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getBank()); case IndexCG: return m_cg.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCG()); + case IndexSceneryOffset: return m_sceneryOffset.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getSceneryOffset()); case IndexGroundSpeed: return m_groundSpeed.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getGroundSpeed()); case IndexGroundElevationPlane: case IndexGroundElevationPlusInfo: @@ -392,12 +397,12 @@ namespace BlackMisc return this->isPositionNull(); } - bool CAircraftSituation::isThisElevationInfoBetter(CAircraftSituation::GndElevationInfo info, bool transferred) const + bool CAircraftSituation::isOtherElevationInfoBetter(CAircraftSituation::GndElevationInfo otherInfo, bool transferred) const { - if (info == NoElevationInfo || info == Test) { return false; } - const int i = static_cast(info); - if (i > m_elvInfo) { return true; } - if (i == m_elvInfo) + if (otherInfo == NoElevationInfo || otherInfo == Test) { return false; } + const int otherInfoInt = static_cast(otherInfo); + if (otherInfoInt > m_elvInfo) { return true; } + if (otherInfoInt == m_elvInfo) { if (m_isElvInfoTransferred == transferred) { return false; } // not better (equal) return !transferred; // if not transferred it is better @@ -434,6 +439,8 @@ namespace BlackMisc m_onGroundDetails = CAircraftSituation::NotSetGroundDetails; m_elvInfo = NoElevationInfo; m_isElvInfoTransferred = false; + m_cg.setNull(); + m_sceneryOffset.setNull(); } bool CAircraftSituation::isOnGroundFromParts() const @@ -811,7 +818,7 @@ namespace BlackMisc if (elevationPlane.isNull()) { return false; } const CLength distance = this->calculateGreatCircleDistance(elevationPlane); if (distance > elevationPlane.getRadiusOrMinimumRadius()) { return false; } - if (m_groundElevationPlane.isNull() || this->isThisElevationInfoBetter(info, transferred)) + if (m_groundElevationPlane.isNull() || this->isOtherElevationInfoBetter(info, transferred)) { // better values this->setGroundElevation(elevationPlane, info, transferred); @@ -928,10 +935,10 @@ namespace BlackMisc CAircraftSituation::AltitudeCorrection CAircraftSituation::correctAltitude(const CLength ¢erOfGravity, bool enableDragToGround) { - CAircraftSituation::AltitudeCorrection altCor = CAircraftSituation::UnknownCorrection; - this->setAltitude(this->getCorrectedAltitude(centerOfGravity, enableDragToGround, &altCor)); + CAircraftSituation::AltitudeCorrection altitudeCorrection = CAircraftSituation::UnknownCorrection; + this->setAltitude(this->getCorrectedAltitude(centerOfGravity, enableDragToGround, &altitudeCorrection)); this->setCG(centerOfGravity); - return altCor; + return altitudeCorrection; } void CAircraftSituation::setAltitude(const CAltitude &altitude) @@ -1018,6 +1025,17 @@ namespace BlackMisc m_cg = cg.switchedUnit(this->getAltitudeOrDefaultUnit()); } + const CLength &CAircraftSituation::getSceneryOffsetOrZero() const + { + static const CLength zero(0, CLengthUnit::ft()); + return this->hasSceneryOffset() ? m_sceneryOffset : zero; + } + + void CAircraftSituation::setSceneryOffset(const CLength &sceneryOffset) + { + m_sceneryOffset = sceneryOffset.switchedUnit(this->getAltitudeOrDefaultUnit()); + } + bool CAircraftSituation::adjustGroundFlag(const CAircraftParts &parts, bool alwaysSetDetails, double timeDeviationFactor, qint64 *differenceMs) { Q_ASSERT_X(timeDeviationFactor >= 0 && timeDeviationFactor <= 1.0, Q_FUNC_INFO, "Expect 0..1"); diff --git a/src/blackmisc/aviation/aircraftsituation.h b/src/blackmisc/aviation/aircraftsituation.h index 82ae206ae..f565b109a 100644 --- a/src/blackmisc/aviation/aircraftsituation.h +++ b/src/blackmisc/aviation/aircraftsituation.h @@ -48,7 +48,8 @@ namespace BlackMisc //! Value object encapsulating information of an aircraft's situation class BLACKMISC_EXPORT CAircraftSituation : public CValueObject, - public Geo::ICoordinateGeodetic, public ITimestampWithOffsetBased + public Geo::ICoordinateGeodetic, + public ITimestampWithOffsetBased { public: //! Properties by index @@ -73,6 +74,7 @@ namespace BlackMisc IndexGroundElevationPlusInfo, IndexCallsign, IndexCG, + IndexSceneryOffset, IndexCanLikelySkipNearGroundInterpolation }; @@ -174,7 +176,7 @@ namespace BlackMisc virtual bool isNull() const override; //! Is given info better (more accurate)? - bool isThisElevationInfoBetter(GndElevationInfo info, bool transferred) const; + bool isOtherElevationInfoBetter(GndElevationInfo otherInfo, bool transferred) const; //! Equal pitch, bank heading //! \sa Geo::ICoordinateGeodetic::equalNormalVectorDouble @@ -446,6 +448,18 @@ namespace BlackMisc //! Has CG set? bool hasCG() const { return !m_cg.isNull(); } + //! Get scenery offset if any + const PhysicalQuantities::CLength &getSceneryOffset() const { return m_sceneryOffset; } + + //! Get scenery offset if any or zero ("0") + const PhysicalQuantities::CLength &getSceneryOffsetOrZero() const; + + //! Set scenery offset + void setSceneryOffset(const PhysicalQuantities::CLength &sceneryOffset); + + //! Has scenery offset? + bool hasSceneryOffset() const { return !m_sceneryOffset.isNull(); } + //! Set flag indicating this is an interim position update void setInterimFlag(bool flag) { m_isInterim = flag; } @@ -539,6 +553,7 @@ namespace BlackMisc PhysicalQuantities::CAngle m_bank { 0, nullptr }; PhysicalQuantities::CSpeed m_groundSpeed { 0, nullptr }; PhysicalQuantities::CLength m_cg { 0, nullptr }; + PhysicalQuantities::CLength m_sceneryOffset { 0, nullptr }; bool m_isInterim = false; //!< interim situation? bool m_isElvInfoTransferred = false; //!< the gnd.elevation has been transferred int m_onGround = static_cast(CAircraftSituation::OnGroundSituationUnknown); @@ -563,6 +578,7 @@ namespace BlackMisc BLACK_METAMEMBER(bank), BLACK_METAMEMBER(groundSpeed), BLACK_METAMEMBER(cg), + BLACK_METAMEMBER(sceneryOffset), BLACK_METAMEMBER(groundElevationPlane), BLACK_METAMEMBER(onGround), BLACK_METAMEMBER(onGroundDetails), diff --git a/src/blackmisc/aviation/aircraftsituationchange.h b/src/blackmisc/aviation/aircraftsituationchange.h index 26a2461c4..153c5ce35 100644 --- a/src/blackmisc/aviation/aircraftsituationchange.h +++ b/src/blackmisc/aviation/aircraftsituationchange.h @@ -138,7 +138,7 @@ namespace BlackMisc PhysicalQuantities::CLengthPair getMinMaxGroundDistance() const { return PhysicalQuantities::CLengthPair(m_minGroundDistance, m_maxGroundDistance); } //! Scnenery deviation (if it can be calculated, otherwise PhysicalQuantities::CLength::null) - //! This is without CG, so substract CG to get deviation + //! \remark This is without CG, so substract CG to get deviation const PhysicalQuantities::CLength &getGuessedSceneryDeviation() const { return m_guessedSceneryDeviation; } //! Get scenery deviation under consideration of CG diff --git a/src/blackmisc/aviation/aircraftsituationchangelist.cpp b/src/blackmisc/aviation/aircraftsituationchangelist.cpp index 142e7ea09..e06fe6413 100644 --- a/src/blackmisc/aviation/aircraftsituationchangelist.cpp +++ b/src/blackmisc/aviation/aircraftsituationchangelist.cpp @@ -8,7 +8,6 @@ */ #include "blackmisc/aviation/aircraftsituationchangelist.h" - #include namespace BlackMisc @@ -24,5 +23,23 @@ namespace BlackMisc CAircraftSituationChangeList::CAircraftSituationChangeList(std::initializer_list il) : CSequence(il) { } + + CAircraftSituationChange CAircraftSituationChangeList::frontOrNull() const + { + if (this->isEmpty()) { return CAircraftSituationChange::null(); } + return this->front(); + } + + CAircraftSituationChange CAircraftSituationChangeList::backOrNull() const + { + if (this->isEmpty()) { return CAircraftSituationChange::null(); } + return this->back(); + } + + CAircraftSituationChange CAircraftSituationChangeList::indexOrNull(int index) const + { + if (this->size() > index) { return (*this)[index]; } + return CAircraftSituationChange::null(); + } } // namespace } // namespace diff --git a/src/blackmisc/aviation/aircraftsituationchangelist.h b/src/blackmisc/aviation/aircraftsituationchangelist.h index 1009b64a9..033d1bc25 100644 --- a/src/blackmisc/aviation/aircraftsituationchangelist.h +++ b/src/blackmisc/aviation/aircraftsituationchangelist.h @@ -19,8 +19,6 @@ #include "blackmisc/timestampobjectlist.h" #include "blackmisc/variant.h" -#include - namespace BlackMisc { namespace Aviation @@ -42,6 +40,15 @@ namespace BlackMisc //! Construct from initializer list. CAircraftSituationChangeList(std::initializer_list il); + + //! Front or NULL + CAircraftSituationChange frontOrNull() const; + + //! Back or NULL + CAircraftSituationChange backOrNull() const; + + //! Index or NULL + CAircraftSituationChange indexOrNull(int index) const; }; //! Change per callsign diff --git a/src/blackmisc/aviation/aircraftsituationlist.cpp b/src/blackmisc/aviation/aircraftsituationlist.cpp index d7d9bfad0..6c78160e1 100644 --- a/src/blackmisc/aviation/aircraftsituationlist.cpp +++ b/src/blackmisc/aviation/aircraftsituationlist.cpp @@ -38,6 +38,24 @@ namespace BlackMisc CSequence(il) { } + CAircraftSituation CAircraftSituationList::frontOrNull() const + { + if (this->isEmpty()) { return CAircraftSituation::null(); } + return this->front(); + } + + CAircraftSituation CAircraftSituationList::backOrNull() const + { + if (this->isEmpty()) { return CAircraftSituation::null(); } + return this->back(); + } + + CAircraftSituation CAircraftSituationList::indexOrNull(int index) const + { + if (this->size() > index) { return (*this)[index]; } + return CAircraftSituation::null(); + } + int CAircraftSituationList::setGroundElevationChecked(const CElevationPlane &elevationPlane, CAircraftSituation::GndElevationInfo info, qint64 newerThanAdjustedMs) { if (elevationPlane.isNull()) { return 0; } diff --git a/src/blackmisc/aviation/aircraftsituationlist.h b/src/blackmisc/aviation/aircraftsituationlist.h index 82aef7cdc..c7d829f6c 100644 --- a/src/blackmisc/aviation/aircraftsituationlist.h +++ b/src/blackmisc/aviation/aircraftsituationlist.h @@ -56,6 +56,15 @@ namespace BlackMisc //! Construct from initializer list. CAircraftSituationList(std::initializer_list il); + //! Front or NULL + CAircraftSituation frontOrNull() const; + + //! Back or NULL + CAircraftSituation backOrNull() const; + + //! Index or NULL + CAircraftSituation indexOrNull(int index) const; + //! Set ground elevation from elevation plane int setGroundElevationChecked(const Geo::CElevationPlane &elevationPlane, CAircraftSituation::GndElevationInfo info, qint64 newerThanAdjustedMs = -1); diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index ae820da63..db23748b3 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -80,7 +80,7 @@ namespace BlackMisc // get the changes, we need the second value as we want to look in the past // the first value is already based on the latest situation const CAircraftSituationChangeList changes = this->remoteAircraftSituationChanges(m_callsign); - m_pastSituationsChange = (changes.size() > 1) ? changes[1] : CAircraftSituationChange::null(); + m_pastSituationsChange = changes.indexOrNull(1); // fixing offset if (setup.isFixingSceneryOffset() && m_pastSituationsChange.hasSceneryDeviation() && m_model.hasCG())