| [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 | * NotAllAtomsInsideVolumeAction.cpp | 
|---|
| [1cc87e] | 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 |  | 
|---|
| [9eb71b3] | 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" | 
|---|
| [060c7d] | 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 "NotAllAtomsInsideVolumeAction.hpp" | 
|---|
| [1cc87e] | 51 |  | 
|---|
| [ce7fdc] | 52 | using namespace MoleCuilder; | 
|---|
|  | 53 |  | 
|---|
| [1fd675] | 54 | // and construct the stuff | 
|---|
| [eff536] | 55 | #include "NotAllAtomsInsideVolumeAction.def" | 
|---|
| [1fd675] | 56 | #include "Action_impl_pre.hpp" | 
|---|
|  | 57 | /** =========== define the function ====================== */ | 
|---|
| [b5b01e] | 58 | ActionState::ptr SelectionNotAllAtomsInsideVolumeAction::performCall() { | 
|---|
| [eff536] | 59 | LOG(1, "Unselecting all atoms inside a volume."); | 
|---|
| [060c7d] | 60 | std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes(); | 
|---|
|  | 61 | if (selectedShapes.size() != 1){ | 
|---|
| [26b4d62] | 62 | STATUS("There has to be exactly 1 selected shape."); | 
|---|
| [060c7d] | 63 | return Action::failure; | 
|---|
|  | 64 | } | 
|---|
| [a58c16] | 65 | std::vector<const atom *> unselectedAtoms = const_cast<const World &>(World::getInstance()). | 
|---|
|  | 66 | getAllAtoms((!AtomsBySelection()) && AtomsByShape(*selectedShapes[0])); | 
|---|
| [060c7d] | 67 | World::getInstance().unselectAllAtoms(AtomsByShape(*selectedShapes[0])); | 
|---|
| [47d041] | 68 | LOG(0, World::getInstance().countSelectedAtoms() << " atoms remain selected."); | 
|---|
| [b5b01e] | 69 | return ActionState::ptr(new SelectionNotAllAtomsInsideVolumeState(unselectedAtoms, params)); | 
|---|
| [1cc87e] | 70 | } | 
|---|
|  | 71 |  | 
|---|
| [b5b01e] | 72 | ActionState::ptr SelectionNotAllAtomsInsideVolumeAction::performUndo(ActionState::ptr _state) { | 
|---|
| [eff536] | 73 | SelectionNotAllAtomsInsideVolumeState *state = assert_cast<SelectionNotAllAtomsInsideVolumeState*>(_state.get()); | 
|---|
| [1cc87e] | 74 |  | 
|---|
| [060c7d] | 75 | std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes(); | 
|---|
|  | 76 | World::getInstance().selectAllAtoms(AtomsByShape(*selectedShapes[0])); | 
|---|
| [a58c16] | 77 | BOOST_FOREACH(const atom *_atom, state->unselectedAtoms) | 
|---|
| [92d756] | 78 | World::getInstance().unselectAtom(_atom); | 
|---|
| [1cc87e] | 79 |  | 
|---|
| [b5b01e] | 80 | return ActionState::ptr(_state); | 
|---|
| [1cc87e] | 81 | } | 
|---|
|  | 82 |  | 
|---|
| [b5b01e] | 83 | ActionState::ptr SelectionNotAllAtomsInsideVolumeAction::performRedo(ActionState::ptr _state){ | 
|---|
| [eff536] | 84 | //SelectionNotAllAtomsInsideVolumeState *state = assert_cast<SelectionNotAllAtomsInsideVolumeState*>(_state.get()); | 
|---|
| [1cc87e] | 85 |  | 
|---|
| [060c7d] | 86 | std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes(); | 
|---|
|  | 87 | World::getInstance().unselectAllAtoms(AtomsByShape(*selectedShapes[0])); | 
|---|
| [1cc87e] | 88 |  | 
|---|
| [b5b01e] | 89 | return ActionState::ptr(_state); | 
|---|
| [1cc87e] | 90 | } | 
|---|
|  | 91 |  | 
|---|
| [eff536] | 92 | bool SelectionNotAllAtomsInsideVolumeAction::canUndo() { | 
|---|
| [1cc87e] | 93 | return true; | 
|---|
|  | 94 | } | 
|---|
|  | 95 |  | 
|---|
| [eff536] | 96 | bool SelectionNotAllAtomsInsideVolumeAction::shouldUndo() { | 
|---|
| [1cc87e] | 97 | return true; | 
|---|
|  | 98 | } | 
|---|
| [1fd675] | 99 | /** =========== end of function ====================== */ | 
|---|