[e472eab] | 1 | /*
|
---|
| 2 | * AllMoleculesAction.cpp
|
---|
| 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 |
|
---|
[e472eab] | 13 | #include "Helpers/MemDebug.hpp"
|
---|
| 14 |
|
---|
| 15 | #include "Actions/SelectionAction/AllMoleculesAction.hpp"
|
---|
[0430e3] | 16 | #include "Actions/ActionRegistry.hpp"
|
---|
[e472eab] | 17 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
| 18 | #include "atom.hpp"
|
---|
[952f38] | 19 | #include "Helpers/Log.hpp"
|
---|
| 20 | #include "Helpers/Verbose.hpp"
|
---|
[e472eab] | 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"
|
---|
[861874] | 30 | #include "Actions/ValueStorage.hpp"
|
---|
[e472eab] | 31 |
|
---|
| 32 |
|
---|
| 33 | // memento to remember the state when undoing
|
---|
| 34 |
|
---|
| 35 | class SelectionAllMoleculesState : public ActionState {
|
---|
| 36 | public:
|
---|
| 37 | SelectionAllMoleculesState(std::vector<molecule*> selectedMolecules) :
|
---|
| 38 | selectedMolecules(selectedMolecules)
|
---|
| 39 | {}
|
---|
| 40 | std::vector<molecule*> selectedMolecules;
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | const char SelectionAllMoleculesAction::NAME[] = "select-all-molecules";
|
---|
| 44 |
|
---|
| 45 | SelectionAllMoleculesAction::SelectionAllMoleculesAction() :
|
---|
| 46 | Action(NAME)
|
---|
| 47 | {}
|
---|
| 48 |
|
---|
| 49 | SelectionAllMoleculesAction::~SelectionAllMoleculesAction()
|
---|
| 50 | {}
|
---|
| 51 |
|
---|
[3b7dfb] | 52 | void SelectionAllMolecules() {
|
---|
| 53 | ActionRegistry::getInstance().getActionByName(SelectionAllMoleculesAction::NAME)->call(Action::NonInteractive);
|
---|
| 54 | };
|
---|
| 55 |
|
---|
[047878] | 56 | Dialog* SelectionAllMoleculesAction::fillDialog(Dialog *dialog) {
|
---|
| 57 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[e472eab] | 58 |
|
---|
| 59 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 60 |
|
---|
| 61 | return dialog;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | Action::state_ptr SelectionAllMoleculesAction::performCall() {
|
---|
| 65 | std::vector<molecule *> selectedMolecules = World::getInstance().getSelectedMolecules();
|
---|
| 66 | DoLog(1) && (Log() << Verbose(1) << "Selecting all molecules." << endl);
|
---|
| 67 | World::getInstance().selectAllMolecules(AllMolecules());
|
---|
| 68 | return Action::state_ptr(new SelectionAllMoleculesState(selectedMolecules));
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | Action::state_ptr SelectionAllMoleculesAction::performUndo(Action::state_ptr _state) {
|
---|
| 72 | SelectionAllMoleculesState *state = assert_cast<SelectionAllMoleculesState*>(_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 SelectionAllMoleculesState(state->selectedMolecules));
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | Action::state_ptr SelectionAllMoleculesAction::performRedo(Action::state_ptr _state){
|
---|
| 82 | SelectionAllMoleculesState *state = assert_cast<SelectionAllMoleculesState*>(_state.get());
|
---|
| 83 |
|
---|
| 84 | World::getInstance().selectAllMolecules(AllMolecules());
|
---|
| 85 |
|
---|
| 86 | return Action::state_ptr(new SelectionAllMoleculesState(state->selectedMolecules));
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | bool SelectionAllMoleculesAction::canUndo() {
|
---|
| 90 | return true;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | bool SelectionAllMoleculesAction::shouldUndo() {
|
---|
| 94 | return true;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | const string SelectionAllMoleculesAction::getName() {
|
---|
| 98 | return NAME;
|
---|
| 99 | }
|
---|