mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
Ref T296, adding scenery offset as situation member plus utility functions
* frontOrNull/backOrNull * added offset in model * style/renaming
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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, CLength>(CLengthUnit::ft(), 1)));
|
||||
m_columns.addColumn(CColumn("offset", CAircraftSituation::IndexSceneryOffset, new CPhysiqalQuantiyFormatter<CLengthUnit, CLength>(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()));
|
||||
|
||||
@@ -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 <QVariant>
|
||||
|
||||
class QModelIndex;
|
||||
class QObject;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
|
||||
@@ -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<int>(info);
|
||||
if (i > m_elvInfo) { return true; }
|
||||
if (i == m_elvInfo)
|
||||
if (otherInfo == NoElevationInfo || otherInfo == Test) { return false; }
|
||||
const int otherInfoInt = static_cast<int>(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");
|
||||
|
||||
@@ -48,7 +48,8 @@ namespace BlackMisc
|
||||
//! Value object encapsulating information of an aircraft's situation
|
||||
class BLACKMISC_EXPORT CAircraftSituation :
|
||||
public CValueObject<CAircraftSituation>,
|
||||
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<int>(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),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include "blackmisc/aviation/aircraftsituationchangelist.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -24,5 +23,23 @@ namespace BlackMisc
|
||||
CAircraftSituationChangeList::CAircraftSituationChangeList(std::initializer_list<CAircraftSituationChange> il) :
|
||||
CSequence<CAircraftSituationChange>(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
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#include "blackmisc/timestampobjectlist.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QMetaType>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
@@ -42,6 +40,15 @@ namespace BlackMisc
|
||||
|
||||
//! Construct from initializer list.
|
||||
CAircraftSituationChangeList(std::initializer_list<CAircraftSituationChange> il);
|
||||
|
||||
//! Front or NULL
|
||||
CAircraftSituationChange frontOrNull() const;
|
||||
|
||||
//! Back or NULL
|
||||
CAircraftSituationChange backOrNull() const;
|
||||
|
||||
//! Index or NULL
|
||||
CAircraftSituationChange indexOrNull(int index) const;
|
||||
};
|
||||
|
||||
//! Change per callsign
|
||||
|
||||
@@ -38,6 +38,24 @@ namespace BlackMisc
|
||||
CSequence<CAircraftSituation>(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; }
|
||||
|
||||
@@ -56,6 +56,15 @@ namespace BlackMisc
|
||||
//! Construct from initializer list.
|
||||
CAircraftSituationList(std::initializer_list<CAircraftSituation> 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);
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user