| [e2009b] | 1 | /*
 | 
|---|
| [521bbf] | 2 |  * NotAtomByIdAction.cpp
 | 
|---|
| [e2009b] | 3 |  *
 | 
|---|
 | 4 |  *  Created on: May 12, 2010
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [bf3817] | 8 | // include config.h
 | 
|---|
 | 9 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 10 | #include <config.h>
 | 
|---|
 | 11 | #endif
 | 
|---|
 | 12 | 
 | 
|---|
| [e2009b] | 13 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | #include "Actions/SelectionAction/NotAtomByIdAction.hpp"
 | 
|---|
| [0430e3] | 16 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| [e2009b] | 17 | #include "atom.hpp"
 | 
|---|
| [952f38] | 18 | #include "Helpers/Log.hpp"
 | 
|---|
 | 19 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [e2009b] | 20 | #include "World.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include <iostream>
 | 
|---|
 | 23 | #include <string>
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | using namespace std;
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 28 | #include "UIElements/Dialog.hpp"
 | 
|---|
| [861874] | 29 | #include "Actions/ValueStorage.hpp"
 | 
|---|
| [e2009b] | 30 | 
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | // memento to remember the state when undoing
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 | class SelectionNotAtomByIdState : public ActionState {
 | 
|---|
 | 35 | public:
 | 
|---|
 | 36 |   SelectionNotAtomByIdState(atom* _walker) :
 | 
|---|
 | 37 |     walker(_walker)
 | 
|---|
 | 38 |   {}
 | 
|---|
 | 39 |   atom* walker;
 | 
|---|
 | 40 | };
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | const char SelectionNotAtomByIdAction::NAME[] = "unselect-atom-by-id";
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 | SelectionNotAtomByIdAction::SelectionNotAtomByIdAction() :
 | 
|---|
 | 45 |   Action(NAME)
 | 
|---|
 | 46 | {}
 | 
|---|
 | 47 | 
 | 
|---|
 | 48 | SelectionNotAtomByIdAction::~SelectionNotAtomByIdAction()
 | 
|---|
 | 49 | {}
 | 
|---|
 | 50 | 
 | 
|---|
| [3b7dfb] | 51 | void SelectionNotAtomById(atom *_atom) {
 | 
|---|
 | 52 |   ValueStorage::getInstance().setCurrentValue(SelectionNotAtomByIdAction::NAME, _atom);
 | 
|---|
 | 53 |   ActionRegistry::getInstance().getActionByName(SelectionNotAtomByIdAction::NAME)->call(Action::NonInteractive);
 | 
|---|
 | 54 | };
 | 
|---|
 | 55 | 
 | 
|---|
| [047878] | 56 | Dialog* SelectionNotAtomByIdAction::fillDialog(Dialog *dialog) {
 | 
|---|
 | 57 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| [533838] | 58 | 
 | 
|---|
 | 59 |   dialog->queryAtom(NAME, ValueStorage::getInstance().getDescription(NAME));
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 |   return dialog;
 | 
|---|
 | 62 | }
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 | Action::state_ptr SelectionNotAtomByIdAction::performCall() {
 | 
|---|
| [e2009b] | 65 |   atom *Walker = NULL;
 | 
|---|
 | 66 | 
 | 
|---|
| [533838] | 67 |   ValueStorage::getInstance().queryCurrentValue(NAME, Walker);
 | 
|---|
| [e2009b] | 68 | 
 | 
|---|
| [533838] | 69 |   if (World::getInstance().isSelected(Walker)) {
 | 
|---|
 | 70 |     DoLog(1) && (Log() << Verbose(1) << "Unselecting atom " << *Walker << endl);
 | 
|---|
 | 71 |     World::getInstance().unselectAtom(Walker);
 | 
|---|
 | 72 |     return Action::state_ptr(new SelectionNotAtomByIdState(Walker));
 | 
|---|
| [e2009b] | 73 |   } else {
 | 
|---|
| [533838] | 74 |     return Action::success;
 | 
|---|
| [e2009b] | 75 |   }
 | 
|---|
 | 76 | }
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | Action::state_ptr SelectionNotAtomByIdAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 79 |   SelectionNotAtomByIdState *state = assert_cast<SelectionNotAtomByIdState*>(_state.get());
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 |   if (state->walker != NULL)
 | 
|---|
 | 82 |     World::getInstance().selectAtom(state->walker);
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 |   return Action::state_ptr(new SelectionNotAtomByIdState(state->walker));
 | 
|---|
 | 85 | }
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | Action::state_ptr SelectionNotAtomByIdAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 88 |   SelectionNotAtomByIdState *state = assert_cast<SelectionNotAtomByIdState*>(_state.get());
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 |   if (state->walker != NULL)
 | 
|---|
 | 91 |     World::getInstance().unselectAtom(state->walker);
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 |   return Action::state_ptr(new SelectionNotAtomByIdState(state->walker));
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | bool SelectionNotAtomByIdAction::canUndo() {
 | 
|---|
 | 97 |   return true;
 | 
|---|
 | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | bool SelectionNotAtomByIdAction::shouldUndo() {
 | 
|---|
 | 101 |   return true;
 | 
|---|
 | 102 | }
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 | const string SelectionNotAtomByIdAction::getName() {
 | 
|---|
 | 105 |   return NAME;
 | 
|---|
 | 106 | }
 | 
|---|