Enroute Flight Navigation
A navigation app for VFR pilots
Decoder.h
1/***************************************************************************
2 * Copyright (C) 2020-2024 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/* This is a heavily altered version of a file from the metaf library package
22 * Copyright (C) 2018-2020 Nick Naumenko (https://gitlab.com/nnaumenko)
23 * Distributed under the terms of the MIT license.
24 */
25
26#pragma once
27
28#include <QCoreApplication>
29#include <QDate>
30#include <QObject>
31
32#include <cstring> // Necessary to work around an issue in metaf
33
34#include "navigation/Aircraft.h"
35#include "../3rdParty/metaf/include/metaf.hpp"
36using namespace metaf;
37
38
39namespace Weather {
40
41
48
49class Decoder : private metaf::Visitor<QString>
50{
51 Q_DECLARE_TR_FUNCTIONS(Weather::Decoder)
52
53public:
54 // This constructor creates an invalid Decoder instance.
55 Decoder() = default;
56
57 explicit Decoder(const QString& rawText, const QDate& referenceDate);
58
59 virtual ~Decoder() = default;
60
61
62 //
63 // Methods
64 //
65
75 [[nodiscard]] QString currentWeather()
76 {
77 if (m_currentWeather.isEmpty())
78 {
79 (void)decodedText({}, {});
80 }
81 return m_currentWeather;
82 }
83
94 [[nodiscard]] QString decodedText(const Navigation::Aircraft& act, const QDateTime& time);
95
100 [[nodiscard]] bool isValid() const
101 {
102 return (m_parseResult.reportMetadata.error == metaf::ReportError::NONE);
103 }
104
105
106private:
107 Q_DISABLE_COPY_MOVE(Decoder)
108
109 // Explanation functions
110 static QString explainCloudType(const metaf::CloudType &ct);
111 static QString explainDirection(metaf::Direction direction, bool trueCardinalDirections=true);
112 static QString explainDirectionSector(const std::vector<metaf::Direction>& dir);
113 QString explainDistance(metaf::Distance distance);
114 static QString explainDistance_FT(metaf::Distance distance);
115 QString explainMetafTime(metaf::MetafTime metafTime);
116 static QString explainPrecipitation(metaf::Precipitation precipitation);
117 static QString explainPressure(metaf::Pressure pressure);
118 static QString explainRunway(metaf::Runway runway);
119 QString explainSpeed(metaf::Speed speed);
120 static QString explainSurfaceFriction(metaf::SurfaceFriction surfaceFriction);
121 static QString explainTemperature(metaf::Temperature temperature);
122 static QString explainWaveHeight(metaf::WaveHeight waveHeight);
123 QString explainWeatherPhenomena(const metaf::WeatherPhenomena& wp);
124
125 // … toString Methods
126 static QString brakingActionToString(metaf::SurfaceFriction::BrakingAction brakingAction);
127 static QString cardinalDirectionToString(metaf::Direction::Cardinal cardinal);
128 static QString cloudAmountToString(metaf::CloudGroup::Amount amount);
129 static QString cloudHighLayerToString(metaf::LowMidHighCloudGroup::HighLayer highLayer);
130 static QString cloudLowLayerToString(metaf::LowMidHighCloudGroup::LowLayer lowLayer);
131 static QString cloudMidLayerToString(metaf::LowMidHighCloudGroup::MidLayer midLayer);
132 static QString cloudTypeToString(metaf::CloudType::Type type);
133 static QString convectiveTypeToString(metaf::CloudGroup::ConvectiveType type);
134 static QString distanceMilesFractionToString(metaf::Distance::MilesFraction f);
135 static QString distanceUnitToString(metaf::Distance::Unit unit);
136 static QString layerForecastGroupTypeToString(metaf::LayerForecastGroup::Type type);
137 static QString pressureTendencyTrendToString(metaf::PressureTendencyGroup::Trend trend);
138 static QString pressureTendencyTypeToString(metaf::PressureTendencyGroup::Type type);
139 static QString probabilityToString(metaf::TrendGroup::Probability prob);
140 static QString runwayStateDepositsToString(metaf::RunwayStateGroup::Deposits deposits);
141 static QString runwayStateExtentToString(metaf::RunwayStateGroup::Extent extent);
142 static QString specialWeatherPhenomenaToString(const metaf::WeatherPhenomena& wp);
143 static QString stateOfSeaSurfaceToString(metaf::WaveHeight::StateOfSurface stateOfSurface);
144 static QString visTrendToString(metaf::VisibilityGroup::Trend trend);
145 static QString weatherPhenomenaDescriptorToString(metaf::WeatherPhenomena::Descriptor descriptor);
146 static QString weatherPhenomenaQualifierToString(metaf::WeatherPhenomena::Qualifier qualifier);
147 static QString weatherPhenomenaWeatherToString(metaf::WeatherPhenomena::Weather weather);
148
149 // visitor Methods
150 QString visitCloudGroup(const CloudGroup& group, ReportPart reportPart, const std::string& rawString) override;
151 QString visitCloudTypesGroup(const CloudTypesGroup& group, ReportPart reportPart, const std::string& rawString) override;
152 QString visitKeywordGroup(const KeywordGroup& group, ReportPart reportPart, const std::string& rawString) override;
153 QString visitLayerForecastGroup(const LayerForecastGroup& group, ReportPart reportPart, const std::string& rawString) override;
154 QString visitLightningGroup(const LightningGroup& group, ReportPart reportPart, const std::string& rawString) override;
155 QString visitLocationGroup(const LocationGroup& group, ReportPart reportPart, const std::string& rawString) override;
156 QString visitLowMidHighCloudGroup(const LowMidHighCloudGroup& group, ReportPart reportPart, const std::string& rawString) override;
157 QString visitMinMaxTemperatureGroup(const MinMaxTemperatureGroup& group, ReportPart reportPart, const std::string& rawString) override;
158 QString visitMiscGroup(const MiscGroup& group, ReportPart reportPart, const std::string& rawString) override;
159 QString visitPressureGroup(const PressureGroup& group, ReportPart reportPart, const std::string& rawString) override;
160 QString visitPressureTendencyGroup(const PressureTendencyGroup& group, ReportPart reportPart, const std::string& rawString) override;
161 QString visitReportTimeGroup(const ReportTimeGroup& group, ReportPart reportPart, const std::string& rawString) override;
162 QString visitPrecipitationGroup(const PrecipitationGroup& group, ReportPart reportPart, const std::string& rawString) override;
163 QString visitRunwayStateGroup(const RunwayStateGroup& group, ReportPart reportPart, const std::string& rawString) override;
164 QString visitSeaSurfaceGroup(const SeaSurfaceGroup& group, ReportPart reportPart, const std::string& rawString) override;
165 QString visitTemperatureGroup(const TemperatureGroup& group, ReportPart reportPart, const std::string& rawString) override;
166 QString visitTrendGroup(const TrendGroup& group, ReportPart reportPart, const std::string& rawString) override;
167 QString visitUnknownGroup(const UnknownGroup& group, ReportPart reportPart, const std::string& rawString) override;
168 QString visitVicinityGroup(const VicinityGroup& group, ReportPart reportPart, const std::string& rawString) override;
169 QString visitVisibilityGroup(const VisibilityGroup& group, ReportPart reportPart, const std::string& rawString) override;
170 QString visitWeatherGroup(const WeatherGroup& group, ReportPart reportPart, const std::string& rawString) override;
171 QString visitWindGroup(const WindGroup& group, ReportPart reportPart, const std::string& rawString) override;
172
173
174 // Stored for internal use by the method decodedText()
175 Navigation::Aircraft m_aircraft;
176
177 // Stored for internal use by the method decodedText()
178 QDateTime m_currentTime;
179
180 // Current weather, as read from METAR
181 QString m_currentWeather;
182
183 // Reference date
184 QDate m_referenceDate;
185
186 // Result of the parser
187 ParseResult m_parseResult;
188};
189
190} // namespace Weather
This extremely simple class holds a few numbers that describe an aircraft.
Definition Aircraft.h:35
METAR/TAF decoder.
Definition Decoder.h:50
QString currentWeather()
Description of the current weather.
Definition Decoder.h:75
bool isValid() const
Indicates if raw text could be parsed correctly.
Definition Decoder.h:100
QString decodedText(const Navigation::Aircraft &act, const QDateTime &time)
Decoded text.