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