| [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 |  | 
|---|
| [3139b2] | 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 | { | 
|---|
|  | 66 | Action* action; | 
|---|
| [24a5e0] | 67 | while((action=actions->removeLastAction())){ | 
|---|
| [1fa107] | 68 | delete action; | 
|---|
|  | 69 | } | 
|---|
|  | 70 | delete actions; | 
|---|
|  | 71 | } | 
|---|
|  | 72 |  | 
|---|
| [047878] | 73 | Dialog* MakroAction::fillDialog(Dialog *dialog) { | 
|---|
|  | 74 | return actions->fillAllDialogs(dialog); | 
|---|
| [80951de] | 75 | } | 
|---|
| [1fa107] | 76 |  | 
|---|
| [5b0b98] | 77 | Action::state_ptr MakroAction::performCall(){ | 
|---|
| [2efa90] | 78 | ActionSequence::stateSet states = actions->callAll(true); | 
|---|
| [5b0b98] | 79 | return Action::state_ptr(new MakroActionState(states)); | 
|---|
| [1fa107] | 80 | } | 
|---|
|  | 81 |  | 
|---|
| [5b0b98] | 82 | Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) { | 
|---|
|  | 83 | MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get()); | 
|---|
| [67e2b3] | 84 | ASSERT(state,"Type mismatch for the state of the MakroAction"); | 
|---|
|  | 85 | ActionSequence::stateSet states = actions->undoAll(state->states); | 
|---|
| [5b0b98] | 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)); | 
|---|
| [1fa107] | 94 | } | 
|---|
|  | 95 |  | 
|---|
|  | 96 | bool MakroAction::canUndo() { | 
|---|
|  | 97 | return actions->canUndo(); | 
|---|
|  | 98 | } | 
|---|
| [67e2b3] | 99 |  | 
|---|
|  | 100 | bool MakroAction::shouldUndo() { | 
|---|
|  | 101 | return actions->shouldUndo(); | 
|---|
|  | 102 | } | 
|---|