1 | /*
|
---|
2 | * MoleculeOfAtomAction.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/MoleculeOfAtomAction.hpp"
|
---|
16 | #include "Actions/ActionRegistry.hpp"
|
---|
17 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
18 | #include "atom.hpp"
|
---|
19 | #include "Helpers/Log.hpp"
|
---|
20 | #include "Helpers/Verbose.hpp"
|
---|
21 | #include "World.hpp"
|
---|
22 |
|
---|
23 | #include <iostream>
|
---|
24 | #include <string>
|
---|
25 |
|
---|
26 | using namespace std;
|
---|
27 |
|
---|
28 | #include "UIElements/UIFactory.hpp"
|
---|
29 | #include "UIElements/Dialog.hpp"
|
---|
30 | #include "Actions/ValueStorage.hpp"
|
---|
31 |
|
---|
32 |
|
---|
33 | // memento to remember the state when undoing
|
---|
34 |
|
---|
35 | class SelectionMoleculeOfAtomState : public ActionState {
|
---|
36 | public:
|
---|
37 | SelectionMoleculeOfAtomState(std::vector<molecule*> selectedMolecules, atom *_Walker) :
|
---|
38 | selectedMolecules(selectedMolecules),
|
---|
39 | Walker(_Walker)
|
---|
40 | {}
|
---|
41 | std::vector<molecule*> selectedMolecules;
|
---|
42 | atom *Walker;
|
---|
43 | };
|
---|
44 |
|
---|
45 | const char SelectionMoleculeOfAtomAction::NAME[] = "select-molecule-of-atom";
|
---|
46 |
|
---|
47 | SelectionMoleculeOfAtomAction::SelectionMoleculeOfAtomAction() :
|
---|
48 | Action(NAME)
|
---|
49 | {}
|
---|
50 |
|
---|
51 | SelectionMoleculeOfAtomAction::~SelectionMoleculeOfAtomAction()
|
---|
52 | {}
|
---|
53 |
|
---|
54 | void SelectionMoleculeOfAtom() {
|
---|
55 | ActionRegistry::getInstance().getActionByName(SelectionMoleculeOfAtomAction::NAME)->call(Action::NonInteractive);
|
---|
56 | };
|
---|
57 |
|
---|
58 | Dialog* SelectionMoleculeOfAtomAction::fillDialog(Dialog *dialog) {
|
---|
59 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
60 |
|
---|
61 | dialog->queryAtom(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
62 |
|
---|
63 | return dialog;
|
---|
64 | }
|
---|
65 |
|
---|
66 | Action::state_ptr SelectionMoleculeOfAtomAction::performCall() {
|
---|
67 | atom *Walker = NULL;
|
---|
68 |
|
---|
69 | ValueStorage::getInstance().queryCurrentValue(NAME, Walker);
|
---|
70 |
|
---|
71 | std::vector<molecule *> selectedMolecules = World::getInstance().getSelectedMolecules();
|
---|
72 | DoLog(1) && (Log() << Verbose(1) << "Selecting molecule to which " << Walker->getName() << " belongs." << endl);
|
---|
73 | World::getInstance().selectMoleculeOfAtom(Walker);
|
---|
74 | return Action::state_ptr(new SelectionMoleculeOfAtomState(selectedMolecules, Walker));
|
---|
75 | }
|
---|
76 |
|
---|
77 | Action::state_ptr SelectionMoleculeOfAtomAction::performUndo(Action::state_ptr _state) {
|
---|
78 | SelectionMoleculeOfAtomState *state = assert_cast<SelectionMoleculeOfAtomState*>(_state.get());
|
---|
79 |
|
---|
80 | World::getInstance().clearMoleculeSelection();
|
---|
81 | for(std::vector<molecule *>::iterator iter = state->selectedMolecules.begin(); iter != state->selectedMolecules.end(); ++iter)
|
---|
82 | World::getInstance().selectMolecule(*iter);
|
---|
83 |
|
---|
84 | return Action::state_ptr(new SelectionMoleculeOfAtomState(state->selectedMolecules, state->Walker));
|
---|
85 | }
|
---|
86 |
|
---|
87 | Action::state_ptr SelectionMoleculeOfAtomAction::performRedo(Action::state_ptr _state){
|
---|
88 | SelectionMoleculeOfAtomState *state = assert_cast<SelectionMoleculeOfAtomState*>(_state.get());
|
---|
89 |
|
---|
90 | World::getInstance().selectMoleculeOfAtom(state->Walker);
|
---|
91 |
|
---|
92 | return Action::state_ptr(new SelectionMoleculeOfAtomState(state->selectedMolecules, state->Walker));
|
---|
93 | }
|
---|
94 |
|
---|
95 | bool SelectionMoleculeOfAtomAction::canUndo() {
|
---|
96 | return true;
|
---|
97 | }
|
---|
98 |
|
---|
99 | bool SelectionMoleculeOfAtomAction::shouldUndo() {
|
---|
100 | return true;
|
---|
101 | }
|
---|
102 |
|
---|
103 | const string SelectionMoleculeOfAtomAction::getName() {
|
---|
104 | return NAME;
|
---|
105 | }
|
---|