1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * ActionHistory.cpp
|
---|
10 | *
|
---|
11 | * Created on: Mar 25, 2010
|
---|
12 | * Author: crueger
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "CodePatterns/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "Actions/ActionHistory.hpp"
|
---|
23 |
|
---|
24 | #include <iostream>
|
---|
25 |
|
---|
26 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
27 | #include "CodePatterns/Assert.hpp"
|
---|
28 |
|
---|
29 | ActionHistory::ActionHistory()
|
---|
30 | {}
|
---|
31 |
|
---|
32 | ActionHistory::~ActionHistory()
|
---|
33 | {}
|
---|
34 |
|
---|
35 | void ActionHistory::undoLast(){
|
---|
36 | ASSERT(history.size(),"Undo performed when the undo-queue was empty");
|
---|
37 | HistoryElement elem = history.back();
|
---|
38 | history.pop_back();
|
---|
39 | Action::state_ptr newState = elem.action->undo(elem.state);
|
---|
40 | yrotsih.push_back(HistoryElement(elem.action,newState));
|
---|
41 | }
|
---|
42 | void ActionHistory::redoLast(){
|
---|
43 | ASSERT(yrotsih.size(),"Redo performed when the redo-queue was empty");
|
---|
44 | HistoryElement elem = yrotsih.back();
|
---|
45 | yrotsih.pop_back();
|
---|
46 | Action::state_ptr oldState = elem.action->redo(elem.state);
|
---|
47 | history.push_back(HistoryElement(elem.action,oldState));
|
---|
48 | }
|
---|
49 |
|
---|
50 | bool ActionHistory::hasUndo(){
|
---|
51 | return history.size()>0;
|
---|
52 | }
|
---|
53 |
|
---|
54 | bool ActionHistory::hasRedo(){
|
---|
55 | return yrotsih.size()>0;
|
---|
56 | }
|
---|
57 |
|
---|
58 | void ActionHistory::addElement(Action* action,Action::state_ptr state){
|
---|
59 | yrotsih.clear();
|
---|
60 | history.push_back(HistoryElement(action,state));
|
---|
61 | }
|
---|
62 |
|
---|
63 | void ActionHistory::clear(){
|
---|
64 | history.clear();
|
---|
65 | yrotsih.clear();
|
---|
66 | }
|
---|
67 |
|
---|
68 | void ActionHistory::init(){
|
---|
69 | ActionHistory *hist = new ActionHistory();
|
---|
70 | setInstance(hist);
|
---|
71 | }
|
---|
72 |
|
---|
73 | CONSTRUCT_SINGLETON(ActionHistory)
|
---|
74 |
|
---|
75 | /****************** Contained actions *******************/
|
---|
76 |
|
---|