6#include <QStringBuilder>
19using namespace swift::misc::physical_quantities;
20using namespace swift::misc::math;
22namespace swift::misc::aviation
28 qRegisterMetaType<CAltitude::ReferenceDatum>();
29 qRegisterMetaType<CAltitude::AltitudeType>();
35 { 300, 1000 }, { 600, 2000 }, { 900, 3000 }, { 1200, 3900 }, { 1200, 4000 }, { 1500, 4900 },
36 { 1500, 5000 }, { 1800, 5900 }, { 1850, 6000 }, { 2100, 6900 }, { 2150, 7000 }, { 2400, 7900 },
37 { 2450, 8000 }, { 2700, 8900 }, { 2750, 9000 }, { 3000, 9800 }, { 3050, 10000 }, { 3300, 10800 },
38 { 3350, 11000 }, { 3600, 11800 }, { 3650, 12000 }, { 3900, 12800 }, { 3950, 13000 }, { 4200, 13800 },
39 { 4250, 14000 }, { 4500, 14800 }, { 4550, 15000 }, { 4800, 15700 }, { 4900, 16000 }, { 5100, 16700 },
40 { 5200, 17000 }, { 5400, 17700 }, { 5500, 18000 }, { 5700, 18700 }, { 5800, 19000 }, { 6000, 19700 },
41 { 6100, 20000 }, { 6300, 20700 }, { 6400, 21000 }, { 6600, 21700 }, { 6700, 22000 }, { 6900, 22600 },
42 { 7000, 23000 }, { 7200, 23600 }, { 7300, 24000 }, { 7500, 24600 }, { 7600, 25000 }, { 7800, 25600 },
43 { 7900, 26000 }, { 8100, 26600 }, { 8250, 27000 }, { 8400, 27600 }, { 8550, 28000 }, { 8600, 28200 },
44 { 8850, 29000 }, { 8900, 29100 }, { 9100, 29900 }, { 9150, 30000 }, { 9200, 30100 }, { 9450, 31000 },
45 { 9500, 31100 }, { 9600, 31500 }, { 9750, 32000 }, { 9800, 32100 }, { 10050, 33000 }, { 10100, 33100 },
46 { 10350, 34000 }, { 10400, 34100 }, { 10600, 34800 }, { 10650, 35000 }, { 10700, 35100 }, { 10950, 36000 },
47 { 11000, 36100 }, { 11100, 36400 }, { 11300, 37000 }, { 11300, 37100 }, { 11600, 38000 }, { 11600, 38100 },
48 { 11900, 39000 }, { 11900, 39100 }, { 12100, 39700 }, { 12200, 40000 }, { 12200, 40100 }, { 12500, 41000 },
49 { 13100, 43000 }, { 13700, 44900 }, { 13700, 45000 }, { 14100, 46300 }, { 14300, 46900 }, { 14350, 47000 },
50 { 14900, 48900 }, { 14950, 49000 }, { 15100, 49500 }, { 15550, 51000 },
79 if (newUnit.
isNull() || this->getUnit().isNull() || this->getUnit() == newUnit)
89 if (newUnit.
isNull() || this->getUnit().isNull() || this->getUnit() == newUnit)
100 static const QString n(
"null");
109 return QStringLiteral(
"FL%1").arg(fl);
121 return this->
compare(compareValue);
158 const double deltaAltitudeV = deltaPressureV * 30.0;
160 *
this += deltaAltitude;
166 if (seaLevelPressure.
isNull())
193 const int dv = v.
toInt(&ok) * 100;
204 const int dv = v.
toInt(&ok) * 100;
259 bool beforeDigit =
true;
261 for (
int i = 0; i < v.
length(); i++)
263 const QChar c = v[i];
386 if (flInt < 10 || flInt >= 1000)
417 return QStringLiteral(
"S%1").arg(m, 4, 10,
QChar(
'0'));
420 return QStringLiteral(
"FL%1").arg(ft, 3, 10,
QChar(
'0'));
426 return QStringLiteral(
"M%1").arg(m, 4, 10,
QChar(
'0'));
429 return QStringLiteral(
"A%1").
arg(ft, 3, 10,
QChar(
'0'));
449 R
"(([Ff][Ll]?\d{2,3})|([Ss]\d{2,4})|([Aa]\d{2,3})|([Mm]\d{2,4})|(\d{3,5}(ft|m)))");
458 "FL085, F85 flight level in hecto feets%1S0150 metric level in tens of meters%1A055 altitude in hundreds "
459 "of feet%012000ft altitude in ft%1M0610 altitude in tens of meters%016100m altitude in meters");
460 return e.
arg(separator);
465 static const QString e(
"FL085, F85, S0150, A055, 1200ft, M0610, 6100m");
486 const int ftR = roundDown ?
static_cast<int>(floor(ft)) * 100 : qRound(ft) * 100;
496 if (std::get<1>(m) == feet)
return std::get<0>(m);
506 if (std::get<0>(m) == metric)
return std::get<1>(m);
523 return standardPressure;
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Non-owning reference to a CPropertyIndex with a subset of its features.
bool isMyself() const
Myself index, used with nesting.
void push_back(const T &value)
Appends an element at the end of the sequence.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
QString asFpVatsimAltitudeString() const
As simple VATSIM string, only FLxxx or altitude as ft.
CAltitude switchedUnit(const physical_quantities::CLengthUnit &newUnit) const
Value in switched unit.
void parseFromString(const QString &value)
Parse value from string.
bool isValidFpAltitude(CStatusMessageList *msgs=nullptr) const
Is this a valid FP altitude.
static physical_quantities::CLengthUnit defaultUnit()
Default unit for calculations.
static QString fpAltitudeExamples()
Examples of FP altitude strings.
static int findMetricAltitude(int feet)
Search the corresponding feet <-> metric / metric <-> feet.
bool toFlightLevel()
MSL to flightlevel.
int comparePropertyByIndex(CPropertyIndexRef index, const CAltitude &compareValue) const
Set property by index.
QString asFpICAOAltitudeString() const
Altitude string (official version).
bool parseFromFpAltitudeString(const QString &value, CStatusMessageList *msgs=nullptr)
Parse from FP altitude string.
static void registerMetadata()
Register metadata.
bool isMeanSeaLevel() const
MSL Mean sea level?
CAltitude withOffset(const CLength &offset) const
Altitude with offset.
static int findAltitudeForMetricAltitude(int metric)
Search the corresponding feet <-> metric / metric <-> feet.
QString convertToQString(bool i18n=false) const
Cast as QString.
bool isFlightLevel() const
Flight level?
CAltitude & switchUnit(const physical_quantities::CLengthUnit &newUnit)
Value in switched unit.
static QString fpAltitudeInfo(const QString &separator=", ")
Info for FP altitude strings.
int compare(const CAltitude &otherAltitude) const
Return negative, zero, or positive if a is less than, equal to, or greater than b.
CAltitude()
Default constructor: 0m Altitude MSL.
@ PressureAltitude
Altitude above the standard datum plane.
void convertToPressureAltitude(const physical_quantities::CPressure &seaLevelPressure)
Converts this to pressure altitude. Requires the current barometric pressure at MSL.
CAltitude roundedToNearest100ft(bool roundDown) const
Round to the nearest 100ft, like needed for China and Russia.
void addOffset(const CLength &offset)
Add offset value.
ReferenceDatum
Enum type to distinguish between MSL and AGL.
@ FlightLevel
Flight level.
static const QRegularExpression & fpAltitudeRegExp()
Checking FP altitude strings like "A20", "FL100".
static const CAltitude & null()
Null altitude (MSL).
std::tuple< int, int > MetricTuple
Metric tuple.
swift::misc::CIcons::IconIndex toIcon() const
As icon, not implemented by all classes.
ReferenceDatum getReferenceDatum() const
Get reference datum (MSL or AGL).
CAltitude toPressureAltitude(const physical_quantities::CPressure &seaLevelPressure) const
Returns the altitude converted to pressure altitude. Requires the current barometric pressure at MSL.
static const physical_quantities::CPressure & standardISASeaLevelPressure()
Standard pressure 1013.25mbar/hPa.
bool toMeanSeaLevel()
Flightlevel to MSL.
static bool epsilonZero(double v, double epsilon)
Epsilon safe zero.
int comparePropertyByIndex(CPropertyIndexRef index, const CLength &compareValue) const
CLength()
Default constructor.
Specialized class for distance units (meter, foot, nautical miles).
static CLengthUnit nullUnit()
Null unit.
static CLengthUnit m()
Meter m.
static CLengthUnit ft()
Foot ft.
bool isNull() const
Is unit null?
static const CPressure & ISASeaLevelPressure()
International Standard Atmosphere pressure at mean sea level, 1013.25hPa.
bool isNegativeWithEpsilonConsidered() const
void setValueSameUnit(double value)
PQ switchedUnit(const MU &newUnit) const
Return copy with switched unit.
const CLengthUnit & getUnit() const
int valueInteger(CLengthUnit unit) const
CLength & switchUnit(const CLengthUnit &newUnit)
double value(CLengthUnit unit) const
QString valueIntegerAsString(MU unit) const
As integer value.
void setUnit(const CLengthUnit &unit)
friend int compare(const CLength &a, const CLength &b)
QString valueRoundedWithUnit(const CLengthUnit &unit, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
bool isZeroEpsilonConsidered() const
Quantity value <= epsilon.
static PQ parse(const QString &value, SeparatorMode mode=SeparatorQtDefault)
Parse into concrete type.
SeparatorMode
Number separators / group separators.
@ SeparatorBestGuess
try to figure out
static CPressureUnit mbar()
Millibar, actually the same as hPa.
int compare(T a, T b)
Compare arithmetic values.
QString char09OnlyString(const QString &string)
String only with 0-9.
bool isDigit(char32_t ucs4)
char32_t toLower(char32_t ucs4)
char32_t toUpper(char32_t ucs4)
QString arg(Args &&... args) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype length() const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QString trimmed() const const