Skip to content

Commit

Permalink
Merge pull request #1508 from ghutchis/auto-load-mesh-for-surfaces
Browse files Browse the repository at this point in the history
Make sure to automatically load the "Meshes" display type
  • Loading branch information
ghutchis authored Dec 6, 2023
2 parents 3931456 + 0bdf8c4 commit d1f1560
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
7 changes: 2 additions & 5 deletions avogadro/qtplugins/surfaces/surfacedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ void SurfaceDialog::smoothingComboChanged(int n)
m_ui->smoothingPassesSpinBox->setValue(0);
m_ui->smoothingPassesSpinBox->setEnabled(false);
break;
case 1: // Light smoothing
m_ui->smoothingPassesSpinBox->setValue(1);
m_ui->smoothingPassesSpinBox->setEnabled(false);
break;
case 2: // Medium smoothing
m_ui->smoothingPassesSpinBox->setValue(5);
m_ui->smoothingPassesSpinBox->setEnabled(false);
Expand All @@ -136,8 +132,9 @@ void SurfaceDialog::smoothingComboChanged(int n)
m_ui->smoothingPassesSpinBox->setValue(5);
m_ui->smoothingPassesSpinBox->setEnabled(true);
break;
case 1: // Light smoothing
default:
m_ui->smoothingPassesSpinBox->setValue(5);
m_ui->smoothingPassesSpinBox->setValue(1);
m_ui->smoothingPassesSpinBox->setEnabled(false);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions avogadro/qtplugins/surfaces/surfacedialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@
<bool>true</bool>
</property>
<property name="currentText">
<string>Medium</string>
<string>Light</string>
</property>
<property name="currentIndex">
<number>2</number>
<number>1</number>
</property>
<item>
<property name="text">
Expand Down Expand Up @@ -407,7 +407,7 @@
<number>1</number>
</property>
<property name="value">
<number>5</number>
<number>1</number>
</property>
</widget>
</item>
Expand Down
45 changes: 28 additions & 17 deletions avogadro/qtplugins/surfaces/surfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ using namespace tinycolormap;
namespace Avogadro::QtPlugins {

using Core::Array;
using Core::Cube;
using Core::GaussianSet;
using Core::NeighborPerceiver;
using QtGui::Molecule;
Expand Down Expand Up @@ -707,29 +708,36 @@ void Surfaces::displayMesh()
}
m_meshGenerator1->initialize(m_cube, m_mesh1, -m_isoValue, m_smoothingPasses);

// TODO - only do this if we're generating an orbital
// and we need two meshes
// How do we know? - likely ask the cube if it's an MO?
qDebug() << "Cube " << m_cube->name().c_str() << " type "
<< m_cube->cubeType();
bool isMO = false;
// if it's from a file we should "play it safe"
if (m_cube->cubeType() == Cube::Type::MO ||
m_cube->cubeType() == Cube::Type::FromFile) {
isMO = true;
}

if (!m_mesh2)
m_mesh2 = m_molecule->addMesh();
if (!m_meshGenerator2) {
m_meshGenerator2 = new QtGui::MeshGenerator;
connect(m_meshGenerator2, SIGNAL(finished()), SLOT(meshFinished()));
if (isMO) {
if (!m_mesh2)
m_mesh2 = m_molecule->addMesh();
if (!m_meshGenerator2) {
m_meshGenerator2 = new QtGui::MeshGenerator;
connect(m_meshGenerator2, SIGNAL(finished()), SLOT(meshFinished()));
}
m_meshGenerator2->initialize(m_cube, m_mesh2, m_isoValue, m_smoothingPasses,
true);
}
m_meshGenerator2->initialize(m_cube, m_mesh2, m_isoValue, m_smoothingPasses,
true);

// Start the mesh generation - this needs an improved mutex with a read lock
// to function as expected. Write locks are exclusive, read locks can have
// many read locks but no write lock.
m_meshGenerator1->start();
m_meshGenerator2->start();
if (isMO)
m_meshGenerator2->start();

// Track how many meshes are left to show.
m_meshesLeft = 2;
if (isMO)
m_meshesLeft = 2;
else
m_meshesLeft = 1;
}

Core::Color3f Surfaces::chargeGradient(double value, double clamp,
Expand Down Expand Up @@ -825,6 +833,12 @@ void Surfaces::meshFinished()
--m_meshesLeft;
if (m_meshesLeft == 0) {
colorMesh();

// finished, so request to enable the mesh display type
QStringList displayTypes;
displayTypes << tr("Meshes");
requestActiveDisplayTypes(displayTypes);

if (m_recordingMovie) {
// Move to the next frame.
qDebug() << "Let's get to the next frame…";
Expand All @@ -834,12 +848,9 @@ void Surfaces::meshFinished()
if (m_dialog != nullptr)
m_dialog->reenableCalculateButton();

qDebug() << " mesh finished";

m_molecule->emitChanged(QtGui::Molecule::Added);
}
}
// TODO: enable the mesh display type
}

void Surfaces::recordMovie()
Expand Down

0 comments on commit d1f1560

Please sign in to comment.