source: src/Actions/ActionSequence.cpp@ c38826

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 c38826 was bcf653, checked in by Frederik Heber <heber@…>, 14 years ago

Added copyright note to each .cpp file and an extensive one to builder.cpp.

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