/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * * * This file is part of MoleCuilder. * * MoleCuilder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MoleCuilder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MoleCuilder. If not, see . */ /* * 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.get() << " with radius " << params.radius.get() << "."); Shape s = translate(resize(Sphere(),params.radius.get()),params.position.get()); 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 ====================== */