| [e2009b] | 1 | /* | 
|---|
| [521bbf] | 2 | * NotMoleculeByIdAction.cpp | 
|---|
| [e2009b] | 3 | * | 
|---|
|  | 4 | *  Created on: May 12, 2010 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #include "Helpers/MemDebug.hpp" | 
|---|
|  | 9 |  | 
|---|
|  | 10 | #include "Actions/SelectionAction/NotMoleculeByIdAction.hpp" | 
|---|
| [0430e3] | 11 | #include "Actions/ActionRegistry.hpp" | 
|---|
| [533838] | 12 | #include "molecule.hpp" | 
|---|
| [952f38] | 13 | #include "Helpers/Log.hpp" | 
|---|
|  | 14 | #include "Helpers/Verbose.hpp" | 
|---|
| [e2009b] | 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" | 
|---|
| [e2009b] | 25 |  | 
|---|
|  | 26 |  | 
|---|
|  | 27 | // memento to remember the state when undoing | 
|---|
|  | 28 |  | 
|---|
|  | 29 | class SelectionNotMoleculeByIdState : public ActionState { | 
|---|
|  | 30 | public: | 
|---|
|  | 31 | SelectionNotMoleculeByIdState(molecule* _mol) : | 
|---|
|  | 32 | mol(_mol) | 
|---|
|  | 33 | {} | 
|---|
|  | 34 | molecule* mol; | 
|---|
|  | 35 | }; | 
|---|
|  | 36 |  | 
|---|
| [533838] | 37 | const char SelectionNotMoleculeByIdAction::NAME[] = "unselect-molecule-by-id"; | 
|---|
| [e2009b] | 38 |  | 
|---|
|  | 39 | SelectionNotMoleculeByIdAction::SelectionNotMoleculeByIdAction() : | 
|---|
|  | 40 | Action(NAME) | 
|---|
|  | 41 | {} | 
|---|
|  | 42 |  | 
|---|
|  | 43 | SelectionNotMoleculeByIdAction::~SelectionNotMoleculeByIdAction() | 
|---|
|  | 44 | {} | 
|---|
|  | 45 |  | 
|---|
| [3b7dfb] | 46 | void SelectionNotMoleculeById(molecule *_mol) { | 
|---|
|  | 47 | ValueStorage::getInstance().setCurrentValue(SelectionNotMoleculeByIdAction::NAME, _mol); | 
|---|
|  | 48 | ActionRegistry::getInstance().getActionByName(SelectionNotMoleculeByIdAction::NAME)->call(Action::NonInteractive); | 
|---|
|  | 49 | }; | 
|---|
|  | 50 |  | 
|---|
| [047878] | 51 | Dialog* SelectionNotMoleculeByIdAction::fillDialog(Dialog *dialog) { | 
|---|
|  | 52 | ASSERT(dialog,"No Dialog given when filling action dialog"); | 
|---|
| [533838] | 53 |  | 
|---|
|  | 54 | dialog->queryMolecule(NAME, ValueStorage::getInstance().getDescription(NAME)); | 
|---|
|  | 55 |  | 
|---|
|  | 56 | return dialog; | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
|  | 59 | Action::state_ptr SelectionNotMoleculeByIdAction::performCall() { | 
|---|
| [e2009b] | 60 | molecule *mol = NULL; | 
|---|
|  | 61 |  | 
|---|
| [533838] | 62 | ValueStorage::getInstance().queryCurrentValue(NAME, mol); | 
|---|
| [e2009b] | 63 |  | 
|---|
| [533838] | 64 | if (World::getInstance().isSelected(mol)) { | 
|---|
|  | 65 | DoLog(1) && (Log() << Verbose(1) << "Unselecting molecule " << mol->name << endl); | 
|---|
|  | 66 | World::getInstance().unselectMolecule(mol); | 
|---|
|  | 67 | return Action::state_ptr(new SelectionNotMoleculeByIdState(mol)); | 
|---|
| [e2009b] | 68 | } else { | 
|---|
| [533838] | 69 | return Action::success; | 
|---|
| [e2009b] | 70 | } | 
|---|
|  | 71 | } | 
|---|
|  | 72 |  | 
|---|
|  | 73 | Action::state_ptr SelectionNotMoleculeByIdAction::performUndo(Action::state_ptr _state) { | 
|---|
|  | 74 | SelectionNotMoleculeByIdState *state = assert_cast<SelectionNotMoleculeByIdState*>(_state.get()); | 
|---|
|  | 75 |  | 
|---|
|  | 76 | if (state->mol != NULL) | 
|---|
|  | 77 | World::getInstance().selectMolecule(state->mol); | 
|---|
|  | 78 |  | 
|---|
|  | 79 | return Action::state_ptr(new SelectionNotMoleculeByIdState(state->mol)); | 
|---|
|  | 80 | } | 
|---|
|  | 81 |  | 
|---|
|  | 82 | Action::state_ptr SelectionNotMoleculeByIdAction::performRedo(Action::state_ptr _state){ | 
|---|
|  | 83 | SelectionNotMoleculeByIdState *state = assert_cast<SelectionNotMoleculeByIdState*>(_state.get()); | 
|---|
|  | 84 |  | 
|---|
|  | 85 | if (state->mol != NULL) | 
|---|
|  | 86 | World::getInstance().unselectMolecule(state->mol); | 
|---|
|  | 87 |  | 
|---|
|  | 88 | return Action::state_ptr(new SelectionNotMoleculeByIdState(state->mol)); | 
|---|
|  | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | bool SelectionNotMoleculeByIdAction::canUndo() { | 
|---|
|  | 92 | return true; | 
|---|
|  | 93 | } | 
|---|
|  | 94 |  | 
|---|
|  | 95 | bool SelectionNotMoleculeByIdAction::shouldUndo() { | 
|---|
|  | 96 | return true; | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 | const string SelectionNotMoleculeByIdAction::getName() { | 
|---|
|  | 100 | return NAME; | 
|---|
|  | 101 | } | 
|---|