source: src/Actions/ActionSequence.cpp@ 4e4c4d

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

Actions can now be called non-interactively, MissingValueException thrown.

  • new exception MissingValue which is thrown when MapOfActions does not have a desired entry in CurrentValue map.
  • new enum Action::QueryOptions.
  • Action::call() has flag whether call should be interactive (popping up dialog) or not.
  • cleaned-up Makefile.am a bit ...
  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[a5041ec]1/*
2 * ActionSequenze.cpp
3 *
4 * Created on: Dec 17, 2009
5 * Author: crueger
6 */
7
[112b09]8#include "Helpers/MemDebug.hpp"
9
[a5041ec]10#include "Actions/ActionSequence.hpp"
11#include "Actions/Action.hpp"
[80951de]12#include "UIElements/Dialog.hpp"
[a5041ec]13
[67e2b3]14#include "Helpers/Assert.hpp"
15
[a5041ec]16using namespace std;
17
18ActionSequence::ActionSequence()
[1fa107]19{}
[a5041ec]20
21ActionSequence::~ActionSequence()
[1fa107]22{}
[a5041ec]23
24
25void ActionSequence::addAction(Action* _action){
26 actions.push_back(_action);
27}
28
29Action* ActionSequence::removeLastAction(){
[1fa107]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 }
[a5041ec]39}
40
[80951de]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
[4e145c]47 Dialog * dialog = (*it)->createDialog();
48 if (dialog != NULL) {
49 dialog->display();
50 delete(dialog);
51 }
[80951de]52 }
53}
54
55// This method is used internally when MakroActions are constructed.
56// In this case only the makro Action should be registered and
57// handle the states
58ActionSequence::stateSet ActionSequence::callAllDialogs(bool){
59 stateSet states;
60 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
61 // we want to have a global bookkeeping for all actions in the sequence, so
62 // we bypass the normal call
63 (*it)->createDialog()->display();
64 }
65 return states;
66}
67
[2efa90]68// this method is used outside the ActionModule
69// Each action registers itself with the history
70void ActionSequence::callAll(){
71 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
72 // we want to have a global bookkeeping for all actions in the sequence, so
73 // we bypass the normal call
74 (*it)->call();
75 }
76}
77
78// This method is used internally when MakroActions are constructed.
79// In this case only the makro Action should be registered and
80// handle the states
81ActionSequence::stateSet ActionSequence::callAll(bool){
[67e2b3]82 stateSet states;
83 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
84 // we want to have a global bookkeeping for all actions in the sequence, so
85 // we bypass the normal call
[5b0b98]86 Action::state_ptr state = (*it)->performCall();
[67e2b3]87 states.push_back(state);
88 }
89 return states;
90}
91
[5b0b98]92ActionSequence::stateSet ActionSequence::undoAll(stateSet states){
[67e2b3]93 ASSERT(canUndo(),"Trying to undo a sequence that contains methods that can't be undone");
94 stateSet res;
95 actionSet::reverse_iterator actionRit = actions.rbegin();
96 stateSet::reverse_iterator stateRit = states.rbegin();
97 for(;actionRit!=actions.rend();++actionRit,++stateRit){
98 ASSERT(stateRit!=states.rend(),"End of states prematurely reached.");
99 if((*actionRit)->shouldUndo()){
[5b0b98]100 Action::state_ptr newState = (*actionRit)->performUndo(*stateRit);
[67e2b3]101 // The order of the states has to correspond to the order of the actions
102 // this is why we have to add at the beginning
103 res.push_front(newState);
104 }
105 else{
106 res.push_front(Action::success);
107 }
108 }
109 return res;
[a5041ec]110}
111
[5b0b98]112ActionSequence::stateSet ActionSequence::redoAll(stateSet states){
[67e2b3]113 stateSet res;
114 actionSet::iterator actionIt = actions.begin();
115 stateSet::iterator stateIt = states.begin();
116 for(;actionIt!=actions.end();++actionIt,++stateIt){
117 ASSERT(stateIt!=states.end(),"End of states prematurely reached.");
118 if((*actionIt)->shouldUndo()){
[5b0b98]119 Action::state_ptr newState =(*actionIt)->performRedo(*stateIt);
[67e2b3]120 res.push_back(newState);
121 }
122 else{
123 res.push_back(Action::success);
124 }
125 }
126 return res;
[a5041ec]127}
128
129bool ActionSequence::canUndo(){
130 bool canUndo=true;
[67e2b3]131 for(deque<Action*>::iterator it=actions.begin(); it!=actions.end(); ++it){
132 if((*it)->shouldUndo()){
133 canUndo &= (*it)->canUndo();
134 }
135 }
[a5041ec]136 return canUndo;
137}
[67e2b3]138
139bool ActionSequence::shouldUndo(){
140 bool shouldUndo = false;
141 for(deque<Action*>::iterator it=actions.begin();it!=actions.end();++it){
142 shouldUndo |= (*it)->shouldUndo();
143 }
144 return shouldUndo;
145}
Note: See TracBrowser for help on using the repository browser.