source: src/Actions/ActionHistory.cpp@ 8f4df1

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 8f4df1 was 047878, checked in by Tillmann Crueger <crueger@…>, 14 years ago

made all actions pass on the dialogs and add the corresponding queries

  • Property mode set to 100644
File size: 3.3 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::fillDialog(Dialog *dialog){
89 ASSERT(dialog,"No Dialog given when filling action dialog");
90 return dialog;
91}
92
93Action::state_ptr ActionHistory::UndoAction::performCall(){
94 hist->undoLast();
95 return Action::success;
96}
97
98Action::state_ptr ActionHistory::UndoAction::performUndo(Action::state_ptr){
99 ASSERT(0,"Cannot undo an undo (should use redo for this");
100 return Action::success;
101}
102
103Action::state_ptr ActionHistory::UndoAction::performRedo(Action::state_ptr){
104 ASSERT(0,"Cannot redo an undo");
105 return Action::success;
106}
107
108ActionHistory::RedoAction::RedoAction(ActionHistory *_hist) :
109 Action("Redo"),
110 hist(_hist)
111{}
112
113ActionHistory::RedoAction::~RedoAction(){}
114
115bool ActionHistory::RedoAction::canUndo(){
116 return false;
117}
118
119bool ActionHistory::RedoAction::shouldUndo(){
120 return false;
121}
122
123bool ActionHistory::RedoAction::isActive(){
124 return hist->hasRedo();
125}
126
127Dialog* ActionHistory::RedoAction::fillDialog(Dialog *dialog){
128 ASSERT(dialog,"No Dialog given when filling action dialog");
129 return dialog;
130}
131
132Action::state_ptr ActionHistory::RedoAction::performCall(){
133 hist->redoLast();
134 return Action::success;
135}
136
137Action::state_ptr ActionHistory::RedoAction::performUndo(Action::state_ptr){
138 ASSERT(0,"Cannot undo a redo (should use undo for this");
139 return Action::success;
140}
141
142Action::state_ptr ActionHistory::RedoAction::performRedo(Action::state_ptr){
143 ASSERT(0,"Cannot redo a redo");
144 return Action::success;
145}
Note: See TracBrowser for help on using the repository browser.