1 | /*
|
---|
2 | * NotAllAtomsOfMoleculeAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 12, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/SelectionAction/NotAllAtomsOfMoleculeAction.hpp"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
13 | #include "atom.hpp"
|
---|
14 | #include "molecule.hpp"
|
---|
15 | #include "Helpers/Log.hpp"
|
---|
16 | #include "Helpers/Verbose.hpp"
|
---|
17 | #include "World.hpp"
|
---|
18 |
|
---|
19 | #include <iostream>
|
---|
20 | #include <string>
|
---|
21 |
|
---|
22 | using namespace std;
|
---|
23 |
|
---|
24 | #include "UIElements/UIFactory.hpp"
|
---|
25 | #include "UIElements/Dialog.hpp"
|
---|
26 | #include "Actions/ValueStorage.hpp"
|
---|
27 |
|
---|
28 |
|
---|
29 | // memento to remember the state when undoing
|
---|
30 |
|
---|
31 | class SelectionNotAllAtomsOfMoleculeState : public ActionState {
|
---|
32 | public:
|
---|
33 | SelectionNotAllAtomsOfMoleculeState(std::vector<atom*> _selectedAtoms, molecule *_mol) :
|
---|
34 | selectedAtoms(_selectedAtoms),
|
---|
35 | mol(_mol)
|
---|
36 | {}
|
---|
37 | std::vector<atom*> selectedAtoms;
|
---|
38 | molecule *mol;
|
---|
39 | };
|
---|
40 |
|
---|
41 | const char SelectionNotAllAtomsOfMoleculeAction::NAME[] = "unselect-molecules-atoms";
|
---|
42 |
|
---|
43 | SelectionNotAllAtomsOfMoleculeAction::SelectionNotAllAtomsOfMoleculeAction() :
|
---|
44 | Action(NAME)
|
---|
45 | {}
|
---|
46 |
|
---|
47 | SelectionNotAllAtomsOfMoleculeAction::~SelectionNotAllAtomsOfMoleculeAction()
|
---|
48 | {}
|
---|
49 |
|
---|
50 | void SelectionNotAllAtomsOfMolecule() {
|
---|
51 | ActionRegistry::getInstance().getActionByName(SelectionNotAllAtomsOfMoleculeAction::NAME)->call(Action::NonInteractive);
|
---|
52 | };
|
---|
53 |
|
---|
54 | Dialog* SelectionNotAllAtomsOfMoleculeAction::fillDialog(Dialog *dialog) {
|
---|
55 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
56 |
|
---|
57 | dialog->queryMolecule(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
58 |
|
---|
59 | return dialog;
|
---|
60 | }
|
---|
61 |
|
---|
62 | Action::state_ptr SelectionNotAllAtomsOfMoleculeAction::performCall() {
|
---|
63 | molecule *mol = NULL;
|
---|
64 | std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
|
---|
65 |
|
---|
66 | ValueStorage::getInstance().queryCurrentValue(NAME, mol);
|
---|
67 |
|
---|
68 | DoLog(1) && (Log() << Verbose(1) << "Unselecting all atoms of molecule " << mol->getName() << "." << endl);
|
---|
69 | World::getInstance().unselectAtomsOfMolecule(mol);
|
---|
70 | return Action::state_ptr(new SelectionNotAllAtomsOfMoleculeState(selectedAtoms, mol));
|
---|
71 | }
|
---|
72 |
|
---|
73 | Action::state_ptr SelectionNotAllAtomsOfMoleculeAction::performUndo(Action::state_ptr _state) {
|
---|
74 | SelectionNotAllAtomsOfMoleculeState *state = assert_cast<SelectionNotAllAtomsOfMoleculeState*>(_state.get());
|
---|
75 |
|
---|
76 | World::getInstance().clearAtomSelection();
|
---|
77 | for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
|
---|
78 | World::getInstance().selectAtom(*iter);
|
---|
79 |
|
---|
80 | return Action::state_ptr(new SelectionNotAllAtomsOfMoleculeState(state->selectedAtoms, state->mol));
|
---|
81 | }
|
---|
82 |
|
---|
83 | Action::state_ptr SelectionNotAllAtomsOfMoleculeAction::performRedo(Action::state_ptr _state){
|
---|
84 | SelectionNotAllAtomsOfMoleculeState *state = assert_cast<SelectionNotAllAtomsOfMoleculeState*>(_state.get());
|
---|
85 |
|
---|
86 | World::getInstance().unselectAtomsOfMolecule(state->mol);
|
---|
87 |
|
---|
88 | return Action::state_ptr(new SelectionNotAllAtomsOfMoleculeState(state->selectedAtoms, state->mol));
|
---|
89 | }
|
---|
90 |
|
---|
91 | bool SelectionNotAllAtomsOfMoleculeAction::canUndo() {
|
---|
92 | return true;
|
---|
93 | }
|
---|
94 |
|
---|
95 | bool SelectionNotAllAtomsOfMoleculeAction::shouldUndo() {
|
---|
96 | return true;
|
---|
97 | }
|
---|
98 |
|
---|
99 | const string SelectionNotAllAtomsOfMoleculeAction::getName() {
|
---|
100 | return NAME;
|
---|
101 | }
|
---|