swift
aircraftvelocity.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2021 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QStringBuilder>
7 
8 #include "misc/verify.h"
9 
10 using namespace swift::misc::physical_quantities;
11 
12 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::aviation, CAircraftVelocity)
13 
14 namespace swift::misc::aviation
15 {
16  const CSpeedUnit CAircraftVelocity::c_xyzSpeedUnit = CSpeedUnit::m_s();
17  const CLengthUnit CAircraftVelocity::c_xyzLengthUnit = CLengthUnit::m();
18  const CAngleUnit CAircraftVelocity::c_pbhAngleUnit = CAngleUnit::rad();
19  const CTimeUnit CAircraftVelocity::c_timeUnit = CTimeUnit::s();
20 
21  CAircraftVelocity::CAircraftVelocity(double x, double y, double z, CSpeedUnit xyzUnit, double pitch, double roll,
22  double heading, CAngleUnit pbhAngleUnit, CTimeUnit pbhTimeUnit)
23  {
24  setLinearVelocity(x, y, z, xyzUnit);
25  setAngularVelocity(pitch, roll, heading, pbhAngleUnit, pbhTimeUnit);
26  }
27 
28  void CAircraftVelocity::setLinearVelocity(double x, double y, double z, CSpeedUnit xyzUnit)
29  {
30  m_x = c_xyzSpeedUnit.convertFrom(x, xyzUnit);
31  m_y = c_xyzSpeedUnit.convertFrom(y, xyzUnit);
32  m_z = c_xyzSpeedUnit.convertFrom(z, xyzUnit);
33  }
34 
35  void CAircraftVelocity::setAngularVelocity(double pitch, double roll, double heading, CAngleUnit pbhAngleUnit,
36  CTimeUnit pbhTimeUnit)
37  {
38  m_pitch = pbhTimeUnit.convertFrom(c_pbhAngleUnit.convertFrom(pitch, pbhAngleUnit), c_timeUnit);
39  m_roll = pbhTimeUnit.convertFrom(c_pbhAngleUnit.convertFrom(roll, pbhAngleUnit), c_timeUnit);
40  m_heading = pbhTimeUnit.convertFrom(c_pbhAngleUnit.convertFrom(heading, pbhAngleUnit), c_timeUnit);
41  }
42 
43  double CAircraftVelocity::getVelocityX(CSpeedUnit unit) const { return unit.convertFrom(m_x, c_xyzSpeedUnit); }
44 
45  double CAircraftVelocity::getVelocityY(CSpeedUnit unit) const { return unit.convertFrom(m_y, c_xyzSpeedUnit); }
46 
47  double CAircraftVelocity::getVelocityZ(CSpeedUnit unit) const { return unit.convertFrom(m_z, c_xyzSpeedUnit); }
48 
49  double CAircraftVelocity::getPitchVelocity(CAngleUnit angleUnit, CTimeUnit timeUnit) const
50  {
51  return c_timeUnit.convertFrom(angleUnit.convertFrom(m_pitch, c_pbhAngleUnit), timeUnit);
52  }
53 
54  double CAircraftVelocity::getRollVelocity(CAngleUnit angleUnit, CTimeUnit timeUnit) const
55  {
56  return c_timeUnit.convertFrom(angleUnit.convertFrom(m_roll, c_pbhAngleUnit), timeUnit);
57  }
58 
59  double CAircraftVelocity::getHeadingVelocity(CAngleUnit angleUnit, CTimeUnit timeUnit) const
60  {
61  return c_timeUnit.convertFrom(angleUnit.convertFrom(m_heading, c_pbhAngleUnit), timeUnit);
62  }
63 
64  QString CAircraftVelocity::convertToQString(bool i18n) const
65  {
66  return u"Velocity: " % QStringLiteral("%1 %2 %3 ").arg(m_x).arg(m_y).arg(m_z) %
67  c_xyzSpeedUnit.convertToQString(i18n) % u" | Rotation: " %
68  QStringLiteral("%1 %2 %3 ").arg(m_pitch).arg(m_roll).arg(m_heading) %
69  c_pbhAngleUnit.convertToQString(i18n) % u"/" % c_timeUnit.convertToQString(i18n);
70  }
71 
72  QVariant CAircraftVelocity::propertyByIndex(CPropertyIndexRef index) const
73  {
74  SWIFT_VERIFY(index.isMyself());
75  return QVariant::fromValue(*this);
76  }
77 
78  void CAircraftVelocity::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
79  {
80  SWIFT_VERIFY(index.isMyself());
81  *this = variant.value<CAircraftVelocity>();
82  }
83 
84  int CAircraftVelocity::comparePropertyByIndex(CPropertyIndexRef index, const CAircraftVelocity &compareValue) const
85  {
86  SWIFT_VERIFY(index.isMyself());
87  return compare(*this, compareValue);
88  }
89 } // namespace swift::misc::aviation
Non-owning reference to a CPropertyIndex with a subset of its features.
bool isMyself() const
Myself index, used with nesting.
Velocity and angular velocity for 6DOF bodies.
Specialized class for angles (degrees, radian).
Definition: units.h:233
static CAngleUnit rad()
Radians.
Definition: units.h:270
Specialized class for distance units (meter, foot, nautical miles).
Definition: units.h:95
static CLengthUnit m()
Meter m.
Definition: units.h:142
double convertFrom(double value, const CMeasurementUnit &unit) const
Convert from other unit to this unit.
Specialized class for speed units (m/s, ft/s, NM/h).
Definition: units.h:778
static CSpeedUnit m_s()
Meter/second m/s.
Definition: units.h:824
Specialized class for time units (ms, hour, min).
Definition: units.h:909
static CTimeUnit s()
Second s.
Definition: units.h:954
QString arg(Args &&... args) const const
QVariant fromValue(T &&value)
T value() const &const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67
#define SWIFT_VERIFY(COND)
A weaker kind of assert.
Definition: verify.h:29