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