| 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 | * 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 "Helpers/MemDebug.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include "Actions/CommandAction/VerboseAction.hpp"
|
|---|
| 23 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 24 | #include "Helpers/Log.hpp"
|
|---|
| 25 | #include "Helpers/Verbose.hpp"
|
|---|
| 26 |
|
|---|
| 27 | #include <iostream>
|
|---|
| 28 | #include <string>
|
|---|
| 29 |
|
|---|
| 30 | using namespace std;
|
|---|
| 31 |
|
|---|
| 32 | #include "UIElements/UIFactory.hpp"
|
|---|
| 33 | #include "UIElements/Dialog.hpp"
|
|---|
| 34 | #include "Actions/ValueStorage.hpp"
|
|---|
| 35 |
|
|---|
| 36 | // memento to remember the state when undoing
|
|---|
| 37 |
|
|---|
| 38 | class CommandVerboseState : public ActionState {
|
|---|
| 39 | public:
|
|---|
| 40 | CommandVerboseState(const int _oldverbosity, const int _newverbosity) :
|
|---|
| 41 | oldverbosity(_oldverbosity),
|
|---|
| 42 | newverbosity(_newverbosity)
|
|---|
| 43 | {}
|
|---|
| 44 | int oldverbosity;
|
|---|
| 45 | int newverbosity;
|
|---|
| 46 | };
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | const char CommandVerboseAction::NAME[] = "verbose";
|
|---|
| 50 |
|
|---|
| 51 | CommandVerboseAction::CommandVerboseAction() :
|
|---|
| 52 | Action(NAME)
|
|---|
| 53 | {}
|
|---|
| 54 |
|
|---|
| 55 | CommandVerboseAction::~CommandVerboseAction()
|
|---|
| 56 | {}
|
|---|
| 57 |
|
|---|
| 58 | void CommandVerbose(int verbosity) {
|
|---|
| 59 | ValueStorage::getInstance().setCurrentValue(CommandVerboseAction::NAME, verbosity);
|
|---|
| 60 | ActionRegistry::getInstance().getActionByName(CommandVerboseAction::NAME)->call(Action::NonInteractive);
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | void CommandVerboseAction::getParametersfromValueStorage()
|
|---|
| 64 | {};
|
|---|
| 65 |
|
|---|
| 66 | Dialog* CommandVerboseAction::fillDialog(Dialog *dialog) {
|
|---|
| 67 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| 68 |
|
|---|
| 69 | dialog->queryInt(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 70 |
|
|---|
| 71 | return dialog;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | Action::state_ptr CommandVerboseAction::performCall() {
|
|---|
| 75 | int oldverbosity = getVerbosity();
|
|---|
| 76 | int newverbosity = 2;
|
|---|
| 77 |
|
|---|
| 78 | ValueStorage::getInstance().queryCurrentValue(NAME, newverbosity);
|
|---|
| 79 |
|
|---|
| 80 | if (oldverbosity != newverbosity) {
|
|---|
| 81 | CommandVerboseState *UndoState = new CommandVerboseState(oldverbosity, newverbosity);
|
|---|
| 82 | setVerbosity(newverbosity);
|
|---|
| 83 | DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << oldverbosity << " to " << newverbosity << "." << endl);
|
|---|
| 84 | return Action::state_ptr(UndoState);
|
|---|
| 85 | } else {
|
|---|
| 86 | DoLog(0) && (Log() << Verbose(0) << "Verbosity remains unchanged at " << oldverbosity << "." << endl);
|
|---|
| 87 | return Action::failure;
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | Action::state_ptr CommandVerboseAction::performUndo(Action::state_ptr _state) {
|
|---|
| 92 | CommandVerboseState *state = assert_cast<CommandVerboseState*>(_state.get());
|
|---|
| 93 |
|
|---|
| 94 | DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << state->newverbosity << " to " << state->oldverbosity << "." << endl);
|
|---|
| 95 | setVerbosity(state->oldverbosity);
|
|---|
| 96 |
|
|---|
| 97 | return Action::state_ptr(_state);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | Action::state_ptr CommandVerboseAction::performRedo(Action::state_ptr _state){
|
|---|
| 101 | CommandVerboseState *state = assert_cast<CommandVerboseState*>(_state.get());
|
|---|
| 102 |
|
|---|
| 103 | DoLog(0) && (Log() << Verbose(0) << "Setting verbosity from " << state->oldverbosity << " to " << state->newverbosity << "." << endl);
|
|---|
| 104 | setVerbosity(state->newverbosity);
|
|---|
| 105 |
|
|---|
| 106 | return Action::state_ptr(_state);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | bool CommandVerboseAction::canUndo() {
|
|---|
| 110 | return true;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | bool CommandVerboseAction::shouldUndo() {
|
|---|
| 114 | return true;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | const string CommandVerboseAction::getName() {
|
|---|
| 118 | return NAME;
|
|---|
| 119 | }
|
|---|