source: src/Actions/ActionHistory.cpp@ 67c75b

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 67c75b was 632bc3, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added a small memory tracker to the programm.

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