source: src/Actions/ActionHistory.cpp@ fdd840

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 fdd840 was 2efa90, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added detailed documentation for the Action class

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * ActionHistory.cpp
3 *
4 * Created on: Mar 25, 2010
5 * Author: crueger
6 */
7
8#include "ActionHistory.hpp"
9
10#include <iostream>
11
12#include "Patterns/Singleton_impl.hpp"
13#include "Helpers/Assert.hpp"
14
15using namespace std;
16
17ActionHistory::ActionHistory()
18{}
19
20ActionHistory::~ActionHistory()
21{}
22
23void ActionHistory::undoLast(){
24 ASSERT(history.size(),"Undo performed when the undo-queue was empty");
25 HistoryElement elem = history.back();
26 history.pop_back();
27 Action::state_ptr newState = elem.action->undo(elem.state);
28 yrotsih.push_back(HistoryElement(elem.action,newState));
29}
30void ActionHistory::redoLast(){
31 ASSERT(yrotsih.size(),"Redo performed when the redo-queue was empty");
32 HistoryElement elem = yrotsih.back();
33 yrotsih.pop_back();
34 Action::state_ptr oldState = elem.action->redo(elem.state);
35 history.push_back(HistoryElement(elem.action,oldState));
36}
37
38bool ActionHistory::hasUndo(){
39 return history.size()>0;
40}
41
42bool ActionHistory::hasRedo(){
43 return yrotsih.size()>0;
44}
45
46void ActionHistory::addElement(Action* action,Action::state_ptr state){
47 yrotsih.clear();
48 history.push_back(HistoryElement(action,state));
49}
50
51void ActionHistory::clear(){
52 history.clear();
53 yrotsih.clear();
54}
55
56void ActionHistory::init(){
57 ActionHistory *hist = new ActionHistory();
58 setInstance(hist);
59 new UndoAction(hist);
60 new RedoAction(hist);
61}
62
63CONSTRUCT_SINGLETON(ActionHistory)
64
65/****************** Contained actions *******************/
66ActionHistory::UndoAction::UndoAction(ActionHistory *_hist) :
67 Action("Undo"),
68 hist(_hist)
69{}
70
71ActionHistory::UndoAction::~UndoAction(){}
72
73bool ActionHistory::UndoAction::canUndo(){
74 return false;
75}
76
77bool ActionHistory::UndoAction::shouldUndo(){
78 return false;
79}
80
81bool ActionHistory::UndoAction::isActive(){
82 return hist->hasUndo();
83}
84
85Action::state_ptr ActionHistory::UndoAction::performCall(){
86 hist->undoLast();
87 return Action::success;
88}
89
90Action::state_ptr ActionHistory::UndoAction::performUndo(Action::state_ptr){
91 ASSERT(0,"Cannot undo an undo (should use redo for this");
92 return Action::success;
93}
94
95Action::state_ptr ActionHistory::UndoAction::performRedo(Action::state_ptr){
96 ASSERT(0,"Cannot redo an undo");
97 return Action::success;
98}
99
100ActionHistory::RedoAction::RedoAction(ActionHistory *_hist) :
101 Action("Redo"),
102 hist(_hist)
103{}
104
105ActionHistory::RedoAction::~RedoAction(){}
106
107bool ActionHistory::RedoAction::canUndo(){
108 return false;
109}
110
111bool ActionHistory::RedoAction::shouldUndo(){
112 return false;
113}
114
115bool ActionHistory::RedoAction::isActive(){
116 return hist->hasRedo();
117}
118
119Action::state_ptr ActionHistory::RedoAction::performCall(){
120 hist->redoLast();
121 return Action::success;
122}
123
124Action::state_ptr ActionHistory::RedoAction::performUndo(Action::state_ptr){
125 ASSERT(0,"Cannot undo a redo (should use undo for this");
126 return Action::success;
127}
128
129Action::state_ptr ActionHistory::RedoAction::performRedo(Action::state_ptr){
130 ASSERT(0,"Cannot redo a redo");
131 return Action::success;
132}
Note: See TracBrowser for help on using the repository browser.