/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * CopyAction.cpp * * Created on: May 10, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Actions/UndoRedoHelpers.hpp" #include "CodePatterns/Log.hpp" #include "CodePatterns/Verbose.hpp" #include "LinearAlgebra/Vector.hpp" #include "Atom/atom.hpp" #include "Bond/bond.hpp" #include "molecule.hpp" #include "World.hpp" #include #include #include #include #include "Actions/MoleculeAction/CopyAction.hpp" using namespace MoleCuilder; // and construct the stuff #include "CopyAction.def" #include "Action_impl_pre.hpp" /** =========== define the function ====================== */ Action::state_ptr MoleculeCopyAction::performCall() { std::vector molecules; for (World::MoleculeSelectionConstIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) { molecule * const copy = (iter->second)->CopyMolecule(); Vector *Center = (iter->second)->DetermineCenterOfAll(); *Center *= -1.; *Center += params.position.get(); copy->Translate(Center); delete(Center); molecules.push_back(copy->getId()); } return Action::state_ptr(new MoleculeCopyState(molecules,params)); } Action::state_ptr MoleculeCopyAction::performUndo(Action::state_ptr _state) { MoleculeCopyState *state = assert_cast(_state.get()); RemoveMoleculesWithAtomsByIds(state->copies); return Action::state_ptr(_state); } Action::state_ptr MoleculeCopyAction::performRedo(Action::state_ptr _state){ return performCall(); } bool MoleculeCopyAction::canUndo() { return true; } bool MoleculeCopyAction::shouldUndo() { return true; } /** =========== end of function ====================== */