| [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 | /* | 
|---|
| [eff536] | 24 | * AllAtomsInsideVolumeAction.cpp | 
|---|
| [1cc87e] | 25 | * | 
|---|
|  | 26 | *  Created on: Aug 9, 2010 | 
|---|
| [eff536] | 27 | *      Author: heber, ankele | 
|---|
| [1cc87e] | 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" | 
|---|
| [ff9e5a] | 43 | #include "Shapes/ShapeRegistry.hpp" | 
|---|
| [1cc87e] | 44 | #include "World.hpp" | 
|---|
|  | 45 |  | 
|---|
| [92d756] | 46 | #include <boost/foreach.hpp> | 
|---|
| [1cc87e] | 47 | #include <iostream> | 
|---|
|  | 48 | #include <string> | 
|---|
|  | 49 |  | 
|---|
| [eff536] | 50 | #include "AllAtomsInsideVolumeAction.hpp" | 
|---|
| [1cc87e] | 51 |  | 
|---|
| [ce7fdc] | 52 | using namespace MoleCuilder; | 
|---|
|  | 53 |  | 
|---|
| [1fd675] | 54 | // and construct the stuff | 
|---|
| [eff536] | 55 | #include "AllAtomsInsideVolumeAction.def" | 
|---|
| [1fd675] | 56 | #include "Action_impl_pre.hpp" | 
|---|
|  | 57 | /** =========== define the function ====================== */ | 
|---|
| [eff536] | 58 | Action::state_ptr SelectionAllAtomsInsideVolumeAction::performCall() { | 
|---|
|  | 59 | LOG(1, "Selecting all atoms inside a volume."); | 
|---|
| [ff9e5a] | 60 | std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes(); | 
|---|
|  | 61 | if (selectedShapes.size() != 1){ | 
|---|
|  | 62 | ELOG(1, "SelectionAllAtomsInsideVolumeAction::performCall(): there has to be exactly 1 selected shape."); | 
|---|
|  | 63 | return Action::failure; | 
|---|
|  | 64 | } | 
|---|
|  | 65 | std::vector<atom *> selectedAtoms = World::getInstance().getAllAtoms(AtomsBySelection() && AtomsByShape(*selectedShapes[0])); | 
|---|
|  | 66 | World::getInstance().selectAllAtoms(AtomsByShape(*selectedShapes[0])); | 
|---|
| [47d041] | 67 | LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected."); | 
|---|
| [eff536] | 68 | return Action::state_ptr(new SelectionAllAtomsInsideVolumeState(selectedAtoms, params)); | 
|---|
| [1cc87e] | 69 | } | 
|---|
|  | 70 |  | 
|---|
| [eff536] | 71 | Action::state_ptr SelectionAllAtomsInsideVolumeAction::performUndo(Action::state_ptr _state) { | 
|---|
|  | 72 | SelectionAllAtomsInsideVolumeState *state = assert_cast<SelectionAllAtomsInsideVolumeState*>(_state.get()); | 
|---|
| [1cc87e] | 73 |  | 
|---|
| [ff9e5a] | 74 | std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes(); | 
|---|
|  | 75 | if (selectedShapes.size() != 1) | 
|---|
|  | 76 | return Action::failure; | 
|---|
|  | 77 | World::getInstance().unselectAllAtoms(AtomsByShape(*selectedShapes[0])); | 
|---|
| [92d756] | 78 | BOOST_FOREACH(atom *_atom, state->selectedAtoms) | 
|---|
|  | 79 | World::getInstance().selectAtom(_atom); | 
|---|
| [1cc87e] | 80 |  | 
|---|
| [1fd675] | 81 | return Action::state_ptr(_state); | 
|---|
| [1cc87e] | 82 | } | 
|---|
|  | 83 |  | 
|---|
| [eff536] | 84 | Action::state_ptr SelectionAllAtomsInsideVolumeAction::performRedo(Action::state_ptr _state){ | 
|---|
|  | 85 | //SelectionAllAtomsInsideVolumeState *state = assert_cast<SelectionAllAtomsInsideVolumeState*>(_state.get()); | 
|---|
| [1cc87e] | 86 |  | 
|---|
| [ff9e5a] | 87 | std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes(); | 
|---|
|  | 88 | if (selectedShapes.size() != 1) | 
|---|
|  | 89 | return Action::failure; | 
|---|
|  | 90 | World::getInstance().selectAllAtoms(AtomsByShape(*selectedShapes[0])); | 
|---|
| [1cc87e] | 91 |  | 
|---|
| [1fd675] | 92 | return Action::state_ptr(_state); | 
|---|
| [1cc87e] | 93 | } | 
|---|
|  | 94 |  | 
|---|
| [eff536] | 95 | bool SelectionAllAtomsInsideVolumeAction::canUndo() { | 
|---|
| [1cc87e] | 96 | return true; | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
| [eff536] | 99 | bool SelectionAllAtomsInsideVolumeAction::shouldUndo() { | 
|---|
| [1cc87e] | 100 | return true; | 
|---|
|  | 101 | } | 
|---|
| [1fd675] | 102 | /** =========== end of function ====================== */ | 
|---|