/* * SelectionNotAtomByIdAction.cpp * * Created on: May 12, 2010 * Author: heber */ #include "Helpers/MemDebug.hpp" #include "Actions/SelectionAction/NotAtomByIdAction.hpp" #include "atom.hpp" #include "log.hpp" #include "verbose.hpp" #include "World.hpp" #include #include using namespace std; #include "UIElements/UIFactory.hpp" #include "UIElements/Dialog.hpp" #include "UIElements/ValueStorage.hpp" // memento to remember the state when undoing class SelectionNotAtomByIdState : public ActionState { public: SelectionNotAtomByIdState(atom* _walker) : walker(_walker) {} atom* walker; }; const char SelectionNotAtomByIdAction::NAME[] = "unselect-atom-by-id"; SelectionNotAtomByIdAction::SelectionNotAtomByIdAction() : Action(NAME) {} SelectionNotAtomByIdAction::~SelectionNotAtomByIdAction() {} Dialog* SelectionNotAtomByIdAction::createDialog() { Dialog *dialog = UIFactory::getInstance().makeDialog(); dialog->queryAtom(NAME, ValueStorage::getInstance().getDescription(NAME)); return dialog; } Action::state_ptr SelectionNotAtomByIdAction::performCall() { atom *Walker = NULL; ValueStorage::getInstance().queryCurrentValue(NAME, Walker); if (World::getInstance().isSelected(Walker)) { DoLog(1) && (Log() << Verbose(1) << "Unselecting atom " << *Walker << endl); World::getInstance().unselectAtom(Walker); return Action::state_ptr(new SelectionNotAtomByIdState(Walker)); } else { return Action::success; } } Action::state_ptr SelectionNotAtomByIdAction::performUndo(Action::state_ptr _state) { SelectionNotAtomByIdState *state = assert_cast(_state.get()); if (state->walker != NULL) World::getInstance().selectAtom(state->walker); return Action::state_ptr(new SelectionNotAtomByIdState(state->walker)); } Action::state_ptr SelectionNotAtomByIdAction::performRedo(Action::state_ptr _state){ SelectionNotAtomByIdState *state = assert_cast(_state.get()); if (state->walker != NULL) World::getInstance().unselectAtom(state->walker); return Action::state_ptr(new SelectionNotAtomByIdState(state->walker)); } bool SelectionNotAtomByIdAction::canUndo() { return true; } bool SelectionNotAtomByIdAction::shouldUndo() { return true; } const string SelectionNotAtomByIdAction::getName() { return NAME; }