/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * AllAtomsOfMoleculeAction.cpp * * Created on: May 12, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "Helpers/MemDebug.hpp" #include "Actions/SelectionAction/AllAtomsOfMoleculeAction.hpp" #include "Actions/ActionRegistry.hpp" #include "Descriptors/AtomDescriptor.hpp" #include "atom.hpp" #include "molecule.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 SelectionAllAtomsOfMoleculeState : public ActionState { public: SelectionAllAtomsOfMoleculeState(std::vector _selectedAtoms, molecule *_mol) : selectedAtoms(_selectedAtoms), mol(_mol) {} std::vector selectedAtoms; molecule *mol; }; const char SelectionAllAtomsOfMoleculeAction::NAME[] = "select-molecules-atoms"; SelectionAllAtomsOfMoleculeAction::SelectionAllAtomsOfMoleculeAction() : Action(NAME) {} SelectionAllAtomsOfMoleculeAction::~SelectionAllAtomsOfMoleculeAction() {} void SelectionAllAtomsOfMolecule() { ActionRegistry::getInstance().getActionByName(SelectionAllAtomsOfMoleculeAction::NAME)->call(Action::NonInteractive); }; Dialog* SelectionAllAtomsOfMoleculeAction::fillDialog(Dialog *dialog) { ASSERT(dialog,"No Dialog given when filling action dialog"); dialog->queryMolecule(NAME, ValueStorage::getInstance().getDescription(NAME)); return dialog; } Action::state_ptr SelectionAllAtomsOfMoleculeAction::performCall() { molecule *mol = NULL; std::vector selectedAtoms = World::getInstance().getSelectedAtoms(); ValueStorage::getInstance().queryCurrentValue(NAME, mol); DoLog(1) && (Log() << Verbose(1) << "Selecting all atoms of molecule " << mol->getName() << "." << endl); World::getInstance().selectAtomsOfMolecule(mol); return Action::state_ptr(new SelectionAllAtomsOfMoleculeState(selectedAtoms, mol)); } Action::state_ptr SelectionAllAtomsOfMoleculeAction::performUndo(Action::state_ptr _state) { SelectionAllAtomsOfMoleculeState *state = assert_cast(_state.get()); World::getInstance().clearAtomSelection(); for(std::vector::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter) World::getInstance().selectAtom(*iter); return Action::state_ptr(new SelectionAllAtomsOfMoleculeState(state->selectedAtoms, state->mol)); } Action::state_ptr SelectionAllAtomsOfMoleculeAction::performRedo(Action::state_ptr _state){ SelectionAllAtomsOfMoleculeState *state = assert_cast(_state.get()); World::getInstance().selectAtomsOfMolecule(state->mol); return Action::state_ptr(new SelectionAllAtomsOfMoleculeState(state->selectedAtoms, state->mol)); } bool SelectionAllAtomsOfMoleculeAction::canUndo() { return true; } bool SelectionAllAtomsOfMoleculeAction::shouldUndo() { return true; } const string SelectionAllAtomsOfMoleculeAction::getName() { return NAME; }