mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T223, use const values for standard pressure
* standardISASeaLevelPressure * use static const values for standard pressure * minor formatting
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
//! \ingroup sampleblackmiscquantities
|
||||
|
||||
#include "samplesphysicalquantities.h"
|
||||
#include "blackmisc/aviation/altitude.h"
|
||||
#include "blackmisc/pq/acceleration.h"
|
||||
#include "blackmisc/pq/angle.h"
|
||||
#include "blackmisc/pq/frequency.h"
|
||||
@@ -28,6 +29,7 @@
|
||||
#include <QTextStream>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackSample
|
||||
@@ -96,7 +98,7 @@ namespace BlackSample
|
||||
w2.switchUnit(CMassUnit::lb());
|
||||
out << w1 << " " << w1.valueRoundedWithUnit(CMassUnit::kg()) << " " << w2 << endl;
|
||||
|
||||
CPressure p1(1013.25, CPressureUnit::hPa());
|
||||
CPressure p1(CAltitude::standardISASeaLevelPressure());
|
||||
out << p1 << " " << p1.valueRoundedWithUnit(CPressureUnit::psi()) << " " << p1.valueRoundedWithUnit(CPressureUnit::inHg()) << endl;
|
||||
|
||||
CTemperature t1;
|
||||
@@ -130,5 +132,4 @@ namespace BlackSample
|
||||
out << "-----------------------------------------------" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackGui
|
||||
@@ -57,12 +58,12 @@ namespace BlackGui
|
||||
|
||||
CAircraftSituation CSituationForm::getSituation() const
|
||||
{
|
||||
const BlackMisc::Geo::CCoordinateGeodetic position = ui->comp_Coordinate->getCoordinate();
|
||||
const CCoordinateGeodetic position = ui->comp_Coordinate->getCoordinate();
|
||||
const CAltitude pressureAltitude(position.geodeticHeight().toPressureAltitude(this->getBarometricPressureMsl()));
|
||||
|
||||
CAircraftSituation s(position);
|
||||
s.setBank(this->getBankAngle());
|
||||
s.setPitch(this->getPitchAngle());
|
||||
|
||||
CAltitude pressureAltitude(position.geodeticHeight().toPressureAltitude(this->getBarometricPressureMsl()));
|
||||
s.setPressureAltitude(pressureAltitude);
|
||||
return s;
|
||||
}
|
||||
@@ -100,13 +101,13 @@ namespace BlackGui
|
||||
const QString v(ui->le_Pressure->text().replace(',', '.'));
|
||||
bool ok;
|
||||
double vd = v.toDouble(&ok);
|
||||
if (!ok) { vd = 1013.25; }
|
||||
if (!ok) { vd = CAltitude::standardISASeaLevelPressure().value(CPressureUnit::mbar()); }
|
||||
return vd;
|
||||
}
|
||||
|
||||
CPressure CSituationForm::getBarometricPressureMsl() const
|
||||
{
|
||||
return CPressure (getBarometricPressureMslMillibar(), CPressureUnit::mbar());
|
||||
return CPressure(getBarometricPressureMslMillibar(), CPressureUnit::mbar());
|
||||
}
|
||||
|
||||
void CSituationForm::setReadOnly(bool readonly)
|
||||
@@ -207,8 +208,10 @@ namespace BlackGui
|
||||
|
||||
void CSituationForm::resetPressure()
|
||||
{
|
||||
ui->le_Pressure->setText("1013.00");
|
||||
ui->hs_Pressure->setValue(1013);
|
||||
static const int v = CAltitude::standardISASeaLevelPressure().valueInteger(CPressureUnit::mbar());
|
||||
static const QString vs(dotToLocaleDecimalPoint(QString::number(CAltitude::standardISASeaLevelPressure().valueRounded(CPressureUnit::mbar(), 2))));
|
||||
ui->le_Pressure->setText(vs);
|
||||
ui->hs_Pressure->setValue(v);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace BlackGui
|
||||
//! Get pitch angle
|
||||
double getPitchAngleDegrees() const;
|
||||
|
||||
//! Get barometric pressure at mean sea level
|
||||
//! Get barometric pressure at MSL (mean sea level)
|
||||
BlackMisc::PhysicalQuantities::CPressure getBarometricPressureMsl() const;
|
||||
|
||||
//! Get pressure at mean sea level
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "blackmisc/iconlist.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/pq/measurementunit.h"
|
||||
#include "blackmisc/pq/constants.h"
|
||||
#include "blackmisc/pq/pqstring.h"
|
||||
|
||||
#include <Qt>
|
||||
@@ -22,7 +23,7 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
CAltitude::CAltitude(const QString &altitudeAsString, PhysicalQuantities::CPqString::SeparatorMode mode) : CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::m()), m_datum(MeanSeaLevel)
|
||||
CAltitude::CAltitude(const QString &altitudeAsString, CPqString::SeparatorMode mode) : CLength(0, CLengthUnit::m()), m_datum(MeanSeaLevel)
|
||||
{
|
||||
this->parseFromString(altitudeAsString, mode);
|
||||
}
|
||||
@@ -31,7 +32,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (this->m_datum == FlightLevel)
|
||||
{
|
||||
int fl = qRound(this->CLength::value(CLengthUnit::ft()) / 100.0);
|
||||
const int fl = qRound(this->CLength::value(CLengthUnit::ft()) / 100.0);
|
||||
return QString("FL%1").arg(fl);
|
||||
}
|
||||
else
|
||||
@@ -45,7 +46,7 @@ namespace BlackMisc
|
||||
{
|
||||
s = this->CLength::valueRoundedWithUnit(CLengthUnit::ft(), 0, i18n);
|
||||
}
|
||||
return s.append(this->isMeanSeaLevel() ? " MSL" : " AGL");
|
||||
return s.append(this->isMeanSeaLevel() ? QStringLiteral(" MSL") : QStringLiteral(" AGL"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,10 +82,10 @@ namespace BlackMisc
|
||||
|
||||
void CAltitude::parseFromString(const QString &value)
|
||||
{
|
||||
this->parseFromString(value, PhysicalQuantities::CPqString::SeparatorsCLocale);
|
||||
this->parseFromString(value, CPqString::SeparatorsCLocale);
|
||||
}
|
||||
|
||||
void CAltitude::parseFromString(const QString &value, PhysicalQuantities::CPqString::SeparatorMode mode)
|
||||
void CAltitude::parseFromString(const QString &value, CPqString::SeparatorMode mode)
|
||||
{
|
||||
QString v = value.trimmed();
|
||||
|
||||
@@ -94,8 +95,8 @@ namespace BlackMisc
|
||||
v = v.replace("FL", "", Qt::CaseInsensitive).trimmed();
|
||||
bool ok = false;
|
||||
double dv = v.toDouble(&ok) * 100.0;
|
||||
CAltitude a(ok ? dv : 0.0, FlightLevel,
|
||||
ok ? CLengthUnit::ft() : nullptr);
|
||||
const CAltitude a(ok ? dv : 0.0, FlightLevel,
|
||||
ok ? CLengthUnit::ft() : nullptr);
|
||||
*this = a;
|
||||
return;
|
||||
}
|
||||
@@ -113,7 +114,7 @@ namespace BlackMisc
|
||||
rd = AboveGround;
|
||||
}
|
||||
|
||||
const CLength l = BlackMisc::PhysicalQuantities::CPqString::parse<CLength>(v, mode);
|
||||
const CLength l = CPqString::parse<CLength>(v, mode);
|
||||
*this = CAltitude(l, rd);
|
||||
}
|
||||
|
||||
@@ -313,5 +314,12 @@ namespace BlackMisc
|
||||
static const CAltitude null(0, CAltitude::MeanSeaLevel, CLengthUnit::nullUnit());
|
||||
return null;
|
||||
}
|
||||
|
||||
const CPressure &CAltitude::standardISASeaLevelPressure()
|
||||
{
|
||||
// Average sea-level pressure is 1013.25mbar or 1013.25hPa
|
||||
static const CPressure standardPressure(CPhysicalQuantitiesConstants::ISASeaLevelPressure());
|
||||
return standardPressure;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -168,6 +168,9 @@ namespace BlackMisc
|
||||
//! Null altitude (MSL)
|
||||
static const CAltitude &null();
|
||||
|
||||
//! Standard pressure 1013.25mbar/hPa
|
||||
static const PhysicalQuantities::CPressure &standardISASeaLevelPressure();
|
||||
|
||||
private:
|
||||
ReferenceDatum m_datum; //!< MSL or AGL?
|
||||
AltitudeType m_altitudeType = TrueAltitude;
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace BlackMisc
|
||||
{
|
||||
namespace PhysicalQuantities
|
||||
{
|
||||
|
||||
/*!
|
||||
* Physical quantities constants
|
||||
*/
|
||||
@@ -43,14 +42,14 @@ namespace BlackMisc
|
||||
//! International Standard Atmosphere pressure at mean sea level, 1013.25hPa
|
||||
static const CPressure &ISASeaLevelPressure()
|
||||
{
|
||||
static CPressure p(1013.25, CPressureUnit::hPa());
|
||||
static CPressure p(1013.25, CPressureUnit::mbar());
|
||||
return p;
|
||||
}
|
||||
|
||||
//! ICAO standard pressure datum for flight levels, 1013.2hPa
|
||||
static const CPressure &ICAOFlightLevelPressure()
|
||||
{
|
||||
static CPressure p(1013.2, CPressureUnit::hPa());
|
||||
static CPressure p(1013.2, CPressureUnit::mbar());
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace BlackMisc
|
||||
//! \copydoc CPhysicalQuantity(const QString &unitString)
|
||||
CPressure(const QString &unitString) : CPhysicalQuantity(unitString) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CPressure)
|
||||
|
||||
|
||||
@@ -300,6 +300,12 @@ namespace BlackMisc
|
||||
return input.replace('.', QLocale::system().decimalPoint());
|
||||
}
|
||||
|
||||
QString dotToLocaleDecimalPoint(const QString &input)
|
||||
{
|
||||
QString copy(input);
|
||||
return copy.replace('.', QLocale::system().decimalPoint());
|
||||
}
|
||||
|
||||
bool stringCompare(const QString &c1, const QString &c2, Qt::CaseSensitivity cs)
|
||||
{
|
||||
if (cs == Qt::CaseSensitive) { return c1 == c2; }
|
||||
|
||||
@@ -145,6 +145,9 @@ namespace BlackMisc
|
||||
//! Replace dot '.' by locale decimal point
|
||||
BLACKMISC_EXPORT QString dotToLocaleDecimalPoint(QString &input);
|
||||
|
||||
//! Replace dot '.' by locale decimal point
|
||||
BLACKMISC_EXPORT QString dotToLocaleDecimalPoint(const QString &input);
|
||||
|
||||
//! Int to hex value (per byte, 2 digits)
|
||||
BLACKMISC_EXPORT QString bytesToHexString(const QByteArray &bytes);
|
||||
|
||||
|
||||
@@ -12,18 +12,19 @@
|
||||
#ifndef BLACKMISC_WEATHER_GRIDPOINT_H
|
||||
#define BLACKMISC_WEATHER_GRIDPOINT_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/geo/coordinategeodetic.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
#include "blackmisc/pq/pressure.h"
|
||||
#include "blackmisc/pq/units.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/weather/cloudlayerlist.h"
|
||||
#include "blackmisc/weather/temperaturelayerlist.h"
|
||||
#include "blackmisc/weather/visibilitylayerlist.h"
|
||||
#include "blackmisc/weather/windlayerlist.h"
|
||||
#include "blackmisc/geo/coordinategeodetic.h"
|
||||
#include "blackmisc/pq/pressure.h"
|
||||
#include "blackmisc/pq/constants.h"
|
||||
#include "blackmisc/pq/units.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
@@ -41,7 +42,7 @@ namespace BlackMisc
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexIdentifier = BlackMisc::CPropertyIndex::GlobalIndexCGridPoint,
|
||||
IndexIdentifier = CPropertyIndex::GlobalIndexCGridPoint,
|
||||
IndexPosition,
|
||||
IndexCloudLayers,
|
||||
IndexTemperatureLayers,
|
||||
@@ -69,37 +70,37 @@ namespace BlackMisc
|
||||
void setIdentifier(const QString &identifier) { m_identifier = identifier; }
|
||||
|
||||
//! Get identifier
|
||||
QString getIdentifier() const { return m_identifier; }
|
||||
const QString &getIdentifier() const { return m_identifier; }
|
||||
|
||||
//! Set position
|
||||
void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { m_position = position; }
|
||||
void setPosition(const Geo::CCoordinateGeodetic &position) { m_position = position; }
|
||||
|
||||
//! Get position
|
||||
const BlackMisc::Geo::CCoordinateGeodetic getPosition() const { return m_position; }
|
||||
const Geo::CCoordinateGeodetic &getPosition() const { return m_position; }
|
||||
|
||||
//! Set cloud layers
|
||||
void setCloudLayers(const CCloudLayerList &cloudLayers) { m_cloudLayers = cloudLayers; }
|
||||
|
||||
//! Get cloud layers
|
||||
CCloudLayerList getCloudLayers() const { return m_cloudLayers; }
|
||||
const CCloudLayerList &getCloudLayers() const { return m_cloudLayers; }
|
||||
|
||||
//! Set temperature layers
|
||||
void setTemperatureLayers(const CTemperatureLayerList &temperatureLayers) { m_temperatureLayers = temperatureLayers; }
|
||||
|
||||
//! Get temperature layers
|
||||
CTemperatureLayerList getTemperatureLayers() const { return m_temperatureLayers; }
|
||||
const CTemperatureLayerList &getTemperatureLayers() const { return m_temperatureLayers; }
|
||||
|
||||
//! Set visibility layers
|
||||
void setVisibilityLayers(const CVisibilityLayerList &visibilityLayers) { m_visibilityLayers = visibilityLayers; }
|
||||
|
||||
//! Get visibility layers
|
||||
CVisibilityLayerList getVisibilityLayers() const { return m_visibilityLayers; }
|
||||
const CVisibilityLayerList &getVisibilityLayers() const { return m_visibilityLayers; }
|
||||
|
||||
//! Set wind layers
|
||||
void setWindLayers(const CWindLayerList &windLayers) { m_windLayers = windLayers; }
|
||||
|
||||
//! Get wind layers
|
||||
CWindLayerList getWindLayers() const { return m_windLayers; }
|
||||
const CWindLayerList &getWindLayers() const { return m_windLayers; }
|
||||
|
||||
//! Copies all weather data from other without modifying identifier and position.
|
||||
void copyWeatherDataFrom(const CGridPoint &other);
|
||||
@@ -108,7 +109,7 @@ namespace BlackMisc
|
||||
void setSurfacePressure(const PhysicalQuantities::CPressure &pressure) { m_surfacePressure = pressure; }
|
||||
|
||||
//! Get surface pressure
|
||||
PhysicalQuantities::CPressure getSurfacePressure() const { return m_surfacePressure; }
|
||||
const PhysicalQuantities::CPressure &getSurfacePressure() const { return m_surfacePressure; }
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
@@ -120,14 +121,13 @@ namespace BlackMisc
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
// Identifier is intentionally string based. MSFS uses ICAO but others don't.
|
||||
QString m_identifier;
|
||||
BlackMisc::Geo::CCoordinateGeodetic m_position;
|
||||
QString m_identifier; //!< Identifier is intentionally string based. MSFS uses ICAO, but others don't.
|
||||
Geo::CCoordinateGeodetic m_position;
|
||||
CCloudLayerList m_cloudLayers;
|
||||
CTemperatureLayerList m_temperatureLayers;
|
||||
CVisibilityLayerList m_visibilityLayers;
|
||||
CWindLayerList m_windLayers;
|
||||
PhysicalQuantities::CPressure m_surfacePressure = { 1013.25, PhysicalQuantities::CPressureUnit::hPa() };
|
||||
PhysicalQuantities::CPressure m_surfacePressure = { PhysicalQuantities::CPhysicalQuantitiesConstants::ISASeaLevelPressure() };
|
||||
|
||||
BLACK_METACLASS(
|
||||
CGridPoint,
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace BlackMisc
|
||||
CTemperatureLayerList { temperatureLayer },
|
||||
CVisibilityLayerList { visibilityLayer } ,
|
||||
CWindLayerList { windLayer },
|
||||
{ 1013.25, PhysicalQuantities::CPressureUnit::hPa() }
|
||||
{ CAltitude::standardISASeaLevelPressure() }
|
||||
};
|
||||
|
||||
static const CWeatherGrid weatherGrid = { gridPointGLOB };
|
||||
@@ -162,7 +162,7 @@ namespace BlackMisc
|
||||
CTemperatureLayerList { temperatureLayer },
|
||||
CVisibilityLayerList { visibilityLayer },
|
||||
CWindLayerList { windLayer1, windLayer2 },
|
||||
{ 1013.25, PhysicalQuantities::CPressureUnit::hPa() }
|
||||
{ CAltitude::standardISASeaLevelPressure() }
|
||||
};
|
||||
|
||||
static const CWeatherGrid weatherGrid({ gridPointGLOB });
|
||||
|
||||
@@ -46,8 +46,9 @@ namespace BlackWxPlugin
|
||||
|
||||
double millibarToLevel(double millibar)
|
||||
{
|
||||
static const double hPaStandardPressure = CPhysicalQuantitiesConstants::ICAOFlightLevelPressure().value(CPressureUnit::mbar());
|
||||
millibar /= 100;
|
||||
double level = (1 - std::pow(millibar / 1013.25, 0.190284)) * 145366.45;
|
||||
double level = (1 - std::pow(millibar / hPaStandardPressure, 0.190284)) * 145366.45;
|
||||
return level;
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace BlackMiscTest
|
||||
*/
|
||||
void CTestPhysicalQuantities::pressureTests()
|
||||
{
|
||||
const CPressure p1(1013.25, CPressureUnit::hPa());
|
||||
const CPressure p1(CPhysicalQuantitiesConstants::ISASeaLevelPressure());
|
||||
const CPressure p2(29.92, CPressureUnit::inHg());
|
||||
CPressure p4(p1);
|
||||
p4.switchUnit(CPressureUnit::mbar());
|
||||
|
||||
Reference in New Issue
Block a user