diff --git a/Source/Controller.cpp b/Source/Controller.cpp index 43d9006..126d0f3 100644 --- a/Source/Controller.cpp +++ b/Source/Controller.cpp @@ -23,6 +23,19 @@ #include "Common.h" #include "Controller.h" +//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +void Controller::enableRelaxParamsWidgets(bool bEnable) +{ + for(auto& widget: m_RelaxParamsWidgets) { + auto cbWidget = dynamic_cast(widget); + if(cbWidget != nullptr) { + cbWidget->setEnabled(bEnable); + } else { + widget->setEnabled(bEnable); + } + } +} + //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ void Controller::updateRelaxParams() { @@ -50,7 +63,7 @@ void Controller::setDefaultParams() m_cbMaxIterations->setCurrentIndex(0); m_cbCheckFrequency->setCurrentIndex(2); m_cbIntersectionThreshold->setCurrentIndex(2); - m_cbInitialJitter->setCurrentIndex(1); + m_cbInitialJitter->setCurrentIndex(4); m_cbSPHCFLFactor->setCurrentIndex(4); m_cbSPHPressureStiffness->setCurrentIndex(6); @@ -91,7 +104,7 @@ void Controller::connectWidgets() //////////////////////////////////////////////////////////////////////////////// // materials and particle color mode connect(m_smParticleColorMode, static_cast(&QSignalMapper::mapped), m_RenderWidget, &RenderWidget::setParticleColorMode); - connect( m_msParticleMaterial, &MaterialSelector::materialChanged, m_RenderWidget, &RenderWidget::setParticleMaterial); + connect(m_msParticleMaterial, &MaterialSelector::materialChanged, m_RenderWidget, &RenderWidget::setParticleMaterial); //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -106,7 +119,7 @@ void Controller::connectWidgets() //////////////////////////////////////////////////////////////////////////////// // buttons - connect( m_btnResetCamera, &QPushButton::clicked, m_RenderWidget, &RenderWidget::resetCameraPosition); + connect(m_btnResetCamera, &QPushButton::clicked, m_RenderWidget, &RenderWidget::resetCameraPosition); connect(m_btnClipViewPlane, &QPushButton::clicked, m_RenderWidget, &RenderWidget::enableClipPlane); //////////////////////////////////////////////////////////////////////////////// } @@ -136,21 +149,21 @@ void Controller::setupColorModeControllers() rdbColorRamp->setChecked(true); //////////////////////////////////////////////////////////////////////////////// QGridLayout* layoutColorMode = new QGridLayout; - layoutColorMode->addWidget( rdbColorRandom, 0, 0, 1, 1); - layoutColorMode->addWidget( rdbColorRamp, 0, 1, 1, 1); + layoutColorMode->addWidget(rdbColorRandom, 0, 0, 1, 1); + layoutColorMode->addWidget(rdbColorRamp, 0, 1, 1, 1); layoutColorMode->addWidget(rdbColorUniform, 1, 0, 1, 1); - layoutColorMode->addWidget( rdbColorObjIdx, 1, 1, 1, 1); + layoutColorMode->addWidget(rdbColorObjIdx, 1, 1, 1, 1); //////////////////////////////////////////////////////////////////////////////// m_smParticleColorMode = new QSignalMapper(this); - connect( rdbColorRandom, SIGNAL(clicked()), m_smParticleColorMode, SLOT(map())); - connect( rdbColorRamp, SIGNAL(clicked()), m_smParticleColorMode, SLOT(map())); + connect(rdbColorRandom, SIGNAL(clicked()), m_smParticleColorMode, SLOT(map())); + connect(rdbColorRamp, SIGNAL(clicked()), m_smParticleColorMode, SLOT(map())); connect(rdbColorUniform, SIGNAL(clicked()), m_smParticleColorMode, SLOT(map())); - connect( rdbColorObjIdx, SIGNAL(clicked()), m_smParticleColorMode, SLOT(map())); + connect(rdbColorObjIdx, SIGNAL(clicked()), m_smParticleColorMode, SLOT(map())); - m_smParticleColorMode->setMapping( rdbColorRandom, static_cast(ParticleColorMode::Random)); - m_smParticleColorMode->setMapping( rdbColorRamp, static_cast(ParticleColorMode::Ramp)); + m_smParticleColorMode->setMapping(rdbColorRandom, static_cast(ParticleColorMode::Random)); + m_smParticleColorMode->setMapping(rdbColorRamp, static_cast(ParticleColorMode::Ramp)); m_smParticleColorMode->setMapping(rdbColorUniform, static_cast(ParticleColorMode::UniformMaterial)); - m_smParticleColorMode->setMapping( rdbColorObjIdx, static_cast(ParticleColorMode::ObjectIndex)); + m_smParticleColorMode->setMapping(rdbColorObjIdx, static_cast(ParticleColorMode::ObjectIndex)); //////////////////////////////////////////////////////////////////////////////// QVBoxLayout* layoutColorCtrls = new QVBoxLayout; layoutColorCtrls->addLayout(layoutColorMode); @@ -183,17 +196,20 @@ void Controller::setupSceneControllers() m_cbScene = new EnhancedComboBox; m_cbScene->addItem(QString("None")); m_cbScene->addItems(QtAppUtils::getFiles(QtAppUtils::getDefaultPath("Scenes"))); + m_RelaxParamsWidgets.push_back(m_cbScene); //////////////////////////////////////////////////////////////////////////////// m_btnReloadScene = new QPushButton(" Reload "); m_chkReloadVizData = new QCheckBox("Reload vizualization data"); + m_RelaxParamsWidgets.push_back(m_btnReloadScene); + m_RelaxParamsWidgets.push_back(m_chkReloadVizData); //////////////////////////////////////////////////////////////////////////////// QHBoxLayout* layoutReloadScene = new QHBoxLayout; layoutReloadScene->addWidget(m_chkReloadVizData, 10); layoutReloadScene->addStretch(1); layoutReloadScene->addWidget(m_btnReloadScene, 10); QVBoxLayout* layoutScene = new QVBoxLayout; - layoutScene->addLayout( m_cbScene->getLayout()); - layoutScene->addLayout( QtAppUtils::getLayoutSeparator(5)); + layoutScene->addLayout(m_cbScene->getLayout()); + layoutScene->addLayout(QtAppUtils::getLayoutSeparator(5)); layoutScene->addLayout(layoutReloadScene); QGroupBox* grScene = new QGroupBox; grScene->setTitle("Scene"); @@ -211,6 +227,11 @@ void Controller::setupSamplingParametersControllers() m_cbIntersectionThreshold = new EnhancedComboBox; m_cbInitialJitter = new EnhancedComboBox; + m_RelaxParamsWidgets.push_back(m_cbMaxIterations); + m_RelaxParamsWidgets.push_back(m_cbCheckFrequency); + m_RelaxParamsWidgets.push_back(m_cbIntersectionThreshold); + m_RelaxParamsWidgets.push_back(m_cbInitialJitter); + m_cbMaxIterations->addItems({ "100", "500", "1000", "2000", "5000", "10000" }); m_cbCheckFrequency->addItems({ "1", "5", "10", "20", "30", "40", "50", "100" }); m_cbIntersectionThreshold->addItems({ "1.5", "1.6", "1.7", "1.8", "1.9", "2.0" }); @@ -240,6 +261,14 @@ void Controller::setupSamplingParametersControllers() m_cbSPHNearPressureStiffness = new EnhancedComboBox; m_cbSPHBoundaryRestitution = new EnhancedComboBox; + m_RelaxParamsWidgets.push_back(m_cbSPHCFLFactor); + m_RelaxParamsWidgets.push_back(m_cbSPHPressureStiffness); + m_RelaxParamsWidgets.push_back(m_cbSPHViscosity); + m_RelaxParamsWidgets.push_back(m_cbSPHOverlapThreshold); + m_RelaxParamsWidgets.push_back(m_cbSPHNearKernelRadiusRatio); + m_RelaxParamsWidgets.push_back(m_cbSPHNearPressureStiffness); + m_RelaxParamsWidgets.push_back(m_cbSPHBoundaryRestitution); + m_cbSPHCFLFactor->addItems({ "0.001", "0.005", "0.01", "0.05", "0.1", "0.5", "1.0" }); m_cbSPHViscosity->addItems({ "0.001", "0.005", "0.01", "0.05", "0.1", "0.5", "1.0" }); m_cbSPHOverlapThreshold->addItems({ "0.001", "0.01", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1.0" }); @@ -286,6 +315,7 @@ void Controller::setupSamplingParametersControllers() void Controller::setupButtons() { m_btnResetParams = new QPushButton("Reset Parameters"); + m_RelaxParamsWidgets.push_back(m_btnResetParams); m_LayoutRelaxationControllers->addSpacing(10); m_LayoutRelaxationControllers->addWidget(m_btnResetParams); //////////////////////////////////////////////////////////////////////////////// @@ -298,9 +328,9 @@ void Controller::setupButtons() //////////////////////////////////////////////////////////////////////////////// QGridLayout* layoutButtons = new QGridLayout; layoutButtons->addWidget(m_btnStartStopRelaxation, 0, 0, 1, 2); - layoutButtons->addWidget( m_btnResetCamera, 1, 0, 1, 2); - layoutButtons->addWidget( m_btnClipViewPlane, 2, 0, 1, 1); - layoutButtons->addWidget( m_btnEditClipPlane, 2, 1, 1, 1); + layoutButtons->addWidget(m_btnResetCamera, 1, 0, 1, 2); + layoutButtons->addWidget(m_btnClipViewPlane, 2, 0, 1, 1); + layoutButtons->addWidget(m_btnEditClipPlane, 2, 1, 1, 1); //////////////////////////////////////////////////////////////////////////////// m_MainLayout->addStretch(); m_MainLayout->addLayout(layoutButtons); diff --git a/Source/Controller.h b/Source/Controller.h index 21071cf..0b0f3d1 100644 --- a/Source/Controller.h +++ b/Source/Controller.h @@ -47,13 +47,14 @@ class Controller : public OpenGLController } public slots: + void enableRelaxParamsWidgets(bool bEnable); void updateRelaxParams(); void setDefaultParams(); private: - QWidget* m_RelaxationControllers = new QWidget; - QVBoxLayout* m_LayoutRelaxationControllers = new QVBoxLayout; - + QWidget* m_RelaxationControllers = new QWidget; + QVBoxLayout* m_LayoutRelaxationControllers = new QVBoxLayout; + Vector m_RelaxParamsWidgets; //////////////////////////////////////////////////////////////////////////////// void setupGUI(); void connectWidgets(); diff --git a/Source/MainWindow.cpp b/Source/MainWindow.cpp index 3fd75ac..f8932a4 100644 --- a/Source/MainWindow.cpp +++ b/Source/MainWindow.cpp @@ -117,8 +117,7 @@ void MainWindow::changeScene(bool bReload) if(sceneFile == "None") { return; } - m_Controller->m_btnReloadScene->setDisabled(true); - m_Controller->m_cbScene->setDisabled(true); + m_Controller->enableRelaxParamsWidgets(false); updateStatusRelaxation("Building scene..."); m_BusyBar->setBusy(true); //////////////////////////////////////////////////////////////////////////////// @@ -139,8 +138,7 @@ void MainWindow::startNewScene(const QString& sceneFile) m_FrameNumber = 0; updateWindowTitle(QtAppUtils::getDefaultPath("Scenes") + "/" + sceneFile); updateStatusRelaxation("Ready"); - m_Controller->m_btnReloadScene->setEnabled(true); - m_Controller->m_cbScene->setEnabled(true); + m_Controller->enableRelaxParamsWidgets(true); m_BusyBar->reset(); } @@ -157,8 +155,7 @@ void MainWindow::startStopRelaxation() } bool isRunning = m_Sampler->isRunning(); if(!isRunning) { - m_Controller->m_cbScene->setDisabled(true); - m_Controller->m_btnReloadScene->setDisabled(true); + m_Controller->enableRelaxParamsWidgets(false); updateStatusRelaxation("Running relaxation..."); fut = std::async(std::launch::async, [&] { @@ -167,8 +164,7 @@ void MainWindow::startStopRelaxation() }); } else { m_Sampler->stop(); - m_Controller->m_cbScene->setDisabled(false); - m_Controller->m_btnReloadScene->setDisabled(false); + m_Controller->enableRelaxParamsWidgets(true); updateStatusRelaxation("Stopped"); } m_Controller->m_btnStartStopRelaxation->setText(!isRunning ? QString("Stop") : QString("Resume")); @@ -199,8 +195,7 @@ void MainWindow::finishRelaxation(bool bSuccess) } else { updateStatusRelaxation("Relaxation failed."); } - m_Controller->m_cbScene->setDisabled(false); - m_Controller->m_btnReloadScene->setDisabled(false); + m_Controller->enableRelaxParamsWidgets(true); m_BusyBar->reset(); } @@ -209,8 +204,7 @@ void MainWindow::pauseRelaxation() { m_Controller->m_btnStartStopRelaxation->setText(QString("Resume")); updateStatusRelaxation("Relaxation paused"); - m_Controller->m_cbScene->setDisabled(false); - m_Controller->m_btnReloadScene->setDisabled(false); + m_Controller->enableRelaxParamsWidgets(true); m_BusyBar->reset(); }