/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * UndoRedoHelpers.cpp * * Created on: Apr 5, 2012 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "UndoRedoHelpers.hpp" #include #include "Atom/atom.hpp" #include "Descriptors/AtomIdDescriptor.hpp" #include "CodePatterns/Assert.hpp" #include "CodePatterns/Log.hpp" #include "World.hpp" bool MoleCuilder::AddAtomsFromAtomicInfo(std::vector &atoms) { size_t i=0; for (; i &atoms) { BOOST_FOREACH(const AtomicInfo &_atom, atoms) { World::getInstance().destroyAtom(_atom.getId()); } } void MoleCuilder::StoreBondInformationFromAtoms( const std::vector &atoms, std::vector< BondInfo > &bonds) { ASSERT( bonds.empty(), "StoreBondInformationFromAtoms() - give bonds vector is not empty."); bonds.reserve(atoms.size()*4); for (std::vector::const_iterator atomiter = atoms.begin(); atomiter != atoms.end(); ++atomiter) { const BondList & _atom_bonds = (*atomiter)->getListOfBonds(); for(BondList::const_iterator iter = _atom_bonds.begin(); iter != _atom_bonds.end(); ++iter) bonds.push_back( BondInfo(*iter) ); } } bool MoleCuilder::AddBondsFromBondInfo(const std::vector< BondInfo > &bonds) { bool status = true; for(std::vector< BondInfo >::const_iterator iter = bonds.begin(); iter != bonds.end(); ++iter) if (!(*iter).RecreateBond()) status = false; return status; } void MoleCuilder::SetAtomsFromAtomicInfo(std::vector &movedatoms) { BOOST_FOREACH( const AtomicInfo &_atominfo, movedatoms) { const atomId_t id = _atominfo.getId(); atom * const _atom = World::getInstance().getAtom(AtomById(id)); ASSERT( _atom != NULL, "MoleCuilder::SetAtomsFromAtomicInfo() - cannot find atom with id " +toString(id)+" in the world."); _atominfo.setAtom( *_atom ); } } void MoleCuilder::SelectAtomsFromAtomicInfo(std::vector &movedatoms) { BOOST_FOREACH( const AtomicInfo &_atominfo, movedatoms) { const atomId_t id = _atominfo.getId(); World::getInstance().selectAtom(id); } } void MoleCuilder::ResetAtomPosition(const std::vector &movedatoms, const std::vector &MovedToVector) { std::vector::const_iterator positer = MovedToVector.begin(); ASSERT(movedatoms.size() == MovedToVector.size(), "MoleCuilder::ResetAtomPosition() - the number of atoms " +toString(movedatoms.size())+" and the number of positions " +toString(MovedToVector.size())+" is not the same."); BOOST_FOREACH( const AtomicInfo &_atominfo, movedatoms) { const atomId_t id = _atominfo.getId(); atom * const _atom = World::getInstance().getAtom(AtomById(id)); ASSERT( _atom != NULL, "FillSphericalSurfaceAction::performRedo() - cannot find atom with id " +toString(id)+" in the world."); _atom->setPosition( *positer ); ++positer; } }