swift
metar.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "misc/weather/metar.h"
5 
6 #include <QtGlobal>
7 
8 #include "misc/pq/units.h"
11 
12 using namespace swift::misc::physical_quantities;
13 using namespace swift::misc::aviation;
14 
15 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::weather, CMetar)
16 
17 namespace swift::misc::weather
18 {
19  CMetar::CMetar() { setCavok(); }
20 
21  void CMetar::setMessage(const QString &message) { m_metarMessage = message; }
22 
23  bool CMetar::hasMessage() const { return !this->getMessage().isEmpty(); }
24 
25  void CMetar::setReportType(ReportType type) { m_reportType = type; }
26 
27  void CMetar::setAirportIcaoCode(const CAirportIcaoCode &icao) { m_airport = icao; }
28 
29  void CMetar::setDayTime(int reportDay, const physical_quantities::CTime &reportTime)
30  {
31  m_reportDay = reportDay;
32  m_reportTime = reportTime;
33  }
34 
35  void CMetar::setAutomated(bool isAutomated) { m_isAutomated = isAutomated; }
36 
37  void CMetar::setCavok()
38  {
39  m_visibility = CLength(10000, CLengthUnit::km());
40  m_presentWeathers.clear();
41  m_cloudLayers.clear();
42  }
43 
44  void CMetar::setWindLayer(const CWindLayer &windLayer) { m_windLayer = windLayer; }
45 
46  void CMetar::setVisibility(const physical_quantities::CLength &visibility) { m_visibility = visibility; }
47 
48  physical_quantities::CLength CMetar::getVisibility() const { return m_visibility; }
49 
50  void CMetar::addPresentWeather(const CPresentWeather &presentWeather)
51  {
52  m_presentWeathers.push_back(presentWeather);
53  }
54 
55  void CMetar::addCloudLayer(const CCloudLayer &cloudLayer) { m_cloudLayers.push_back(cloudLayer); }
56 
57  void CMetar::setTemperature(const physical_quantities::CTemperature &temperature) { m_temperature = temperature; }
58 
59  physical_quantities::CTemperature CMetar::getTemperature() const { return m_temperature; }
60 
61  void CMetar::setDewPoint(const physical_quantities::CTemperature &dewPoint) { m_dewPoint = dewPoint; }
62 
63  void CMetar::setAltimeter(const physical_quantities::CPressure &altimeter) { m_altimeter = altimeter; }
64 
65  QString CMetar::getMetarText() const
66  {
67  QString presentWeathers;
68  for (const auto &presentWeather : m_presentWeathers)
69  {
70  if (!presentWeathers.isEmpty()) presentWeathers += ",";
71  presentWeathers += u' ' % presentWeather.toQString();
72  }
73 
74  QString clouds;
75  for (const auto &layer : m_cloudLayers)
76  {
77  if (!clouds.isEmpty()) clouds += ",";
78  clouds += u' ' % layer.toQString();
79  }
80 
81  const QString metarDescription =
82  QStringLiteral("Station: %1 \n").arg(m_airport.getIcaoCode()) %
83  QStringLiteral("Date/Time: %1 %2 UTC\n").arg(m_reportDay).arg(m_reportTime.formattedHrsMin()) %
84  m_windLayer.toQString() % u'\n' % QStringLiteral("Visibility: %1\n").arg(m_visibility.toQString()) %
85  u"Weather: " % presentWeathers.simplified() % u'\n' % u"Clouds:" % clouds % u'\n' %
86  QStringLiteral("Temperature: %1\n").arg(m_temperature.toQString()) %
87  QStringLiteral("Dewpoint: %1\n").arg(m_dewPoint.toQString()) %
88  QStringLiteral("Altimeter: %1\n").arg(m_altimeter.toQString());
89 
90  return metarDescription;
91  }
92 
93  QString CMetar::convertToQString(bool i18n) const
94  {
95  Q_UNUSED(i18n);
96  QString s(m_airport.getIcaoCode());
97  return s;
98  }
99 
100  CMetar CMetar::CAVOK()
101  {
102  CMetar metar;
103  metar.setCavok();
104  return metar;
105  }
106 } // namespace swift::misc::weather
Value object encapsulating information of airport ICAO data.
QString toQString(bool i18n=false) const
Cast as QString.
Definition: mixinstring.h:76
Physical unit length (length)
Definition: length.h:18
static CLengthUnit km()
Kilometer km.
Definition: units.h:167
Value object for a cloud layer.
Definition: cloudlayer.h:27
Value object encapsulating information about METAR FIXME: runway visibilities FIXME: runway wind shea...
Definition: metar.h:38
ReportType
Report type.
Definition: metar.h:42
void setCavok()
Set the weather to CAVOK.
Definition: metar.cpp:37
Value object for present weather flags.
Value object for a wind layer.
Definition: windlayer.h:28
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67