source: src/Actions/ActionSequence.cpp@ b5b01e

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

ActionState extracted into own header file, rename Action::state_ptr -> ActionState::ptr.

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]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/>.
[bcf653]21 */
22
[a5041ec]23/*
24 * ActionSequenze.cpp
25 *
26 * Created on: Dec 17, 2009
27 * Author: crueger
28 */
29
[bf3817]30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
[ad011c]35#include "CodePatterns/MemDebug.hpp"
[112b09]36
[a5041ec]37#include "Actions/ActionSequence.hpp"
38#include "Actions/Action.hpp"
[80951de]39#include "UIElements/Dialog.hpp"
[a5041ec]40
[ad011c]41#include "CodePatterns/Assert.hpp"
[67e2b3]42
[ce7fdc]43using namespace MoleCuilder;
[a5041ec]44
[9c1324]45ActionSequence::ActionSequence() :
46 loop(1)
[1fa107]47{}
[a5041ec]48
49ActionSequence::~ActionSequence()
[1fa107]50{}
[a5041ec]51
52
53void ActionSequence::addAction(Action* _action){
54 actions.push_back(_action);
55}
56
57Action* ActionSequence::removeLastAction(){
[1fa107]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 }
[a5041ec]67}
68
[80951de]69// this method is used outside the ActionModule
70// Each action registers itself with the history
[047878]71Dialog* ActionSequence::fillAllDialogs(Dialog *dialog){
[80951de]72 for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
[047878]73 dialog = (*it)->fillDialog(dialog);
[80951de]74 }
[047878]75 return dialog;
[80951de]76}
77
[2efa90]78// this method is used outside the ActionModule
79// Each action registers itself with the history
80void ActionSequence::callAll(){
[9c1324]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 }
[2efa90]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){
[67e2b3]93 stateSet states;
[9c1324]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
[b5b01e]98 ActionState::ptr state = (*it)->performCall();
[9c1324]99 states.push_back(state);
100 }
[67e2b3]101 return states;
102}
103
[5b0b98]104ActionSequence::stateSet ActionSequence::undoAll(stateSet states){
[67e2b3]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()){
[b5b01e]112 ActionState::ptr newState = (*actionRit)->performUndo(*stateRit);
[67e2b3]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;
[a5041ec]122}
123
[5b0b98]124ActionSequence::stateSet ActionSequence::redoAll(stateSet states){
[67e2b3]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()){
[b5b01e]131 ActionState::ptr newState =(*actionIt)->performRedo(*stateIt);
[67e2b3]132 res.push_back(newState);
133 }
134 else{
135 res.push_back(Action::success);
136 }
137 }
138 return res;
[a5041ec]139}
140
141bool ActionSequence::canUndo(){
142 bool canUndo=true;
[955b91]143 for(std::deque<Action*>::iterator it=actions.begin(); it!=actions.end(); ++it){
[67e2b3]144 if((*it)->shouldUndo()){
145 canUndo &= (*it)->canUndo();
146 }
147 }
[a5041ec]148 return canUndo;
149}
[67e2b3]150
151bool ActionSequence::shouldUndo(){
152 bool shouldUndo = false;
[955b91]153 for(std::deque<Action*>::iterator it=actions.begin();it!=actions.end();++it){
[67e2b3]154 shouldUndo |= (*it)->shouldUndo();
155 }
156 return shouldUndo;
157}
Note: See TracBrowser for help on using the repository browser.