source: src/Actions/AtomAction/RotateAroundOriginByAngleAction.cpp@ 73c5ca

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 73c5ca was bcf653, checked in by Frederik Heber <heber@…>, 15 years ago

Added copyright note to each .cpp file and an extensive one to builder.cpp.

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