/* * AllMoleculesAction.cpp * * Created on: May 12, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "Helpers/MemDebug.hpp" #include "Actions/SelectionAction/AllMoleculesAction.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 SelectionAllMoleculesState : public ActionState { public: SelectionAllMoleculesState(std::vector selectedMolecules) : selectedMolecules(selectedMolecules) {} std::vector selectedMolecules; }; const char SelectionAllMoleculesAction::NAME[] = "select-all-molecules"; SelectionAllMoleculesAction::SelectionAllMoleculesAction() : Action(NAME) {} SelectionAllMoleculesAction::~SelectionAllMoleculesAction() {} void SelectionAllMolecules() { ActionRegistry::getInstance().getActionByName(SelectionAllMoleculesAction::NAME)->call(Action::NonInteractive); }; Dialog* SelectionAllMoleculesAction::fillDialog(Dialog *dialog) { ASSERT(dialog,"No Dialog given when filling action dialog"); dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME)); return dialog; } Action::state_ptr SelectionAllMoleculesAction::performCall() { std::vector selectedMolecules = World::getInstance().getSelectedMolecules(); DoLog(1) && (Log() << Verbose(1) << "Selecting all molecules." << endl); World::getInstance().selectAllMolecules(AllMolecules()); return Action::state_ptr(new SelectionAllMoleculesState(selectedMolecules)); } Action::state_ptr SelectionAllMoleculesAction::performUndo(Action::state_ptr _state) { SelectionAllMoleculesState *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 SelectionAllMoleculesState(state->selectedMolecules)); } Action::state_ptr SelectionAllMoleculesAction::performRedo(Action::state_ptr _state){ SelectionAllMoleculesState *state = assert_cast(_state.get()); World::getInstance().selectAllMolecules(AllMolecules()); return Action::state_ptr(new SelectionAllMoleculesState(state->selectedMolecules)); } bool SelectionAllMoleculesAction::canUndo() { return true; } bool SelectionAllMoleculesAction::shouldUndo() { return true; } const string SelectionAllMoleculesAction::getName() { return NAME; }