source: src/Actions/ActionSequence.cpp@ 8f4df1

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 8f4df1 was 047878, checked in by Tillmann Crueger <crueger@…>, 14 years ago

made all actions pass on the dialogs and add the corresponding queries

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