source: src/Actions/AtomAction/RotateAroundOriginByAngleAction.cpp@ 13e3c3

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 13e3c3 was bf3817, checked in by Frederik Heber <heber@…>, 15 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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