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 <chrono>
8 #include <string>
9 
11 
12 namespace swift::misc::simulation::settings
13 {
19  {
20  protected:
23 
26 
27  public:
29  const std::string &getDBusServerAddress() const { return m_dBusServerAddress; }
30 
32  void setDBusServerAddress(const std::string &dBusServer) { m_dBusServerAddress = dBusServer; }
33 
35  void setDrawingLabels(bool drawing) { m_drawingLabels = drawing; }
36 
38  bool isDrawingLabels() const { return m_drawingLabels; }
39 
41  void setLabelColor(int rgb) { m_labelColor = rgb; }
42 
44  int getLabelColor() const { return m_labelColor; }
45 
48 
51 
53  void setNightTextureMode(const std::string &mode) { m_nightTextureMode = xplane::qtfreeutils::toLower(mode); }
54 
56  const std::string &getNightTextureMode() const { return m_nightTextureMode; }
57 
59  void setMessageBoxValues(const std::string &positions) { m_msgBox = positions; }
60 
62  void setMessageBoxValues(int leftPx, int topPx, int rightPx, int bottomPx, int lines, int durationMs,
63  int freqRgb, int privRgb, int servRgb, int statRgb, int supRgb)
64  {
65  if (topPx >= 0) { bottomPx = -1; }
66  if (lines < 3) { lines = 3; }
67  this->setMessageBoxValues(
68  std::to_string(leftPx) + ";" + std::to_string(topPx) + ";" + std::to_string(rightPx) + ";" +
69  std::to_string(bottomPx) + ";" + std::to_string(lines) + ";" + std::to_string(durationMs) + ";" +
70  std::to_string(freqRgb) + ";" + std::to_string(privRgb) + ";" + std::to_string(servRgb) + ";" +
71  std::to_string(statRgb) + ";" + std::to_string(supRgb));
72  }
73 
75  const std::string &getMessageBoxValues() const { return m_msgBox; }
76 
78  std::vector<int> getMessageBoxValuesVector() const
79  {
80  constexpr int partCount = 11;
81  std::vector<int> partsInt = { 20, 20, 20, -1, 5, 5000, 0x00ff00, 0xff00ff, 0xda70d6, 0x00ffff, 0xffff00 };
82  const std::vector<std::string> parts = xplane::qtfreeutils::split(m_msgBox, partCount, ";");
83 
84  size_t c = 0;
85  for (const std::string &p : parts)
86  {
87  const int i = std::stoi(p);
88  partsInt[c++] = i;
89  }
90  return partsInt;
91  }
92 
94  bool setMaxPlanes(int planes)
95  {
96  if (planes == m_maxPlanes) { return false; }
97  m_maxPlanes = planes;
98  return true;
99  }
100 
102  int getMaxPlanes() const { return m_maxPlanes; }
103 
105  bool setFollowAircraftDistanceM(int meters)
106  {
107  if (meters == m_followAircraftDistanceM) { return false; }
108  m_followAircraftDistanceM = meters;
109  return true;
110  }
111 
114 
116  double getMaxDrawDistanceNM() const { return m_maxDrawDistanceNM; }
117 
119  bool setMaxDrawDistanceNM(double nauticalMiles)
120  {
121  if (xplane::qtfreeutils::isFuzzyEqual(nauticalMiles, m_maxDrawDistanceNM)) { return false; }
122  m_maxDrawDistanceNM = nauticalMiles;
123  return true;
124  }
125 
127  bool isLogRenderPhases() const { return m_logRenderPhases; }
128 
130  void setLogRenderPhases(bool log) { m_logRenderPhases = log; }
131 
133  bool isTcasEnabled() const { return m_tcasEnabled; }
134 
136  void setTcasEnabled(bool tcas) { m_tcasEnabled = tcas; }
137 
140 
142  void setTerrainProbeEnabled(bool enabled) { m_terrainProbeEnabled = enabled; }
143 
145  bool parseXSwiftBusString(const std::string &json);
146 
148  std::string toXSwiftBusJsonString() const;
149 
151  std::string convertToString() const;
152 
154  int update(const CXSwiftBusSettingsQtFree &newValues);
155 
157  virtual void setCurrentUtcTime()
158  {
159  using namespace std::chrono;
160  const milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
161  m_msSinceEpochQtFree = static_cast<int64_t>(ms.count());
162  }
163 
164  protected:
167  static constexpr char JsonDBusServerAddress[] = "dbusserveradress";
168  static constexpr char JsonDrawingLabels[] = "drawinglabels";
169  static constexpr char JsonLabelColor[] = "labelcolor";
170  static constexpr char JsonLogRenderPhases[] = "renderPhases";
171  static constexpr char JsonTcas[] = "tcas";
172  static constexpr char JsonTerrainProbe[] = "terrainProbe";
173  static constexpr char JsonMaxPlanes[] = "maxplanes";
174  static constexpr char JsonMaxDrawDistance[] = "maxDrawDistance";
175  static constexpr char JsonNightTextureMode[] = "nighttexture";
176  static constexpr char JsonTimestamp[] = "timestamp";
177  static constexpr char JsonMessageBox[] = "msgbox";
178  static constexpr char JsonBundleTaxiLandingLights[] = "bundleLights";
179  static constexpr char JsonFollowAircraftDistanceM[] = "followAircraftDistance";
181 
183  virtual void objectUpdated() = 0;
184 
185  std::string m_dBusServerAddress {
186  "tcp:host=127.0.0.1,port=45001"
187  };
188  std::string m_nightTextureMode { "auto" };
189  std::string m_msgBox {
190  "20;20;20;-1;5;5000;65280;16711935;14315734;65535;16776960"
191  };
192  int m_maxPlanes = 100;
194  bool m_drawingLabels = true;
195  int m_labelColor = 0xffc000;
197  bool m_logRenderPhases = false;
198  bool m_tcasEnabled = true;
199  bool m_terrainProbeEnabled = true;
200  double m_maxDrawDistanceNM = 50.0;
201  int64_t m_msSinceEpochQtFree = 0;
202  };
203 } // namespace swift::misc::simulation::settings
204 
205 #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.