source: src/Actions/ActionSequence.cpp@ 80951de

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

Fixed all remaining Action's and derived classes that lacked createDialog().

  • Property mode set to 100644
File size: 4.0 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
43void ActionSequence::callAllDialogs(){
44 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
45 // we want to have a global bookkeeping for all actions in the sequence, so
46 // we bypass the normal call
47 (*it)->createDialog()->display();
48 }
49}
50
51// This method is used internally when MakroActions are constructed.
52// In this case only the makro Action should be registered and
53// handle the states
54ActionSequence::stateSet ActionSequence::callAllDialogs(bool){
55 stateSet states;
56 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
57 // we want to have a global bookkeeping for all actions in the sequence, so
58 // we bypass the normal call
59 (*it)->createDialog()->display();
60 }
61 return states;
62}
63
64// this method is used outside the ActionModule
65// Each action registers itself with the history
66void ActionSequence::callAll(){
67 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
68 // we want to have a global bookkeeping for all actions in the sequence, so
69 // we bypass the normal call
70 (*it)->call();
71 }
72}
73
74// This method is used internally when MakroActions are constructed.
75// In this case only the makro Action should be registered and
76// handle the states
77ActionSequence::stateSet ActionSequence::callAll(bool){
78 stateSet states;
79 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
80 // we want to have a global bookkeeping for all actions in the sequence, so
81 // we bypass the normal call
82 Action::state_ptr state = (*it)->performCall();
83 states.push_back(state);
84 }
85 return states;
86}
87
88ActionSequence::stateSet ActionSequence::undoAll(stateSet states){
89 ASSERT(canUndo(),"Trying to undo a sequence that contains methods that can't be undone");
90 stateSet res;
91 actionSet::reverse_iterator actionRit = actions.rbegin();
92 stateSet::reverse_iterator stateRit = states.rbegin();
93 for(;actionRit!=actions.rend();++actionRit,++stateRit){
94 ASSERT(stateRit!=states.rend(),"End of states prematurely reached.");
95 if((*actionRit)->shouldUndo()){
96 Action::state_ptr newState = (*actionRit)->performUndo(*stateRit);
97 // The order of the states has to correspond to the order of the actions
98 // this is why we have to add at the beginning
99 res.push_front(newState);
100 }
101 else{
102 res.push_front(Action::success);
103 }
104 }
105 return res;
106}
107
108ActionSequence::stateSet ActionSequence::redoAll(stateSet states){
109 stateSet res;
110 actionSet::iterator actionIt = actions.begin();
111 stateSet::iterator stateIt = states.begin();
112 for(;actionIt!=actions.end();++actionIt,++stateIt){
113 ASSERT(stateIt!=states.end(),"End of states prematurely reached.");
114 if((*actionIt)->shouldUndo()){
115 Action::state_ptr newState =(*actionIt)->performRedo(*stateIt);
116 res.push_back(newState);
117 }
118 else{
119 res.push_back(Action::success);
120 }
121 }
122 return res;
123}
124
125bool ActionSequence::canUndo(){
126 bool canUndo=true;
127 for(deque<Action*>::iterator it=actions.begin(); it!=actions.end(); ++it){
128 if((*it)->shouldUndo()){
129 canUndo &= (*it)->canUndo();
130 }
131 }
132 return canUndo;
133}
134
135bool ActionSequence::shouldUndo(){
136 bool shouldUndo = false;
137 for(deque<Action*>::iterator it=actions.begin();it!=actions.end();++it){
138 shouldUndo |= (*it)->shouldUndo();
139 }
140 return shouldUndo;
141}
Note: See TracBrowser for help on using the repository browser.