mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
refs #201, support for flight level in altitude (needed for flight plan)
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "avaltitude.h"
|
#include "avaltitude.h"
|
||||||
|
#include "pqstring.h"
|
||||||
|
|
||||||
using BlackMisc::PhysicalQuantities::CLength;
|
using BlackMisc::PhysicalQuantities::CLength;
|
||||||
using BlackMisc::PhysicalQuantities::CLengthUnit;
|
using BlackMisc::PhysicalQuantities::CLengthUnit;
|
||||||
@@ -13,13 +14,29 @@ namespace BlackMisc
|
|||||||
namespace Aviation
|
namespace Aviation
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
CAltitude::CAltitude(const QString &altitudeAsString) : BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_datum(MeanSeaLevel)
|
||||||
|
{
|
||||||
|
this->parseFromString(altitudeAsString);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Own implementation for streaming
|
* Own implementation for streaming
|
||||||
*/
|
*/
|
||||||
QString CAltitude::convertToQString(bool /* i18n */) const
|
QString CAltitude::convertToQString(bool /* i18n */) const
|
||||||
{
|
{
|
||||||
QString s = this->CLength::convertToQString();
|
if (this->m_datum == FlightLevel)
|
||||||
return s.append(this->isMeanSeaLevel() ? " MSL" : " AGL");
|
{
|
||||||
|
int fl = qRound(this->CLength::value(CLengthUnit::ft()) / 100.0);
|
||||||
|
return QString("FL%1").arg(fl);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString s = this->CLength::convertToQString();
|
||||||
|
return s.append(this->isMeanSeaLevel() ? " MSL" : " AGL");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -58,6 +75,24 @@ namespace BlackMisc
|
|||||||
return !((*this) == other);
|
return !((*this) == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To FL
|
||||||
|
*/
|
||||||
|
void CAltitude::toFLightLevel()
|
||||||
|
{
|
||||||
|
Q_ASSERT(this->m_datum == MeanSeaLevel || this->m_datum == FlightLevel);
|
||||||
|
this->m_datum = FlightLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To MSL
|
||||||
|
*/
|
||||||
|
void CAltitude::toMeanSeaLevel()
|
||||||
|
{
|
||||||
|
Q_ASSERT(this->m_datum == MeanSeaLevel || this->m_datum == FlightLevel);
|
||||||
|
this->m_datum = MeanSeaLevel;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* metaTypeId
|
* metaTypeId
|
||||||
*/
|
*/
|
||||||
@@ -117,6 +152,44 @@ namespace BlackMisc
|
|||||||
BlackMisc::deserializeJson(json, CAltitude::jsonMembers(), TupleConverter<CAltitude>::toTuple(*this));
|
BlackMisc::deserializeJson(json, CAltitude::jsonMembers(), TupleConverter<CAltitude>::toTuple(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse value
|
||||||
|
*/
|
||||||
|
void CAltitude::parseFromString(const QString &value)
|
||||||
|
{
|
||||||
|
QString v = value.trimmed();
|
||||||
|
|
||||||
|
// special case FL
|
||||||
|
if (v.contains("FL", Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
v = v.replace("FL", "", Qt::CaseInsensitive).trimmed();
|
||||||
|
this->m_datum = FlightLevel;
|
||||||
|
bool ok = false;
|
||||||
|
double dv = v.toDouble(&ok) * 100.0;
|
||||||
|
CLength l(ok ? dv : 0.0,
|
||||||
|
ok ? CLengthUnit::ft() : CLengthUnit::nullUnit());
|
||||||
|
this->set(l);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// normal altitude, AGL/MSL
|
||||||
|
if (v.contains("MSL", Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
v = v.replace("MSL", "", Qt::CaseInsensitive).trimmed();
|
||||||
|
this->m_datum = MeanSeaLevel;
|
||||||
|
}
|
||||||
|
else if (v.contains("AGL"))
|
||||||
|
{
|
||||||
|
v = v.replace("AGL", "", Qt::CaseInsensitive).trimmed();
|
||||||
|
this->m_datum = AboveGround;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this->m_datum = MeanSeaLevel;
|
||||||
|
|
||||||
|
CLength l = BlackMisc::PhysicalQuantities::CPqString::parse<CLength>(v);
|
||||||
|
this->set(l);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Members
|
* Members
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ namespace BlackMisc
|
|||||||
/*!
|
/*!
|
||||||
* Enum type to distinguish between MSL and AGL
|
* Enum type to distinguish between MSL and AGL
|
||||||
*/
|
*/
|
||||||
enum ReferenceDatum
|
enum ReferenceDatum : uint
|
||||||
{
|
{
|
||||||
MeanSeaLevel = 0, //!< MSL
|
MeanSeaLevel = 0, //!< MSL
|
||||||
AboveGround = 1 //!< AGL
|
AboveGround, //!< AGL
|
||||||
|
FlightLevel //!< Flight level
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -51,7 +52,7 @@ namespace BlackMisc
|
|||||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! \brief Default constructor: 0 Altitude true
|
//! Default constructor: 0 Altitude true
|
||||||
CAltitude() : BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_datum(MeanSeaLevel) {}
|
CAltitude() : BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_datum(MeanSeaLevel) {}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -62,38 +63,38 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
CAltitude(double value, ReferenceDatum datum, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : BlackMisc::PhysicalQuantities::CLength(value, unit), m_datum(datum) {}
|
CAltitude(double value, ReferenceDatum datum, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : BlackMisc::PhysicalQuantities::CLength(value, unit), m_datum(datum) {}
|
||||||
|
|
||||||
//! \brief Constructor by CLength
|
//! Altitude as string
|
||||||
|
CAltitude(const QString &altitudeAsString);
|
||||||
|
|
||||||
|
//! Constructor by CLength
|
||||||
CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, ReferenceDatum datum) : BlackMisc::PhysicalQuantities::CLength(altitude), m_datum(datum) {}
|
CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, ReferenceDatum datum) : BlackMisc::PhysicalQuantities::CLength(altitude), m_datum(datum) {}
|
||||||
|
|
||||||
//! \brief Equal operator ==
|
//! Equal operator ==
|
||||||
bool operator ==(const CAltitude &other) const;
|
bool operator ==(const CAltitude &other) const;
|
||||||
|
|
||||||
//! \brief Unequal operator !=
|
//! Unequal operator !=
|
||||||
bool operator !=(const CAltitude &other) const;
|
bool operator !=(const CAltitude &other) const;
|
||||||
|
|
||||||
//! \brief AGL Above ground level?
|
//! AGL Above ground level?
|
||||||
bool isAboveGroundLevel() const
|
bool isAboveGroundLevel() const { return AboveGround == this->m_datum; }
|
||||||
{
|
|
||||||
return AboveGround == this->m_datum;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief MSL Mean sea level?
|
//! MSL Mean sea level?
|
||||||
bool isMeanSeaLevel() const
|
bool isMeanSeaLevel() const { return MeanSeaLevel == this->m_datum; }
|
||||||
{
|
|
||||||
return MeanSeaLevel == this->m_datum;
|
//! Flight level?
|
||||||
}
|
bool isFlightLevel() const { return FlightLevel == this->m_datum; }
|
||||||
|
|
||||||
//! \copydoc CValueObject::toQVariant
|
//! \copydoc CValueObject::toQVariant
|
||||||
virtual QVariant toQVariant() const override
|
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||||
{
|
|
||||||
return QVariant::fromValue(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Get reference datum (MSL or AGL)
|
//! Get reference datum (MSL or AGL)
|
||||||
ReferenceDatum getReferenceDatum() const
|
ReferenceDatum getReferenceDatum() const { return m_datum; }
|
||||||
{
|
|
||||||
return m_datum;
|
//! MSL to flightlevel
|
||||||
}
|
void toFLightLevel();
|
||||||
|
|
||||||
|
//! Flightlevel to MSL
|
||||||
|
void toMeanSeaLevel();
|
||||||
|
|
||||||
//! \copydoc CValueObject::toJson
|
//! \copydoc CValueObject::toJson
|
||||||
virtual QJsonObject toJson() const override;
|
virtual QJsonObject toJson() const override;
|
||||||
@@ -101,7 +102,10 @@ namespace BlackMisc
|
|||||||
//! \copydoc CValueObject::fromJson
|
//! \copydoc CValueObject::fromJson
|
||||||
void fromJson(const QJsonObject &json) override;
|
void fromJson(const QJsonObject &json) override;
|
||||||
|
|
||||||
//! \brief Register metadata
|
//! \copydoc CValueObject::fromJson
|
||||||
|
void parseFromString(const QString &value) override;
|
||||||
|
|
||||||
|
//! Register metadata
|
||||||
static void registerMetadata();
|
static void registerMetadata();
|
||||||
|
|
||||||
//! \copydoc TupleConverter<>::jsonMembers()
|
//! \copydoc TupleConverter<>::jsonMembers()
|
||||||
|
|||||||
Reference in New Issue
Block a user