source: src/Actions/MoleculeAction/RotateAroundOriginByAngleAction.cpp@ 4a06d6

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 4a06d6 was 4a06d6, checked in by Frederik Heber <heber@…>, 14 years ago

FIX: friend function of RotateAroundOriginByAngleAction had wrong signature.

  • also fixed RotateAroundOriginByAngleAction::performCall(): RotationAxis and "done" out of loop.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * RotateAroundOriginByAngleAction.cpp
3 *
4 * Created on: Aug 06, 2010
5 * Author: heber
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include "Actions/MoleculeAction/RotateAroundOriginByAngleAction.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 "molecule.hpp"
17
18
19#include <iostream>
20#include <fstream>
21#include <string>
22
23using namespace std;
24
25#include "UIElements/UIFactory.hpp"
26#include "UIElements/Dialog.hpp"
27#include "Actions/ValueStorage.hpp"
28
29/****** MoleculeRotateAroundOriginByAngleAction *****/
30
31// memento to remember the state when undoing
32
33class MoleculeRotateAroundOriginByAngleState : public ActionState {
34public:
35 MoleculeRotateAroundOriginByAngleState(const std::vector<molecule*> &_molecules,const Vector &_Axis, const double _alpha) :
36 molecules(_molecules),
37 Axis(_Axis),
38 alpha(_alpha)
39 {}
40 std::vector<molecule*> molecules;
41 Vector Axis;
42 double alpha;
43};
44
45const char MoleculeRotateAroundOriginByAngleAction::NAME[] = "rotate-origin";
46
47MoleculeRotateAroundOriginByAngleAction::MoleculeRotateAroundOriginByAngleAction() :
48 Action(NAME)
49{}
50
51MoleculeRotateAroundOriginByAngleAction::~MoleculeRotateAroundOriginByAngleAction()
52{}
53
54void MoleculeRotateAroundOriginByAngle(const Vector &Axis, double angle) {
55 ValueStorage::getInstance().setCurrentValue(MoleculeRotateAroundOriginByAngleAction::NAME, angle);
56 ValueStorage::getInstance().setCurrentValue("position", Axis);
57 ActionRegistry::getInstance().getActionByName(MoleculeRotateAroundOriginByAngleAction::NAME)->call(Action::NonInteractive);
58};
59
60Dialog* MoleculeRotateAroundOriginByAngleAction::fillDialog(Dialog *dialog) {
61 ASSERT(dialog,"No Dialog given when filling action dialog");
62
63 dialog->queryDouble(NAME, MapOfActions::getInstance().getDescription(NAME));
64 dialog->queryVector("position", false, MapOfActions::getInstance().getDescription("position"));
65
66 return dialog;
67}
68
69Action::state_ptr MoleculeRotateAroundOriginByAngleAction::performCall() {
70 molecule *mol = NULL;
71 double alpha = 0.;
72 Vector Axis;
73
74 // obtain axis to rotate to
75 ValueStorage::getInstance().queryCurrentValue(NAME, alpha);
76 ValueStorage::getInstance().queryCurrentValue("position", Axis);
77
78 // check whether Axis is valid
79 if (Axis.IsZero())
80 return Action::failure;
81
82 // convert from degrees to radian
83 alpha *= M_PI/180.;
84
85 // Creation Line that is the rotation axis
86 Line RotationAxis(Vector(0.,0.,0.), Axis);
87
88 DoLog(0) && (Log() << Verbose(0) << "Rotate around origin by " << alpha << " radian, axis from origin to " << Axis << "." << endl);
89 for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
90 mol = iter->second;
91
92 for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
93 *((*iter)->node) = RotationAxis.rotateVector(*((*iter)->node), alpha);
94 }
95 }
96 DoLog(0) && (Log() << Verbose(0) << "done." << endl);
97 return Action::state_ptr(new MoleculeRotateAroundOriginByAngleState(World::getInstance().getSelectedMolecules(), Axis, alpha));
98}
99
100Action::state_ptr MoleculeRotateAroundOriginByAngleAction::performUndo(Action::state_ptr _state) {
101 MoleculeRotateAroundOriginByAngleState *state = assert_cast<MoleculeRotateAroundOriginByAngleState*>(_state.get());
102 molecule *mol = NULL;
103
104 for (std::vector<molecule *>::const_iterator iter = state->molecules.begin(); iter != state->molecules.end(); ++iter) {
105 mol = *iter;
106
107 // Creation Line that is the rotation axis
108 Line RotationAxis(Vector(0.,0.,0.), state->Axis);
109
110 for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
111 *((*iter)->node) = RotationAxis.rotateVector(*((*iter)->node), -state->alpha);
112 }
113 }
114
115 return Action::state_ptr(_state);
116}
117
118Action::state_ptr MoleculeRotateAroundOriginByAngleAction::performRedo(Action::state_ptr _state){
119 MoleculeRotateAroundOriginByAngleState *state = assert_cast<MoleculeRotateAroundOriginByAngleState*>(_state.get());
120 molecule *mol = NULL;
121
122 for (std::vector<molecule *>::const_iterator iter = state->molecules.begin(); iter != state->molecules.end(); ++iter) {
123 mol = *iter;
124
125 // Creation Line that is the rotation axis
126 Line RotationAxis(Vector(0.,0.,0.), state->Axis);
127
128 for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
129 *((*iter)->node) = RotationAxis.rotateVector(*((*iter)->node), state->alpha);
130 }
131 }
132
133 return Action::state_ptr(_state);
134}
135
136bool MoleculeRotateAroundOriginByAngleAction::canUndo() {
137 return true;
138}
139
140bool MoleculeRotateAroundOriginByAngleAction::shouldUndo() {
141 return true;
142}
143
144const string MoleculeRotateAroundOriginByAngleAction::getName() {
145 return NAME;
146}
Note: See TracBrowser for help on using the repository browser.