[97ebf8] | 1 | /*
|
---|
| 2 | * FastParsingAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/CmdAction/FastParsingAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[97ebf8] | 12 | #include "config.hpp"
|
---|
[952f38] | 13 | #include "Helpers/Log.hpp"
|
---|
| 14 | #include "Helpers/Verbose.hpp"
|
---|
[97ebf8] | 15 | #include "World.hpp"
|
---|
| 16 |
|
---|
| 17 | #include <iostream>
|
---|
| 18 | #include <string>
|
---|
| 19 |
|
---|
| 20 | using namespace std;
|
---|
| 21 |
|
---|
| 22 | #include "UIElements/UIFactory.hpp"
|
---|
| 23 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 24 | #include "Actions/ValueStorage.hpp"
|
---|
[ccf31f] | 25 |
|
---|
| 26 | // memento to remember the state when undoing
|
---|
| 27 |
|
---|
| 28 | class CommandLineFastParsingState : public ActionState {
|
---|
| 29 | public:
|
---|
[7e37a3] | 30 | CommandLineFastParsingState(const bool _oldvalue, const bool _newvalue) :
|
---|
| 31 | oldvalue(_oldvalue),
|
---|
| 32 | newvalue(_newvalue)
|
---|
[ccf31f] | 33 | {}
|
---|
[7e37a3] | 34 | bool oldvalue;
|
---|
| 35 | bool newvalue;
|
---|
[ccf31f] | 36 | };
|
---|
| 37 |
|
---|
[97ebf8] | 38 |
|
---|
| 39 | const char CommandLineFastParsingAction::NAME[] = "fastparsing";
|
---|
| 40 |
|
---|
| 41 | CommandLineFastParsingAction::CommandLineFastParsingAction() :
|
---|
| 42 | Action(NAME)
|
---|
| 43 | {}
|
---|
| 44 |
|
---|
| 45 | CommandLineFastParsingAction::~CommandLineFastParsingAction()
|
---|
| 46 | {}
|
---|
| 47 |
|
---|
[ecbc9a] | 48 | void CommandFastParsing(bool fastparsing) {
|
---|
| 49 | ValueStorage::getInstance().setCurrentValue(CommandLineFastParsingAction::NAME, fastparsing);
|
---|
| 50 | ActionRegistry::getInstance().getActionByName(CommandLineFastParsingAction::NAME)->call(Action::NonInteractive);
|
---|
| 51 | };
|
---|
| 52 |
|
---|
[047878] | 53 | Dialog* CommandLineFastParsingAction::fillDialog(Dialog *dialog) {
|
---|
| 54 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[97ebf8] | 55 |
|
---|
[c89fb4] | 56 | dialog->queryBoolean(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
[ccf31f] | 57 |
|
---|
| 58 | return dialog;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | Action::state_ptr CommandLineFastParsingAction::performCall() {
|
---|
[97ebf8] | 62 | config *configuration = World::getInstance().getConfig();
|
---|
[7e37a3] | 63 | bool oldvalue = configuration->FastParsing;
|
---|
| 64 | bool newvalue;
|
---|
| 65 | ValueStorage::getInstance().queryCurrentValue(NAME, newvalue);
|
---|
| 66 | configuration->FastParsing = newvalue;
|
---|
[ccf31f] | 67 | if (configuration->FastParsing)
|
---|
| 68 | DoLog(0) && (Log() << Verbose(0) << "I won't parse trajectories." << endl);
|
---|
| 69 | else
|
---|
| 70 | DoLog(0) && (Log() << Verbose(0) << "I will parse trajectories." << endl);
|
---|
[7e37a3] | 71 | return Action::state_ptr(new CommandLineFastParsingState(oldvalue, newvalue));
|
---|
[97ebf8] | 72 | }
|
---|
| 73 |
|
---|
| 74 | Action::state_ptr CommandLineFastParsingAction::performUndo(Action::state_ptr _state) {
|
---|
[ccf31f] | 75 | CommandLineFastParsingState *state = assert_cast<CommandLineFastParsingState*>(_state.get());
|
---|
| 76 |
|
---|
| 77 | config *configuration = World::getInstance().getConfig();
|
---|
[7e37a3] | 78 | configuration->FastParsing = state->oldvalue;
|
---|
| 79 | if (configuration->FastParsing)
|
---|
| 80 | DoLog(0) && (Log() << Verbose(0) << "I won't parse trajectories." << endl);
|
---|
| 81 | else
|
---|
| 82 | DoLog(0) && (Log() << Verbose(0) << "I will parse trajectories." << endl);
|
---|
[97ebf8] | 83 |
|
---|
[7e37a3] | 84 | return Action::state_ptr(_state);
|
---|
[97ebf8] | 85 | }
|
---|
| 86 |
|
---|
| 87 | Action::state_ptr CommandLineFastParsingAction::performRedo(Action::state_ptr _state){
|
---|
[7e37a3] | 88 | CommandLineFastParsingState *state = assert_cast<CommandLineFastParsingState*>(_state.get());
|
---|
| 89 |
|
---|
| 90 | config *configuration = World::getInstance().getConfig();
|
---|
| 91 | configuration->FastParsing = state->newvalue;
|
---|
| 92 | if (configuration->FastParsing)
|
---|
| 93 | DoLog(0) && (Log() << Verbose(0) << "I won't parse trajectories." << endl);
|
---|
| 94 | else
|
---|
| 95 | DoLog(0) && (Log() << Verbose(0) << "I will parse trajectories." << endl);
|
---|
| 96 |
|
---|
| 97 | return Action::state_ptr(_state);
|
---|
[97ebf8] | 98 | }
|
---|
| 99 |
|
---|
| 100 | bool CommandLineFastParsingAction::canUndo() {
|
---|
[ccf31f] | 101 | return true;
|
---|
[97ebf8] | 102 | }
|
---|
| 103 |
|
---|
| 104 | bool CommandLineFastParsingAction::shouldUndo() {
|
---|
[ccf31f] | 105 | return true;
|
---|
[97ebf8] | 106 | }
|
---|
| 107 |
|
---|
| 108 | const string CommandLineFastParsingAction::getName() {
|
---|
| 109 | return NAME;
|
---|
| 110 | }
|
---|