source: src/Actions/ActionHistory.cpp@ bbbad5

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 bbbad5 was 446bc1, checked in by Frederik Heber <heber@…>, 15 years ago

Added Undo/Redo actions to MapOfActions.

  • ActionHistory:UndoAction and ::RedoAction now have ::NAME[], "undo", "redo"
  • added as command line arguments
  • TESTFIX: added translation of atom test (Simple_configuration/9)
  • TESTFIX: added undo/redo for this translation test

From now on, undo/redo should be tested within the testsuite by adding under the
same test case block another one with additional "--undo" and "--undo --redo"
added to check for correct implementation of ::performUndo() and ::performRedo()
as well.

  • Property mode set to 100644
File size: 3.4 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 *******************/
69
70const char ActionHistory::UndoAction::NAME[] = "undo";
71
72ActionHistory::UndoAction::UndoAction(ActionHistory *_hist) :
73 Action(NAME),
74 hist(_hist)
75{}
76
77ActionHistory::UndoAction::~UndoAction(){}
78
79bool ActionHistory::UndoAction::canUndo(){
80 return false;
81}
82
83bool ActionHistory::UndoAction::shouldUndo(){
84 return false;
85}
86
87bool ActionHistory::UndoAction::isActive(){
88 return hist->hasUndo();
89}
90
91Dialog* ActionHistory::UndoAction::fillDialog(Dialog *dialog){
92 ASSERT(dialog,"No Dialog given when filling action dialog");
93 return dialog;
94}
95
96Action::state_ptr ActionHistory::UndoAction::performCall(){
97 std::cout << "Undo" << std::endl;
98 hist->undoLast();
99 return Action::success;
100}
101
102Action::state_ptr ActionHistory::UndoAction::performUndo(Action::state_ptr){
103 ASSERT(0,"Cannot undo an undo (should use redo for this");
104 return Action::success;
105}
106
107Action::state_ptr ActionHistory::UndoAction::performRedo(Action::state_ptr){
108 ASSERT(0,"Cannot redo an undo");
109 return Action::success;
110}
111
112const char ActionHistory::RedoAction::NAME[] = "redo";
113
114ActionHistory::RedoAction::RedoAction(ActionHistory *_hist) :
115 Action(NAME),
116 hist(_hist)
117{}
118
119ActionHistory::RedoAction::~RedoAction(){}
120
121bool ActionHistory::RedoAction::canUndo(){
122 return false;
123}
124
125bool ActionHistory::RedoAction::shouldUndo(){
126 return false;
127}
128
129bool ActionHistory::RedoAction::isActive(){
130 std::cout << "Redo" << std::endl;
131 return hist->hasRedo();
132}
133
134Dialog* ActionHistory::RedoAction::fillDialog(Dialog *dialog){
135 ASSERT(dialog,"No Dialog given when filling action dialog");
136 return dialog;
137}
138
139Action::state_ptr ActionHistory::RedoAction::performCall(){
140 hist->redoLast();
141 return Action::success;
142}
143
144Action::state_ptr ActionHistory::RedoAction::performUndo(Action::state_ptr){
145 ASSERT(0,"Cannot undo a redo (should use undo for this");
146 return Action::success;
147}
148
149Action::state_ptr ActionHistory::RedoAction::performRedo(Action::state_ptr){
150 ASSERT(0,"Cannot redo a redo");
151 return Action::success;
152}
Note: See TracBrowser for help on using the repository browser.