[e472eab] | 1 | /*
|
---|
| 2 | * NotAllAtomsAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 12, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
| 10 | #include "Actions/SelectionAction/NotAllAtomsAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[e472eab] | 12 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
| 13 | #include "atom.hpp"
|
---|
| 14 | #include "log.hpp"
|
---|
| 15 | #include "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 "UIElements/ValueStorage.hpp"
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | // memento to remember the state when undoing
|
---|
| 29 |
|
---|
[53fb71] | 30 | class SelectionNotAllAtomsState : public ActionState {
|
---|
[e472eab] | 31 | public:
|
---|
[53fb71] | 32 | SelectionNotAllAtomsState(std::vector<atom*> _selectedAtoms) :
|
---|
[e472eab] | 33 | selectedAtoms(_selectedAtoms)
|
---|
| 34 | {}
|
---|
| 35 | std::vector<atom*> selectedAtoms;
|
---|
| 36 | };
|
---|
| 37 |
|
---|
| 38 | const char SelectionNotAllAtomsAction::NAME[] = "unselect-all-atoms";
|
---|
| 39 |
|
---|
| 40 | SelectionNotAllAtomsAction::SelectionNotAllAtomsAction() :
|
---|
| 41 | Action(NAME)
|
---|
| 42 | {}
|
---|
| 43 |
|
---|
| 44 | SelectionNotAllAtomsAction::~SelectionNotAllAtomsAction()
|
---|
| 45 | {}
|
---|
| 46 |
|
---|
[3b7dfb] | 47 | void SelectionNotAllAtoms() {
|
---|
| 48 | ActionRegistry::getInstance().getActionByName(SelectionNotAllAtomsAction::NAME)->call(Action::NonInteractive);
|
---|
| 49 | };
|
---|
| 50 |
|
---|
[047878] | 51 | Dialog* SelectionNotAllAtomsAction::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 SelectionNotAllAtomsAction::performCall() {
|
---|
| 60 | std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
|
---|
| 61 | DoLog(1) && (Log() << Verbose(1) << "Unselecting all atoms." << endl);
|
---|
| 62 | World::getInstance().clearAtomSelection();
|
---|
[53fb71] | 63 | return Action::state_ptr(new SelectionNotAllAtomsState(selectedAtoms));
|
---|
[e472eab] | 64 | }
|
---|
| 65 |
|
---|
| 66 | Action::state_ptr SelectionNotAllAtomsAction::performUndo(Action::state_ptr _state) {
|
---|
[53fb71] | 67 | SelectionNotAllAtomsState *state = assert_cast<SelectionNotAllAtomsState*>(_state.get());
|
---|
[e472eab] | 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 |
|
---|
[53fb71] | 73 | return Action::state_ptr(new SelectionNotAllAtomsState(state->selectedAtoms));
|
---|
[e472eab] | 74 | }
|
---|
| 75 |
|
---|
| 76 | Action::state_ptr SelectionNotAllAtomsAction::performRedo(Action::state_ptr _state){
|
---|
[53fb71] | 77 | SelectionNotAllAtomsState *state = assert_cast<SelectionNotAllAtomsState*>(_state.get());
|
---|
[e472eab] | 78 |
|
---|
| 79 | World::getInstance().clearAtomSelection();
|
---|
| 80 |
|
---|
[53fb71] | 81 | return Action::state_ptr(new SelectionNotAllAtomsState(state->selectedAtoms));
|
---|
[e472eab] | 82 | }
|
---|
| 83 |
|
---|
| 84 | bool SelectionNotAllAtomsAction::canUndo() {
|
---|
| 85 | return true;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | bool SelectionNotAllAtomsAction::shouldUndo() {
|
---|
| 89 | return true;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | const string SelectionNotAllAtomsAction::getName() {
|
---|
| 93 | return NAME;
|
---|
| 94 | }
|
---|