mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
use enums instead of bools to distinguish true/magnetic headings and tracks and MSL/AGL altitudes
This commit is contained in:
@@ -16,8 +16,8 @@ namespace BlackMiscTest
|
||||
*/
|
||||
int CSamplesAviation::samples()
|
||||
{
|
||||
CHeading h1(180, true, CAngleUnit::deg());
|
||||
CHeading h2(180, false, CAngleUnit::deg());
|
||||
CHeading h1(180, CHeading::Magnetic, CAngleUnit::deg());
|
||||
CHeading h2(180, CHeading::True, CAngleUnit::deg());
|
||||
|
||||
qDebug() << h1;
|
||||
qDebug() << h1 << h2 << (h1 == h2) << (h1 != h2) << (h1 == h1);
|
||||
|
||||
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
|
||||
BlackmisctestTestserviceInterface testserviceInterface(Testservice::ServiceName, Testservice::ServicePath, connection, &a);
|
||||
|
||||
CSpeed speed(200, BlackMisc::PhysicalQuantities::CSpeedUnit::km_h());
|
||||
CAltitude al(1000, true, CLengthUnit::ft());
|
||||
CAltitude al(1000, CAltitude::MeanSeaLevel, CLengthUnit::ft());
|
||||
|
||||
while (true) {
|
||||
QDBusMessage m = QDBusMessage::createSignal(
|
||||
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
|
||||
testserviceInterface.receiveTransponder(transponder);
|
||||
qDebug() << "Send transponder via interface" << transponder;
|
||||
|
||||
CTrack track(123.45, true, CAngleUnit::deg());
|
||||
CTrack track(123.45, CTrack::Magnetic, CAngleUnit::deg());
|
||||
testserviceInterface.receiveTrack(track);
|
||||
qDebug() << "Send track via interface" << track;
|
||||
|
||||
@@ -139,7 +139,7 @@ int main(int argc, char *argv[])
|
||||
testserviceInterface.receiveLength(len);
|
||||
qDebug() << "Send length via interface" << len;
|
||||
|
||||
CAltitude alt(33, true, CLengthUnit::m());
|
||||
CAltitude alt(33, CAltitude::MeanSeaLevel, CLengthUnit::m());
|
||||
testserviceInterface.receiveLength(alt);
|
||||
qDebug() << "Send altitude via interface" << alt;
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@ int main(int argc, char *argv[])
|
||||
CSpeed speed(20, CSpeedUnit::kts());
|
||||
CCoordinateNed ned;
|
||||
|
||||
ned = interpolator.pushUpdate(vecGeo, speed, CHeading(80, false, CAngleUnit::deg()), zeroAngle, zeroAngle);
|
||||
ned = interpolator.pushUpdate(vecGeo, speed, CHeading(80, CHeading::True, CAngleUnit::deg()), zeroAngle, zeroAngle);
|
||||
cout << "Interpolator NED 1: " << ned << endl;
|
||||
ned = interpolator.pushUpdate(vecGeo2, speed, CHeading(250, false, CAngleUnit::deg()), zeroAngle, zeroAngle);
|
||||
ned = interpolator.pushUpdate(vecGeo2, speed, CHeading(250, CHeading::True, CAngleUnit::deg()), zeroAngle, zeroAngle);
|
||||
cout << "Interpolator NED 2: " << ned << endl;
|
||||
|
||||
double duration = timer.nsecsElapsed();
|
||||
|
||||
@@ -67,7 +67,7 @@ CCoordinateNed CInterpolator::pushUpdate(const CCoordinateGeodetic &pos, const C
|
||||
|
||||
m_state_end->timestamp = m_time.elapsed();
|
||||
m_state_end->position = CCoordinateTransformation::toEcef(pos);
|
||||
m_state_end->orientation.heading = CHeading(normalizeRadians(heading), false);
|
||||
m_state_end->orientation.heading = CHeading(normalizeRadians(heading), CHeading::True);
|
||||
m_state_end->orientation.pitch = normalizeRadians(pitch);
|
||||
m_state_end->orientation.bank = normalizeRadians(bank);
|
||||
m_state_end->groundspeed = groundSpeed;
|
||||
@@ -131,7 +131,7 @@ bool CInterpolator::stateNow(TPlaneState *state)
|
||||
// Plane Orientation
|
||||
double vEast = state->velNED.east();
|
||||
double vNorth = state->velNED.north();
|
||||
state->orientation.heading = CHeading(atan2(vNorth, vEast), false, CAngleUnit::rad());
|
||||
state->orientation.heading = CHeading(atan2(vNorth, vEast), CHeading::True, CAngleUnit::rad());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ void CMultiPlayer::onPositionUpdate(const FSD::FSD_MSG_Plane_Position *plane_pos
|
||||
|
||||
plane->addPosition(position,
|
||||
CSpeed(plane_position->Speed(), CSpeedUnit::kts()),
|
||||
CHeading((qint32)pitchBankHeading.hdg, false, CAngleUnit::deg()),
|
||||
CHeading((qint32)pitchBankHeading.hdg, CHeading::True, CAngleUnit::deg()),
|
||||
CAngle((qint32)pitchBankHeading.pitch, CAngleUnit::deg()),
|
||||
CAngle((qint32)pitchBankHeading.bank, CAngleUnit::deg()));
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Aviation
|
||||
QString CAltitude::convertToQString(bool /* i18n */) const
|
||||
{
|
||||
QString s = this->CLength::convertToQString();
|
||||
return s.append(this->m_msl ? " MSL" : " AGL");
|
||||
return s.append(this->isMeanSeaLevel() ? " MSL" : " AGL");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -27,7 +27,7 @@ QString CAltitude::convertToQString(bool /* i18n */) const
|
||||
*/
|
||||
bool CAltitude::operator ==(const CAltitude &other)
|
||||
{
|
||||
return other.m_msl == this->m_msl && this->CLength::operator ==(other);
|
||||
return other.m_datum == this->m_datum && this->CLength::operator ==(other);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,8 +18,18 @@ namespace Aviation
|
||||
*/
|
||||
class CAltitude : public BlackMisc::PhysicalQuantities::CLength
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Enum type to distinguish between MSL and AGL
|
||||
*/
|
||||
enum ReferenceDatum
|
||||
{
|
||||
MeanSeaLevel = 0, //!< MSL
|
||||
AboveGround = 1, //!< AGL
|
||||
};
|
||||
|
||||
private:
|
||||
bool m_msl; //!< MSL or AGL?
|
||||
ReferenceDatum m_datum; //!< MSL or AGL?
|
||||
|
||||
protected:
|
||||
/*!
|
||||
@@ -36,7 +46,7 @@ protected:
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
this->CLength::marshallToDbus(argument);
|
||||
argument << this->m_msl;
|
||||
argument << qint32(this->m_datum);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -46,37 +56,31 @@ protected:
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
this->CLength::unmarshallFromDbus(argument);
|
||||
argument >> this->m_msl;
|
||||
qint32 datum;
|
||||
argument >> datum;
|
||||
this->m_datum = static_cast<ReferenceDatum>(datum);
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor: 0 Altitude true
|
||||
*/
|
||||
CAltitude() : BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_msl(true) {}
|
||||
CAltitude() : BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_datum(MeanSeaLevel) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param value
|
||||
* \param msl MSL or AGL?
|
||||
* \param datum MSL or AGL?
|
||||
* \param unit
|
||||
*/
|
||||
CAltitude(double value, bool msl, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : BlackMisc::PhysicalQuantities::CLength(value, unit), m_msl(msl) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param value
|
||||
* \param msl MSL or AGL?
|
||||
* \param unit
|
||||
*/
|
||||
CAltitude(int value, bool msl, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : CLength(value, unit), m_msl(msl) {}
|
||||
CAltitude(double value, ReferenceDatum datum, const BlackMisc::PhysicalQuantities::CLengthUnit &unit) : BlackMisc::PhysicalQuantities::CLength(value, unit), m_datum(datum) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by CLength
|
||||
* \param altitude
|
||||
* \param msl
|
||||
* \param datum
|
||||
*/
|
||||
CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, bool msl) : BlackMisc::PhysicalQuantities::CLength(altitude), m_msl(msl) {}
|
||||
CAltitude(BlackMisc::PhysicalQuantities::CLength altitude, ReferenceDatum datum) : BlackMisc::PhysicalQuantities::CLength(altitude), m_datum(datum) {}
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
@@ -98,7 +102,7 @@ public:
|
||||
*/
|
||||
bool isAboveGroundLevel() const
|
||||
{
|
||||
return !this->m_msl;
|
||||
return AboveGround == this->m_datum;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -107,9 +111,15 @@ public:
|
||||
*/
|
||||
bool isMeanSeaLevel() const
|
||||
{
|
||||
return this->m_msl;
|
||||
return MeanSeaLevel == this->m_datum;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Get reference datum (MSL or AGL)
|
||||
* \return
|
||||
*/
|
||||
ReferenceDatum getReferenceDatum() const { return m_datum; }
|
||||
|
||||
/*!
|
||||
* \brief Register metadata
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Aviation
|
||||
QString CHeading::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s = CAngle::convertToQString(i18n);
|
||||
return s.append(this->m_magnetic ? " magnetic" : " true");
|
||||
return s.append(this->isMagneticHeading() ? " magnetic" : " true");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -27,7 +27,7 @@ QString CHeading::convertToQString(bool i18n) const
|
||||
*/
|
||||
bool CHeading::operator ==(const CHeading &other)
|
||||
{
|
||||
return other.m_magnetic == this->m_magnetic && this->CAngle::operator ==(other);
|
||||
return other.m_north == this->m_north && this->CAngle::operator ==(other);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,8 +18,18 @@ namespace Aviation
|
||||
*/
|
||||
class CHeading : public BlackMisc::PhysicalQuantities::CAngle
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Enum type to distinguish between true north and magnetic north
|
||||
*/
|
||||
enum ReferenceNorth
|
||||
{
|
||||
Magnetic = 0, //!< magnetic north
|
||||
True = 1, //!< true north
|
||||
};
|
||||
|
||||
private:
|
||||
bool m_magnetic; //!< magnetic or true heading?
|
||||
ReferenceNorth m_north; //!< magnetic or true?
|
||||
|
||||
protected:
|
||||
/*!
|
||||
@@ -36,7 +46,7 @@ protected:
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
this->CAngle::marshallToDbus(argument);
|
||||
argument << this->m_magnetic;
|
||||
argument << qint32(this->m_north);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -46,37 +56,31 @@ protected:
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
this->CAngle::unmarshallFromDbus(argument);
|
||||
argument >> this->m_magnetic;
|
||||
qint32 north;
|
||||
argument >> north;
|
||||
this->m_north = static_cast<ReferenceNorth>(north);
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor: 0 heading true
|
||||
*/
|
||||
CHeading() : CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_magnetic(true) {}
|
||||
CHeading() : CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_north(Magnetic) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param value
|
||||
* \param magnetic
|
||||
* \param north
|
||||
* \param unit
|
||||
*/
|
||||
CHeading(double value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_magnetic(magnetic) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param value
|
||||
* \param magnetic
|
||||
* \param unit
|
||||
*/
|
||||
CHeading(int value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_magnetic(magnetic) {}
|
||||
CHeading(double value, ReferenceNorth north, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_north(north) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by CAngle
|
||||
* \param heading
|
||||
* \param north
|
||||
* \param magnetic
|
||||
*/
|
||||
CHeading(CAngle heading, bool magnetic) : CAngle(heading), m_magnetic(magnetic) {}
|
||||
CHeading(CAngle heading, ReferenceNorth north) : CAngle(heading), m_north(north) {}
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
@@ -96,13 +100,19 @@ public:
|
||||
* \brief Magnetic heading?
|
||||
* \return
|
||||
*/
|
||||
bool isMagneticHeading() const { return this->m_magnetic; }
|
||||
bool isMagneticHeading() const { return Magnetic == this->m_north; }
|
||||
|
||||
/*!
|
||||
* \brief True heading?
|
||||
* \return
|
||||
*/
|
||||
bool isTrueHeading() const { return !this->m_magnetic; }
|
||||
bool isTrueHeading() const { return True == this->m_north; }
|
||||
|
||||
/*!
|
||||
* \brief Get reference north (magnetic or true)
|
||||
* \return
|
||||
*/
|
||||
ReferenceNorth getReferenceNorth() const { return m_north; }
|
||||
|
||||
/*!
|
||||
* \brief Register metadata
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Aviation
|
||||
QString CTrack::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s = CAngle::convertToQString(i18n);
|
||||
return s.append(this->m_magnetic ? " magnetic" : " true");
|
||||
return s.append(this->isMagneticTrack() ? " magnetic" : " true");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -27,7 +27,7 @@ QString CTrack::convertToQString(bool i18n) const
|
||||
*/
|
||||
bool CTrack::operator ==(const CTrack &other)
|
||||
{
|
||||
return other.m_magnetic == this->m_magnetic && this->CAngle::operator ==(other);
|
||||
return other.m_north == this->m_north && this->CAngle::operator ==(other);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,8 +18,18 @@ namespace Aviation
|
||||
*/
|
||||
class CTrack : public BlackMisc::PhysicalQuantities::CAngle
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Enum type to distinguish between true north and magnetic north
|
||||
*/
|
||||
enum ReferenceNorth
|
||||
{
|
||||
Magnetic = 0, //!< magnetic north
|
||||
True = 1, //!< true north
|
||||
};
|
||||
|
||||
private:
|
||||
bool m_magnetic; //!< magnetic or true Track?
|
||||
ReferenceNorth m_north; //!< magnetic or true?
|
||||
|
||||
protected:
|
||||
/*!
|
||||
@@ -35,7 +45,7 @@ protected:
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
this->CAngle::marshallToDbus(argument);
|
||||
argument << this->m_magnetic;
|
||||
argument << qint32(this->m_north);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -45,37 +55,31 @@ protected:
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
this->CAngle::unmarshallFromDbus(argument);
|
||||
argument >> this->m_magnetic;
|
||||
qint32 north;
|
||||
argument >> north;
|
||||
this->m_north = static_cast<ReferenceNorth>(north);
|
||||
}
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Default constructor: 0 Track magnetic
|
||||
*/
|
||||
CTrack() : BlackMisc::PhysicalQuantities::CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_magnetic(true) {}
|
||||
CTrack() : BlackMisc::PhysicalQuantities::CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_north(Magnetic) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param value
|
||||
* \param magnetic
|
||||
* \param north
|
||||
* \param unit
|
||||
*/
|
||||
CTrack(double value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_magnetic(magnetic) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
* \param value
|
||||
* \param magnetic
|
||||
* \param unit
|
||||
*/
|
||||
CTrack(int value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_magnetic(magnetic) {}
|
||||
CTrack(double value, ReferenceNorth north, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : BlackMisc::PhysicalQuantities::CAngle(value, unit), m_north(north) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor by CAngle
|
||||
* \param track
|
||||
* \param magnetic
|
||||
* \param north
|
||||
*/
|
||||
CTrack(BlackMisc::PhysicalQuantities::CAngle track, bool magnetic) : BlackMisc::PhysicalQuantities::CAngle(track), m_magnetic(magnetic) {}
|
||||
CTrack(BlackMisc::PhysicalQuantities::CAngle track, ReferenceNorth north) : BlackMisc::PhysicalQuantities::CAngle(track), m_north(north) {}
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
@@ -97,9 +101,8 @@ public:
|
||||
*/
|
||||
bool isMagneticTrack() const
|
||||
{
|
||||
return this->m_magnetic;
|
||||
return Magnetic == this->m_north;
|
||||
(void)QT_TRANSLATE_NOOP("Aviation", "magnetic");
|
||||
(void)QT_TRANSLATE_NOOP("Aviation", "true");
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -108,9 +111,16 @@ public:
|
||||
*/
|
||||
bool isTrueTrack() const
|
||||
{
|
||||
return !this->m_magnetic;
|
||||
return True == this->m_north;
|
||||
(void)QT_TRANSLATE_NOOP("Aviation", "true");
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Get reference north (magnetic or true)
|
||||
* \return
|
||||
*/
|
||||
ReferenceNorth getReferenceNorth() const { return m_north; }
|
||||
|
||||
/*!
|
||||
* \brief Register metadata
|
||||
*/
|
||||
|
||||
@@ -24,9 +24,9 @@ CTestAviation::CTestAviation(QObject *parent): QObject(parent)
|
||||
*/
|
||||
void CTestAviation::headingBasics()
|
||||
{
|
||||
CHeading h1(180, true, CAngleUnit::deg());
|
||||
CHeading h2(180, false, CAngleUnit::deg());
|
||||
CHeading h3(181, true, CAngleUnit::deg());
|
||||
CHeading h1(180, CHeading::Magnetic, CAngleUnit::deg());
|
||||
CHeading h2(180, CHeading::True, CAngleUnit::deg());
|
||||
CHeading h3(181, CHeading::Magnetic, CAngleUnit::deg());
|
||||
CAngle a1(200, CAngleUnit::deg());
|
||||
CHeading h4;
|
||||
h4 = h1;
|
||||
|
||||
Reference in New Issue
Block a user