8 #include <QApplication>
12 #include <QPushButton>
14 #include <QStringList>
18 #include "ui_settingssimulatorcomponent.h"
40 using namespace swift::misc::physical_quantities;
41 using namespace swift::misc::aviation;
42 using namespace swift::misc::simulation;
43 using namespace swift::misc::simulation::settings;
45 using namespace swift::core::context;
49 CSettingsSimulatorComponent::CSettingsSimulatorComponent(QWidget *parent)
52 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing sGui");
58 ui->led_RestrictedRendering->setValues(CLedWidget::Yellow, CLedWidget::Black, shape,
"Limited",
"Unlimited",
60 ui->led_RenderingEnabled->setValues(CLedWidget::Yellow, CLedWidget::Black, shape,
"Rendering enabled",
61 "No aircraft will be rendered", 14);
63 ui->le_MaxAircraft->setValidator(
new QIntValidator(ui->le_MaxAircraft));
64 ui->le_MaxDistance->setValidator(
new QIntValidator(ui->le_MaxDistance));
68 &CSettingsSimulatorComponent::pluginStateChanged);
70 &CSettingsSimulatorComponent::showPluginConfig);
72 connect(ui->pb_Reload, &QCheckBox::pressed,
this, &CSettingsSimulatorComponent::onReload, Qt::QueuedConnection);
73 connect(ui->pb_ApplyMaxAircraft, &QCheckBox::pressed,
this,
74 &CSettingsSimulatorComponent::onApplyMaxRenderedAircraft, Qt::QueuedConnection);
75 connect(ui->pb_ApplyMaxDistance, &QCheckBox::pressed,
this,
76 &CSettingsSimulatorComponent::onApplyMaxRenderedDistance, Qt::QueuedConnection);
77 connect(ui->pb_ApplyComSync, &QCheckBox::pressed,
this, &CSettingsSimulatorComponent::onApplyComSync,
78 Qt::QueuedConnection);
79 connect(ui->pb_ApplyCGSource, &QCheckBox::pressed,
this, &CSettingsSimulatorComponent::onApplyCGSource,
80 Qt::QueuedConnection);
81 connect(ui->pb_ApplyRecordOwnAircraftGnd, &QCheckBox::pressed,
this,
82 &CSettingsSimulatorComponent::onApplyRecordGnd, Qt::QueuedConnection);
84 connect(ui->pb_ClearRestrictedRendering, &QCheckBox::pressed,
this,
85 &CSettingsSimulatorComponent::clearRestricedRendering);
86 connect(ui->pb_DisableRendering, &QCheckBox::pressed,
this,
87 &CSettingsSimulatorComponent::onApplyDisableRendering);
88 connect(ui->pb_Check, &QCheckBox::pressed,
this, &CSettingsSimulatorComponent::checkSimulatorPlugins);
89 connect(ui->le_MaxAircraft, &QLineEdit::editingFinished,
this,
90 &CSettingsSimulatorComponent::onApplyMaxRenderedAircraft);
91 connect(ui->le_MaxDistance, &QLineEdit::editingFinished,
this,
92 &CSettingsSimulatorComponent::onApplyMaxRenderedDistance);
93 connect(ui->le_MaxAircraft, &QLineEdit::returnPressed,
this,
94 &CSettingsSimulatorComponent::onApplyMaxRenderedAircraft);
95 connect(ui->le_MaxDistance, &QLineEdit::returnPressed,
this,
96 &CSettingsSimulatorComponent::onApplyMaxRenderedDistance);
100 for (
const auto &p : plugins)
103 ui->pluginSelector_EnabledSimulators->addPlugin(p.getIdentifier(), p.getName(), !config.isEmpty(),
false);
107 ui->pluginSelector_EnabledSimulators->setMinimumHeight(h);
110 this->reloadPluginConfig(plugins);
117 &CSettingsSimulatorComponent::simulatorPluginChanged, Qt::QueuedConnection);
119 &CSettingsSimulatorComponent::onReload, Qt::QueuedConnection);
125 void CSettingsSimulatorComponent::setGuiValues()
132 ui->pb_ApplyComSync->setEnabled(m_pluginLoaded);
133 ui->cb_ComSync->setEnabled(m_pluginLoaded);
136 ui->comp_CGSourceSelector->setEnabled(m_pluginLoaded);
139 ui->pb_ApplyRecordOwnAircraftGnd->setEnabled(m_pluginLoaded);
140 ui->cb_RecordOwnGndPositions->setEnabled(m_pluginLoaded);
141 ui->le_RecordOwnGndPositionsRadius->setEnabled(m_pluginLoaded);
147 ui->le_MaxDistance->setEnabled(m_pluginLoaded);
148 ui->le_MaxAircraft->setEnabled(m_pluginLoaded);
149 ui->pb_ApplyMaxAircraft->setEnabled(m_pluginLoaded);
150 ui->pb_ApplyMaxDistance->setEnabled(m_pluginLoaded);
151 ui->pb_ClearRestrictedRendering->setEnabled((m_pluginLoaded));
152 ui->pb_DisableRendering->setEnabled(m_pluginLoaded);
153 ui->pb_Check->setEnabled(!m_pluginLoaded);
154 ui->pb_ApplyCGSource->setEnabled(m_pluginLoaded);
155 ui->pb_Reload->setEnabled(m_pluginLoaded);
166 ui->comp_CGSourceSelector->setValue(settings);
169 ui->le_RecordOwnGndPositionsRadius->setText(
178 ui->le_MaxDistance->setText(
182 else { ui->led_RenderingEnabled->setOn(
false); }
191 void CSettingsSimulatorComponent::pluginStateChanged(
const QString &identifier,
bool enabled)
199 CLogMessage(
this).
error(u
"Simulator plugin does not exist: '%1'") << identifier;
218 void CSettingsSimulatorComponent::onApplyMaxRenderedAircraft()
225 const int noRequested =
226 ui->le_MaxAircraft->text().isEmpty() ? setup.
InfiniteAircraft() : ui->le_MaxAircraft->text().toInt();
228 if (oldValue == noRequested) {
return; }
237 if (noRequested == noRendered) {
CLogMessage(
this).
info(u
"Max.rendered aircraft: %1") << noRendered; }
240 CLogMessage(
this).
info(u
"Max.rendered aircraft: %1, requested: %2") << noRendered << noRequested;
241 ui->le_MaxAircraft->setText(QString::number(noRendered));
243 this->setGuiValues();
246 void CSettingsSimulatorComponent::onApplyMaxRenderedDistance()
253 CLength newDistance(0,
nullptr);
254 if (!ui->le_MaxDistance->text().isEmpty())
256 newDistance =
CLength(ui->le_MaxDistance->text().toInt(), CLengthUnit::NM());
260 if (currentDistance == newDistance) {
return; }
262 CLogMessage(
this).
info(u
"Max.distance requested: %1") << newDistance.valueRoundedWithUnit(2,
true);
265 this->setGuiValues();
268 void CSettingsSimulatorComponent::onApplyDisableRendering()
276 this->setGuiValues();
299 void CSettingsSimulatorComponent::onApplyComSync()
303 if (!ok || !settings.
setComIntegrated(ui->cb_ComSync->isChecked())) {
return; }
304 this->setSimulatorSettings(settings);
307 void CSettingsSimulatorComponent::onApplyCGSource()
312 if (!ok || !settings.
setCGSource(source)) {
return; }
313 this->setSimulatorSettings(settings);
316 void CSettingsSimulatorComponent::onApplyRecordGnd()
323 CLength radius = CLength::null();
324 QString radiusString = ui->le_RecordOwnGndPositionsRadius->text().trimmed();
325 if (!radiusString.isEmpty())
327 if (!CMeasurementUnit::endWithValidUnitSymbol<CLengthUnit>(radiusString)) { radiusString +=
"m"; }
334 if (!c1 && !c2) {
return; }
335 this->setSimulatorSettings(settings);
338 void CSettingsSimulatorComponent::onReload() { this->setGuiValues(); }
340 void CSettingsSimulatorComponent::onEnabledSimulatorsChanged()
342 this->reloadPluginConfig(CSettingsSimulatorComponent::getAvailablePlugins());
345 void CSettingsSimulatorComponent::clearRestricedRendering()
352 this->setGuiValues();
363 m_pluginLoaded =
true;
364 ui->lbl_PluginInfo->setText(
"Connected to: " % info.
getName());
368 m_pluginLoaded =
false;
369 ui->lbl_PluginInfo->setText(
"No connection to simulator");
371 this->setGuiValues();
374 void CSettingsSimulatorComponent::showPluginConfig(
const QString &identifier)
380 IPluginConfig *config = m_plugins->
getPluginById<IPluginConfig>(configId);
382 if (!config) {
return; }
384 CPluginConfigWindow *window = config->createConfigWindow(qApp->activeWindow());
386 if (!window) {
return; }
388 window->setAttribute(Qt::WA_DeleteOnClose);
395 const auto enabledSimulators = m_enabledSimulators.
getThreadLocal();
396 for (
const auto &p : plugins)
398 ui->pluginSelector_EnabledSimulators->setEnabled(p.getIdentifier(),
399 enabledSimulators.contains(p.getIdentifier()));
403 void CSettingsSimulatorComponent::checkSimulatorPlugins()
bool isShuttingDown() const
Is application shutting down?
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
Manages plugins for the simulator context.
virtual void collectPlugins()
Looks for all available plugins.
T * getPluginById(const QString &identifier)
Loads the given plugin (if necessary), casts it to the desired type and returns its instance....
QString getPluginConfigId(const QString &identifier)
If the plugin specifies its config plugin, its identifier can be obtained using this method....
virtual swift::misc::simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const =0
Simulator info, currently loaded plugin.
virtual void setInterpolationAndRenderingSetupGlobal(const swift::misc::simulation::CInterpolationAndRenderingSetupGlobal &setup)=0
Set the global setup.
virtual int checkListeners()=0
Check all listeners enabled if simulator is connected.
bool isSimulatorAvailable() const
Simulator avialable (driver available)?
virtual swift::misc::simulation::settings::CSimulatorSettings getSimulatorSettings() const =0
Get the current simulator settings.
virtual swift::misc::simulation::CInterpolationAndRenderingSetupGlobal getInterpolationAndRenderingSetupGlobal() const =0
The global setup.
virtual bool setSimulatorSettings(const swift::misc::simulation::settings::CSimulatorSettings &settings, const swift::misc::simulation::CSimulatorInfo &simulator)=0
Set settings for give simulator.
virtual swift::misc::simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const =0
Return list of available simulator plugins.
static QSizeF fontMetricsLazyDog43Chars(bool withRatio=false)
43 characters width/height "the quick brown ..."
void pluginStateChanged(const QString &identifier, bool enabled)
Emitted when user enables/disables the particular plugin.
void pluginConfigRequested(const QString &identifier)
Emitted when user clicks the "Settings" button.
All simulator settings component (GUI)
virtual ~CSettingsSimulatorComponent()
Destructor.
CStatusMessage set(const T &value, qint64 timestamp=0)
Write a new value. Must be called from the thread in which the owner lives.
const T & getThreadLocal() const
Read the current value.
Class for emitting a log message.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
size_type size() const
Returns number of elements in the sequence.
Streamable status message, e.g.
bool isWarningOrAbove() const
Warning or above.
Physical unit length (length)
void parseFromString(const QString &value)
Parse value from string.
QString valueRoundedWithUnit(const MU &unit, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
Value to QString with the given unit, e.g. "5.00m".
Value object for interpolator and rendering.
bool setMaxRenderedDistance(const physical_quantities::CLength &distance)
Max.distance for rendering.
QString getRenderRestrictionText() const
Text describing the restrictions.
bool isRenderingEnabled() const
Rendering enabled (at all)?
int getMaxRenderedAircraft() const
Max.number of aircraft rendered.
physical_quantities::CLength getMaxRenderedDistance() const
Max.distance for rendering.
bool setMaxRenderedAircraft(int maxRenderedAircraft)
Max.number of aircraft rendered.
bool isMaxDistanceRestricted() const
Restricted by distance?
void clearAllRenderingRestrictions()
Remove all render restrictions.
bool isMaxAircraftRestricted() const
Restricted by quantity?
void disableRendering()
Entirely disable rendering.
static int InfiniteAircraft()
Considered as "all aircraft".
bool isRenderingRestricted() const
Rendering enabled, but restricted.
Simple hardcoded info about the corresponding simulator.
bool isSingleSimulator() const
Single simulator selected.
Describing a simulator plugin.
const QString & getIdentifier() const
Identifier.
const QString & getName() const
Name.
const CSimulatorInfo & getSimulatorInfo() const
Simulator info object.
bool isUnspecified() const
Unspecified simulator.
Value object encapsulating a list of SimulatorInfo objects.
Settings for simulator Driver independent parts (such as directories), also used in model loaders.
bool isComIntegrated() const
COM unit integration.
swift::misc::physical_quantities::CLength getRecordedGndRadius() const
Record GND values with radius.
CGSource
Where we get the CG (aka vertical offset) from.
bool isRecordOwnAircraftGnd() const
Record GND values (of own aircraft)
bool setCGSource(CGSource source)
CG source.
bool setRecordedGndRadius(const swift::misc::physical_quantities::CLength &radius)
Record GND values with radius.
bool setRecordOwnAircraftGnd(bool record)
Record GND values (of own aircraft)
bool setComIntegrated(bool integrated)
COM unit integration.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Free functions in swift::misc.
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.