| [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 | 
 | 
|---|
| [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"
 | 
|---|
| [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){
 | 
|---|
 | 62 |     ELOG(1, "SelectionNotAllAtomsInsideVolumeAction::performCall(): there has to be exactly 1 selected shape.");
 | 
|---|
 | 63 |     return Action::failure;
 | 
|---|
 | 64 |   }
 | 
|---|
 | 65 |   std::vector<atom *> unselectedAtoms = World::getInstance().getAllAtoms((!AtomsBySelection()) && AtomsByShape(*selectedShapes[0]));
 | 
|---|
 | 66 |   World::getInstance().unselectAllAtoms(AtomsByShape(*selectedShapes[0]));
 | 
|---|
| [47d041] | 67 |   LOG(0, World::getInstance().countSelectedAtoms() << " atoms remain selected.");
 | 
|---|
| [b5b01e] | 68 |   return ActionState::ptr(new SelectionNotAllAtomsInsideVolumeState(unselectedAtoms, params));
 | 
|---|
| [1cc87e] | 69 | }
 | 
|---|
 | 70 | 
 | 
|---|
| [b5b01e] | 71 | ActionState::ptr SelectionNotAllAtomsInsideVolumeAction::performUndo(ActionState::ptr _state) {
 | 
|---|
| [eff536] | 72 |   SelectionNotAllAtomsInsideVolumeState *state = assert_cast<SelectionNotAllAtomsInsideVolumeState*>(_state.get());
 | 
|---|
| [1cc87e] | 73 | 
 | 
|---|
| [060c7d] | 74 |   std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
 | 
|---|
 | 75 |   if (selectedShapes.size() != 1)
 | 
|---|
 | 76 |     return Action::failure;
 | 
|---|
 | 77 |   World::getInstance().selectAllAtoms(AtomsByShape(*selectedShapes[0]));
 | 
|---|
| [92d756] | 78 |   BOOST_FOREACH(atom *_atom, state->unselectedAtoms)
 | 
|---|
 | 79 |     World::getInstance().unselectAtom(_atom);
 | 
|---|
| [1cc87e] | 80 | 
 | 
|---|
| [b5b01e] | 81 |   return ActionState::ptr(_state);
 | 
|---|
| [1cc87e] | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
| [b5b01e] | 84 | ActionState::ptr SelectionNotAllAtomsInsideVolumeAction::performRedo(ActionState::ptr _state){
 | 
|---|
| [eff536] | 85 |   //SelectionNotAllAtomsInsideVolumeState *state = assert_cast<SelectionNotAllAtomsInsideVolumeState*>(_state.get());
 | 
|---|
| [1cc87e] | 86 | 
 | 
|---|
| [060c7d] | 87 |   std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
 | 
|---|
 | 88 |   if (selectedShapes.size() != 1)
 | 
|---|
 | 89 |     return Action::failure;
 | 
|---|
 | 90 |   World::getInstance().unselectAllAtoms(AtomsByShape(*selectedShapes[0]));
 | 
|---|
| [1cc87e] | 91 | 
 | 
|---|
| [b5b01e] | 92 |   return ActionState::ptr(_state);
 | 
|---|
| [1cc87e] | 93 | }
 | 
|---|
 | 94 | 
 | 
|---|
| [eff536] | 95 | bool SelectionNotAllAtomsInsideVolumeAction::canUndo() {
 | 
|---|
| [1cc87e] | 96 |   return true;
 | 
|---|
 | 97 | }
 | 
|---|
 | 98 | 
 | 
|---|
| [eff536] | 99 | bool SelectionNotAllAtomsInsideVolumeAction::shouldUndo() {
 | 
|---|
| [1cc87e] | 100 |   return true;
 | 
|---|
 | 101 | }
 | 
|---|
| [1fd675] | 102 | /** =========== end of function ====================== */
 | 
|---|