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