| [bcf653] | 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| [0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| [94d5ac6] | 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/>.
|
|---|
| [bcf653] | 21 | */
|
|---|
| 22 |
|
|---|
| [1fa107] | 23 | /*
|
|---|
| 24 | * MakroAction.cpp
|
|---|
| 25 | *
|
|---|
| 26 | * Created on: Dec 17, 2009
|
|---|
| 27 | * Author: crueger
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| [bf3817] | 30 | // include config.h
|
|---|
| 31 | #ifdef HAVE_CONFIG_H
|
|---|
| 32 | #include <config.h>
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| [112b09] | 36 |
|
|---|
| [cc04b7] | 37 | #include <string>
|
|---|
| 38 |
|
|---|
| [1fa107] | 39 | #include "Actions/MakroAction.hpp"
|
|---|
| 40 | #include "Actions/Action.hpp"
|
|---|
| 41 | #include "Actions/ActionSequence.hpp"
|
|---|
| [ad011c] | 42 | #include "CodePatterns/Assert.hpp"
|
|---|
| [1fa107] | 43 |
|
|---|
| [ce7fdc] | 44 | using namespace MoleCuilder;
|
|---|
| [cc04b7] | 45 |
|
|---|
| [67e2b3] | 46 | class MakroActionState : public ActionState{
|
|---|
| 47 | public:
|
|---|
| 48 | MakroActionState(ActionSequence::stateSet _states) :
|
|---|
| 49 | states(_states)
|
|---|
| 50 | {}
|
|---|
| 51 | virtual ~MakroActionState(){
|
|---|
| [5b0b98] | 52 | // All contained states are destroyed by the shared ptrs
|
|---|
| [67e2b3] | 53 | }
|
|---|
| 54 |
|
|---|
| 55 | ActionSequence::stateSet states;
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| [22b786] | 58 | MakroAction::MakroAction(const ActionTrait &_trait,ActionSequence& _actions,bool _doRegister) :
|
|---|
| [e4afb4] | 59 | Action(_trait,_doRegister),
|
|---|
| [1fa107] | 60 | actions(_actions)
|
|---|
| 61 | {
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | MakroAction::~MakroAction()
|
|---|
| 65 | {
|
|---|
| [22b786] | 66 | // emptying the sequence is someone else responsibility
|
|---|
| 67 | // Action* action;
|
|---|
| 68 | // while((action=actions.removeLastAction())){
|
|---|
| 69 | // delete action;
|
|---|
| 70 | // }
|
|---|
| [1fa107] | 71 | }
|
|---|
| 72 |
|
|---|
| [22b786] | 73 | void MakroAction::prepare(ActionRegistry &AR)
|
|---|
| 74 | {}
|
|---|
| 75 |
|
|---|
| 76 | void MakroAction::unprepare(ActionRegistry &AR)
|
|---|
| 77 | {}
|
|---|
| 78 |
|
|---|
| [047878] | 79 | Dialog* MakroAction::fillDialog(Dialog *dialog) {
|
|---|
| [22b786] | 80 | return actions.fillAllDialogs(dialog);
|
|---|
| [80951de] | 81 | }
|
|---|
| [1fa107] | 82 |
|
|---|
| [5b0b98] | 83 | Action::state_ptr MakroAction::performCall(){
|
|---|
| [22b786] | 84 | ActionSequence::stateSet states = actions.callAll(true);
|
|---|
| [5b0b98] | 85 | return Action::state_ptr(new MakroActionState(states));
|
|---|
| [1fa107] | 86 | }
|
|---|
| 87 |
|
|---|
| [5b0b98] | 88 | Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) {
|
|---|
| 89 | MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
|
|---|
| [67e2b3] | 90 | ASSERT(state,"Type mismatch for the state of the MakroAction");
|
|---|
| [22b786] | 91 | ActionSequence::stateSet states = actions.undoAll(state->states);
|
|---|
| [5b0b98] | 92 | return Action::state_ptr(new MakroActionState(states));
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | Action::state_ptr MakroAction::performRedo(Action::state_ptr _state){
|
|---|
| 96 | MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
|
|---|
| 97 | ASSERT(state,"Type mismatch for the state of the MakroAction");
|
|---|
| [22b786] | 98 | ActionSequence::stateSet states = actions.redoAll(state->states);
|
|---|
| [5b0b98] | 99 | return Action::state_ptr(new MakroActionState(states));
|
|---|
| [1fa107] | 100 | }
|
|---|
| 101 |
|
|---|
| 102 | bool MakroAction::canUndo() {
|
|---|
| [22b786] | 103 | return actions.canUndo();
|
|---|
| [1fa107] | 104 | }
|
|---|
| [67e2b3] | 105 |
|
|---|
| 106 | bool MakroAction::shouldUndo() {
|
|---|
| [22b786] | 107 | return actions.shouldUndo();
|
|---|
| [67e2b3] | 108 | }
|
|---|