source: src/Actions/ActionSequence.cpp@ 9c1324

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 9c1324 was 9c1324, checked in by Frederik Heber <heber@…>, 11 years ago

Equipped MakroAction with some boost::preprocessor magic, ActionSequence with loop.

  • ActionSequence now has a loop integer specifying how often the sequence is repeated. This is required to have actions in a loop but each of them generate their dialog only once.
  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * ActionSequenze.cpp
25 *
26 * Created on: Dec 17, 2009
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "Actions/ActionSequence.hpp"
38#include "Actions/Action.hpp"
39#include "UIElements/Dialog.hpp"
40
41#include "CodePatterns/Assert.hpp"
42
43using namespace MoleCuilder;
44
45ActionSequence::ActionSequence() :
46 loop(1)
47{}
48
49ActionSequence::~ActionSequence()
50{}
51
52
53void ActionSequence::addAction(Action* _action){
54 actions.push_back(_action);
55}
56
57Action* ActionSequence::removeLastAction(){
58 if(actions.empty()) {
59 return 0;
60 }
61 else {
62 Action* theAction;
63 theAction = actions.back();
64 actions.pop_back();
65 return theAction;
66 }
67}
68
69// this method is used outside the ActionModule
70// Each action registers itself with the history
71Dialog* ActionSequence::fillAllDialogs(Dialog *dialog){
72 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
73 dialog = (*it)->fillDialog(dialog);
74 }
75 return dialog;
76}
77
78// this method is used outside the ActionModule
79// Each action registers itself with the history
80void ActionSequence::callAll(){
81 for (int i=0;i<loop;++i)
82 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
83 // we want to have a global bookkeeping for all actions in the sequence, so
84 // we bypass the normal call
85 (*it)->call();
86 }
87}
88
89// This method is used internally when MakroActions are constructed.
90// In this case only the makro Action should be registered and
91// handle the states
92ActionSequence::stateSet ActionSequence::callAll(bool){
93 stateSet states;
94 for (int i=0;i<loop;++i)
95 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
96 // we want to have a global bookkeeping for all actions in the sequence, so
97 // we bypass the normal call
98 Action::state_ptr state = (*it)->performCall();
99 states.push_back(state);
100 }
101 return states;
102}
103
104ActionSequence::stateSet ActionSequence::undoAll(stateSet states){
105 ASSERT(canUndo(),"Trying to undo a sequence that contains methods that can't be undone");
106 stateSet res;
107 actionSet::reverse_iterator actionRit = actions.rbegin();
108 stateSet::reverse_iterator stateRit = states.rbegin();
109 for(;actionRit!=actions.rend();++actionRit,++stateRit){
110 ASSERT(stateRit!=states.rend(),"End of states prematurely reached.");
111 if((*actionRit)->shouldUndo()){
112 Action::state_ptr newState = (*actionRit)->performUndo(*stateRit);
113 // The order of the states has to correspond to the order of the actions
114 // this is why we have to add at the beginning
115 res.push_front(newState);
116 }
117 else{
118 res.push_front(Action::success);
119 }
120 }
121 return res;
122}
123
124ActionSequence::stateSet ActionSequence::redoAll(stateSet states){
125 stateSet res;
126 actionSet::iterator actionIt = actions.begin();
127 stateSet::iterator stateIt = states.begin();
128 for(;actionIt!=actions.end();++actionIt,++stateIt){
129 ASSERT(stateIt!=states.end(),"End of states prematurely reached.");
130 if((*actionIt)->shouldUndo()){
131 Action::state_ptr newState =(*actionIt)->performRedo(*stateIt);
132 res.push_back(newState);
133 }
134 else{
135 res.push_back(Action::success);
136 }
137 }
138 return res;
139}
140
141bool ActionSequence::canUndo(){
142 bool canUndo=true;
143 for(std::deque<Action*>::iterator it=actions.begin(); it!=actions.end(); ++it){
144 if((*it)->shouldUndo()){
145 canUndo &= (*it)->canUndo();
146 }
147 }
148 return canUndo;
149}
150
151bool ActionSequence::shouldUndo(){
152 bool shouldUndo = false;
153 for(std::deque<Action*>::iterator it=actions.begin();it!=actions.end();++it){
154 shouldUndo |= (*it)->shouldUndo();
155 }
156 return shouldUndo;
157}
Note: See TracBrowser for help on using the repository browser.