swift
Loading...
Searching...
No Matches
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
13namespace 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)
67 {
68 bottomPx = -1;
69 }
70 lines = std::max(lines, 3);
72 std::to_string(leftPx) + ";" + std::to_string(topPx) + ";" + std::to_string(rightPx) + ";" +
73 std::to_string(bottomPx) + ";" + std::to_string(lines) + ";" + std::to_string(durationMs) + ";" +
74 std::to_string(freqRgb) + ";" + std::to_string(privRgb) + ";" + std::to_string(servRgb) + ";" +
75 std::to_string(statRgb) + ";" + std::to_string(supRgb));
76 }
77
79 const std::string &getMessageBoxValues() const { return m_msgBox; }
80
82 std::vector<int> getMessageBoxValuesVector() const
83 {
84 constexpr int partCount = 11;
85 std::vector<int> partsInt = { 20, 20, 20, -1, 5, 5000, 0x00ff00, 0xff00ff, 0xda70d6, 0x00ffff, 0xffff00 };
86 const std::vector<std::string> parts = xplane::qtfreeutils::split(m_msgBox, partCount, ";");
87
88 size_t c = 0;
89 for (const std::string &p : parts)
90 {
91 const int i = std::stoi(p);
92 partsInt[c++] = i;
93 }
94 return partsInt;
95 }
96
98 bool setMaxPlanes(int planes)
99 {
100 if (planes == m_maxPlanes)
101 {
102 return false;
103 }
104 m_maxPlanes = planes;
105 return true;
106 }
107
109 int getMaxPlanes() const { return m_maxPlanes; }
110
113 {
114 if (meters == m_followAircraftDistanceM)
115 {
116 return false;
117 }
119 return true;
120 }
121
124
126 double getMaxDrawDistanceNM() const { return m_maxDrawDistanceNM; }
127
129 bool setMaxDrawDistanceNM(double nauticalMiles)
130 {
132 {
133 return false;
134 }
135 m_maxDrawDistanceNM = nauticalMiles;
136 return true;
137 }
138
140 bool isLogRenderPhases() const { return m_logRenderPhases; }
141
143 void setLogRenderPhases(bool log) { m_logRenderPhases = log; }
144
146 bool isTcasEnabled() const { return m_tcasEnabled; }
147
149 void setTcasEnabled(bool tcas) { m_tcasEnabled = tcas; }
150
153
155 void setTerrainProbeEnabled(bool enabled) { m_terrainProbeEnabled = enabled; }
156
158 bool parseXSwiftBusString(const std::string &json);
159
161 std::string toXSwiftBusJsonString() const;
162
164 std::string convertToString() const;
165
167 int update(const CXSwiftBusSettingsQtFree &newValues);
168
170 virtual void setCurrentUtcTime()
171 {
172 using namespace std::chrono;
173 const milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
174 m_msSinceEpochQtFree = static_cast<int64_t>(ms.count());
175 }
176
177 protected:
180 static constexpr char JsonDBusServerAddress[] = "dbusserveradress";
181 static constexpr char JsonDrawingLabels[] = "drawinglabels";
182 static constexpr char JsonLabelColor[] = "labelcolor";
183 static constexpr char JsonLogRenderPhases[] = "renderPhases";
184 static constexpr char JsonTcas[] = "tcas";
185 static constexpr char JsonTerrainProbe[] = "terrainProbe";
186 static constexpr char JsonMaxPlanes[] = "maxplanes";
187 static constexpr char JsonMaxDrawDistance[] = "maxDrawDistance";
188 static constexpr char JsonNightTextureMode[] = "nighttexture";
189 static constexpr char JsonTimestamp[] = "timestamp";
190 static constexpr char JsonMessageBox[] = "msgbox";
191 static constexpr char JsonBundleTaxiLandingLights[] = "bundleLights";
192 static constexpr char JsonFollowAircraftDistanceM[] = "followAircraftDistance";
194
196 virtual void objectUpdated() = 0;
197
199 "tcp:host=127.0.0.1,port=45001"
200 };
201 std::string m_nightTextureMode { "auto" };
202 std::string m_msgBox {
203 "20;20;20;-1;5;5000;65280;16711935;14315734;65535;16776960"
204 };
205 int m_maxPlanes = 100;
207 bool m_drawingLabels = true;
208 int m_labelColor = 0xffc000;
210 bool m_logRenderPhases = false;
211 bool m_tcasEnabled = true;
213 double m_maxDrawDistanceNM = 50.0;
215 };
216} // namespace swift::misc::simulation::settings
217
218#endif // SWIFT_MISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
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.
int getLabelColor() const
Get the color to draw the callsign labels above aircraft.
bool setMaxPlanes(int planes)
Set the maximum number of aircraft.
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?
std::vector< int > getMessageBoxValuesVector() const
Left, top, right, bottom, lines, duration, color(freq, priv, serv, stat, sup).
const std::string & getMessageBoxValues() const
Left, top, right, bottom, lines, duration, color(freq, priv, serv, stat, sup).
const std::string & getNightTextureMode() const
The the night texture mode.
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).
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.
bool isFuzzyEqual(double v1, double v2)
Qt free version of fuzzy compare.
std::vector< std::string > split(const std::string &str, size_t maxSplitCount=0, const std::string &delimiter=" ")
Split string by delimiter and maxSplitCount times.
Definition qtfreeutils.h:70
std::string toLower(std::string s)
String to lower case.