[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[bcf653] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[1cc87e] | 8 | /*
|
---|
| 9 | * AllAtomsInsideSphereAction.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Aug 9, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
[1cc87e] | 21 |
|
---|
| 22 | #include "Descriptors/AtomShapeDescriptor.hpp"
|
---|
[92d756] | 23 | #include "Descriptors/AtomSelectionDescriptor.hpp"
|
---|
[6f0841] | 24 | #include "Atom/atom.hpp"
|
---|
[ad011c] | 25 | #include "CodePatterns/Log.hpp"
|
---|
| 26 | #include "CodePatterns/Verbose.hpp"
|
---|
[1cc87e] | 27 | #include "LinearAlgebra/Vector.hpp"
|
---|
| 28 | #include "Shapes/BaseShapes.hpp"
|
---|
| 29 | #include "Shapes/Shape.hpp"
|
---|
| 30 | #include "Shapes/ShapeOps.hpp"
|
---|
| 31 | #include "World.hpp"
|
---|
| 32 |
|
---|
[92d756] | 33 | #include <boost/foreach.hpp>
|
---|
[1cc87e] | 34 | #include <iostream>
|
---|
| 35 | #include <string>
|
---|
| 36 |
|
---|
[125002] | 37 | #include "AllAtomsInsideSphereAction.hpp"
|
---|
[1cc87e] | 38 |
|
---|
[ce7fdc] | 39 | using namespace MoleCuilder;
|
---|
| 40 |
|
---|
[1fd675] | 41 | // and construct the stuff
|
---|
| 42 | #include "AllAtomsInsideSphereAction.def"
|
---|
| 43 | #include "Action_impl_pre.hpp"
|
---|
| 44 | /** =========== define the function ====================== */
|
---|
[1cc87e] | 45 | Action::state_ptr SelectionAllAtomsInsideSphereAction::performCall() {
|
---|
[f10b0c] | 46 | LOG(1, "Selecting all atoms inside a sphere at " << params.position.get() << " with radius " << params.radius.get() << ".");
|
---|
| 47 | Shape s = translate(resize(Sphere(),params.radius.get()),params.position.get());
|
---|
[d927ab] | 48 | std::vector<atom *> selectedAtoms = World::getInstance().getAllAtoms(AtomsBySelection() && AtomsByShape(s));
|
---|
| 49 | World::getInstance().selectAllAtoms(AtomsByShape(s));
|
---|
[47d041] | 50 | LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected.");
|
---|
[92d756] | 51 | return Action::state_ptr(new SelectionAllAtomsInsideSphereState(selectedAtoms, s, params));
|
---|
[1cc87e] | 52 | }
|
---|
| 53 |
|
---|
| 54 | Action::state_ptr SelectionAllAtomsInsideSphereAction::performUndo(Action::state_ptr _state) {
|
---|
| 55 | SelectionAllAtomsInsideSphereState *state = assert_cast<SelectionAllAtomsInsideSphereState*>(_state.get());
|
---|
| 56 |
|
---|
[d927ab] | 57 | World::getInstance().unselectAllAtoms(AtomsByShape(state->s));
|
---|
[92d756] | 58 | BOOST_FOREACH(atom *_atom, state->selectedAtoms)
|
---|
| 59 | World::getInstance().selectAtom(_atom);
|
---|
[1cc87e] | 60 |
|
---|
[1fd675] | 61 | return Action::state_ptr(_state);
|
---|
[1cc87e] | 62 | }
|
---|
| 63 |
|
---|
| 64 | Action::state_ptr SelectionAllAtomsInsideSphereAction::performRedo(Action::state_ptr _state){
|
---|
| 65 | SelectionAllAtomsInsideSphereState *state = assert_cast<SelectionAllAtomsInsideSphereState*>(_state.get());
|
---|
| 66 |
|
---|
[d927ab] | 67 | World::getInstance().selectAllAtoms(AtomsByShape(state->s));
|
---|
[1cc87e] | 68 |
|
---|
[1fd675] | 69 | return Action::state_ptr(_state);
|
---|
[1cc87e] | 70 | }
|
---|
| 71 |
|
---|
| 72 | bool SelectionAllAtomsInsideSphereAction::canUndo() {
|
---|
| 73 | return true;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | bool SelectionAllAtomsInsideSphereAction::shouldUndo() {
|
---|
| 77 | return true;
|
---|
| 78 | }
|
---|
[1fd675] | 79 | /** =========== end of function ====================== */
|
---|