Skip to content

Commit

Permalink
🐾 improve gui
Browse files Browse the repository at this point in the history
  • Loading branch information
ttnghia committed Jun 14, 2018
1 parent faeb968 commit 9029eaa
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
64 changes: 47 additions & 17 deletions Source/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
#include "Common.h"
#include "Controller.h"

//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
void Controller::enableRelaxParamsWidgets(bool bEnable)
{
for(auto& widget: m_RelaxParamsWidgets) {
auto cbWidget = dynamic_cast<EnhancedComboBox*>(widget);
if(cbWidget != nullptr) {
cbWidget->setEnabled(bEnable);
} else {
widget->setEnabled(bEnable);
}
}
}

//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
void Controller::updateRelaxParams()
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -91,7 +104,7 @@ void Controller::connectWidgets()
////////////////////////////////////////////////////////////////////////////////
// materials and particle color mode
connect(m_smParticleColorMode, static_cast<void (QSignalMapper::*)(int)>(&QSignalMapper::mapped), m_RenderWidget, &RenderWidget::setParticleColorMode);
connect( m_msParticleMaterial, &MaterialSelector::materialChanged, m_RenderWidget, &RenderWidget::setParticleMaterial);
connect(m_msParticleMaterial, &MaterialSelector::materialChanged, m_RenderWidget, &RenderWidget::setParticleMaterial);
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -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);
////////////////////////////////////////////////////////////////////////////////
}
Expand Down Expand Up @@ -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<int>(ParticleColorMode::Random));
m_smParticleColorMode->setMapping( rdbColorRamp, static_cast<int>(ParticleColorMode::Ramp));
m_smParticleColorMode->setMapping(rdbColorRandom, static_cast<int>(ParticleColorMode::Random));
m_smParticleColorMode->setMapping(rdbColorRamp, static_cast<int>(ParticleColorMode::Ramp));
m_smParticleColorMode->setMapping(rdbColorUniform, static_cast<int>(ParticleColorMode::UniformMaterial));
m_smParticleColorMode->setMapping( rdbColorObjIdx, static_cast<int>(ParticleColorMode::ObjectIndex));
m_smParticleColorMode->setMapping(rdbColorObjIdx, static_cast<int>(ParticleColorMode::ObjectIndex));
////////////////////////////////////////////////////////////////////////////////
QVBoxLayout* layoutColorCtrls = new QVBoxLayout;
layoutColorCtrls->addLayout(layoutColorMode);
Expand Down Expand Up @@ -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");
Expand All @@ -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" });
Expand Down Expand Up @@ -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" });
Expand Down Expand Up @@ -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);
////////////////////////////////////////////////////////////////////////////////
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions Source/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QWidget*> m_RelaxParamsWidgets;
////////////////////////////////////////////////////////////////////////////////
void setupGUI();
void connectWidgets();
Expand Down
18 changes: 6 additions & 12 deletions Source/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
////////////////////////////////////////////////////////////////////////////////
Expand All @@ -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();
}

Expand All @@ -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, [&]
{
Expand All @@ -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"));
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down

0 comments on commit 9029eaa

Please sign in to comment.