Changeset 2204b0
- Timestamp:
- Aug 6, 2010, 3:25:16 PM (15 years ago)
- Branches:
- 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
- Children:
- e97a44
- Parents:
- 4bb63c
- Location:
- src/Actions/MoleculeAction
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/MoleculeAction/RotateAroundOriginByAngleAction.cpp
r4bb63c r2204b0 31 31 // memento to remember the state when undoing 32 32 33 //class MoleculeRotateAroundOriginByAngleState : public ActionState { 34 //public: 35 // MoleculeRotateAroundOriginByAngleState(molecule* _mol,std::string _lastName) : 36 // mol(_mol), 37 // lastName(_lastName) 38 // {} 39 // molecule* mol; 40 // std::string lastName; 41 //}; 33 class MoleculeRotateAroundOriginByAngleState : public ActionState { 34 public: 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 }; 42 44 43 45 const char MoleculeRotateAroundOriginByAngleAction::NAME[] = "rotate-origin"; … … 73 75 ValueStorage::getInstance().queryCurrentValue("position", Axis); 74 76 75 DoLog(0) && (Log() << Verbose(0) << "Rotate around origin by " << alpha << ", axis from origin to " << Axis << "." << endl); 77 // check whether Axis is valid 78 if (Axis.IsZero()) 79 return Action::failure; 80 81 // convert from degrees to radian 82 alpha *= M_PI/180.; 83 84 DoLog(0) && (Log() << Verbose(0) << "Rotate around origin by " << alpha << " radian, axis from origin to " << Axis << "." << endl); 76 85 for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) { 77 86 mol = iter->second; … … 85 94 DoLog(0) && (Log() << Verbose(0) << "done." << endl); 86 95 } 87 return Action::s uccess;96 return Action::state_ptr(new MoleculeRotateAroundOriginByAngleState(World::getInstance().getSelectedMolecules(), Axis, alpha)); 88 97 } 89 98 90 99 Action::state_ptr MoleculeRotateAroundOriginByAngleAction::performUndo(Action::state_ptr _state) { 91 // MoleculeRotateOriginState *state = assert_cast<MoleculeRotateOriginState*>(_state.get()); 100 MoleculeRotateAroundOriginByAngleState *state = assert_cast<MoleculeRotateAroundOriginByAngleState*>(_state.get()); 101 molecule *mol = NULL; 92 102 93 // string newName = state->mol->getName(); 94 // state->mol->setName(state->lastName);103 for (std::vector<molecule *>::const_iterator iter = state->molecules.begin(); iter != state->molecules.end(); ++iter) { 104 mol = *iter; 95 105 96 return Action::failure; 106 // Creation Line that is the rotation axis 107 Line RotationAxis(Vector(0.,0.,0.), state->Axis); 108 109 for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) { 110 *((*iter)->node) = RotationAxis.rotateVector(*((*iter)->node), -state->alpha); 111 } 112 } 113 114 return Action::state_ptr(_state); 97 115 } 98 116 99 117 Action::state_ptr MoleculeRotateAroundOriginByAngleAction::performRedo(Action::state_ptr _state){ 100 // Undo and redo have to do the same for this action 101 return performUndo(_state); 118 MoleculeRotateAroundOriginByAngleState *state = assert_cast<MoleculeRotateAroundOriginByAngleState*>(_state.get()); 119 molecule *mol = NULL; 120 121 for (std::vector<molecule *>::const_iterator iter = state->molecules.begin(); iter != state->molecules.end(); ++iter) { 122 mol = *iter; 123 124 // Creation Line that is the rotation axis 125 Line RotationAxis(Vector(0.,0.,0.), state->Axis); 126 127 for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) { 128 *((*iter)->node) = RotationAxis.rotateVector(*((*iter)->node), state->alpha); 129 } 130 } 131 132 return Action::state_ptr(_state); 102 133 } 103 134 104 135 bool MoleculeRotateAroundOriginByAngleAction::canUndo() { 105 return false;136 return true; 106 137 } 107 138 108 139 bool MoleculeRotateAroundOriginByAngleAction::shouldUndo() { 109 return false;140 return true; 110 141 } 111 142 -
src/Actions/MoleculeAction/RotateAroundSelfByAngleAction.cpp
r4bb63c r2204b0 32 32 // memento to remember the state when undoing 33 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 //};34 class MoleculeRotateAroundSelfByAngleState : public ActionState { 35 public: 36 MoleculeRotateAroundSelfByAngleState(molecule * const _mol, const double _alpha) : 37 mol(_mol), 38 alpha(_alpha) 39 {} 40 molecule* const mol; 41 double alpha; 42 }; 43 43 44 44 const char MoleculeRotateAroundSelfByAngleAction::NAME[] = "rotate-self"; … … 88 88 DoLog(0) && (Log() << Verbose(0) << "done." << endl); 89 89 90 return Action::s uccess;90 return Action::state_ptr(new MoleculeRotateAroundSelfByAngleState(mol, alpha)); 91 91 } 92 92 93 93 Action::state_ptr MoleculeRotateAroundSelfByAngleAction::performUndo(Action::state_ptr _state) { 94 // MoleculeRotateOriginState *state = assert_cast<MoleculeRotateOriginState*>(_state.get());94 MoleculeRotateAroundSelfByAngleState *state = assert_cast<MoleculeRotateAroundSelfByAngleState*>(_state.get()); 95 95 96 // string newName = state->mol->getName(); 97 // state->mol->setName(state->lastName); 96 Vector *CenterOfGravity = state->mol->DetermineCenterOfGravity(); 97 Line RotationAxis(*CenterOfGravity, (World::getInstance().beginAtomSelection()->second)->x); 98 delete(CenterOfGravity); 98 99 99 return Action::failure; 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); 100 105 } 101 106 102 107 Action::state_ptr MoleculeRotateAroundSelfByAngleAction::performRedo(Action::state_ptr _state){ 103 // Undo and redo have to do the same for this action 104 return performUndo(_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); 105 119 } 106 120 107 121 bool MoleculeRotateAroundSelfByAngleAction::canUndo() { 108 return false;122 return true; 109 123 } 110 124 111 125 bool MoleculeRotateAroundSelfByAngleAction::shouldUndo() { 112 return false;126 return true; 113 127 } 114 128
Note:
See TracChangeset
for help on using the changeset viewer.