1 | /*
|
---|
2 | * NotAtomByIdAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 12, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | // include config.h
|
---|
9 | #ifdef HAVE_CONFIG_H
|
---|
10 | #include <config.h>
|
---|
11 | #endif
|
---|
12 |
|
---|
13 | #include "Helpers/MemDebug.hpp"
|
---|
14 |
|
---|
15 | #include "Actions/SelectionAction/NotAtomByIdAction.hpp"
|
---|
16 | #include "Actions/ActionRegistry.hpp"
|
---|
17 | #include "atom.hpp"
|
---|
18 | #include "Helpers/Log.hpp"
|
---|
19 | #include "Helpers/Verbose.hpp"
|
---|
20 | #include "World.hpp"
|
---|
21 |
|
---|
22 | #include <iostream>
|
---|
23 | #include <string>
|
---|
24 |
|
---|
25 | using namespace std;
|
---|
26 |
|
---|
27 | #include "UIElements/UIFactory.hpp"
|
---|
28 | #include "UIElements/Dialog.hpp"
|
---|
29 | #include "Actions/ValueStorage.hpp"
|
---|
30 |
|
---|
31 |
|
---|
32 | // memento to remember the state when undoing
|
---|
33 |
|
---|
34 | class SelectionNotAtomByIdState : public ActionState {
|
---|
35 | public:
|
---|
36 | SelectionNotAtomByIdState(atom* _walker) :
|
---|
37 | walker(_walker)
|
---|
38 | {}
|
---|
39 | atom* walker;
|
---|
40 | };
|
---|
41 |
|
---|
42 | const char SelectionNotAtomByIdAction::NAME[] = "unselect-atom-by-id";
|
---|
43 |
|
---|
44 | SelectionNotAtomByIdAction::SelectionNotAtomByIdAction() :
|
---|
45 | Action(NAME)
|
---|
46 | {}
|
---|
47 |
|
---|
48 | SelectionNotAtomByIdAction::~SelectionNotAtomByIdAction()
|
---|
49 | {}
|
---|
50 |
|
---|
51 | void SelectionNotAtomById(atom *_atom) {
|
---|
52 | ValueStorage::getInstance().setCurrentValue(SelectionNotAtomByIdAction::NAME, _atom);
|
---|
53 | ActionRegistry::getInstance().getActionByName(SelectionNotAtomByIdAction::NAME)->call(Action::NonInteractive);
|
---|
54 | };
|
---|
55 |
|
---|
56 | Dialog* SelectionNotAtomByIdAction::fillDialog(Dialog *dialog) {
|
---|
57 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
58 |
|
---|
59 | dialog->queryAtom(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
60 |
|
---|
61 | return dialog;
|
---|
62 | }
|
---|
63 |
|
---|
64 | Action::state_ptr SelectionNotAtomByIdAction::performCall() {
|
---|
65 | atom *Walker = NULL;
|
---|
66 |
|
---|
67 | ValueStorage::getInstance().queryCurrentValue(NAME, Walker);
|
---|
68 |
|
---|
69 | if (World::getInstance().isSelected(Walker)) {
|
---|
70 | DoLog(1) && (Log() << Verbose(1) << "Unselecting atom " << *Walker << endl);
|
---|
71 | World::getInstance().unselectAtom(Walker);
|
---|
72 | return Action::state_ptr(new SelectionNotAtomByIdState(Walker));
|
---|
73 | } else {
|
---|
74 | return Action::success;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | Action::state_ptr SelectionNotAtomByIdAction::performUndo(Action::state_ptr _state) {
|
---|
79 | SelectionNotAtomByIdState *state = assert_cast<SelectionNotAtomByIdState*>(_state.get());
|
---|
80 |
|
---|
81 | if (state->walker != NULL)
|
---|
82 | World::getInstance().selectAtom(state->walker);
|
---|
83 |
|
---|
84 | return Action::state_ptr(new SelectionNotAtomByIdState(state->walker));
|
---|
85 | }
|
---|
86 |
|
---|
87 | Action::state_ptr SelectionNotAtomByIdAction::performRedo(Action::state_ptr _state){
|
---|
88 | SelectionNotAtomByIdState *state = assert_cast<SelectionNotAtomByIdState*>(_state.get());
|
---|
89 |
|
---|
90 | if (state->walker != NULL)
|
---|
91 | World::getInstance().unselectAtom(state->walker);
|
---|
92 |
|
---|
93 | return Action::state_ptr(new SelectionNotAtomByIdState(state->walker));
|
---|
94 | }
|
---|
95 |
|
---|
96 | bool SelectionNotAtomByIdAction::canUndo() {
|
---|
97 | return true;
|
---|
98 | }
|
---|
99 |
|
---|
100 | bool SelectionNotAtomByIdAction::shouldUndo() {
|
---|
101 | return true;
|
---|
102 | }
|
---|
103 |
|
---|
104 | const string SelectionNotAtomByIdAction::getName() {
|
---|
105 | return NAME;
|
---|
106 | }
|
---|