| 1 | /*
|
|---|
| 2 | * NotAllMoleculesAction.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/NotAllMoleculesAction.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 SelectionNotAllMoleculesState : public ActionState {
|
|---|
| 36 | public:
|
|---|
| 37 | SelectionNotAllMoleculesState(std::vector<molecule*> selectedMolecules) :
|
|---|
| 38 | selectedMolecules(selectedMolecules)
|
|---|
| 39 | {}
|
|---|
| 40 | std::vector<molecule*> selectedMolecules;
|
|---|
| 41 | };
|
|---|
| 42 |
|
|---|
| 43 | const char SelectionNotAllMoleculesAction::NAME[] = "unselect-all-molecules";
|
|---|
| 44 |
|
|---|
| 45 | SelectionNotAllMoleculesAction::SelectionNotAllMoleculesAction() :
|
|---|
| 46 | Action(NAME)
|
|---|
| 47 | {}
|
|---|
| 48 |
|
|---|
| 49 | SelectionNotAllMoleculesAction::~SelectionNotAllMoleculesAction()
|
|---|
| 50 | {}
|
|---|
| 51 |
|
|---|
| 52 | void SelectionNotAllMolecules() {
|
|---|
| 53 | ActionRegistry::getInstance().getActionByName(SelectionNotAllMoleculesAction::NAME)->call(Action::NonInteractive);
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | Dialog* SelectionNotAllMoleculesAction::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 SelectionNotAllMoleculesAction::performCall() {
|
|---|
| 65 | std::vector<molecule *> selectedMolecules = World::getInstance().getSelectedMolecules();
|
|---|
| 66 | DoLog(1) && (Log() << Verbose(1) << "Unselecting all molecules." << endl);
|
|---|
| 67 | World::getInstance().clearMoleculeSelection();
|
|---|
| 68 | return Action::state_ptr(new SelectionNotAllMoleculesState(selectedMolecules));
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | Action::state_ptr SelectionNotAllMoleculesAction::performUndo(Action::state_ptr _state) {
|
|---|
| 72 | SelectionNotAllMoleculesState *state = assert_cast<SelectionNotAllMoleculesState*>(_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 SelectionNotAllMoleculesState(state->selectedMolecules));
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | Action::state_ptr SelectionNotAllMoleculesAction::performRedo(Action::state_ptr _state){
|
|---|
| 82 | SelectionNotAllMoleculesState *state = assert_cast<SelectionNotAllMoleculesState*>(_state.get());
|
|---|
| 83 |
|
|---|
| 84 | World::getInstance().clearMoleculeSelection();
|
|---|
| 85 |
|
|---|
| 86 | return Action::state_ptr(new SelectionNotAllMoleculesState(state->selectedMolecules));
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | bool SelectionNotAllMoleculesAction::canUndo() {
|
|---|
| 90 | return true;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | bool SelectionNotAllMoleculesAction::shouldUndo() {
|
|---|
| 94 | return true;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | const string SelectionNotAllMoleculesAction::getName() {
|
|---|
| 98 | return NAME;
|
|---|
| 99 | }
|
|---|