1 | /*
|
---|
2 | * NotAllAtomsInsideCuboidAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: Aug 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | // include config.h
|
---|
9 | #ifdef HAVE_CONFIG_H
|
---|
10 | #include <config.h>
|
---|
11 | #endif
|
---|
12 |
|
---|
13 | #include "Helpers/MemDebug.hpp"
|
---|
14 |
|
---|
15 | #include "Actions/SelectionAction/NotAllAtomsInsideCuboidAction.hpp"
|
---|
16 | #include "Actions/ActionRegistry.hpp"
|
---|
17 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
18 | #include "Descriptors/AtomShapeDescriptor.hpp"
|
---|
19 | #include "atom.hpp"
|
---|
20 | #include "Helpers/Log.hpp"
|
---|
21 | #include "Helpers/Verbose.hpp"
|
---|
22 | #include "LinearAlgebra/Matrix.hpp"
|
---|
23 | #include "LinearAlgebra/Vector.hpp"
|
---|
24 | #include "Shapes/BaseShapes.hpp"
|
---|
25 | #include "Shapes/Shape.hpp"
|
---|
26 | #include "Shapes/ShapeOps.hpp"
|
---|
27 | #include "World.hpp"
|
---|
28 |
|
---|
29 | #include <iostream>
|
---|
30 | #include <string>
|
---|
31 |
|
---|
32 | using namespace std;
|
---|
33 |
|
---|
34 | #include "UIElements/UIFactory.hpp"
|
---|
35 | #include "UIElements/Dialog.hpp"
|
---|
36 | #include "Actions/ValueStorage.hpp"
|
---|
37 |
|
---|
38 |
|
---|
39 | // memento to remember the state when undoing
|
---|
40 |
|
---|
41 | class SelectionNotAllAtomsInsideCuboidState : public ActionState {
|
---|
42 | public:
|
---|
43 | SelectionNotAllAtomsInsideCuboidState(std::vector<atom*> _selectedAtoms, const Vector &_position, const Vector &_extension, const double _Xangle, const double _Yangle, const double _Zangle) :
|
---|
44 | selectedAtoms(_selectedAtoms),
|
---|
45 | position(_position),
|
---|
46 | extension(_extension),
|
---|
47 | Xangle(_Xangle),
|
---|
48 | Yangle(_Yangle),
|
---|
49 | Zangle(_Zangle)
|
---|
50 | {}
|
---|
51 | std::vector<atom*> selectedAtoms;
|
---|
52 | Vector position;
|
---|
53 | Vector extension;
|
---|
54 | double Xangle;
|
---|
55 | double Yangle;
|
---|
56 | double Zangle;
|
---|
57 | };
|
---|
58 |
|
---|
59 | const char SelectionNotAllAtomsInsideCuboidAction::NAME[] = "unselect-atoms-inside-cuboid";
|
---|
60 |
|
---|
61 | SelectionNotAllAtomsInsideCuboidAction::SelectionNotAllAtomsInsideCuboidAction() :
|
---|
62 | Action(NAME)
|
---|
63 | {}
|
---|
64 |
|
---|
65 | SelectionNotAllAtomsInsideCuboidAction::~SelectionNotAllAtomsInsideCuboidAction()
|
---|
66 | {}
|
---|
67 |
|
---|
68 | void SelectionNotAllAtomsInsideCuboid(const Vector &position, const Vector &extension) {
|
---|
69 | ValueStorage::getInstance().setCurrentValue(SelectionNotAllAtomsInsideCuboidAction::NAME, extension);
|
---|
70 | ValueStorage::getInstance().setCurrentValue("position", position);
|
---|
71 | ActionRegistry::getInstance().getActionByName(SelectionNotAllAtomsInsideCuboidAction::NAME)->call(Action::NonInteractive);
|
---|
72 | };
|
---|
73 |
|
---|
74 | void SelectionNotAllAtomsInsideCuboid(const Vector &position, const Vector &extension, const double Xangle, const double Yangle, const double Zangle) {
|
---|
75 | ValueStorage::getInstance().setCurrentValue(SelectionNotAllAtomsInsideCuboidAction::NAME, extension);
|
---|
76 | ValueStorage::getInstance().setCurrentValue("position", position);
|
---|
77 | ValueStorage::getInstance().setCurrentValue("angle-x", Xangle);
|
---|
78 | ValueStorage::getInstance().setCurrentValue("angle-y", Yangle);
|
---|
79 | ValueStorage::getInstance().setCurrentValue("angle-z", Zangle);
|
---|
80 | ActionRegistry::getInstance().getActionByName(SelectionNotAllAtomsInsideCuboidAction::NAME)->call(Action::NonInteractive);
|
---|
81 | };
|
---|
82 |
|
---|
83 | Dialog* SelectionNotAllAtomsInsideCuboidAction::fillDialog(Dialog *dialog) {
|
---|
84 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
85 |
|
---|
86 | dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
|
---|
87 | dialog->queryVector("position", false, ValueStorage::getInstance().getDescription("position"));
|
---|
88 |
|
---|
89 | return dialog;
|
---|
90 | }
|
---|
91 |
|
---|
92 | Action::state_ptr SelectionNotAllAtomsInsideCuboidAction::performCall() {
|
---|
93 | std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
|
---|
94 | Vector position;
|
---|
95 | Vector extension;
|
---|
96 | double Xangle = 0.;
|
---|
97 | double Yangle = 0.;
|
---|
98 | double Zangle = 0.;
|
---|
99 | Matrix RotationMatrix;
|
---|
100 |
|
---|
101 | ValueStorage::getInstance().queryCurrentValue("position", position);
|
---|
102 | ValueStorage::getInstance().queryCurrentValue(NAME, extension);
|
---|
103 | // check whether a rotation is given.
|
---|
104 | if (ValueStorage::getInstance().queryCurrentValue("angle-x", Xangle, true))
|
---|
105 | Xangle = 0.;
|
---|
106 | if (ValueStorage::getInstance().queryCurrentValue("angle-y", Yangle, true))
|
---|
107 | Yangle = 0.;
|
---|
108 | if (ValueStorage::getInstance().queryCurrentValue("angle-z", Zangle, true))
|
---|
109 | Zangle = 0.;
|
---|
110 | RotationMatrix.rotation(Xangle, Yangle, Zangle);
|
---|
111 |
|
---|
112 | DoLog(1) && (Log() << Verbose(1) << "Unselecting all atoms inside a rotated " << RotationMatrix << " cuboid at " << position << " and extension of " << extension << "." << endl);
|
---|
113 | Shape s = translate(transform(stretch(Cuboid(),extension),RotationMatrix),position);
|
---|
114 |
|
---|
115 | World::getInstance().unselectAllAtoms(AtomByShape(s));
|
---|
116 | return Action::state_ptr(new SelectionNotAllAtomsInsideCuboidState(selectedAtoms, position, extension, Xangle, Yangle, Zangle));
|
---|
117 | }
|
---|
118 |
|
---|
119 | Action::state_ptr SelectionNotAllAtomsInsideCuboidAction::performUndo(Action::state_ptr _state) {
|
---|
120 | SelectionNotAllAtomsInsideCuboidState *state = assert_cast<SelectionNotAllAtomsInsideCuboidState*>(_state.get());
|
---|
121 |
|
---|
122 | World::getInstance().clearAtomSelection();
|
---|
123 | for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
|
---|
124 | World::getInstance().selectAtom(*iter);
|
---|
125 |
|
---|
126 | return Action::state_ptr(_state);
|
---|
127 | }
|
---|
128 |
|
---|
129 | Action::state_ptr SelectionNotAllAtomsInsideCuboidAction::performRedo(Action::state_ptr _state){
|
---|
130 | SelectionNotAllAtomsInsideCuboidState *state = assert_cast<SelectionNotAllAtomsInsideCuboidState*>(_state.get());
|
---|
131 | Matrix RotationMatrix;
|
---|
132 |
|
---|
133 | RotationMatrix.rotation(state->Xangle, state->Yangle, state->Zangle);
|
---|
134 | Shape s = translate(transform(stretch(Cuboid(),state->extension),RotationMatrix),state->position);
|
---|
135 | World::getInstance().unselectAllAtoms(AtomByShape(s));
|
---|
136 |
|
---|
137 | return Action::state_ptr(_state);
|
---|
138 | }
|
---|
139 |
|
---|
140 | bool SelectionNotAllAtomsInsideCuboidAction::canUndo() {
|
---|
141 | return true;
|
---|
142 | }
|
---|
143 |
|
---|
144 | bool SelectionNotAllAtomsInsideCuboidAction::shouldUndo() {
|
---|
145 | return true;
|
---|
146 | }
|
---|
147 |
|
---|
148 | const string SelectionNotAllAtomsInsideCuboidAction::getName() {
|
---|
149 | return NAME;
|
---|
150 | }
|
---|