source: src/Actions/ActionHistory.cpp@ d56640

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

Added full undo functioniality

  • Property mode set to 100644
File size: 2.7 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
38void ActionHistory::addElement(Action* action,Action::state_ptr state){
39 cout << "Adding action to end of history" << endl;
40 yrotsih.clear();
41 history.push_back(HistoryElement(action,state));
42}
43
44void ActionHistory::clear(){
45 cout << "History cleared" << endl;
46 history.clear();
47 yrotsih.clear();
48}
49
50void ActionHistory::init(){
51 ActionHistory *hist = new ActionHistory();
52 setInstance(hist);
53 new UndoAction(hist);
54 new RedoAction(hist);
55}
56
57CONSTRUCT_SINGLETON(ActionHistory)
58
59/****************** Contained actions *******************/
60ActionHistory::UndoAction::UndoAction(ActionHistory *_hist) :
61 Action("Undo"),
62 hist(_hist)
63{}
64
65ActionHistory::UndoAction::~UndoAction(){}
66
67bool ActionHistory::UndoAction::canUndo(){
68 return false;
69}
70
71bool ActionHistory::UndoAction::shouldUndo(){
72 return false;
73}
74
75Action::state_ptr ActionHistory::UndoAction::performCall(){
76 hist->undoLast();
77 return Action::success;
78}
79
80Action::state_ptr ActionHistory::UndoAction::performUndo(Action::state_ptr){
81 ASSERT(0,"Cannot undo an undo (should use redo for this");
82 return Action::success;
83}
84
85Action::state_ptr ActionHistory::UndoAction::performRedo(Action::state_ptr){
86 ASSERT(0,"Cannot redo an undo");
87 return Action::success;
88}
89
90ActionHistory::RedoAction::RedoAction(ActionHistory *_hist) :
91 Action("Redo"),
92 hist(_hist)
93{}
94
95ActionHistory::RedoAction::~RedoAction(){}
96
97bool ActionHistory::RedoAction::canUndo(){
98 return false;
99}
100
101bool ActionHistory::RedoAction::shouldUndo(){
102 return false;
103}
104
105Action::state_ptr ActionHistory::RedoAction::performCall(){
106 hist->redoLast();
107 return Action::success;
108}
109
110Action::state_ptr ActionHistory::RedoAction::performUndo(Action::state_ptr){
111 ASSERT(0,"Cannot undo a redo (should use undo for this");
112 return Action::success;
113}
114
115Action::state_ptr ActionHistory::RedoAction::performRedo(Action::state_ptr){
116 ASSERT(0,"Cannot redo a redo");
117 return Action::success;
118}
Note: See TracBrowser for help on using the repository browser.