diff --git a/src/blackgui/components/settingssimulatorcomponent.cpp b/src/blackgui/components/settingssimulatorcomponent.cpp index 370cc9a8e..3d205eb4c 100644 --- a/src/blackgui/components/settingssimulatorcomponent.cpp +++ b/src/blackgui/components/settingssimulatorcomponent.cpp @@ -40,9 +40,9 @@ using namespace BlackMisc; using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Simulation; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; +using namespace BlackMisc::Simulation::Settings; using namespace BlackCore; using namespace BlackCore::Context; @@ -68,20 +68,23 @@ namespace BlackGui ui->le_MaxDistance->setValidator(new QIntValidator(ui->le_MaxDistance)); // connects - connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CSettingsSimulatorComponent::simulatorPluginChanged); - connect(ui->pluginSelector_EnabledSimulators, &CPluginSelector::pluginStateChanged, this, &CSettingsSimulatorComponent::pluginStateChanged); + connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CSettingsSimulatorComponent::simulatorPluginChanged); + connect(ui->pluginSelector_EnabledSimulators, &CPluginSelector::pluginStateChanged, this, &CSettingsSimulatorComponent::pluginStateChanged); connect(ui->pluginSelector_EnabledSimulators, &CPluginSelector::pluginDetailsRequested, this, &CSettingsSimulatorComponent::showPluginDetails); - connect(ui->pluginSelector_EnabledSimulators, &CPluginSelector::pluginConfigRequested, this, &CSettingsSimulatorComponent::showPluginConfig); - connect(ui->pb_ApplyMaxAircraft, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyMaxRenderedAircraft); - connect(ui->pb_ApplyTimeSync, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyTimeSync); - connect(ui->pb_ApplyMaxDistance, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyMaxRenderedDistance); + connect(ui->pluginSelector_EnabledSimulators, &CPluginSelector::pluginConfigRequested, this, &CSettingsSimulatorComponent::showPluginConfig); + + connect(ui->pb_ApplyMaxAircraft, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyMaxRenderedAircraft, Qt::QueuedConnection); + connect(ui->pb_ApplyTimeSync, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyTimeSync, Qt::QueuedConnection); + connect(ui->pb_ApplyMaxDistance, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyMaxRenderedDistance, Qt::QueuedConnection); + connect(ui->pb_ApplyComSync, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyComSync, Qt::QueuedConnection); + connect(ui->pb_ClearRestrictedRendering, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::clearRestricedRendering); connect(ui->pb_DisableRendering, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::onApplyDisableRendering); connect(ui->pb_Check, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::checkSimulatorPlugins); connect(ui->le_MaxAircraft, &QLineEdit::editingFinished, this, &CSettingsSimulatorComponent::onApplyMaxRenderedAircraft); connect(ui->le_MaxDistance, &QLineEdit::editingFinished, this, &CSettingsSimulatorComponent::onApplyMaxRenderedDistance); - connect(ui->le_MaxAircraft, &QLineEdit::returnPressed, this, &CSettingsSimulatorComponent::onApplyMaxRenderedAircraft); - connect(ui->le_MaxDistance, &QLineEdit::returnPressed, this, &CSettingsSimulatorComponent::onApplyMaxRenderedDistance); + connect(ui->le_MaxAircraft, &QLineEdit::returnPressed, this, &CSettingsSimulatorComponent::onApplyMaxRenderedAircraft); + connect(ui->le_MaxDistance, &QLineEdit::returnPressed, this, &CSettingsSimulatorComponent::onApplyMaxRenderedDistance); // list all available simulators for (const auto &p : getAvailablePlugins()) @@ -91,10 +94,13 @@ namespace BlackGui } // config - reloadPluginConfig(); + this->reloadPluginConfig(); // init - simulatorPluginChanged(sGui->getIContextSimulator()->getSimulatorPluginInfo()); + if (sGui && sGui->getIContextSimulator()) + { + this->simulatorPluginChanged(sGui->getIContextSimulator()->getSimulatorPluginInfo()); + } } CSettingsSimulatorComponent::~CSettingsSimulatorComponent() @@ -110,6 +116,10 @@ namespace BlackGui ui->le_TimeSyncOffset->setEnabled(m_pluginLoaded); ui->pb_ApplyTimeSync->setEnabled(m_pluginLoaded); + // COM unit + ui->pb_ApplyComSync->setEnabled(m_pluginLoaded); + ui->cb_ComSync->setEnabled(m_pluginLoaded); + // led ui->led_RestrictedRendering->setOn(m_pluginLoaded ? setup.isRenderingRestricted() : false); ui->lbl_RestrictionText->setText(m_pluginLoaded ? setup.getRenderRestrictionText() : ""); @@ -124,11 +134,17 @@ namespace BlackGui if (m_pluginLoaded) { - const bool timeSynced = sGui->getIContextSimulator()->isTimeSynchronized(); + const IContextSimulator *sim = sGui->getIContextSimulator(); + const bool timeSynced = sim->isTimeSynchronized(); ui->cb_TimeSync->setChecked(timeSynced); - const CTime timeOffset = sGui->getIContextSimulator()->getTimeSynchronizationOffset(); + const CTime timeOffset = sim->getTimeSynchronizationOffset(); ui->le_TimeSyncOffset->setText(timeOffset.formattedHrsMin()); + // settings + const CSimulatorSettings settings = sim->getSimulatorSettings(); + ui->cb_ComSync->setChecked(settings.isComIntegrated()); + + // rendering const int maxAircraft = setup.getMaxRenderedAircraft(); ui->le_MaxAircraft->setText(setup.isMaxAircraftRestricted() ? QString::number(maxAircraft) : ""); @@ -144,6 +160,7 @@ namespace BlackGui CSimulatorPluginInfoList CSettingsSimulatorComponent::getAvailablePlugins() const { + if (!sGui || !sGui->getIContextSimulator()) { return {}; } return sGui->getIContextSimulator()->getAvailableSimulatorPlugins(); } @@ -182,6 +199,8 @@ namespace BlackGui void CSettingsSimulatorComponent::onApplyMaxRenderedAircraft() { + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextSimulator()) { return; } + // get initial aircraft to render CInterpolationAndRenderingSetupGlobal setup = sGui->getIContextSimulator()->getInterpolationAndRenderingSetupGlobal(); const int noRequested = ui->le_MaxAircraft->text().isEmpty() ? setup.InfiniteAircraft() : ui->le_MaxAircraft->text().toInt(); @@ -209,6 +228,8 @@ namespace BlackGui void CSettingsSimulatorComponent::onApplyMaxRenderedDistance() { + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextSimulator()) { return; } + // get initial aircraft to render CInterpolationAndRenderingSetupGlobal setup = sGui->getIContextSimulator()->getInterpolationAndRenderingSetupGlobal(); CLength newDistance(0, nullptr); @@ -218,21 +239,18 @@ namespace BlackGui } CLength currentDistance(setup.getMaxRenderedDistance()); - if (currentDistance == newDistance) - { - return; - } - else - { - CLogMessage(this).info(u"Max.distance requested: %1") << newDistance.valueRoundedWithUnit(2, true); - setup.setMaxRenderedDistance(newDistance); - sGui->getIContextSimulator()->setInterpolationAndRenderingSetupGlobal(setup); - this->setGuiValues(); - } + if (currentDistance == newDistance) { return; } + + CLogMessage(this).info(u"Max.distance requested: %1") << newDistance.valueRoundedWithUnit(2, true); + setup.setMaxRenderedDistance(newDistance); + sGui->getIContextSimulator()->setInterpolationAndRenderingSetupGlobal(setup); + this->setGuiValues(); } void CSettingsSimulatorComponent::onApplyDisableRendering() { + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextSimulator()) { return; } + CInterpolationAndRenderingSetupGlobal setup = sGui->getIContextSimulator()->getInterpolationAndRenderingSetupGlobal(); setup.disableRendering(); sGui->getIContextSimulator()->setInterpolationAndRenderingSetupGlobal(setup); @@ -241,7 +259,8 @@ namespace BlackGui void CSettingsSimulatorComponent::onApplyTimeSync() { - if (!sGui || sGui->isShuttingDown()) { return; } + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextSimulator()) { return; } + const bool timeSync = ui->cb_TimeSync->isChecked(); const QString os = ui->le_TimeSyncOffset->text(); CTime ost(0, CTimeUnit::hrmin()); @@ -259,8 +278,23 @@ namespace BlackGui } } + void CSettingsSimulatorComponent::onApplyComSync() + { + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextSimulator()) { return; } + + IContextSimulator *sim = sGui->getIContextSimulator(); + const CSimulatorInfo simulator = sim->getSimulatorPluginInfo().getSimulatorInfo(); + if (!simulator.isSingleSimulator()) { return; } + CSimulatorSettings settings = sim->getSimulatorSettings(); + if (settings.isComIntegrated() == ui->cb_ComSync->isChecked()) { return; } + settings.setComIntegrated(ui->cb_ComSync->isChecked()); + sim->setSimulatorSettings(settings, simulator); + } + void CSettingsSimulatorComponent::clearRestricedRendering() { + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextSimulator()) { return; } + CInterpolationAndRenderingSetupGlobal setup; setup.clearAllRenderingRestrictions(); sGui->getIContextSimulator()->setInterpolationAndRenderingSetupGlobal(setup); diff --git a/src/blackgui/components/settingssimulatorcomponent.h b/src/blackgui/components/settingssimulatorcomponent.h index 71cdfba8f..f00b9124a 100644 --- a/src/blackgui/components/settingssimulatorcomponent.h +++ b/src/blackgui/components/settingssimulatorcomponent.h @@ -38,7 +38,7 @@ namespace BlackGui explicit CSettingsSimulatorComponent(QWidget *parent = nullptr); //! Destructor - virtual ~CSettingsSimulatorComponent(); + virtual ~CSettingsSimulatorComponent() override; private: //! Driver plugin enabled/disabled @@ -56,6 +56,9 @@ namespace BlackGui //! Apply time synchronization void onApplyTimeSync(); + //! Apply COM sync + void onApplyComSync(); + //! Clear restricted rendering void clearRestricedRendering(); @@ -82,7 +85,7 @@ namespace BlackGui QScopedPointer ui; //!< UI bool m_pluginLoaded = false; //!< plugin loaded? - BlackCore::CPluginManagerSimulator* m_plugins = nullptr; + BlackCore::CPluginManagerSimulator *m_plugins = nullptr; BlackMisc::CSetting m_enabledSimulators { this, &CSettingsSimulatorComponent::reloadPluginConfig }; }; } diff --git a/src/blackgui/components/settingssimulatorcomponent.ui b/src/blackgui/components/settingssimulatorcomponent.ui index 843bdd5cd..f5898a989 100644 --- a/src/blackgui/components/settingssimulatorcomponent.ui +++ b/src/blackgui/components/settingssimulatorcomponent.ui @@ -5,7 +5,7 @@ Frame - + 2 @@ -18,34 +18,83 @@ 2 - - - - - 0 - 0 - + + + + 4 + + + + + + + restriction info + + + + + + + + + 4 + + + + + no restrictions + + + + + + + + + Current rendering restrictions (if any) + + + Restrictions + + + + + - 60 + 10 0 - - - 60 - 16777215 - + + + + + + Simulator info will go here + + + true + + + + + + + Time synchronization - apply + Time synch. + + 3 + 0 @@ -70,12 +119,6 @@ - - - 0 - 0 - - 75 @@ -96,89 +139,30 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + - - - - - 10 - 0 - - - - - + - - - 0 - 0 - - - - - 60 - 0 - - - - - 60 - 16777215 - - apply - - - Current rendering restrictions (if any) - - - Restrictions - - - - - - - Time synchronization - - - Time synch. - - - - - - - 4 - - - - - - - - restriction info - - - - - - - - - Loaded - - - - Rendering enabled @@ -188,28 +172,28 @@ - + + + + apply + + + + Max.dist.(NM) - - - - 4 + + + + clear - - - - no restrictions - - - - + - + 4 @@ -223,63 +207,13 @@ - - - - Max.aircraft - - - - - - - - 0 - 0 - - - - - 60 - 0 - - - - - 60 - 16777215 - - + + apply - - - - - 0 - 0 - - - - - 60 - 0 - - - - - 60 - 16777215 - - - - clear - - - @@ -290,28 +224,10 @@ - - - - - 0 - 0 - - - - - 60 - 0 - - - - - 60 - 16777215 - - + + - disable + use COM sync. @@ -331,20 +247,54 @@ - - + + - check again + Loaded - - + + - Simulator info will go here + Max.aircraft - - true + + + + + + disable + + + + + + + apply + + + + + + + Synchronize COM unit with simulator + + + COM synch. + + + + + + + + 100 + 0 + + + + check again @@ -369,6 +319,8 @@ cb_TimeSync le_TimeSyncOffset pb_ApplyTimeSync + cb_ComSync + pb_ApplyComSync pb_DisableRendering pb_ClearRestrictedRendering le_MaxAircraft