diff --git a/avogadro/qtplugins/surfaces/orbitals.cpp b/avogadro/qtplugins/surfaces/orbitals.cpp index 69bfedfb07..058cc3b0ab 100644 --- a/avogadro/qtplugins/surfaces/orbitals.cpp +++ b/avogadro/qtplugins/surfaces/orbitals.cpp @@ -75,7 +75,7 @@ void Orbitals::setMolecule(QtGui::Molecule* mol) // Stuff we manage that will not be valid any longer m_queue.clear(); - // m_currentRunningCalculation = -1; + m_currentRunningCalculation = -1; if (m_basis) { delete m_basis; @@ -105,6 +105,12 @@ void Orbitals::loadOrbitals() if (!m_dialog) { m_dialog = new OrbitalWidget(qobject_cast(parent()), Qt::Window); + connect(m_dialog, SIGNAL(orbitalSelected(unsigned int)), this, + SLOT(renderOrbital(unsigned int))); + connect(m_dialog, SIGNAL(renderRequested(unsigned int, double)), this, + SLOT(calculateOrbitalFromWidget(unsigned int, double))); + connect(m_dialog, SIGNAL(calculateAll()), this, + SLOT(precalculateOrbitals())); } m_dialog->fillTable(m_basis); @@ -129,20 +135,22 @@ void Orbitals::openDialog() { if (!m_dialog) { m_dialog = new OrbitalWidget(qobject_cast(parent()), Qt::Window); + connect(m_dialog, SIGNAL(orbitalSelected(unsigned int)), this, + SLOT(renderOrbital(unsigned int))); + connect(m_dialog, SIGNAL(renderRequested(unsigned int, double)), this, + SLOT(calculateOrbitalFromWidget(unsigned int, double))); + connect(m_dialog, SIGNAL(calculateAll()), this, + SLOT(precalculateOrbitals())); } - connect(m_dialog, SIGNAL(orbitalSelected(unsigned int)), this, - SLOT(renderOrbital(unsigned int))); - connect(m_dialog, SIGNAL(renderRequested(unsigned int, double)), this, - SLOT(calculateOrbitalFromWidget(unsigned int, double))); - connect(m_dialog, SIGNAL(calculateAll()), this, SLOT(precalculateOrbitals())); - m_dialog->show(); + m_dialog->raise(); } void Orbitals::calculateOrbitalFromWidget(unsigned int orbital, double resolution) { + m_updateMesh = true; addCalculationToQueue(orbital, resolution, m_dialog->isovalue(), 0); checkQueue(); } @@ -152,6 +160,8 @@ void Orbitals::precalculateOrbitals() if (m_basis == nullptr) return; + m_updateMesh = false; + // Determine HOMO unsigned int homo = m_basis->homo(); @@ -183,7 +193,7 @@ void Orbitals::precalculateOrbitals() qDebug() << " precalculate " << i << " priority " << priority; #endif addCalculationToQueue( - i + 1, // orbital + i, // orbital OrbitalWidget::OrbitalQualityToDouble(m_dialog->defaultQuality()), m_dialog->isovalue(), priority); @@ -334,7 +344,11 @@ void Orbitals::calculateCubeDone() auto* watcher = &m_gaussianConcurrent->watcher(); watcher->disconnect(this); - calculationComplete(); + + if (m_updateMesh) { + calculatePosMesh(); + } else + calculationComplete(); } void Orbitals::calculatePosMesh() @@ -384,6 +398,8 @@ void Orbitals::calculateNegMeshDone() { disconnect(m_meshGenerator, 0, this, 0); + calculationComplete(); + // ask for a repaint m_molecule->emitChanged(QtGui::Molecule::Added); } @@ -404,9 +420,16 @@ void Orbitals::calculationComplete() checkQueue(); } -void Orbitals::renderOrbital(unsigned int orbital) +void Orbitals::renderOrbital(unsigned int row) { + if (row == 0) + return; + + unsigned int orbital = row - 1; + +#ifndef NDEBUG qDebug() << "Rendering orbital " << orbital; +#endif // Find the most recent calc matching the selected orbital: calcInfo calc; @@ -419,16 +442,18 @@ void Orbitals::renderOrbital(unsigned int orbital) } // calculate the meshes - m_currentRunningCalculation = index; + m_molecule->clearMeshes(); if (index == -1) { - qDebug() << "Orbital not found, or still calculating. Cannot render."; - return; + // need to calculate the cube first + calculateOrbitalFromWidget(orbital, OrbitalWidget::OrbitalQualityToDouble( + m_dialog->defaultQuality())); + } else { + // just need to update the meshes + m_currentRunningCalculation = index; + m_runningMutex->tryLock(); + calculatePosMesh(); // will eventually call negMesh too } - // clear previous meshes from the molecule - m_molecule->clearMeshes(); - calculatePosMesh(); // will eventually call negMesh too - // add the orbital to the renderer QStringList displayTypes; displayTypes << tr("Meshes"); diff --git a/avogadro/qtplugins/surfaces/orbitals.h b/avogadro/qtplugins/surfaces/orbitals.h index 8ea4091a65..7557d9f719 100644 --- a/avogadro/qtplugins/surfaces/orbitals.h +++ b/avogadro/qtplugins/surfaces/orbitals.h @@ -157,6 +157,7 @@ private slots: float m_isoValue = 0.01; int m_smoothingPasses = 1; int m_meshesLeft = 0; + bool m_updateMesh = false; OrbitalWidget* m_dialog = nullptr; // OrbitalSettingsDialog* m_orbitalSettingsDialog = nullptr; diff --git a/avogadro/qtplugins/surfaces/orbitaltablemodel.cpp b/avogadro/qtplugins/surfaces/orbitaltablemodel.cpp index 050a5436c9..e0703657ba 100644 --- a/avogadro/qtplugins/surfaces/orbitaltablemodel.cpp +++ b/avogadro/qtplugins/surfaces/orbitaltablemodel.cpp @@ -95,10 +95,10 @@ QVariant OrbitalTableModel::headerData(int section, Qt::Orientation orientation, return tr("Orbital"); case C_Energy: return tr("Energy (eV)"); - case C_Status: - return tr("Status"); case C_Symmetry: return tr("Symmetry"); + case C_Status: + return tr("Status"); default: case COUNT: return QVariant(); @@ -174,7 +174,6 @@ bool OrbitalTableModel::setOrbitals(const Core::BasisSet* basis) // (HOMO|LUMO)(+|-)[0-9]+ .arg((leqHOMO) ? tr("HOMO", "Highest Occupied MO") + num : tr("LUMO", "Lowest Unoccupied MO") + num); - // qDebug() << desc; Orbital* orb = new Orbital; // Get the energy from the molecule property list, if available @@ -223,41 +222,41 @@ bool OrbitalTableModel::clearOrbitals() void OrbitalTableModel::setOrbitalProgressRange(int orbital, int min, int max, int stage, int totalStages) { - Orbital* orb = m_orbitals[orbital - 1]; + Orbital* orb = m_orbitals[orbital]; orb->min = min; orb->current = min; orb->max = max; orb->stage = stage; orb->totalStages = totalStages; // Update display - QModelIndex status = index(orbital - 1, int(C_Status), QModelIndex()); + QModelIndex status = index(orbital, int(C_Status), QModelIndex()); emit dataChanged(status, status); } void OrbitalTableModel::incrementStage(int orbital, int newmin, int newmax) { - Orbital* orb = m_orbitals[orbital - 1]; + Orbital* orb = m_orbitals[orbital]; orb->stage++; orb->min = newmin; orb->current = newmin; orb->max = newmax; // Update display - QModelIndex status = index(orbital - 1, C_Status, QModelIndex()); + QModelIndex status = index(orbital, C_Status, QModelIndex()); emit dataChanged(status, status); } void OrbitalTableModel::setOrbitalProgressValue(int orbital, int currentValue) { - Orbital* orb = m_orbitals[orbital - 1]; + Orbital* orb = m_orbitals[orbital]; orb->current = currentValue; // Update display - QModelIndex status = index(orbital - 1, C_Status, QModelIndex()); + QModelIndex status = index(orbital, C_Status, QModelIndex()); emit dataChanged(status, status); } void OrbitalTableModel::finishProgress(int orbital) { - Orbital* orb = m_orbitals[orbital - 1]; + Orbital* orb = m_orbitals[orbital]; orb->stage = 1; orb->totalStages = 1; orb->min = 0; @@ -265,13 +264,13 @@ void OrbitalTableModel::finishProgress(int orbital) orb->max = 1; // Update display - QModelIndex status = index(orbital - 1, C_Status, QModelIndex()); + QModelIndex status = index(orbital, C_Status, QModelIndex()); emit dataChanged(status, status); } void OrbitalTableModel::resetProgress(int orbital) { - Orbital* orb = m_orbitals[orbital - 1]; + Orbital* orb = m_orbitals[orbital]; orb->stage = 1; orb->totalStages = 1; orb->min = 0; @@ -279,13 +278,13 @@ void OrbitalTableModel::resetProgress(int orbital) orb->max = 0; // Update display - QModelIndex status = index(orbital - 1, C_Status, QModelIndex()); + QModelIndex status = index(orbital, C_Status, QModelIndex()); emit dataChanged(status, status); } void OrbitalTableModel::setProgressToZero(int orbital) { - Orbital* orb = m_orbitals[orbital - 1]; + Orbital* orb = m_orbitals[orbital]; orb->stage = 1; orb->totalStages = 1; orb->min = 0; @@ -293,7 +292,7 @@ void OrbitalTableModel::setProgressToZero(int orbital) orb->max = 1; // Update display - QModelIndex status = index(orbital - 1, C_Status, QModelIndex()); + QModelIndex status = index(orbital, C_Status, QModelIndex()); emit dataChanged(status, status); } diff --git a/avogadro/qtplugins/surfaces/orbitalwidget.ui b/avogadro/qtplugins/surfaces/orbitalwidget.ui index 1fbadfb578..10fbb45ff9 100644 --- a/avogadro/qtplugins/surfaces/orbitalwidget.ui +++ b/avogadro/qtplugins/surfaces/orbitalwidget.ui @@ -28,12 +28,21 @@ 0 + + Qt::ScrollBarAlwaysOff + QAbstractItemView::SingleSelection QAbstractItemView::SelectRows + + QAbstractItemView::ScrollPerItem + + + true + true