diff --git a/avogadro/qtgui/rwmolecule.cpp b/avogadro/qtgui/rwmolecule.cpp index e4ef088cc..a97f23879 100644 --- a/avogadro/qtgui/rwmolecule.cpp +++ b/avogadro/qtgui/rwmolecule.cpp @@ -22,6 +22,7 @@ #include #include +#include namespace Avogadro { namespace QtGui { @@ -1229,6 +1230,25 @@ bool RWMolecule::symmetrizeCell(double cartTol) return true; } +bool RWMolecule::fillUnitCell(unsigned short hallNumber, double cartTol) +{ + // If there is no unit cell, there is nothing to do + if (!m_molecule.unitCell()) + return false; + + // Make a copy of the molecule to edit so we can store the old one + // The atom positions and numbers of atoms may change + Molecule newMolecule = m_molecule; + + Core::SpaceGroups::fillUnitCell(newMolecule, hallNumber, cartTol); + + Molecule::MoleculeChanges changes = Molecule::Added | Molecule::Atoms; + QString undoText = tr("Fill Unit Cell"); + + modifyMolecule(newMolecule, changes, undoText); + return true; +} + void RWMolecule::emitChanged(unsigned int change) { m_molecule.emitChanged(change); diff --git a/avogadro/qtgui/rwmolecule.h b/avogadro/qtgui/rwmolecule.h index 2d0996a82..178c673b2 100644 --- a/avogadro/qtgui/rwmolecule.h +++ b/avogadro/qtgui/rwmolecule.h @@ -487,6 +487,14 @@ class AVOGADROQTGUI_EXPORT RWMolecule : public QObject */ bool symmetrizeCell(double cartTol = 1e-5); + /** + * Fill unit cell using transforms for the space group. Changes are emitted. + * @param hallNumber The hall number to be used for transforming the cell. + * @param cartTol Cartesian tolerance for symmetrization. + * @return True if the algorithm succeeded, and false if it failed. + */ + bool fillUnitCell(unsigned short hallNumber, double cartTol = 1e-5); + /** * @brief Begin or end an interactive edit. * diff --git a/avogadro/qtplugins/spacegroup/spacegroup.cpp b/avogadro/qtplugins/spacegroup/spacegroup.cpp index 429631723..24c7b3d43 100644 --- a/avogadro/qtplugins/spacegroup/spacegroup.cpp +++ b/avogadro/qtplugins/spacegroup/spacegroup.cpp @@ -319,8 +319,7 @@ void SpaceGroup::fillUnitCell() unsigned short hallNumber = view->currentIndex().row() + 1; - Core::SpaceGroups::fillUnitCell(*m_molecule, hallNumber, m_spgTol); - m_molecule->emitChanged(Molecule::Added | Molecule::Atoms); + m_molecule->undoMolecule()->fillUnitCell(hallNumber, m_spgTol); } void SpaceGroup::setTolerance()