| 1 | /* | 
|---|
| 2 | * AllAtomsOfMoleculeAction.cpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: May 12, 2010 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #include "Helpers/MemDebug.hpp" | 
|---|
| 9 |  | 
|---|
| 10 | #include "Actions/SelectionAction/AllAtomsOfMoleculeAction.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 SelectionAllAtomsOfMoleculeState : public ActionState { | 
|---|
| 32 | public: | 
|---|
| 33 | SelectionAllAtomsOfMoleculeState(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 SelectionAllAtomsOfMoleculeAction::NAME[] = "select-molecules-atoms"; | 
|---|
| 42 |  | 
|---|
| 43 | SelectionAllAtomsOfMoleculeAction::SelectionAllAtomsOfMoleculeAction() : | 
|---|
| 44 | Action(NAME) | 
|---|
| 45 | {} | 
|---|
| 46 |  | 
|---|
| 47 | SelectionAllAtomsOfMoleculeAction::~SelectionAllAtomsOfMoleculeAction() | 
|---|
| 48 | {} | 
|---|
| 49 |  | 
|---|
| 50 | void SelectionAllAtomsOfMolecule() { | 
|---|
| 51 | ActionRegistry::getInstance().getActionByName(SelectionAllAtomsOfMoleculeAction::NAME)->call(Action::NonInteractive); | 
|---|
| 52 | }; | 
|---|
| 53 |  | 
|---|
| 54 | Dialog* SelectionAllAtomsOfMoleculeAction::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 SelectionAllAtomsOfMoleculeAction::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) << "Selecting all atoms of molecule " << mol->getName() << "." << endl); | 
|---|
| 69 | World::getInstance().selectAtomsOfMolecule(mol); | 
|---|
| 70 | return Action::state_ptr(new SelectionAllAtomsOfMoleculeState(selectedAtoms, mol)); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | Action::state_ptr SelectionAllAtomsOfMoleculeAction::performUndo(Action::state_ptr _state) { | 
|---|
| 74 | SelectionAllAtomsOfMoleculeState *state = assert_cast<SelectionAllAtomsOfMoleculeState*>(_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 SelectionAllAtomsOfMoleculeState(state->selectedAtoms, state->mol)); | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | Action::state_ptr SelectionAllAtomsOfMoleculeAction::performRedo(Action::state_ptr _state){ | 
|---|
| 84 | SelectionAllAtomsOfMoleculeState *state = assert_cast<SelectionAllAtomsOfMoleculeState*>(_state.get()); | 
|---|
| 85 |  | 
|---|
| 86 | World::getInstance().selectAtomsOfMolecule(state->mol); | 
|---|
| 87 |  | 
|---|
| 88 | return Action::state_ptr(new SelectionAllAtomsOfMoleculeState(state->selectedAtoms, state->mol)); | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | bool SelectionAllAtomsOfMoleculeAction::canUndo() { | 
|---|
| 92 | return true; | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 | bool SelectionAllAtomsOfMoleculeAction::shouldUndo() { | 
|---|
| 96 | return true; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | const string SelectionAllAtomsOfMoleculeAction::getName() { | 
|---|
| 100 | return NAME; | 
|---|
| 101 | } | 
|---|