1 | /*
|
---|
2 | * RotateAroundSelfByAngleAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: Aug 06, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/MoleculeAction/RotateAroundSelfByAngleAction.hpp"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "Helpers/Log.hpp"
|
---|
13 | #include "Helpers/Verbose.hpp"
|
---|
14 | #include "LinearAlgebra/Line.hpp"
|
---|
15 | #include "LinearAlgebra/Vector.hpp"
|
---|
16 | #include "atom.hpp"
|
---|
17 | #include "molecule.hpp"
|
---|
18 |
|
---|
19 |
|
---|
20 | #include <iostream>
|
---|
21 | #include <fstream>
|
---|
22 | #include <string>
|
---|
23 |
|
---|
24 | using namespace std;
|
---|
25 |
|
---|
26 | #include "UIElements/UIFactory.hpp"
|
---|
27 | #include "UIElements/Dialog.hpp"
|
---|
28 | #include "Actions/ValueStorage.hpp"
|
---|
29 |
|
---|
30 | /****** MoleculeRotateAroundSelfByAngleAction *****/
|
---|
31 |
|
---|
32 | // memento to remember the state when undoing
|
---|
33 |
|
---|
34 | //class MoleculeRotateAroundSelfByAngleState : public ActionState {
|
---|
35 | //public:
|
---|
36 | // MoleculeRotateAroundSelfByAngleState(molecule* _mol,std::string _lastName) :
|
---|
37 | // mol(_mol),
|
---|
38 | // lastName(_lastName)
|
---|
39 | // {}
|
---|
40 | // molecule* mol;
|
---|
41 | // std::string lastName;
|
---|
42 | //};
|
---|
43 |
|
---|
44 | const char MoleculeRotateAroundSelfByAngleAction::NAME[] = "rotate-self";
|
---|
45 |
|
---|
46 | MoleculeRotateAroundSelfByAngleAction::MoleculeRotateAroundSelfByAngleAction() :
|
---|
47 | Action(NAME)
|
---|
48 | {}
|
---|
49 |
|
---|
50 | MoleculeRotateAroundSelfByAngleAction::~MoleculeRotateAroundSelfByAngleAction()
|
---|
51 | {}
|
---|
52 |
|
---|
53 | void MoleculeRotateAroundSelfByAngle(double angle) {
|
---|
54 | ValueStorage::getInstance().setCurrentValue(MoleculeRotateAroundSelfByAngleAction::NAME, angle);
|
---|
55 | ActionRegistry::getInstance().getActionByName(MoleculeRotateAroundSelfByAngleAction::NAME)->call(Action::NonInteractive);
|
---|
56 | };
|
---|
57 |
|
---|
58 | Dialog* MoleculeRotateAroundSelfByAngleAction::fillDialog(Dialog *dialog) {
|
---|
59 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
60 |
|
---|
61 | dialog->queryDouble(NAME, MapOfActions::getInstance().getDescription(NAME));
|
---|
62 |
|
---|
63 | return dialog;
|
---|
64 | }
|
---|
65 |
|
---|
66 | Action::state_ptr MoleculeRotateAroundSelfByAngleAction::performCall() {
|
---|
67 | molecule *mol = NULL;
|
---|
68 | double alpha = 0.;
|
---|
69 |
|
---|
70 | // obtain angle around which rotate
|
---|
71 | ValueStorage::getInstance().queryCurrentValue(NAME, alpha);
|
---|
72 |
|
---|
73 | // check whether a single atom and molecule is selected
|
---|
74 | if ((World::getInstance().getSelectedAtoms().size() != 1) || (World::getInstance().getSelectedMolecules().size() != 1))
|
---|
75 | return Action::failure;
|
---|
76 |
|
---|
77 | DoLog(0) && (Log() << Verbose(0) << "Rotate around self by " << alpha << "." << endl);
|
---|
78 | mol = World::getInstance().beginMoleculeSelection()->second;
|
---|
79 |
|
---|
80 | // Creation Line that is the rotation axis
|
---|
81 | Vector *CenterOfGravity = mol->DetermineCenterOfGravity();
|
---|
82 | Line RotationAxis(*CenterOfGravity, (World::getInstance().beginAtomSelection()->second)->x);
|
---|
83 | delete(CenterOfGravity);
|
---|
84 |
|
---|
85 | for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
86 | *((*iter)->node) = RotationAxis.rotateVector(*((*iter)->node), alpha);
|
---|
87 | }
|
---|
88 | DoLog(0) && (Log() << Verbose(0) << "done." << endl);
|
---|
89 |
|
---|
90 | return Action::success;
|
---|
91 | }
|
---|
92 |
|
---|
93 | Action::state_ptr MoleculeRotateAroundSelfByAngleAction::performUndo(Action::state_ptr _state) {
|
---|
94 | // MoleculeRotateOriginState *state = assert_cast<MoleculeRotateOriginState*>(_state.get());
|
---|
95 |
|
---|
96 | // string newName = state->mol->getName();
|
---|
97 | // state->mol->setName(state->lastName);
|
---|
98 |
|
---|
99 | return Action::failure;
|
---|
100 | }
|
---|
101 |
|
---|
102 | Action::state_ptr MoleculeRotateAroundSelfByAngleAction::performRedo(Action::state_ptr _state){
|
---|
103 | // Undo and redo have to do the same for this action
|
---|
104 | return performUndo(_state);
|
---|
105 | }
|
---|
106 |
|
---|
107 | bool MoleculeRotateAroundSelfByAngleAction::canUndo() {
|
---|
108 | return false;
|
---|
109 | }
|
---|
110 |
|
---|
111 | bool MoleculeRotateAroundSelfByAngleAction::shouldUndo() {
|
---|
112 | return false;
|
---|
113 | }
|
---|
114 |
|
---|
115 | const string MoleculeRotateAroundSelfByAngleAction::getName() {
|
---|
116 | return NAME;
|
---|
117 | }
|
---|