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