/* * NotAllMoleculesAction.cpp * * Created on: May 12, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "Helpers/MemDebug.hpp" #include "Actions/SelectionAction/NotAllMoleculesAction.hpp" #include "Actions/ActionRegistry.hpp" #include "Descriptors/MoleculeDescriptor.hpp" #include "atom.hpp" #include "Helpers/Log.hpp" #include "Helpers/Verbose.hpp" #include "World.hpp" #include #include using namespace std; #include "UIElements/UIFactory.hpp" #include "UIElements/Dialog.hpp" #include "Actions/ValueStorage.hpp" // memento to remember the state when undoing class SelectionNotAllMoleculesState : public ActionState { public: SelectionNotAllMoleculesState(std::vector selectedMolecules) : selectedMolecules(selectedMolecules) {} std::vector selectedMolecules; }; const char SelectionNotAllMoleculesAction::NAME[] = "unselect-all-molecules"; SelectionNotAllMoleculesAction::SelectionNotAllMoleculesAction() : Action(NAME) {} SelectionNotAllMoleculesAction::~SelectionNotAllMoleculesAction() {} void SelectionNotAllMolecules() { ActionRegistry::getInstance().getActionByName(SelectionNotAllMoleculesAction::NAME)->call(Action::NonInteractive); }; Dialog* SelectionNotAllMoleculesAction::fillDialog(Dialog *dialog) { ASSERT(dialog,"No Dialog given when filling action dialog"); dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME)); return dialog; } Action::state_ptr SelectionNotAllMoleculesAction::performCall() { std::vector selectedMolecules = World::getInstance().getSelectedMolecules(); DoLog(1) && (Log() << Verbose(1) << "Unselecting all molecules." << endl); World::getInstance().clearMoleculeSelection(); return Action::state_ptr(new SelectionNotAllMoleculesState(selectedMolecules)); } Action::state_ptr SelectionNotAllMoleculesAction::performUndo(Action::state_ptr _state) { SelectionNotAllMoleculesState *state = assert_cast(_state.get()); World::getInstance().clearMoleculeSelection(); for(std::vector::iterator iter = state->selectedMolecules.begin(); iter != state->selectedMolecules.end(); ++iter) World::getInstance().selectMolecule(*iter); return Action::state_ptr(new SelectionNotAllMoleculesState(state->selectedMolecules)); } Action::state_ptr SelectionNotAllMoleculesAction::performRedo(Action::state_ptr _state){ SelectionNotAllMoleculesState *state = assert_cast(_state.get()); World::getInstance().clearMoleculeSelection(); return Action::state_ptr(new SelectionNotAllMoleculesState(state->selectedMolecules)); } bool SelectionNotAllMoleculesAction::canUndo() { return true; } bool SelectionNotAllMoleculesAction::shouldUndo() { return true; } const string SelectionNotAllMoleculesAction::getName() { return NAME; }