| [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 | * NotAllAtomsInsideSphereAction.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 |  | 
|---|
| [92d756] | 37 | #include "Descriptors/AtomSelectionDescriptor.hpp" | 
|---|
| [1cc87e] | 38 | #include "Descriptors/AtomShapeDescriptor.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 "NotAllAtomsInsideSphereAction.hpp" | 
|---|
| [1cc87e] | 53 |  | 
|---|
| [ce7fdc] | 54 | using namespace MoleCuilder; | 
|---|
|  | 55 |  | 
|---|
| [1fd675] | 56 | // and construct the stuff | 
|---|
|  | 57 | #include "NotAllAtomsInsideSphereAction.def" | 
|---|
|  | 58 | #include "Action_impl_pre.hpp" | 
|---|
|  | 59 | /** =========== define the function ====================== */ | 
|---|
| [1cc87e] | 60 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performCall() { | 
|---|
| [f10b0c] | 61 | LOG(1, "Unselecting 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 *> unselectedAtoms = World::getInstance().getAllAtoms((!AtomsBySelection()) && AtomsByShape(s)); | 
|---|
|  | 64 | World::getInstance().unselectAllAtoms(AtomsByShape(s)); | 
|---|
| [47d041] | 65 | LOG(0, World::getInstance().countSelectedAtoms() << " atoms remain selected."); | 
|---|
| [92d756] | 66 | return Action::state_ptr(new SelectionNotAllAtomsInsideSphereState(unselectedAtoms, s, params)); | 
|---|
| [1cc87e] | 67 | } | 
|---|
|  | 68 |  | 
|---|
|  | 69 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performUndo(Action::state_ptr _state) { | 
|---|
|  | 70 | SelectionNotAllAtomsInsideSphereState *state = assert_cast<SelectionNotAllAtomsInsideSphereState*>(_state.get()); | 
|---|
|  | 71 |  | 
|---|
| [d927ab] | 72 | World::getInstance().selectAllAtoms(AtomsByShape(state->s)); | 
|---|
| [92d756] | 73 | BOOST_FOREACH(atom *_atom, state->unselectedAtoms) | 
|---|
|  | 74 | World::getInstance().unselectAtom(_atom); | 
|---|
| [1cc87e] | 75 |  | 
|---|
| [1fd675] | 76 | return Action::state_ptr(_state); | 
|---|
| [1cc87e] | 77 | } | 
|---|
|  | 78 |  | 
|---|
|  | 79 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performRedo(Action::state_ptr _state){ | 
|---|
|  | 80 | SelectionNotAllAtomsInsideSphereState *state = assert_cast<SelectionNotAllAtomsInsideSphereState*>(_state.get()); | 
|---|
|  | 81 |  | 
|---|
| [d927ab] | 82 | World::getInstance().unselectAllAtoms(AtomsByShape(state->s)); | 
|---|
| [1cc87e] | 83 |  | 
|---|
| [1fd675] | 84 | return Action::state_ptr(_state); | 
|---|
| [1cc87e] | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 | bool SelectionNotAllAtomsInsideSphereAction::canUndo() { | 
|---|
|  | 88 | return true; | 
|---|
|  | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | bool SelectionNotAllAtomsInsideSphereAction::shouldUndo() { | 
|---|
|  | 92 | return true; | 
|---|
|  | 93 | } | 
|---|
| [1fd675] | 94 | /** =========== end of function ====================== */ | 
|---|