source: src/Actions/ActionHistory.cpp@ f7ee68

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

Some derived Actions lacked return NULL in createDialog().

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