Skip to content

Commit

Permalink
Added undo commands for fillUnitCell()
Browse files Browse the repository at this point in the history
  • Loading branch information
psavery committed Jul 15, 2016
1 parent b9b8bb7 commit e072c15
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
20 changes: 20 additions & 0 deletions avogadro/qtgui/rwmolecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cassert>

#include <avogadro/core/avospglib.h>
#include <avogadro/core/spacegroups.h>

namespace Avogadro {
namespace QtGui {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions avogadro/qtgui/rwmolecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 1 addition & 2 deletions avogadro/qtplugins/spacegroup/spacegroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e072c15

Please sign in to comment.