[e2009b] | 1 | /*
|
---|
| 2 | * SelectionNotMoleculeByIdAction.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"
|
---|
[533838] | 11 | #include "molecule.hpp"
|
---|
[e2009b] | 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"
|
---|
[533838] | 23 | #include "UIElements/ValueStorage.hpp"
|
---|
[e2009b] | 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 |
|
---|
[533838] | 36 | const char SelectionNotMoleculeByIdAction::NAME[] = "unselect-molecule-by-id";
|
---|
[e2009b] | 37 |
|
---|
| 38 | SelectionNotMoleculeByIdAction::SelectionNotMoleculeByIdAction() :
|
---|
| 39 | Action(NAME)
|
---|
| 40 | {}
|
---|
| 41 |
|
---|
| 42 | SelectionNotMoleculeByIdAction::~SelectionNotMoleculeByIdAction()
|
---|
| 43 | {}
|
---|
| 44 |
|
---|
[533838] | 45 | Dialog* SelectionNotMoleculeByIdAction::createDialog() {
|
---|
[e2009b] | 46 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
[533838] | 47 |
|
---|
| 48 | dialog->queryMolecule(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 49 |
|
---|
| 50 | return dialog;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | Action::state_ptr SelectionNotMoleculeByIdAction::performCall() {
|
---|
[e2009b] | 54 | molecule *mol = NULL;
|
---|
| 55 |
|
---|
[533838] | 56 | ValueStorage::getInstance().queryCurrentValue(NAME, mol);
|
---|
[e2009b] | 57 |
|
---|
[533838] | 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));
|
---|
[e2009b] | 62 | } else {
|
---|
[533838] | 63 | return Action::success;
|
---|
[e2009b] | 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 | }
|
---|