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 |
|
---|
8 | /*
|
---|
9 | * NotAllAtomsInsideSphereAction.cpp
|
---|
10 | *
|
---|
11 | * Created on: Aug 9, 2010
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "Helpers/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "Actions/SelectionAction/NotAllAtomsInsideSphereAction.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 SelectionNotAllAtomsInsideSphereState : public ActionState {
|
---|
48 | public:
|
---|
49 | SelectionNotAllAtomsInsideSphereState(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 SelectionNotAllAtomsInsideSphereAction::NAME[] = "unselect-atoms-inside-sphere";
|
---|
60 |
|
---|
61 | SelectionNotAllAtomsInsideSphereAction::SelectionNotAllAtomsInsideSphereAction() :
|
---|
62 | Action(NAME)
|
---|
63 | {}
|
---|
64 |
|
---|
65 | SelectionNotAllAtomsInsideSphereAction::~SelectionNotAllAtomsInsideSphereAction()
|
---|
66 | {}
|
---|
67 |
|
---|
68 | void SelectionNotAllAtomsInsideSphere(const Vector &position, const double radius) {
|
---|
69 | ValueStorage::getInstance().setCurrentValue(SelectionNotAllAtomsInsideSphereAction::NAME, radius);
|
---|
70 | ValueStorage::getInstance().setCurrentValue("position", position);
|
---|
71 | ActionRegistry::getInstance().getActionByName(SelectionNotAllAtomsInsideSphereAction::NAME)->call(Action::NonInteractive);
|
---|
72 | };
|
---|
73 |
|
---|
74 | void SelectionNotAllAtomsInsideSphereAction::getParametersfromValueStorage()
|
---|
75 | {};
|
---|
76 |
|
---|
77 | Dialog* SelectionNotAllAtomsInsideSphereAction::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 SelectionNotAllAtomsInsideSphereAction::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) << "Unselecting all atoms inside a sphere at " << position << " with radius " << radius << "." << endl);
|
---|
95 | Shape s = translate(resize(Sphere(),radius),position);
|
---|
96 | World::getInstance().unselectAllAtoms(AtomByShape(s));
|
---|
97 | return Action::state_ptr(new SelectionNotAllAtomsInsideSphereState(selectedAtoms, position, radius));
|
---|
98 | }
|
---|
99 |
|
---|
100 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performUndo(Action::state_ptr _state) {
|
---|
101 | SelectionNotAllAtomsInsideSphereState *state = assert_cast<SelectionNotAllAtomsInsideSphereState*>(_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 SelectionNotAllAtomsInsideSphereState(state->selectedAtoms, state->position, state->radius));
|
---|
108 | }
|
---|
109 |
|
---|
110 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performRedo(Action::state_ptr _state){
|
---|
111 | SelectionNotAllAtomsInsideSphereState *state = assert_cast<SelectionNotAllAtomsInsideSphereState*>(_state.get());
|
---|
112 |
|
---|
113 | Shape s = translate(resize(Sphere(),state->radius),state->position);
|
---|
114 | World::getInstance().unselectAllAtoms(AtomByShape(s));
|
---|
115 |
|
---|
116 | return Action::state_ptr(new SelectionNotAllAtomsInsideSphereState(state->selectedAtoms, state->position, state->radius));
|
---|
117 | }
|
---|
118 |
|
---|
119 | bool SelectionNotAllAtomsInsideSphereAction::canUndo() {
|
---|
120 | return true;
|
---|
121 | }
|
---|
122 |
|
---|
123 | bool SelectionNotAllAtomsInsideSphereAction::shouldUndo() {
|
---|
124 | return true;
|
---|
125 | }
|
---|
126 |
|
---|
127 | const string SelectionNotAllAtomsInsideSphereAction::getName() {
|
---|
128 | return NAME;
|
---|
129 | }
|
---|