source: src/Actions/AtomAction/TranslateAction.cpp@ 9cd807

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

Added "periodic" as optional argument to TranslateAction.

  • entails execution of Box::WrapPeriodically() if true.
  • BUGFIX: friend declaration had wrong signature.
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * TranslateAction.cpp
3 *
4 * Created on: May 10, 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/TranslateAction.hpp"
16#include "Actions/ActionRegistry.hpp"
17#include "Helpers/Log.hpp"
18#include "atom.hpp"
19#include "LinearAlgebra/Vector.hpp"
20#include "Helpers/Verbose.hpp"
21#include "World.hpp"
22
23#include <iostream>
24#include <fstream>
25#include <string>
26
27using namespace std;
28
29#include "UIElements/UIFactory.hpp"
30#include "UIElements/Dialog.hpp"
31#include "Actions/ValueStorage.hpp"
32
33/****** AtomTranslateAction *****/
34
35// memento to remember the state when undoing
36
37class AtomTranslateState : public ActionState {
38public:
39 AtomTranslateState(const std::vector<atom*> &_selectedAtoms, const Vector &_v, const bool _periodic) :
40 selectedAtoms(_selectedAtoms),
41 v(_v),
42 periodic(_periodic)
43 {}
44 std::vector<atom*> selectedAtoms;
45 Vector v;
46 bool periodic;
47};
48
49const char AtomTranslateAction::NAME[] = "translate-atoms";
50
51AtomTranslateAction::AtomTranslateAction() :
52 Action(NAME)
53{}
54
55AtomTranslateAction::~AtomTranslateAction()
56{}
57
58void AtomTranslate(Vector &x, bool periodic = false) {
59 ValueStorage::getInstance().setCurrentValue(AtomTranslateAction::NAME, x);
60 ValueStorage::getInstance().setCurrentValue("periodic", periodic);
61 ActionRegistry::getInstance().getActionByName(AtomTranslateAction::NAME)->call(Action::NonInteractive);
62};
63
64Dialog* AtomTranslateAction::fillDialog(Dialog *dialog) {
65 ASSERT(dialog,"No Dialog given when filling action dialog");
66
67 dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
68 dialog->queryBoolean("periodic", ValueStorage::getInstance().getDescription("periodic"));
69
70 return dialog;
71}
72
73Action::state_ptr AtomTranslateAction::performCall() {
74 Vector v;
75 bool periodic = false;
76 Box &domain = World::getInstance().getDomain();
77 std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
78
79 ValueStorage::getInstance().queryCurrentValue(NAME, v);
80 if (!ValueStorage::getInstance().queryCurrentValue("periodic", periodic, true))
81 periodic = false;
82
83 // TODO: use AtomSet::translate
84 for (std::vector<atom *>::iterator iter = selectedAtoms.begin(); iter != selectedAtoms.end(); ++iter) {
85 *(*iter) += v;
86 if (periodic)
87 (*iter)->setPosition(domain.WrapPeriodically((*iter)->getPosition()));
88 }
89
90 return Action::state_ptr(new AtomTranslateState(selectedAtoms, v, periodic));
91}
92
93Action::state_ptr AtomTranslateAction::performUndo(Action::state_ptr _state) {
94 AtomTranslateState *state = assert_cast<AtomTranslateState*>(_state.get());
95 Box &domain = World::getInstance().getDomain();
96
97 for (std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter) {
98 *(*iter) -= state->v;
99 if (state->periodic)
100 (*iter)->setPosition(domain.WrapPeriodically((*iter)->getPosition()));
101 }
102
103 return Action::state_ptr(_state);
104}
105
106Action::state_ptr AtomTranslateAction::performRedo(Action::state_ptr _state){
107 AtomTranslateState *state = assert_cast<AtomTranslateState*>(_state.get());
108 Box &domain = World::getInstance().getDomain();
109
110 for (std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter) {
111 *(*iter) += state->v;
112 if (state->periodic)
113 (*iter)->setPosition(domain.WrapPeriodically((*iter)->getPosition()));
114 }
115
116 return Action::state_ptr(_state);
117}
118
119bool AtomTranslateAction::canUndo() {
120 return true;
121}
122
123bool AtomTranslateAction::shouldUndo() {
124 return true;
125}
126
127const string AtomTranslateAction::getName() {
128 return NAME;
129}
Note: See TracBrowser for help on using the repository browser.