| [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 | /*
 | 
|---|
 | 24 |  * AllAtomsInsideCuboidAction.cpp
 | 
|---|
 | 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 | 
 | 
|---|
 | 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"
 | 
|---|
| [cca9ef] | 42 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| [1cc87e] | 43 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 44 | #include "Shapes/BaseShapes.hpp"
 | 
|---|
 | 45 | #include "Shapes/Shape.hpp"
 | 
|---|
 | 46 | #include "Shapes/ShapeOps.hpp"
 | 
|---|
 | 47 | #include "World.hpp"
 | 
|---|
 | 48 | 
 | 
|---|
| [92d756] | 49 | #include <boost/foreach.hpp>
 | 
|---|
| [1cc87e] | 50 | #include <iostream>
 | 
|---|
 | 51 | #include <string>
 | 
|---|
 | 52 | 
 | 
|---|
| [125002] | 53 | #include "AllAtomsInsideCuboidAction.hpp"
 | 
|---|
| [1cc87e] | 54 | 
 | 
|---|
| [ce7fdc] | 55 | using namespace MoleCuilder;
 | 
|---|
 | 56 | 
 | 
|---|
| [1fd675] | 57 | // and construct the stuff
 | 
|---|
 | 58 | #include "AllAtomsInsideCuboidAction.def"
 | 
|---|
 | 59 | #include "Action_impl_pre.hpp"
 | 
|---|
 | 60 | /** =========== define the function ====================== */
 | 
|---|
| [1cc87e] | 61 | Action::state_ptr SelectionAllAtomsInsideCuboidAction::performCall() {
 | 
|---|
| [cca9ef] | 62 |   RealSpaceMatrix RotationMatrix;
 | 
|---|
| [1cc87e] | 63 | 
 | 
|---|
| [f10b0c] | 64 |   RotationMatrix.setRotation(params.Xangle.get(), params.Yangle.get(), params.Zangle.get());
 | 
|---|
| [1fd675] | 65 | 
 | 
|---|
| [f10b0c] | 66 |   LOG(1, "Selecting all atoms inside a rotated " << RotationMatrix << " cuboid at " << params.position.get() << " and extension of " << params.extension.get() << ".");
 | 
|---|
 | 67 |   Shape s = translate(transform(stretch(Cuboid(),params.extension.get()),RotationMatrix),params.position.get());
 | 
|---|
| [d927ab] | 68 |   std::vector<atom *> selectedAtoms = World::getInstance().getAllAtoms(AtomsBySelection() && AtomsByShape(s));
 | 
|---|
 | 69 |   World::getInstance().selectAllAtoms(AtomsByShape(s));
 | 
|---|
| [47d041] | 70 |   LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected.");
 | 
|---|
| [92d756] | 71 |   return Action::state_ptr(new SelectionAllAtomsInsideCuboidState(selectedAtoms, s, params));
 | 
|---|
| [1cc87e] | 72 | }
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 | Action::state_ptr SelectionAllAtomsInsideCuboidAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 75 |   SelectionAllAtomsInsideCuboidState *state = assert_cast<SelectionAllAtomsInsideCuboidState*>(_state.get());
 | 
|---|
 | 76 | 
 | 
|---|
| [d927ab] | 77 |   World::getInstance().unselectAllAtoms(AtomsByShape(state->s));
 | 
|---|
| [92d756] | 78 |   BOOST_FOREACH(atom *_atom, state->selectedAtoms)
 | 
|---|
 | 79 |     World::getInstance().selectAtom(_atom);
 | 
|---|
| [1cc87e] | 80 | 
 | 
|---|
| [31fb1d] | 81 |   return Action::state_ptr(_state);
 | 
|---|
| [1cc87e] | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | Action::state_ptr SelectionAllAtomsInsideCuboidAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 85 |   SelectionAllAtomsInsideCuboidState *state = assert_cast<SelectionAllAtomsInsideCuboidState*>(_state.get());
 | 
|---|
| [cca9ef] | 86 |   RealSpaceMatrix RotationMatrix;
 | 
|---|
| [1cc87e] | 87 | 
 | 
|---|
| [d927ab] | 88 |   World::getInstance().selectAllAtoms(AtomsByShape(state->s));
 | 
|---|
| [1cc87e] | 89 | 
 | 
|---|
| [31fb1d] | 90 |   return Action::state_ptr(_state);
 | 
|---|
| [1cc87e] | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | bool SelectionAllAtomsInsideCuboidAction::canUndo() {
 | 
|---|
 | 94 |   return true;
 | 
|---|
 | 95 | }
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | bool SelectionAllAtomsInsideCuboidAction::shouldUndo() {
 | 
|---|
 | 98 |   return true;
 | 
|---|
 | 99 | }
 | 
|---|
| [1fd675] | 100 | /** =========== end of function ====================== */
 | 
|---|