Enroute Flight Navigation
A navigation app for VFR pilots
Aircraft.h
1/***************************************************************************
2 * Copyright (C) 2019-2022 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include "units/Distance.h"
24#include "units/Speed.h"
25#include "units/Volume.h"
26#include "units/VolumeFlow.h"
27
28#include <QGeoCoordinate>
29#include <QQmlEngine>
30
31namespace Navigation {
32
34
35class Aircraft {
36 Q_GADGET
37 QML_VALUE_TYPE(aircraft)
38
39public:
41 enum FuelConsumptionUnit : quint8 {
44
47 };
48 Q_ENUM(FuelConsumptionUnit)
49
50
51 enum HorizontalDistanceUnit : quint8 {
54
57
60 };
61 Q_ENUM(HorizontalDistanceUnit)
62
63
64 enum VerticalDistanceUnit : quint8 {
66 Feet = 0,
67
70 };
71 Q_ENUM(VerticalDistanceUnit)
72
73
74 //
75 // Properties
76 //
77
78
83 Q_PROPERTY(Units::Speed cruiseSpeed READ cruiseSpeed WRITE setCruiseSpeed)
84
91 Q_PROPERTY(Units::Speed descentSpeed READ descentSpeed WRITE setDescentSpeed)
92
99 Q_PROPERTY(Units::VolumeFlow fuelConsumption READ fuelConsumption WRITE setFuelConsumption)
100
103
106
108 Q_PROPERTY(Units::Speed maxValidSpeed MEMBER maxValidSpeed CONSTANT)
109
111 Q_PROPERTY(Units::VolumeFlow maxValidFuelConsumption MEMBER maxValidFuelConsumption CONSTANT)
112
118 Q_PROPERTY(Units::Speed minimumSpeed READ minimumSpeed WRITE setMinimumSpeed)
119
121 Q_PROPERTY(Units::VolumeFlow minValidFuelConsumption MEMBER minValidFuelConsumption CONSTANT)
122
124 Q_PROPERTY(Units::Speed minValidSpeed MEMBER minValidSpeed CONSTANT)
125
130 Q_PROPERTY(QString name READ name WRITE setName)
131
134
135
136 //
137 // Getter Methods
138 //
139
144 [[nodiscard]] auto cruiseSpeed() const -> Units::Speed { return m_cruiseSpeed; }
145
150 [[nodiscard]] auto descentSpeed() const -> Units::Speed { return m_descentSpeed; }
151
156 [[nodiscard]] auto fuelConsumption() const -> Units::VolumeFlow { return m_fuelConsumption; }
157
162 [[nodiscard]] auto fuelConsumptionUnit() const -> FuelConsumptionUnit { return m_fuelConsumptionUnit; }
163
168 [[nodiscard]] auto horizontalDistanceUnit() const -> HorizontalDistanceUnit { return m_horizontalDistanceUnit; }
169
174 [[nodiscard]] auto minimumSpeed() const -> Units::Speed { return m_minimumSpeed; }
175
180 [[nodiscard]] auto name() const -> QString { return m_name; }
181
186 [[nodiscard]] auto verticalDistanceUnit() const -> VerticalDistanceUnit { return m_verticalDistanceUnit; }
187
188
189 //
190 // Setter Methods
191 //
192
202
208
213 void setFuelConsumption(Units::VolumeFlow newFuelConsumption);
214
220
226
235
240 void setName(const QString& newName);
241
247
248
249 //
250 // Methods
251 //
252
259 [[nodiscard]] Q_INVOKABLE Navigation::Aircraft clone() const { return {*this}; }
260
269 [[nodiscard]] Q_INVOKABLE QString describeWay(const QGeoCoordinate &from, const QGeoCoordinate &to) const;
270
279 [[nodiscard]] Q_INVOKABLE QString horizontalDistanceToString(Units::Distance distance) const;
280
289 [[nodiscard]] Q_INVOKABLE QString horizontalSpeedToString(Units::Speed speed) const;
290
302 [[nodiscard]] Q_INVOKABLE QString loadFromJSON(const QString& fileName);
303
315 [[nodiscard]] Q_INVOKABLE QString loadFromJSON(const QByteArray &JSON);
316
323 Q_INVOKABLE bool operator==(const Navigation::Aircraft& other) const;
324
334 [[nodiscard]] Q_INVOKABLE QString save(const QString& fileName) const;
335
343 [[nodiscard]] Q_INVOKABLE QByteArray toJSON() const;
344
355 [[nodiscard]] Q_INVOKABLE QString verticalDistanceToString(Units::Distance distance, bool forceSign=false) const;
356
365 [[nodiscard]] Q_INVOKABLE QString verticalSpeedToString(Units::Speed speed) const;
366
375 [[nodiscard]] Q_INVOKABLE QString volumeToString(Units::Volume volume) const;
376
377private:
378 static constexpr Units::Speed minValidSpeed = Units::Speed::fromKN(10.0);
379 static constexpr Units::Speed maxValidSpeed = Units::Speed::fromKN(400.0);
382
383 Units::Speed m_cruiseSpeed {};
384 Units::Speed m_descentSpeed {};
385 Units::VolumeFlow m_fuelConsumption {};
386 FuelConsumptionUnit m_fuelConsumptionUnit {LiterPerHour};
387 HorizontalDistanceUnit m_horizontalDistanceUnit {NauticalMile};
388 Units::Speed m_minimumSpeed {};
389 QString m_name;
390 VerticalDistanceUnit m_verticalDistanceUnit{Feet};
391};
392
393} // namespace Navigation
394
395// Make enums available in QML
396namespace AircraftQML {
397Q_NAMESPACE
398QML_FOREIGN_NAMESPACE(Navigation::Aircraft)
399QML_NAMED_ELEMENT(Aircraft)
400} // Namespace AircraftQML
401
402// Declare meta types
403Q_DECLARE_METATYPE(Navigation::Aircraft)
This extremely simple class holds a few numbers that describe an aircraft.
Definition Aircraft.h:35
Units::Speed minValidSpeed
Minimal speed of the aircraft that is considered valid.
Definition Aircraft.h:124
auto verticalDistanceUnit() const -> VerticalDistanceUnit
Getter function for property of the same name.
Definition Aircraft.h:186
HorizontalDistanceUnit horizontalDistanceUnit
Preferred units of measurement for horizontal distances.
Definition Aircraft.h:105
Q_INVOKABLE QByteArray toJSON() const
Exports to route to JSON.
Q_INVOKABLE QString loadFromJSON(const QByteArray &JSON)
Reads aircraft data from a JSON document.
auto descentSpeed() const -> Units::Speed
Getter function for property of the same name.
Definition Aircraft.h:150
Units::Speed minimumSpeed
Minimum Speed.
Definition Aircraft.h:118
Q_INVOKABLE QString horizontalSpeedToString(Units::Speed speed) const
Convert horizontal speed to string.
Q_INVOKABLE QString horizontalDistanceToString(Units::Distance distance) const
Convert horizontal distance to string.
Units::Speed cruiseSpeed
Cruise Speed.
Definition Aircraft.h:83
Units::Speed maxValidSpeed
Maximal speed of the aircraft that is considered valid.
Definition Aircraft.h:108
QString name
Name.
Definition Aircraft.h:130
VerticalDistanceUnit
Units of measurement for vertical distances.
Definition Aircraft.h:64
Q_INVOKABLE QString verticalDistanceToString(Units::Distance distance, bool forceSign=false) const
Convert vertical distance to string.
auto fuelConsumption() const -> Units::VolumeFlow
Getter function for property of the same name.
Definition Aircraft.h:156
void setHorizontalDistanceUnit(HorizontalDistanceUnit newUnit)
Setter function for property of the same name.
Q_INVOKABLE QString loadFromJSON(const QString &fileName)
Reads aircraft data from a JSON document.
Units::Speed descentSpeed
Decent Speed.
Definition Aircraft.h:91
void setName(const QString &newName)
Setter function for property of the same name.
void setDescentSpeed(Units::Speed newSpeed)
Setter function for property of the same name.
Q_INVOKABLE Navigation::Aircraft clone() const
Return copy of this object.
Definition Aircraft.h:259
Q_INVOKABLE QString save(const QString &fileName) const
Saves aircraft to a file.
void setVerticalDistanceUnit(VerticalDistanceUnit newUnit)
Setter function for property of the same name.
void setMinimumSpeed(Units::Speed newSpeed)
Setter function for property of the same name.
auto name() const -> QString
Getter function for property of the same name.
Definition Aircraft.h:180
Q_INVOKABLE QString verticalSpeedToString(Units::Speed speed) const
Convert vertical speed to string.
void setFuelConsumption(Units::VolumeFlow newFuelConsumption)
Setter function for property of the same name.
Q_INVOKABLE bool operator==(const Navigation::Aircraft &other) const
Equality check.
HorizontalDistanceUnit
Units of measurement for horizontal distances.
Definition Aircraft.h:51
@ NauticalMile
Nautical Mile.
Definition Aircraft.h:53
@ Kilometer
Kilometer.
Definition Aircraft.h:56
@ StatuteMile
Statute Mile.
Definition Aircraft.h:59
void setFuelConsumptionUnit(FuelConsumptionUnit newUnit)
Setter function for property of the same name.
FuelConsumptionUnit
Units of measurement for volumes.
Definition Aircraft.h:41
@ GallonPerHour
Gallon per hour.
Definition Aircraft.h:46
@ LiterPerHour
Liter per hour.
Definition Aircraft.h:43
Units::VolumeFlow maxValidFuelConsumption
Maximal fuel consumption that is considered valid.
Definition Aircraft.h:111
auto minimumSpeed() const -> Units::Speed
Getter function for property of the same name.
Definition Aircraft.h:174
Units::VolumeFlow minValidFuelConsumption
Minimal fuel consumption that is considered valid.
Definition Aircraft.h:121
void setCruiseSpeed(Units::Speed newSpeed)
Setter function for property of the same name.
FuelConsumptionUnit fuelConsumptionUnit
Preferred units of measurement for fuel consumption.
Definition Aircraft.h:102
VerticalDistanceUnit verticalDistanceUnit
Preferred units of measurement for vertical distances.
Definition Aircraft.h:133
auto fuelConsumptionUnit() const -> FuelConsumptionUnit
Getter function for property of the same name.
Definition Aircraft.h:162
Q_INVOKABLE QString volumeToString(Units::Volume volume) const
Convert volume to string.
Q_INVOKABLE QString describeWay(const QGeoCoordinate &from, const QGeoCoordinate &to) const
Description of the way between two points.
auto horizontalDistanceUnit() const -> HorizontalDistanceUnit
Getter function for property of the same name.
Definition Aircraft.h:168
Units::VolumeFlow fuelConsumption
Fuel Consumption.
Definition Aircraft.h:99
Convenience class for distance computations.
Definition Distance.h:35
Convenience class for speed computations.
Definition Speed.h:36
static Q_INVOKABLE constexpr Units::Speed fromKN(double speedInKT)
Constructs a speed.
Definition Speed.h:87
Convenience class for volume flow computations.
Definition VolumeFlow.h:35
static Q_INVOKABLE constexpr Units::VolumeFlow fromLPH(double volumeFlowInLPH)
Constructs a volume flow.
Definition VolumeFlow.h:46
Convenience class for volume computations.
Definition Volume.h:35
Conversion between units used in aviation.
Definition Angle.h:34