swift
Loading...
Searching...
No Matches
xswiftbussettingsqtfree.inc
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#include <chrono>
5#include <string>
6
7#include "nlohmann/json.hpp"
8
9#include "xswiftbussettingsqtfree.h"
10
11#ifdef __GNUC__
12# pragma GCC diagnostic push
13# pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
14#endif
15
16using namespace swift::misc::simulation::settings;
17using namespace swift::misc::simulation::xplane;
18
33
34namespace swift::misc::simulation::settings
35{
36 bool CXSwiftBusSettingsQtFree::parseXSwiftBusString(const std::string &json)
37 {
38 if (json.empty())
39 {
40 return false;
41 }
42
43 const nlohmann::basic_json parsed = nlohmann::json::parse(json, nullptr, false);
44
45 if (parsed.is_discarded())
46 {
47 return false;
48 }
49
50 int c = 0;
53 {
55 c++;
56 }
57 if (parsed.contains(CXSwiftBusSettingsQtFree::JsonMessageBox) &&
59 {
60 m_msgBox = parsed[CXSwiftBusSettingsQtFree::JsonMessageBox].get<std::string>();
61 c++;
62 }
65 {
67 c++;
68 }
71 {
73 c++;
74 }
75 if (parsed.contains(CXSwiftBusSettingsQtFree::JsonLabelColor) &&
76 parsed[CXSwiftBusSettingsQtFree::JsonLabelColor].is_number_integer())
77 {
79 c++;
80 }
83 {
85 c++;
86 }
87 if (parsed.contains(CXSwiftBusSettingsQtFree::JsonTcas) &&
88 parsed[CXSwiftBusSettingsQtFree::JsonTcas].is_boolean())
89 {
91 c++;
92 }
93 if (parsed.contains(CXSwiftBusSettingsQtFree::JsonTerrainProbe) &&
95 {
97 c++;
98 }
101 {
103 c++;
104 }
105 if (parsed.contains(CXSwiftBusSettingsQtFree::JsonMaxPlanes) &&
106 parsed[CXSwiftBusSettingsQtFree::JsonMaxPlanes].is_number_integer())
107 {
109 c++;
110 }
112 parsed[CXSwiftBusSettingsQtFree::JsonMaxDrawDistance].is_number_float())
113 {
115 c++;
116 }
119 {
121 c++;
122 }
123 if (parsed.contains(CXSwiftBusSettingsQtFree::JsonTimestamp) &&
124 parsed[CXSwiftBusSettingsQtFree::JsonTimestamp].is_number_integer())
125 {
127 c++;
128 }
129 this->objectUpdated(); // post processing
130 return c == 13;
131 }
132
134 {
135 nlohmann::json json;
136
139 json[JsonMessageBox] = m_msgBox;
148 json[JsonTcas] = m_tcasEnabled;
150
151 return json.dump(2);
152 }
153
155 {
156 return "DBusServer: " + m_dBusServerAddress + ", drawLabels: " + qtfreeutils::boolToYesNo(m_drawingLabels) +
157 ", labelColor: " + std::to_string((m_labelColor >> 16) & 0xff) + ";" +
158 std::to_string((m_labelColor >> 8) & 0xff) + ";" + std::to_string(m_labelColor & 0xff) +
159 ", bundle lights: " + qtfreeutils::boolToYesNo(m_bundleTaxiLandingLights) +
160 ", phases: " + qtfreeutils::boolToYesNo(m_logRenderPhases) +
161 ", TCAS: " + qtfreeutils::boolToYesNo(m_tcasEnabled) +
162 ", terr.probe: " + qtfreeutils::boolToYesNo(m_terrainProbeEnabled) +
163 ", night t.: " + m_nightTextureMode + ", max planes: " + std::to_string(m_maxPlanes) +
164 ", max distance NM: " + std::to_string(m_maxDrawDistanceNM) +
165 ", follow dist m: " + std::to_string(m_followAircraftDistanceM) + ", msg.box: " + m_msgBox +
166 ", ts: " + std::to_string(m_msSinceEpochQtFree);
167 }
168
170 {
171 int changed = 0;
173 {
175 changed++;
176 }
177 if (m_msgBox != newValues.m_msgBox)
178 {
179 m_msgBox = newValues.m_msgBox;
180 changed++;
181 }
182 if (m_drawingLabels != newValues.m_drawingLabels)
183 {
185 changed++;
186 }
187 if (m_labelColor != newValues.m_labelColor)
188 {
189 m_labelColor = newValues.m_labelColor;
190 changed++;
191 }
192 if (m_nightTextureMode != newValues.m_nightTextureMode)
193 {
195 changed++;
196 }
197 if (m_logRenderPhases != newValues.m_logRenderPhases)
198 {
200 changed++;
201 }
202 if (m_tcasEnabled != newValues.m_tcasEnabled)
203 {
204 m_tcasEnabled = newValues.m_tcasEnabled;
205 changed++;
206 }
208 {
210 changed++;
211 }
212 if (m_maxPlanes != newValues.m_maxPlanes)
213 {
214 m_maxPlanes = newValues.m_maxPlanes;
215 changed++;
216 }
218 {
220 changed++;
221 }
223 {
225 changed++;
226 }
228 {
230 changed++;
231 }
232 if (!qtfreeutils::isFuzzyEqual(m_maxDrawDistanceNM, newValues.m_maxDrawDistanceNM))
233 {
235 changed++;
236 }
237
238 if (changed > 0)
239 {
240 this->objectUpdated();
241 } // post processing
242 return changed;
243 }
244
245} // namespace swift::misc::simulation::settings
246
247#ifdef __GNUC__
248# pragma GCC diagnostic pop
249#endif
xswiftbus/swift side settings class, JSON capable, shared among all services
static constexpr char JsonBundleTaxiLandingLights[]
The JSON members.
int update(const CXSwiftBusSettingsQtFree &newValues)
Update only changed values.
virtual void objectUpdated()=0
Object has been updated.
static constexpr char JsonFollowAircraftDistanceM[]
The JSON members.
std::string m_dBusServerAddress
DBus server (also in class CXSwiftBusConfigWriter).
std::string m_msgBox
left, top, right, bottom, lines, duration, colors
std::string convertToString() const
Convert to string.
bool m_terrainProbeEnabled
terrain probe to establish ground elevation
std::string toXSwiftBusJsonString() const
As JSON string.
bool parseXSwiftBusString(const std::string &json)
Load and parse config file.