| [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 |   }
 | 
|---|
| [4f54b3] | 66 |   std::vector<atom *> selectedAtoms = World::getInstance().getAllAtoms(AtomsBySelection());
 | 
|---|
| [ff9e5a] | 67 |   World::getInstance().selectAllAtoms(AtomsByShape(*selectedShapes[0]));
 | 
|---|
| [47d041] | 68 |   LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected.");
 | 
|---|
| [b5b01e] | 69 |   return ActionState::ptr(new SelectionAllAtomsInsideVolumeState(selectedAtoms, params));
 | 
|---|
| [1cc87e] | 70 | }
 | 
|---|
 | 71 | 
 | 
|---|
| [b5b01e] | 72 | ActionState::ptr SelectionAllAtomsInsideVolumeAction::performUndo(ActionState::ptr _state) {
 | 
|---|
| [eff536] | 73 |   SelectionAllAtomsInsideVolumeState *state = assert_cast<SelectionAllAtomsInsideVolumeState*>(_state.get());
 | 
|---|
| [1cc87e] | 74 | 
 | 
|---|
| [ff9e5a] | 75 |   std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
 | 
|---|
 | 76 |   World::getInstance().unselectAllAtoms(AtomsByShape(*selectedShapes[0]));
 | 
|---|
| [92d756] | 77 |   BOOST_FOREACH(atom *_atom, state->selectedAtoms)
 | 
|---|
 | 78 |     World::getInstance().selectAtom(_atom);
 | 
|---|
| [1cc87e] | 79 | 
 | 
|---|
| [b5b01e] | 80 |   return ActionState::ptr(_state);
 | 
|---|
| [1cc87e] | 81 | }
 | 
|---|
 | 82 | 
 | 
|---|
| [b5b01e] | 83 | ActionState::ptr SelectionAllAtomsInsideVolumeAction::performRedo(ActionState::ptr _state){
 | 
|---|
| [eff536] | 84 |   //SelectionAllAtomsInsideVolumeState *state = assert_cast<SelectionAllAtomsInsideVolumeState*>(_state.get());
 | 
|---|
| [1cc87e] | 85 | 
 | 
|---|
| [ff9e5a] | 86 |   std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
 | 
|---|
 | 87 |   World::getInstance().selectAllAtoms(AtomsByShape(*selectedShapes[0]));
 | 
|---|
| [1cc87e] | 88 | 
 | 
|---|
| [b5b01e] | 89 |   return ActionState::ptr(_state);
 | 
|---|
| [1cc87e] | 90 | }
 | 
|---|
 | 91 | 
 | 
|---|
| [eff536] | 92 | bool SelectionAllAtomsInsideVolumeAction::canUndo() {
 | 
|---|
| [1cc87e] | 93 |   return true;
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
| [eff536] | 96 | bool SelectionAllAtomsInsideVolumeAction::shouldUndo() {
 | 
|---|
| [1cc87e] | 97 |   return true;
 | 
|---|
 | 98 | }
 | 
|---|
| [1fd675] | 99 | /** =========== end of function ====================== */
 | 
|---|