1 | /*
|
---|
2 | * ClearAllMoleculesAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: Aug 09, 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/ClearAllMoleculesAction.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 SelectionClearAllMoleculesState : public ActionState {
|
---|
36 | public:
|
---|
37 | SelectionClearAllMoleculesState(std::vector<molecule*> selectedMolecules) :
|
---|
38 | selectedMolecules(selectedMolecules)
|
---|
39 | {}
|
---|
40 | std::vector<molecule*> selectedMolecules;
|
---|
41 | };
|
---|
42 |
|
---|
43 | const char SelectionClearAllMoleculesAction::NAME[] = "clear-molecule-selection";
|
---|
44 |
|
---|
45 | SelectionClearAllMoleculesAction::SelectionClearAllMoleculesAction() :
|
---|
46 | Action(NAME)
|
---|
47 | {}
|
---|
48 |
|
---|
49 | SelectionClearAllMoleculesAction::~SelectionClearAllMoleculesAction()
|
---|
50 | {}
|
---|
51 |
|
---|
52 | void SelectionClearAllMolecules() {
|
---|
53 | ActionRegistry::getInstance().getActionByName(SelectionClearAllMoleculesAction::NAME)->call(Action::NonInteractive);
|
---|
54 | };
|
---|
55 |
|
---|
56 | Dialog* SelectionClearAllMoleculesAction::fillDialog(Dialog *dialog) {
|
---|
57 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
58 |
|
---|
59 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
60 |
|
---|
61 | return dialog;
|
---|
62 | }
|
---|
63 |
|
---|
64 | Action::state_ptr SelectionClearAllMoleculesAction::performCall() {
|
---|
65 | std::vector<molecule *> selectedMolecules = World::getInstance().getSelectedMolecules();
|
---|
66 | DoLog(1) && (Log() << Verbose(1) << "Clearing molecule selection." << endl);
|
---|
67 | World::getInstance().clearMoleculeSelection();
|
---|
68 | return Action::state_ptr(new SelectionClearAllMoleculesState(selectedMolecules));
|
---|
69 | }
|
---|
70 |
|
---|
71 | Action::state_ptr SelectionClearAllMoleculesAction::performUndo(Action::state_ptr _state) {
|
---|
72 | SelectionClearAllMoleculesState *state = assert_cast<SelectionClearAllMoleculesState*>(_state.get());
|
---|
73 |
|
---|
74 | World::getInstance().clearMoleculeSelection();
|
---|
75 | for(std::vector<molecule *>::iterator iter = state->selectedMolecules.begin(); iter != state->selectedMolecules.end(); ++iter)
|
---|
76 | World::getInstance().selectMolecule(*iter);
|
---|
77 |
|
---|
78 | return Action::state_ptr(new SelectionClearAllMoleculesState(state->selectedMolecules));
|
---|
79 | }
|
---|
80 |
|
---|
81 | Action::state_ptr SelectionClearAllMoleculesAction::performRedo(Action::state_ptr _state){
|
---|
82 | SelectionClearAllMoleculesState *state = assert_cast<SelectionClearAllMoleculesState*>(_state.get());
|
---|
83 |
|
---|
84 | World::getInstance().clearMoleculeSelection();
|
---|
85 |
|
---|
86 | return Action::state_ptr(new SelectionClearAllMoleculesState(state->selectedMolecules));
|
---|
87 | }
|
---|
88 |
|
---|
89 | bool SelectionClearAllMoleculesAction::canUndo() {
|
---|
90 | return true;
|
---|
91 | }
|
---|
92 |
|
---|
93 | bool SelectionClearAllMoleculesAction::shouldUndo() {
|
---|
94 | return true;
|
---|
95 | }
|
---|
96 |
|
---|
97 | const string SelectionClearAllMoleculesAction::getName() {
|
---|
98 | return NAME;
|
---|
99 | }
|
---|