source: src/Actions/ActionSequence.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 bf3817, checked in by Frederik Heber <heber@…>, 14 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: 3.5 KB
Line 
1/*
2 * ActionSequenze.cpp
3 *
4 * Created on: Dec 17, 2009
5 * Author: crueger
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/ActionSequence.hpp"
16#include "Actions/Action.hpp"
17#include "UIElements/Dialog.hpp"
18
19#include "Helpers/Assert.hpp"
20
21using namespace std;
22
23ActionSequence::ActionSequence()
24{}
25
26ActionSequence::~ActionSequence()
27{}
28
29
30void ActionSequence::addAction(Action* _action){
31 actions.push_back(_action);
32}
33
34Action* ActionSequence::removeLastAction(){
35 if(actions.empty()) {
36 return 0;
37 }
38 else {
39 Action* theAction;
40 theAction = actions.back();
41 actions.pop_back();
42 return theAction;
43 }
44}
45
46// this method is used outside the ActionModule
47// Each action registers itself with the history
48Dialog* ActionSequence::fillAllDialogs(Dialog *dialog){
49 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
50 dialog = (*it)->fillDialog(dialog);
51 }
52 return dialog;
53}
54
55// this method is used outside the ActionModule
56// Each action registers itself with the history
57void ActionSequence::callAll(){
58 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
59 // we want to have a global bookkeeping for all actions in the sequence, so
60 // we bypass the normal call
61 (*it)->call();
62 }
63}
64
65// This method is used internally when MakroActions are constructed.
66// In this case only the makro Action should be registered and
67// handle the states
68ActionSequence::stateSet ActionSequence::callAll(bool){
69 stateSet states;
70 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
71 // we want to have a global bookkeeping for all actions in the sequence, so
72 // we bypass the normal call
73 Action::state_ptr state = (*it)->performCall();
74 states.push_back(state);
75 }
76 return states;
77}
78
79ActionSequence::stateSet ActionSequence::undoAll(stateSet states){
80 ASSERT(canUndo(),"Trying to undo a sequence that contains methods that can't be undone");
81 stateSet res;
82 actionSet::reverse_iterator actionRit = actions.rbegin();
83 stateSet::reverse_iterator stateRit = states.rbegin();
84 for(;actionRit!=actions.rend();++actionRit,++stateRit){
85 ASSERT(stateRit!=states.rend(),"End of states prematurely reached.");
86 if((*actionRit)->shouldUndo()){
87 Action::state_ptr newState = (*actionRit)->performUndo(*stateRit);
88 // The order of the states has to correspond to the order of the actions
89 // this is why we have to add at the beginning
90 res.push_front(newState);
91 }
92 else{
93 res.push_front(Action::success);
94 }
95 }
96 return res;
97}
98
99ActionSequence::stateSet ActionSequence::redoAll(stateSet states){
100 stateSet res;
101 actionSet::iterator actionIt = actions.begin();
102 stateSet::iterator stateIt = states.begin();
103 for(;actionIt!=actions.end();++actionIt,++stateIt){
104 ASSERT(stateIt!=states.end(),"End of states prematurely reached.");
105 if((*actionIt)->shouldUndo()){
106 Action::state_ptr newState =(*actionIt)->performRedo(*stateIt);
107 res.push_back(newState);
108 }
109 else{
110 res.push_back(Action::success);
111 }
112 }
113 return res;
114}
115
116bool ActionSequence::canUndo(){
117 bool canUndo=true;
118 for(deque<Action*>::iterator it=actions.begin(); it!=actions.end(); ++it){
119 if((*it)->shouldUndo()){
120 canUndo &= (*it)->canUndo();
121 }
122 }
123 return canUndo;
124}
125
126bool ActionSequence::shouldUndo(){
127 bool shouldUndo = false;
128 for(deque<Action*>::iterator it=actions.begin();it!=actions.end();++it){
129 shouldUndo |= (*it)->shouldUndo();
130 }
131 return shouldUndo;
132}
Note: See TracBrowser for help on using the repository browser.