| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * VerboseAction.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: May 9, 2010
|
|---|
| 12 | * Author: heber
|
|---|
| 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 "CodePatterns/Log.hpp"
|
|---|
| 23 | #include "CodePatterns/Verbose.hpp"
|
|---|
| 24 |
|
|---|
| 25 | #include <iostream>
|
|---|
| 26 | #include <string>
|
|---|
| 27 |
|
|---|
| 28 | #include "Actions/CommandAction/VerboseAction.hpp"
|
|---|
| 29 |
|
|---|
| 30 | using namespace MoleCuilder;
|
|---|
| 31 |
|
|---|
| 32 | // and construct the stuff
|
|---|
| 33 | #include "VerboseAction.def"
|
|---|
| 34 | #include "Action_impl_pre.hpp"
|
|---|
| 35 | /** =========== define the function ====================== */
|
|---|
| 36 | Action::state_ptr CommandVerboseAction::performCall() {
|
|---|
| 37 | int oldverbosity = getVerbosity();
|
|---|
| 38 |
|
|---|
| 39 | if (oldverbosity != params.verbosity) {
|
|---|
| 40 | // prepare undo state
|
|---|
| 41 | CommandVerboseState *UndoState = new CommandVerboseState(oldverbosity, params);
|
|---|
| 42 | // set new verbosity
|
|---|
| 43 | setVerbosity(params.verbosity);
|
|---|
| 44 | LOG(0, "Setting verbosity from " << oldverbosity << " to " << params.verbosity << ".");
|
|---|
| 45 | return Action::state_ptr(UndoState);
|
|---|
| 46 | } else {
|
|---|
| 47 | LOG(0, "Verbosity remains unchanged at " << oldverbosity << ".");
|
|---|
| 48 | return Action::success;
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | Action::state_ptr CommandVerboseAction::performUndo(Action::state_ptr _state) {
|
|---|
| 53 | CommandVerboseState *state = assert_cast<CommandVerboseState*>(_state.get());
|
|---|
| 54 |
|
|---|
| 55 | LOG(0, "Setting verbosity from " << state->params.verbosity << " to " << state->oldverbosity << ".");
|
|---|
| 56 | setVerbosity(state->oldverbosity);
|
|---|
| 57 |
|
|---|
| 58 | return Action::state_ptr(_state);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | Action::state_ptr CommandVerboseAction::performRedo(Action::state_ptr _state){
|
|---|
| 62 | CommandVerboseState *state = assert_cast<CommandVerboseState*>(_state.get());
|
|---|
| 63 |
|
|---|
| 64 | LOG(0, "Setting verbosity from " << state->oldverbosity << " to " << state->params.verbosity << ".");
|
|---|
| 65 | setVerbosity(state->params.verbosity);
|
|---|
| 66 |
|
|---|
| 67 | return Action::state_ptr(_state);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | bool CommandVerboseAction::canUndo() {
|
|---|
| 71 | return true;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | bool CommandVerboseAction::shouldUndo() {
|
|---|
| 75 | return true;
|
|---|
| 76 | }
|
|---|
| 77 | /** =========== end of function ====================== */
|
|---|