| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [94d5ac6] | 5 |  * 
 | 
|---|
 | 6 |  *
 | 
|---|
 | 7 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 12 |  *    (at your option) any later version.
 | 
|---|
 | 13 |  *
 | 
|---|
 | 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 17 |  *    GNU General Public License for more details.
 | 
|---|
 | 18 |  *
 | 
|---|
 | 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [bcf653] | 21 |  */
 | 
|---|
 | 22 | 
 | 
|---|
| [1cc87e] | 23 | /*
 | 
|---|
 | 24 |  * AllAtomsInsideSphereAction.cpp
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  *  Created on: Aug 9, 2010
 | 
|---|
 | 27 |  *      Author: heber
 | 
|---|
 | 28 |  */
 | 
|---|
 | 29 | 
 | 
|---|
| [bf3817] | 30 | // include config.h
 | 
|---|
 | 31 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 32 | #include <config.h>
 | 
|---|
 | 33 | #endif
 | 
|---|
 | 34 | 
 | 
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [1cc87e] | 36 | 
 | 
|---|
 | 37 | #include "Descriptors/AtomShapeDescriptor.hpp"
 | 
|---|
| [92d756] | 38 | #include "Descriptors/AtomSelectionDescriptor.hpp"
 | 
|---|
| [6f0841] | 39 | #include "Atom/atom.hpp"
 | 
|---|
| [ad011c] | 40 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 41 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [1cc87e] | 42 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 43 | #include "Shapes/BaseShapes.hpp"
 | 
|---|
 | 44 | #include "Shapes/Shape.hpp"
 | 
|---|
 | 45 | #include "Shapes/ShapeOps.hpp"
 | 
|---|
 | 46 | #include "World.hpp"
 | 
|---|
 | 47 | 
 | 
|---|
| [92d756] | 48 | #include <boost/foreach.hpp>
 | 
|---|
| [1cc87e] | 49 | #include <iostream>
 | 
|---|
 | 50 | #include <string>
 | 
|---|
 | 51 | 
 | 
|---|
| [125002] | 52 | #include "AllAtomsInsideSphereAction.hpp"
 | 
|---|
| [1cc87e] | 53 | 
 | 
|---|
| [ce7fdc] | 54 | using namespace MoleCuilder;
 | 
|---|
 | 55 | 
 | 
|---|
| [1fd675] | 56 | // and construct the stuff
 | 
|---|
 | 57 | #include "AllAtomsInsideSphereAction.def"
 | 
|---|
 | 58 | #include "Action_impl_pre.hpp"
 | 
|---|
 | 59 | /** =========== define the function ====================== */
 | 
|---|
| [1cc87e] | 60 | Action::state_ptr SelectionAllAtomsInsideSphereAction::performCall() {
 | 
|---|
| [f10b0c] | 61 |   LOG(1, "Selecting all atoms inside a sphere at " << params.position.get() << " with radius " << params.radius.get() << ".");
 | 
|---|
 | 62 |   Shape s = translate(resize(Sphere(),params.radius.get()),params.position.get());
 | 
|---|
| [d927ab] | 63 |   std::vector<atom *> selectedAtoms = World::getInstance().getAllAtoms(AtomsBySelection() && AtomsByShape(s));
 | 
|---|
 | 64 |   World::getInstance().selectAllAtoms(AtomsByShape(s));
 | 
|---|
| [47d041] | 65 |   LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected.");
 | 
|---|
| [92d756] | 66 |   return Action::state_ptr(new SelectionAllAtomsInsideSphereState(selectedAtoms, s, params));
 | 
|---|
| [1cc87e] | 67 | }
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 | Action::state_ptr SelectionAllAtomsInsideSphereAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 70 |   SelectionAllAtomsInsideSphereState *state = assert_cast<SelectionAllAtomsInsideSphereState*>(_state.get());
 | 
|---|
 | 71 | 
 | 
|---|
| [d927ab] | 72 |   World::getInstance().unselectAllAtoms(AtomsByShape(state->s));
 | 
|---|
| [92d756] | 73 |   BOOST_FOREACH(atom *_atom, state->selectedAtoms)
 | 
|---|
 | 74 |     World::getInstance().selectAtom(_atom);
 | 
|---|
| [1cc87e] | 75 | 
 | 
|---|
| [1fd675] | 76 |   return Action::state_ptr(_state);
 | 
|---|
| [1cc87e] | 77 | }
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 | Action::state_ptr SelectionAllAtomsInsideSphereAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 80 |   SelectionAllAtomsInsideSphereState *state = assert_cast<SelectionAllAtomsInsideSphereState*>(_state.get());
 | 
|---|
 | 81 | 
 | 
|---|
| [d927ab] | 82 |   World::getInstance().selectAllAtoms(AtomsByShape(state->s));
 | 
|---|
| [1cc87e] | 83 | 
 | 
|---|
| [1fd675] | 84 |   return Action::state_ptr(_state);
 | 
|---|
| [1cc87e] | 85 | }
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | bool SelectionAllAtomsInsideSphereAction::canUndo() {
 | 
|---|
 | 88 |   return true;
 | 
|---|
 | 89 | }
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 | bool SelectionAllAtomsInsideSphereAction::shouldUndo() {
 | 
|---|
 | 92 |   return true;
 | 
|---|
 | 93 | }
 | 
|---|
| [1fd675] | 94 | /** =========== end of function ====================== */
 | 
|---|