1 | /*
|
---|
2 | * NotMoleculeByIdAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 12, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/SelectionAction/NotMoleculeByIdAction.hpp"
|
---|
11 | #include "molecule.hpp"
|
---|
12 | #include "log.hpp"
|
---|
13 | #include "verbose.hpp"
|
---|
14 | #include "World.hpp"
|
---|
15 |
|
---|
16 | #include <iostream>
|
---|
17 | #include <string>
|
---|
18 |
|
---|
19 | using namespace std;
|
---|
20 |
|
---|
21 | #include "UIElements/UIFactory.hpp"
|
---|
22 | #include "UIElements/Dialog.hpp"
|
---|
23 | #include "UIElements/ValueStorage.hpp"
|
---|
24 |
|
---|
25 |
|
---|
26 | // memento to remember the state when undoing
|
---|
27 |
|
---|
28 | class SelectionNotMoleculeByIdState : public ActionState {
|
---|
29 | public:
|
---|
30 | SelectionNotMoleculeByIdState(molecule* _mol) :
|
---|
31 | mol(_mol)
|
---|
32 | {}
|
---|
33 | molecule* mol;
|
---|
34 | };
|
---|
35 |
|
---|
36 | const char SelectionNotMoleculeByIdAction::NAME[] = "unselect-molecule-by-id";
|
---|
37 |
|
---|
38 | SelectionNotMoleculeByIdAction::SelectionNotMoleculeByIdAction() :
|
---|
39 | Action(NAME)
|
---|
40 | {}
|
---|
41 |
|
---|
42 | SelectionNotMoleculeByIdAction::~SelectionNotMoleculeByIdAction()
|
---|
43 | {}
|
---|
44 |
|
---|
45 | Dialog* SelectionNotMoleculeByIdAction::createDialog() {
|
---|
46 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
47 |
|
---|
48 | dialog->queryMolecule(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
49 |
|
---|
50 | return dialog;
|
---|
51 | }
|
---|
52 |
|
---|
53 | Action::state_ptr SelectionNotMoleculeByIdAction::performCall() {
|
---|
54 | molecule *mol = NULL;
|
---|
55 |
|
---|
56 | ValueStorage::getInstance().queryCurrentValue(NAME, mol);
|
---|
57 |
|
---|
58 | if (World::getInstance().isSelected(mol)) {
|
---|
59 | DoLog(1) && (Log() << Verbose(1) << "Unselecting molecule " << mol->name << endl);
|
---|
60 | World::getInstance().unselectMolecule(mol);
|
---|
61 | return Action::state_ptr(new SelectionNotMoleculeByIdState(mol));
|
---|
62 | } else {
|
---|
63 | return Action::success;
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | Action::state_ptr SelectionNotMoleculeByIdAction::performUndo(Action::state_ptr _state) {
|
---|
68 | SelectionNotMoleculeByIdState *state = assert_cast<SelectionNotMoleculeByIdState*>(_state.get());
|
---|
69 |
|
---|
70 | if (state->mol != NULL)
|
---|
71 | World::getInstance().selectMolecule(state->mol);
|
---|
72 |
|
---|
73 | return Action::state_ptr(new SelectionNotMoleculeByIdState(state->mol));
|
---|
74 | }
|
---|
75 |
|
---|
76 | Action::state_ptr SelectionNotMoleculeByIdAction::performRedo(Action::state_ptr _state){
|
---|
77 | SelectionNotMoleculeByIdState *state = assert_cast<SelectionNotMoleculeByIdState*>(_state.get());
|
---|
78 |
|
---|
79 | if (state->mol != NULL)
|
---|
80 | World::getInstance().unselectMolecule(state->mol);
|
---|
81 |
|
---|
82 | return Action::state_ptr(new SelectionNotMoleculeByIdState(state->mol));
|
---|
83 | }
|
---|
84 |
|
---|
85 | bool SelectionNotMoleculeByIdAction::canUndo() {
|
---|
86 | return true;
|
---|
87 | }
|
---|
88 |
|
---|
89 | bool SelectionNotMoleculeByIdAction::shouldUndo() {
|
---|
90 | return true;
|
---|
91 | }
|
---|
92 |
|
---|
93 | const string SelectionNotMoleculeByIdAction::getName() {
|
---|
94 | return NAME;
|
---|
95 | }
|
---|