1 | /*
|
---|
2 | * FastParsingAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/CmdAction/FastParsingAction.hpp"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "config.hpp"
|
---|
13 | #include "Helpers/Log.hpp"
|
---|
14 | #include "Helpers/Verbose.hpp"
|
---|
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"
|
---|
24 | #include "Actions/ValueStorage.hpp"
|
---|
25 |
|
---|
26 | // memento to remember the state when undoing
|
---|
27 |
|
---|
28 | class CommandLineFastParsingState : public ActionState {
|
---|
29 | public:
|
---|
30 | CommandLineFastParsingState(const bool _oldvalue, const bool _newvalue) :
|
---|
31 | oldvalue(_oldvalue),
|
---|
32 | newvalue(_newvalue)
|
---|
33 | {}
|
---|
34 | bool oldvalue;
|
---|
35 | bool newvalue;
|
---|
36 | };
|
---|
37 |
|
---|
38 |
|
---|
39 | const char CommandLineFastParsingAction::NAME[] = "fastparsing";
|
---|
40 |
|
---|
41 | CommandLineFastParsingAction::CommandLineFastParsingAction() :
|
---|
42 | Action(NAME)
|
---|
43 | {}
|
---|
44 |
|
---|
45 | CommandLineFastParsingAction::~CommandLineFastParsingAction()
|
---|
46 | {}
|
---|
47 |
|
---|
48 | void CommandFastParsing(bool fastparsing) {
|
---|
49 | ValueStorage::getInstance().setCurrentValue(CommandLineFastParsingAction::NAME, fastparsing);
|
---|
50 | ActionRegistry::getInstance().getActionByName(CommandLineFastParsingAction::NAME)->call(Action::NonInteractive);
|
---|
51 | };
|
---|
52 |
|
---|
53 | Dialog* CommandLineFastParsingAction::fillDialog(Dialog *dialog) {
|
---|
54 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
55 |
|
---|
56 | dialog->queryBoolean(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
57 |
|
---|
58 | return dialog;
|
---|
59 | }
|
---|
60 |
|
---|
61 | Action::state_ptr CommandLineFastParsingAction::performCall() {
|
---|
62 | config *configuration = World::getInstance().getConfig();
|
---|
63 | bool oldvalue = configuration->FastParsing;
|
---|
64 | bool newvalue;
|
---|
65 | ValueStorage::getInstance().queryCurrentValue(NAME, newvalue);
|
---|
66 | configuration->FastParsing = newvalue;
|
---|
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);
|
---|
71 | return Action::state_ptr(new CommandLineFastParsingState(oldvalue, newvalue));
|
---|
72 | }
|
---|
73 |
|
---|
74 | Action::state_ptr CommandLineFastParsingAction::performUndo(Action::state_ptr _state) {
|
---|
75 | CommandLineFastParsingState *state = assert_cast<CommandLineFastParsingState*>(_state.get());
|
---|
76 |
|
---|
77 | config *configuration = World::getInstance().getConfig();
|
---|
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);
|
---|
83 |
|
---|
84 | return Action::state_ptr(_state);
|
---|
85 | }
|
---|
86 |
|
---|
87 | Action::state_ptr CommandLineFastParsingAction::performRedo(Action::state_ptr _state){
|
---|
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);
|
---|
98 | }
|
---|
99 |
|
---|
100 | bool CommandLineFastParsingAction::canUndo() {
|
---|
101 | return true;
|
---|
102 | }
|
---|
103 |
|
---|
104 | bool CommandLineFastParsingAction::shouldUndo() {
|
---|
105 | return true;
|
---|
106 | }
|
---|
107 |
|
---|
108 | const string CommandLineFastParsingAction::getName() {
|
---|
109 | return NAME;
|
---|
110 | }
|
---|