source: src/Actions/MoleculeAction/RotateAroundSelfByAngleAction.cpp@ 2204b0

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 2204b0 was 2204b0, checked in by Frederik Heber <heber@…>, 14 years ago

Added Undo/Redo capability to rotate-origin and rotate-self Actions.

  • Property mode set to 100644
File size: 4.2 KB
Line 
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
24using 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
34class MoleculeRotateAroundSelfByAngleState : public ActionState {
35public:
36 MoleculeRotateAroundSelfByAngleState(molecule * const _mol, const double _alpha) :
37 mol(_mol),
38 alpha(_alpha)
39 {}
40 molecule* const mol;
41 double alpha;
42};
43
44const char MoleculeRotateAroundSelfByAngleAction::NAME[] = "rotate-self";
45
46MoleculeRotateAroundSelfByAngleAction::MoleculeRotateAroundSelfByAngleAction() :
47 Action(NAME)
48{}
49
50MoleculeRotateAroundSelfByAngleAction::~MoleculeRotateAroundSelfByAngleAction()
51{}
52
53void MoleculeRotateAroundSelfByAngle(double angle) {
54 ValueStorage::getInstance().setCurrentValue(MoleculeRotateAroundSelfByAngleAction::NAME, angle);
55 ActionRegistry::getInstance().getActionByName(MoleculeRotateAroundSelfByAngleAction::NAME)->call(Action::NonInteractive);
56};
57
58Dialog* 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
66Action::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::state_ptr(new MoleculeRotateAroundSelfByAngleState(mol, alpha));
91}
92
93Action::state_ptr MoleculeRotateAroundSelfByAngleAction::performUndo(Action::state_ptr _state) {
94 MoleculeRotateAroundSelfByAngleState *state = assert_cast<MoleculeRotateAroundSelfByAngleState*>(_state.get());
95
96 Vector *CenterOfGravity = state->mol->DetermineCenterOfGravity();
97 Line RotationAxis(*CenterOfGravity, (World::getInstance().beginAtomSelection()->second)->x);
98 delete(CenterOfGravity);
99
100 for (molecule::iterator iter = state->mol->begin(); iter != state->mol->end(); ++iter) {
101 *((*iter)->node) = RotationAxis.rotateVector(*((*iter)->node), -state->alpha);
102 }
103
104 return Action::state_ptr(_state);
105}
106
107Action::state_ptr MoleculeRotateAroundSelfByAngleAction::performRedo(Action::state_ptr _state){
108 MoleculeRotateAroundSelfByAngleState *state = assert_cast<MoleculeRotateAroundSelfByAngleState*>(_state.get());
109
110 Vector *CenterOfGravity = state->mol->DetermineCenterOfGravity();
111 Line RotationAxis(*CenterOfGravity, (World::getInstance().beginAtomSelection()->second)->x);
112 delete(CenterOfGravity);
113
114 for (molecule::iterator iter = state->mol->begin(); iter != state->mol->end(); ++iter) {
115 *((*iter)->node) = RotationAxis.rotateVector(*((*iter)->node), state->alpha);
116 }
117
118 return Action::state_ptr(_state);
119}
120
121bool MoleculeRotateAroundSelfByAngleAction::canUndo() {
122 return true;
123}
124
125bool MoleculeRotateAroundSelfByAngleAction::shouldUndo() {
126 return true;
127}
128
129const string MoleculeRotateAroundSelfByAngleAction::getName() {
130 return NAME;
131}
Note: See TracBrowser for help on using the repository browser.