source: src/Actions/MoleculeAction/RotateAroundSelfByAngleAction.cpp@ eaf4ae

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

Added two new actions.

  • Property mode set to 100644
File size: 3.4 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
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
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::success;
91}
92
93Action::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
102Action::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
107bool MoleculeRotateAroundSelfByAngleAction::canUndo() {
108 return false;
109}
110
111bool MoleculeRotateAroundSelfByAngleAction::shouldUndo() {
112 return false;
113}
114
115const string MoleculeRotateAroundSelfByAngleAction::getName() {
116 return NAME;
117}
Note: See TracBrowser for help on using the repository browser.