swift
xswiftbussettingsqtfree.h
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_MISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
5 #define SWIFT_MISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
6 
7 #include <algorithm>
8 #include <chrono>
9 #include <string>
10 
12 
13 namespace swift::misc::simulation::settings
14 {
20  {
21  protected:
24 
26  virtual ~CXSwiftBusSettingsQtFree() = default;
27 
28  public:
30  const std::string &getDBusServerAddress() const { return m_dBusServerAddress; }
31 
33  void setDBusServerAddress(const std::string &dBusServer) { m_dBusServerAddress = dBusServer; }
34 
36  void setDrawingLabels(bool drawing) { m_drawingLabels = drawing; }
37 
39  bool isDrawingLabels() const { return m_drawingLabels; }
40 
42  void setLabelColor(int rgb) { m_labelColor = rgb; }
43 
45  int getLabelColor() const { return m_labelColor; }
46 
49 
52 
54  void setNightTextureMode(const std::string &mode) { m_nightTextureMode = xplane::qtfreeutils::toLower(mode); }
55 
57  const std::string &getNightTextureMode() const { return m_nightTextureMode; }
58 
60  void setMessageBoxValues(const std::string &positions) { m_msgBox = positions; }
61 
63  void setMessageBoxValues(int leftPx, int topPx, int rightPx, int bottomPx, int lines, int durationMs,
64  int freqRgb, int privRgb, int servRgb, int statRgb, int supRgb)
65  {
66  if (topPx >= 0) { bottomPx = -1; }
67  lines = std::max(lines, 3);
68  this->setMessageBoxValues(
69  std::to_string(leftPx) + ";" + std::to_string(topPx) + ";" + std::to_string(rightPx) + ";" +
70  std::to_string(bottomPx) + ";" + std::to_string(lines) + ";" + std::to_string(durationMs) + ";" +
71  std::to_string(freqRgb) + ";" + std::to_string(privRgb) + ";" + std::to_string(servRgb) + ";" +
72  std::to_string(statRgb) + ";" + std::to_string(supRgb));
73  }
74 
76  const std::string &getMessageBoxValues() const { return m_msgBox; }
77 
79  std::vector<int> getMessageBoxValuesVector() const
80  {
81  constexpr int partCount = 11;
82  std::vector<int> partsInt = { 20, 20, 20, -1, 5, 5000, 0x00ff00, 0xff00ff, 0xda70d6, 0x00ffff, 0xffff00 };
83  const std::vector<std::string> parts = xplane::qtfreeutils::split(m_msgBox, partCount, ";");
84 
85  size_t c = 0;
86  for (const std::string &p : parts)
87  {
88  const int i = std::stoi(p);
89  partsInt[c++] = i;
90  }
91  return partsInt;
92  }
93 
95  bool setMaxPlanes(int planes)
96  {
97  if (planes == m_maxPlanes) { return false; }
98  m_maxPlanes = planes;
99  return true;
100  }
101 
103  int getMaxPlanes() const { return m_maxPlanes; }
104 
106  bool setFollowAircraftDistanceM(int meters)
107  {
108  if (meters == m_followAircraftDistanceM) { return false; }
109  m_followAircraftDistanceM = meters;
110  return true;
111  }
112 
115 
117  double getMaxDrawDistanceNM() const { return m_maxDrawDistanceNM; }
118 
120  bool setMaxDrawDistanceNM(double nauticalMiles)
121  {
122  if (xplane::qtfreeutils::isFuzzyEqual(nauticalMiles, m_maxDrawDistanceNM)) { return false; }
123  m_maxDrawDistanceNM = nauticalMiles;
124  return true;
125  }
126 
128  bool isLogRenderPhases() const { return m_logRenderPhases; }
129 
131  void setLogRenderPhases(bool log) { m_logRenderPhases = log; }
132 
134  bool isTcasEnabled() const { return m_tcasEnabled; }
135 
137  void setTcasEnabled(bool tcas) { m_tcasEnabled = tcas; }
138 
141 
143  void setTerrainProbeEnabled(bool enabled) { m_terrainProbeEnabled = enabled; }
144 
146  bool parseXSwiftBusString(const std::string &json);
147 
149  std::string toXSwiftBusJsonString() const;
150 
152  std::string convertToString() const;
153 
155  int update(const CXSwiftBusSettingsQtFree &newValues);
156 
158  virtual void setCurrentUtcTime()
159  {
160  using namespace std::chrono;
161  const milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
162  m_msSinceEpochQtFree = static_cast<int64_t>(ms.count());
163  }
164 
165  protected:
168  static constexpr char JsonDBusServerAddress[] = "dbusserveradress";
169  static constexpr char JsonDrawingLabels[] = "drawinglabels";
170  static constexpr char JsonLabelColor[] = "labelcolor";
171  static constexpr char JsonLogRenderPhases[] = "renderPhases";
172  static constexpr char JsonTcas[] = "tcas";
173  static constexpr char JsonTerrainProbe[] = "terrainProbe";
174  static constexpr char JsonMaxPlanes[] = "maxplanes";
175  static constexpr char JsonMaxDrawDistance[] = "maxDrawDistance";
176  static constexpr char JsonNightTextureMode[] = "nighttexture";
177  static constexpr char JsonTimestamp[] = "timestamp";
178  static constexpr char JsonMessageBox[] = "msgbox";
179  static constexpr char JsonBundleTaxiLandingLights[] = "bundleLights";
180  static constexpr char JsonFollowAircraftDistanceM[] = "followAircraftDistance";
182 
184  virtual void objectUpdated() = 0;
185 
186  std::string m_dBusServerAddress {
187  "tcp:host=127.0.0.1,port=45001"
188  };
189  std::string m_nightTextureMode { "auto" };
190  std::string m_msgBox {
191  "20;20;20;-1;5;5000;65280;16711935;14315734;65535;16776960"
192  };
193  int m_maxPlanes = 100;
195  bool m_drawingLabels = true;
196  int m_labelColor = 0xffc000;
198  bool m_logRenderPhases = false;
199  bool m_tcasEnabled = true;
200  bool m_terrainProbeEnabled = true;
201  double m_maxDrawDistanceNM = 50.0;
202  int64_t m_msSinceEpochQtFree = 0;
203  };
204 } // namespace swift::misc::simulation::settings
205 
206 #endif // SWIFT_MISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
xswiftbus/swift side settings class, JSON capable, shared among all services
static constexpr char JsonBundleTaxiLandingLights[]
The JSON members.
bool isDrawingLabels() const
Get whether the plugin draws type and callsign labels above aircraft.
int update(const CXSwiftBusSettingsQtFree &newValues)
Update only changed values.
void setBundlingTaxiAndLandingLights(bool bundle)
Bundle taxi and landing lights.
std::vector< int > getMessageBoxValuesVector() const
Left, top, right, bottom, lines, duration, color(freq, priv, serv, stat, sup)
int getLabelColor() const
Get the color to draw the callsign labels above aircraft.
bool setMaxPlanes(int planes)
Set the maximum number of aircraft.
const std::string & getMessageBoxValues() const
Left, top, right, bottom, lines, duration, color(freq, priv, serv, stat, sup)
double getMaxDrawDistanceNM() const
Set the maximum distance at which to draw aircraft (nautical miles).
void setTerrainProbeEnabled(bool enabled)
Terrain probe to query ground elevation enabled?
void setDrawingLabels(bool drawing)
Set whether the plugin draws type and callsign labels above aircraft.
bool isTerrainProbeEnabled() const
Terrain probe to query ground elevation enabled?
virtual void objectUpdated()=0
Object has been updated.
void setDBusServerAddress(const std::string &dBusServer)
Set DBus server.
static constexpr char JsonFollowAircraftDistanceM[]
The JSON members.
int getFollowAircraftDistanceM() const
Get follow aircraft distance.
bool isBundlingTaxiAndLandingLights() const
Bundle taxi and landing lights.
std::string m_dBusServerAddress
DBus server (also in class CXSwiftBusConfigWriter)
static constexpr char JsonDBusServerAddress[]
The JSON members.
std::string m_msgBox
left, top, right, bottom, lines, duration, colors
void setNightTextureMode(const std::string &mode)
The the night texture mode.
std::string convertToString() const
Convert to string.
bool setMaxDrawDistanceNM(double nauticalMiles)
Set the maximum distance at which to draw aircraft (nautical miles).
bool m_terrainProbeEnabled
terrain probe to establish ground elevation
void setMessageBoxValues(int leftPx, int topPx, int rightPx, int bottomPx, int lines, int durationMs, int freqRgb, int privRgb, int servRgb, int statRgb, int supRgb)
Left, top, right, bottom, lines, duration, color(freq, priv, serv, stat, sup)
int getMaxPlanes() const
Get the maximum number of aircraft.
void setMessageBoxValues(const std::string &positions)
Left, top, right, bottom, lines, duration, color(freq, priv, serv, stat, sup)
std::string toXSwiftBusJsonString() const
As JSON string.
bool setFollowAircraftDistanceM(int meters)
Set follow aircraft distance.
bool parseXSwiftBusString(const std::string &json)
Load and parse config file.
void setLabelColor(int rgb)
Set the color to draw the callsign labels above aircraft.
const std::string & getNightTextureMode() const
The the night texture mode.