/* * 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. */ /* * AllAtomsInsideSphereAction.cpp * * Created on: Aug 9, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Descriptors/AtomShapeDescriptor.hpp" #include "Descriptors/AtomSelectionDescriptor.hpp" #include "Atom/atom.hpp" #include "CodePatterns/Log.hpp" #include "CodePatterns/Verbose.hpp" #include "LinearAlgebra/Vector.hpp" #include "Shapes/BaseShapes.hpp" #include "Shapes/Shape.hpp" #include "Shapes/ShapeOps.hpp" #include "World.hpp" #include #include #include #include "AllAtomsInsideSphereAction.hpp" using namespace MoleCuilder; // and construct the stuff #include "AllAtomsInsideSphereAction.def" #include "Action_impl_pre.hpp" /** =========== define the function ====================== */ Action::state_ptr SelectionAllAtomsInsideSphereAction::performCall() { LOG(1, "Selecting all atoms inside a sphere at " << params.position << " with radius " << params.radius << "."); Shape s = translate(resize(Sphere(),params.radius),params.position); std::vector selectedAtoms = World::getInstance().getAllAtoms(AtomsBySelection() && AtomsByShape(s)); World::getInstance().selectAllAtoms(AtomsByShape(s)); LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected."); return Action::state_ptr(new SelectionAllAtomsInsideSphereState(selectedAtoms, s, params)); } Action::state_ptr SelectionAllAtomsInsideSphereAction::performUndo(Action::state_ptr _state) { SelectionAllAtomsInsideSphereState *state = assert_cast(_state.get()); World::getInstance().unselectAllAtoms(AtomsByShape(state->s)); BOOST_FOREACH(atom *_atom, state->selectedAtoms) World::getInstance().selectAtom(_atom); return Action::state_ptr(_state); } Action::state_ptr SelectionAllAtomsInsideSphereAction::performRedo(Action::state_ptr _state){ SelectionAllAtomsInsideSphereState *state = assert_cast(_state.get()); World::getInstance().selectAllAtoms(AtomsByShape(state->s)); return Action::state_ptr(_state); } bool SelectionAllAtomsInsideSphereAction::canUndo() { return true; } bool SelectionAllAtomsInsideSphereAction::shouldUndo() { return true; } /** =========== end of function ====================== */