[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"
|
---|
[eff536] | 43 | #include "Shapes/ShapeFactory.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.");
|
---|
| 60 | Shape s = ShapeFactory::getInstance().produce();
|
---|
[d927ab] | 61 | std::vector<atom *> selectedAtoms = World::getInstance().getAllAtoms(AtomsBySelection() && AtomsByShape(s));
|
---|
| 62 | World::getInstance().selectAllAtoms(AtomsByShape(s));
|
---|
[47d041] | 63 | LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected.");
|
---|
[eff536] | 64 | return Action::state_ptr(new SelectionAllAtomsInsideVolumeState(selectedAtoms, params));
|
---|
[1cc87e] | 65 | }
|
---|
| 66 |
|
---|
[eff536] | 67 | Action::state_ptr SelectionAllAtomsInsideVolumeAction::performUndo(Action::state_ptr _state) {
|
---|
| 68 | SelectionAllAtomsInsideVolumeState *state = assert_cast<SelectionAllAtomsInsideVolumeState*>(_state.get());
|
---|
[1cc87e] | 69 |
|
---|
[eff536] | 70 | Shape s = ShapeFactory::getInstance().produce();
|
---|
| 71 | World::getInstance().unselectAllAtoms(AtomsByShape(s));
|
---|
[92d756] | 72 | BOOST_FOREACH(atom *_atom, state->selectedAtoms)
|
---|
| 73 | World::getInstance().selectAtom(_atom);
|
---|
[1cc87e] | 74 |
|
---|
[1fd675] | 75 | return Action::state_ptr(_state);
|
---|
[1cc87e] | 76 | }
|
---|
| 77 |
|
---|
[eff536] | 78 | Action::state_ptr SelectionAllAtomsInsideVolumeAction::performRedo(Action::state_ptr _state){
|
---|
| 79 | //SelectionAllAtomsInsideVolumeState *state = assert_cast<SelectionAllAtomsInsideVolumeState*>(_state.get());
|
---|
[1cc87e] | 80 |
|
---|
[eff536] | 81 | Shape s = ShapeFactory::getInstance().produce();
|
---|
| 82 | World::getInstance().selectAllAtoms(AtomsByShape(s));
|
---|
[1cc87e] | 83 |
|
---|
[1fd675] | 84 | return Action::state_ptr(_state);
|
---|
[1cc87e] | 85 | }
|
---|
| 86 |
|
---|
[eff536] | 87 | bool SelectionAllAtomsInsideVolumeAction::canUndo() {
|
---|
[1cc87e] | 88 | return true;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[eff536] | 91 | bool SelectionAllAtomsInsideVolumeAction::shouldUndo() {
|
---|
[1cc87e] | 92 | return true;
|
---|
| 93 | }
|
---|
[1fd675] | 94 | /** =========== end of function ====================== */
|
---|