[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){
|
---|
| 63 | ELOG(1, "SelectionAllAtomsInsideVolumeAction::performCall(): there has to be exactly 1 selected shape.");
|
---|
| 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 | if (selectedShapes.size() != 1)
|
---|
| 77 | return Action::failure;
|
---|
| 78 | World::getInstance().unselectAllAtoms(AtomsByShape(*selectedShapes[0]));
|
---|
[92d756] | 79 | BOOST_FOREACH(atom *_atom, state->selectedAtoms)
|
---|
| 80 | World::getInstance().selectAtom(_atom);
|
---|
[1cc87e] | 81 |
|
---|
[b5b01e] | 82 | return ActionState::ptr(_state);
|
---|
[1cc87e] | 83 | }
|
---|
| 84 |
|
---|
[b5b01e] | 85 | ActionState::ptr SelectionAllAtomsInsideVolumeAction::performRedo(ActionState::ptr _state){
|
---|
[eff536] | 86 | //SelectionAllAtomsInsideVolumeState *state = assert_cast<SelectionAllAtomsInsideVolumeState*>(_state.get());
|
---|
[1cc87e] | 87 |
|
---|
[ff9e5a] | 88 | std::vector<Shape*> selectedShapes = ShapeRegistry::getInstance().getSelectedShapes();
|
---|
| 89 | if (selectedShapes.size() != 1)
|
---|
| 90 | return Action::failure;
|
---|
| 91 | World::getInstance().selectAllAtoms(AtomsByShape(*selectedShapes[0]));
|
---|
[1cc87e] | 92 |
|
---|
[b5b01e] | 93 | return ActionState::ptr(_state);
|
---|
[1cc87e] | 94 | }
|
---|
| 95 |
|
---|
[eff536] | 96 | bool SelectionAllAtomsInsideVolumeAction::canUndo() {
|
---|
[1cc87e] | 97 | return true;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[eff536] | 100 | bool SelectionAllAtomsInsideVolumeAction::shouldUndo() {
|
---|
[1cc87e] | 101 | return true;
|
---|
| 102 | }
|
---|
[1fd675] | 103 | /** =========== end of function ====================== */
|
---|