1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * MakroAction.cpp
|
---|
25 | *
|
---|
26 | * Created on: Dec 17, 2009
|
---|
27 | * Author: crueger
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "CodePatterns/MemDebug.hpp"
|
---|
36 |
|
---|
37 | #include <string>
|
---|
38 |
|
---|
39 | #include "Actions/MakroAction.hpp"
|
---|
40 | #include "Actions/Action.hpp"
|
---|
41 | #include "Actions/ActionSequence.hpp"
|
---|
42 | #include "CodePatterns/Assert.hpp"
|
---|
43 |
|
---|
44 | using namespace MoleCuilder;
|
---|
45 |
|
---|
46 | class MakroActionState : public ActionState{
|
---|
47 | public:
|
---|
48 | MakroActionState(ActionSequence::stateSet _states) :
|
---|
49 | states(_states)
|
---|
50 | {}
|
---|
51 | virtual ~MakroActionState(){
|
---|
52 | // All contained states are destroyed by the shared ptrs
|
---|
53 | }
|
---|
54 |
|
---|
55 | ActionSequence::stateSet states;
|
---|
56 | };
|
---|
57 |
|
---|
58 | MakroAction::MakroAction(const ActionTrait &_trait,ActionSequence* _actions,bool _doRegister) :
|
---|
59 | Action(_trait,_doRegister),
|
---|
60 | actions(_actions)
|
---|
61 | {
|
---|
62 | }
|
---|
63 |
|
---|
64 | MakroAction::~MakroAction()
|
---|
65 | {
|
---|
66 | Action* action;
|
---|
67 | while((action=actions->removeLastAction())){
|
---|
68 | delete action;
|
---|
69 | }
|
---|
70 | delete actions;
|
---|
71 | }
|
---|
72 |
|
---|
73 | Dialog* MakroAction::fillDialog(Dialog *dialog) {
|
---|
74 | return actions->fillAllDialogs(dialog);
|
---|
75 | }
|
---|
76 |
|
---|
77 | Action::state_ptr MakroAction::performCall(){
|
---|
78 | ActionSequence::stateSet states = actions->callAll(true);
|
---|
79 | return Action::state_ptr(new MakroActionState(states));
|
---|
80 | }
|
---|
81 |
|
---|
82 | Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) {
|
---|
83 | MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
|
---|
84 | ASSERT(state,"Type mismatch for the state of the MakroAction");
|
---|
85 | ActionSequence::stateSet states = actions->undoAll(state->states);
|
---|
86 | return Action::state_ptr(new MakroActionState(states));
|
---|
87 | }
|
---|
88 |
|
---|
89 | Action::state_ptr MakroAction::performRedo(Action::state_ptr _state){
|
---|
90 | MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
|
---|
91 | ASSERT(state,"Type mismatch for the state of the MakroAction");
|
---|
92 | ActionSequence::stateSet states = actions->redoAll(state->states);
|
---|
93 | return Action::state_ptr(new MakroActionState(states));
|
---|
94 | }
|
---|
95 |
|
---|
96 | bool MakroAction::canUndo() {
|
---|
97 | return actions->canUndo();
|
---|
98 | }
|
---|
99 |
|
---|
100 | bool MakroAction::shouldUndo() {
|
---|
101 | return actions->shouldUndo();
|
---|
102 | }
|
---|