[e212ff] | 1 | /*
|
---|
| 2 | * ClearAllAtomsAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 09, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
| 10 | #include "Actions/SelectionAction/ClearAllAtomsAction.hpp"
|
---|
| 11 | #include "Actions/ActionRegistry.hpp"
|
---|
| 12 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
| 13 | #include "atom.hpp"
|
---|
| 14 | #include "Helpers/Log.hpp"
|
---|
| 15 | #include "Helpers/Verbose.hpp"
|
---|
| 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"
|
---|
| 25 | #include "Actions/ValueStorage.hpp"
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | // memento to remember the state when undoing
|
---|
| 29 |
|
---|
| 30 | class SelectionClearAllAtomsState : public ActionState {
|
---|
| 31 | public:
|
---|
| 32 | SelectionClearAllAtomsState(std::vector<atom*> _selectedAtoms) :
|
---|
| 33 | selectedAtoms(_selectedAtoms)
|
---|
| 34 | {}
|
---|
| 35 | std::vector<atom*> selectedAtoms;
|
---|
| 36 | };
|
---|
| 37 |
|
---|
| 38 | const char SelectionClearAllAtomsAction::NAME[] = "clear-atom-selection";
|
---|
| 39 |
|
---|
| 40 | SelectionClearAllAtomsAction::SelectionClearAllAtomsAction() :
|
---|
| 41 | Action(NAME)
|
---|
| 42 | {}
|
---|
| 43 |
|
---|
| 44 | SelectionClearAllAtomsAction::~SelectionClearAllAtomsAction()
|
---|
| 45 | {}
|
---|
| 46 |
|
---|
| 47 | void SelectionClearAllAtoms() {
|
---|
| 48 | ActionRegistry::getInstance().getActionByName(SelectionClearAllAtomsAction::NAME)->call(Action::NonInteractive);
|
---|
| 49 | };
|
---|
| 50 |
|
---|
| 51 | Dialog* SelectionClearAllAtomsAction::fillDialog(Dialog *dialog) {
|
---|
| 52 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
| 53 |
|
---|
| 54 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 55 |
|
---|
| 56 | return dialog;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | Action::state_ptr SelectionClearAllAtomsAction::performCall() {
|
---|
| 60 | std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
|
---|
| 61 | DoLog(1) && (Log() << Verbose(1) << "Clearing atoms selection." << endl);
|
---|
| 62 | World::getInstance().clearAtomSelection();
|
---|
| 63 | return Action::state_ptr(new SelectionClearAllAtomsState(selectedAtoms));
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | Action::state_ptr SelectionClearAllAtomsAction::performUndo(Action::state_ptr _state) {
|
---|
| 67 | SelectionClearAllAtomsState *state = assert_cast<SelectionClearAllAtomsState*>(_state.get());
|
---|
| 68 |
|
---|
| 69 | World::getInstance().clearAtomSelection();
|
---|
| 70 | for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
|
---|
| 71 | World::getInstance().selectAtom(*iter);
|
---|
| 72 |
|
---|
| 73 | return Action::state_ptr(new SelectionClearAllAtomsState(state->selectedAtoms));
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | Action::state_ptr SelectionClearAllAtomsAction::performRedo(Action::state_ptr _state){
|
---|
| 77 | SelectionClearAllAtomsState *state = assert_cast<SelectionClearAllAtomsState*>(_state.get());
|
---|
| 78 |
|
---|
| 79 | World::getInstance().clearAtomSelection();
|
---|
| 80 |
|
---|
| 81 | return Action::state_ptr(new SelectionClearAllAtomsState(state->selectedAtoms));
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | bool SelectionClearAllAtomsAction::canUndo() {
|
---|
| 85 | return true;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | bool SelectionClearAllAtomsAction::shouldUndo() {
|
---|
| 89 | return true;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | const string SelectionClearAllAtomsAction::getName() {
|
---|
| 93 | return NAME;
|
---|
| 94 | }
|
---|