mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 17:55:45 +08:00
Improved METAR string building
* use static const arg1s (not always create temp. arg strings) * use QStringBuilder to concatenate several parts at once * done during Ref T275, but not really related
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QStringBuilder>
|
||||||
|
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
@@ -238,8 +239,9 @@ namespace BlackMisc
|
|||||||
// Q = specifier for altimeter in millibars
|
// Q = specifier for altimeter in millibars
|
||||||
simconnectMetar += QLatin1String(" Q");
|
simconnectMetar += QLatin1String(" Q");
|
||||||
// NNNN = altimeter in millibars
|
// NNNN = altimeter in millibars
|
||||||
|
static const QString arg1s("%1");
|
||||||
const auto altimeter = gridPoint.getSurfacePressure().valueInteger(CPressureUnit::mbar());
|
const auto altimeter = gridPoint.getSurfacePressure().valueInteger(CPressureUnit::mbar());
|
||||||
simconnectMetar += QStringLiteral("%1").arg(altimeter, 4, 10, QLatin1Char('0'));
|
simconnectMetar += arg1s.arg(altimeter, 4, 10, QLatin1Char('0'));
|
||||||
|
|
||||||
return simconnectMetar;
|
return simconnectMetar;
|
||||||
}
|
}
|
||||||
@@ -252,9 +254,10 @@ namespace BlackMisc
|
|||||||
|
|
||||||
QString CSimConnectUtilities::windsToSimConnectMetar(const CWindLayerList &windLayers)
|
QString CSimConnectUtilities::windsToSimConnectMetar(const CWindLayerList &windLayers)
|
||||||
{
|
{
|
||||||
|
static const QString arg1s("%1");
|
||||||
QString simconnectWinds;
|
QString simconnectWinds;
|
||||||
bool surface = true;
|
bool surface = true;
|
||||||
for (const auto &windLayer : windLayers)
|
for (const CWindLayer &windLayer : windLayers)
|
||||||
{
|
{
|
||||||
simconnectWinds += QLatin1Char(' ');
|
simconnectWinds += QLatin1Char(' ');
|
||||||
|
|
||||||
@@ -268,17 +271,15 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// DDD = Direction (0-360 degrees)
|
const int speed = windLayer.getSpeed().valueInteger(CSpeedUnit::kts());
|
||||||
const auto direction = windLayer.getDirection().valueInteger(CAngleUnit::deg());
|
const int direction = windLayer.getDirection().valueInteger(CAngleUnit::deg());
|
||||||
simconnectWinds += QStringLiteral("%1").arg(direction, 3, 10, QLatin1Char('0'));
|
|
||||||
|
|
||||||
// SSS = Speed
|
simconnectWinds += arg1s.arg(direction, 3, 10, QLatin1Char('0')) % // DDD = Direction (0-360 degrees)
|
||||||
const auto speed = windLayer.getSpeed().valueInteger(CSpeedUnit::kts());
|
arg1s.arg(speed, 3, 10, QLatin1Char('0')); // SSS = Speed
|
||||||
simconnectWinds += QStringLiteral("%1").arg(speed, 3, 10, QLatin1Char('0'));
|
|
||||||
}
|
}
|
||||||
// XX = Gust speed
|
// XX = Gust speed
|
||||||
const auto gustSpeed = windLayer.getGustSpeed().valueInteger(CSpeedUnit::kts());
|
const int gustSpeed = windLayer.getGustSpeed().valueInteger(CSpeedUnit::kts());
|
||||||
if (gustSpeed) { simconnectWinds += QStringLiteral("G%1").arg(gustSpeed, 2, 10, QLatin1Char('0')); }
|
if (gustSpeed > 0) { simconnectWinds += QStringLiteral("G") % arg1s.arg(gustSpeed, 2, 10, QLatin1Char('0')); }
|
||||||
|
|
||||||
// UUU = Speed units
|
// UUU = Speed units
|
||||||
simconnectWinds += QLatin1String("KT");
|
simconnectWinds += QLatin1String("KT");
|
||||||
@@ -287,27 +288,25 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
// Surface extension:
|
// Surface extension:
|
||||||
// &DNNNNTS
|
// &DNNNNTS
|
||||||
// D = specifier for surface layer
|
static const QString surfaceWinds =
|
||||||
simconnectWinds += QLatin1String("&D");
|
QLatin1String("&D") % // D = specifier for surface layer
|
||||||
// Surface default depth is 1000 feet or 305m
|
QLatin1String("305") % // Surface default depth is 1000 feet or 305m
|
||||||
simconnectWinds += QLatin1String("305");
|
QLatin1String("NG"); // We don't have turbulence or wind shear information, hence we use the defaults
|
||||||
// We don't have turbulence or wind shear information, hence we use the defaults
|
simconnectWinds += surfaceWinds;
|
||||||
simconnectWinds += QLatin1String("NG");
|
|
||||||
surface = false;
|
surface = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Winds aloft extension:
|
|
||||||
// &ANNNNTS
|
|
||||||
// A = specifier for altitude above mean sea-level (MSL)
|
|
||||||
simconnectWinds += QLatin1String("&A");
|
|
||||||
// NNNN = depth (height) in meters.
|
|
||||||
auto altitude = windLayer.getLevel();
|
auto altitude = windLayer.getLevel();
|
||||||
altitude.toMeanSeaLevel();
|
altitude.toMeanSeaLevel();
|
||||||
int altitudeValue = altitude.valueInteger(CLengthUnit::m());
|
int altitudeValue = altitude.valueInteger(CLengthUnit::m());
|
||||||
simconnectWinds += QStringLiteral("%1").arg(altitudeValue, 4, 10, QLatin1Char('0'));
|
|
||||||
// We don't have turbulence or wind shear information, hence we use the defaults
|
// Winds aloft extension:
|
||||||
simconnectWinds += QLatin1String("NG");
|
// &ANNNNTS
|
||||||
|
simconnectWinds +=
|
||||||
|
QLatin1String("&A") % // A = specifier for altitude above mean sea-level (MSL)
|
||||||
|
arg1s.arg(altitudeValue, 4, 10, QLatin1Char('0')) % // NNNN = depth (height) in meters.
|
||||||
|
QLatin1String("NG"); // We don't have turbulence or wind shear information, hence we use the defaults
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return simconnectWinds;
|
return simconnectWinds;
|
||||||
@@ -347,7 +346,8 @@ namespace BlackMisc
|
|||||||
// Format:
|
// Format:
|
||||||
// CCCNNN&BXXXX&DYYYY
|
// CCCNNN&BXXXX&DYYYY
|
||||||
QString simconnectClouds;
|
QString simconnectClouds;
|
||||||
for (const auto &cloudLayer : cloudLayers)
|
static const QString arg1s("%1");
|
||||||
|
for (const CCloudLayer &cloudLayer : cloudLayers)
|
||||||
{
|
{
|
||||||
simconnectClouds += QLatin1Char(' ');
|
simconnectClouds += QLatin1Char(' ');
|
||||||
|
|
||||||
@@ -368,9 +368,8 @@ namespace BlackMisc
|
|||||||
auto level = cloudLayer.getTop().valueInteger(CLengthUnit::ft()) / 100;
|
auto level = cloudLayer.getTop().valueInteger(CLengthUnit::ft()) / 100;
|
||||||
// Ignore clouds higher than 99900 feet
|
// Ignore clouds higher than 99900 feet
|
||||||
if (level > 999) { continue; }
|
if (level > 999) { continue; }
|
||||||
simconnectClouds += QStringLiteral("%1").arg(level, 3, 10, QLatin1Char('0'));
|
simconnectClouds += arg1s.arg(level, 3, 10, QLatin1Char('0')) %
|
||||||
|
QLatin1Char('&');
|
||||||
simconnectClouds += QLatin1Char('&');
|
|
||||||
|
|
||||||
// TT = Cloud type
|
// TT = Cloud type
|
||||||
switch (cloudLayer.getClouds())
|
switch (cloudLayer.getClouds())
|
||||||
@@ -431,22 +430,21 @@ namespace BlackMisc
|
|||||||
// Format:
|
// Format:
|
||||||
// TT/DD&ANNNNN
|
// TT/DD&ANNNNN
|
||||||
QString simconnectTemperatures;
|
QString simconnectTemperatures;
|
||||||
for (const auto &temperatureLayer : temperatureLayers)
|
static const QString arg1s("%1");
|
||||||
|
|
||||||
|
for (const CTemperatureLayer &temperatureLayer : temperatureLayers)
|
||||||
{
|
{
|
||||||
simconnectTemperatures += QLatin1Char(' ');
|
simconnectTemperatures += QLatin1Char(' ');
|
||||||
|
|
||||||
// TT = temperature in Celsius
|
const int temperature = temperatureLayer.getTemperature().valueInteger(CTemperatureUnit::C());
|
||||||
auto temperature = temperatureLayer.getTemperature().valueInteger(CTemperatureUnit::C());
|
const int dewPoint = temperatureLayer.getDewPoint().valueInteger(CTemperatureUnit::C());
|
||||||
simconnectTemperatures += QStringLiteral("%1/").arg(temperature, 2, 10, QLatin1Char('0'));
|
const int altitude = temperatureLayer.getLevel().valueInteger(CLengthUnit::m());
|
||||||
// DD = dewpoint in Celsius
|
|
||||||
auto dewPoint = temperatureLayer.getDewPoint().valueInteger(CTemperatureUnit::C());
|
|
||||||
simconnectTemperatures += QStringLiteral("%1").arg(dewPoint, 2, 10, QLatin1Char('0'));
|
|
||||||
|
|
||||||
simconnectTemperatures += QLatin1String("&A");
|
simconnectTemperatures += arg1s.arg(temperature, 2, 10, QLatin1Char('0')) % // TT = temperature in Celsius
|
||||||
|
QLatin1String("/") %
|
||||||
// NNNNN = altitude of the temperatures in meters.
|
arg1s.arg(dewPoint, 2, 10, QLatin1Char('0')) % // DD = dewpoint in Celsius
|
||||||
auto altitude = temperatureLayer.getLevel().valueInteger(CLengthUnit::m());
|
QLatin1String("&A") %
|
||||||
simconnectTemperatures += QStringLiteral("%1").arg(altitude, 5, 10, QLatin1Char('0'));
|
arg1s.arg(altitude, 5, 10, QLatin1Char('0')); // NNNNN = altitude of the temperatures in meters.
|
||||||
}
|
}
|
||||||
return simconnectTemperatures;
|
return simconnectTemperatures;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user