[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 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 |
|
---|
[1cc87e] | 20 | #include "Helpers/MemDebug.hpp"
|
---|
| 21 |
|
---|
| 22 | #include "Actions/SelectionAction/AllAtomsInsideSphereAction.hpp"
|
---|
| 23 | #include "Actions/ActionRegistry.hpp"
|
---|
| 24 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
| 25 | #include "Descriptors/AtomShapeDescriptor.hpp"
|
---|
| 26 | #include "atom.hpp"
|
---|
| 27 | #include "Helpers/Log.hpp"
|
---|
| 28 | #include "Helpers/Verbose.hpp"
|
---|
| 29 | #include "LinearAlgebra/Vector.hpp"
|
---|
| 30 | #include "Shapes/BaseShapes.hpp"
|
---|
| 31 | #include "Shapes/Shape.hpp"
|
---|
| 32 | #include "Shapes/ShapeOps.hpp"
|
---|
| 33 | #include "World.hpp"
|
---|
| 34 |
|
---|
| 35 | #include <iostream>
|
---|
| 36 | #include <string>
|
---|
| 37 |
|
---|
| 38 | using namespace std;
|
---|
| 39 |
|
---|
| 40 | #include "UIElements/UIFactory.hpp"
|
---|
| 41 | #include "UIElements/Dialog.hpp"
|
---|
| 42 | #include "Actions/ValueStorage.hpp"
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | // memento to remember the state when undoing
|
---|
| 46 |
|
---|
| 47 | class SelectionAllAtomsInsideSphereState : public ActionState {
|
---|
| 48 | public:
|
---|
| 49 | SelectionAllAtomsInsideSphereState(std::vector<atom*> _selectedAtoms, const Vector &_position, const double _radius) :
|
---|
| 50 | selectedAtoms(_selectedAtoms),
|
---|
| 51 | position(_position),
|
---|
| 52 | radius(_radius)
|
---|
| 53 | {}
|
---|
| 54 | std::vector<atom*> selectedAtoms;
|
---|
| 55 | Vector position;
|
---|
| 56 | double radius;
|
---|
| 57 | };
|
---|
| 58 |
|
---|
| 59 | const char SelectionAllAtomsInsideSphereAction::NAME[] = "select-atoms-inside-sphere";
|
---|
| 60 |
|
---|
| 61 | SelectionAllAtomsInsideSphereAction::SelectionAllAtomsInsideSphereAction() :
|
---|
| 62 | Action(NAME)
|
---|
| 63 | {}
|
---|
| 64 |
|
---|
| 65 | SelectionAllAtomsInsideSphereAction::~SelectionAllAtomsInsideSphereAction()
|
---|
| 66 | {}
|
---|
| 67 |
|
---|
| 68 | void SelectionAllAtomsInsideSphere(const Vector &position, const double radius) {
|
---|
| 69 | ValueStorage::getInstance().setCurrentValue(SelectionAllAtomsInsideSphereAction::NAME, radius);
|
---|
| 70 | ValueStorage::getInstance().setCurrentValue("position", position);
|
---|
| 71 | ActionRegistry::getInstance().getActionByName(SelectionAllAtomsInsideSphereAction::NAME)->call(Action::NonInteractive);
|
---|
| 72 | };
|
---|
| 73 |
|
---|
[0b2ce9] | 74 | void SelectionAllAtomsInsideSphereAction::getParametersfromValueStorage()
|
---|
| 75 | {};
|
---|
| 76 |
|
---|
[1cc87e] | 77 | Dialog* SelectionAllAtomsInsideSphereAction::fillDialog(Dialog *dialog) {
|
---|
| 78 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
| 79 |
|
---|
| 80 | dialog->queryDouble(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 81 | dialog->queryVector("position", false, ValueStorage::getInstance().getDescription("position"));
|
---|
| 82 |
|
---|
| 83 | return dialog;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | Action::state_ptr SelectionAllAtomsInsideSphereAction::performCall() {
|
---|
| 87 | std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
|
---|
| 88 | double radius = 0.;
|
---|
| 89 | Vector position;
|
---|
| 90 |
|
---|
| 91 | ValueStorage::getInstance().queryCurrentValue(NAME, radius);
|
---|
| 92 | ValueStorage::getInstance().queryCurrentValue("position", position);
|
---|
| 93 |
|
---|
| 94 | DoLog(1) && (Log() << Verbose(1) << "Selecting all atoms inside a sphere at " << position << " with radius " << radius << "." << endl);
|
---|
| 95 | Shape s = translate(resize(Sphere(),radius),position);
|
---|
| 96 | World::getInstance().selectAllAtoms(AtomByShape(s));
|
---|
| 97 | return Action::state_ptr(new SelectionAllAtomsInsideSphereState(selectedAtoms, position, radius));
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | Action::state_ptr SelectionAllAtomsInsideSphereAction::performUndo(Action::state_ptr _state) {
|
---|
| 101 | SelectionAllAtomsInsideSphereState *state = assert_cast<SelectionAllAtomsInsideSphereState*>(_state.get());
|
---|
| 102 |
|
---|
| 103 | World::getInstance().clearAtomSelection();
|
---|
| 104 | for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
|
---|
| 105 | World::getInstance().selectAtom(*iter);
|
---|
| 106 |
|
---|
| 107 | return Action::state_ptr(new SelectionAllAtomsInsideSphereState(state->selectedAtoms, state->position, state->radius));
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | Action::state_ptr SelectionAllAtomsInsideSphereAction::performRedo(Action::state_ptr _state){
|
---|
| 111 | SelectionAllAtomsInsideSphereState *state = assert_cast<SelectionAllAtomsInsideSphereState*>(_state.get());
|
---|
| 112 |
|
---|
| 113 | Shape s = translate(resize(Sphere(),state->radius),state->position);
|
---|
| 114 | World::getInstance().selectAllAtoms(AtomByShape(s));
|
---|
| 115 |
|
---|
| 116 | return Action::state_ptr(new SelectionAllAtomsInsideSphereState(state->selectedAtoms, state->position, state->radius));
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | bool SelectionAllAtomsInsideSphereAction::canUndo() {
|
---|
| 120 | return true;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | bool SelectionAllAtomsInsideSphereAction::shouldUndo() {
|
---|
| 124 | return true;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | const string SelectionAllAtomsInsideSphereAction::getName() {
|
---|
| 128 | return NAME;
|
---|
| 129 | }
|
---|