/* * ChangeElementAction.cpp * * Created on: May 9, 2010 * Author: heber */ #include "Helpers/MemDebug.hpp" #include "Actions/AtomAction/ChangeElementAction.hpp" #include "Actions/ActionCalls.hpp" #include "atom.hpp" #include "element.hpp" #include "log.hpp" #include "vector.hpp" #include "verbose.hpp" #include "World.hpp" #include #include using namespace std; #include "UIElements/UIFactory.hpp" #include "UIElements/Dialog.hpp" #include "UIElements/ValueStorage.hpp" const char AtomChangeElementAction::NAME[] = "change-element"; AtomChangeElementAction::AtomChangeElementAction() : Action(NAME) {} AtomChangeElementAction::~AtomChangeElementAction() {} void AtomChangeElement(element *elemental) { ValueStorage::getInstance().setCurrentValue(AtomChangeElementAction::NAME, elemental); ActionRegistry::getInstance().getActionByName(AtomChangeElementAction::NAME)->call(Action::NonInteractive); }; Dialog* AtomChangeElementAction::createDialog() { Dialog *dialog = UIFactory::getInstance().makeDialog(); dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME)); return dialog; } Action::state_ptr AtomChangeElementAction::performCall() { atom *first = NULL; element *elemental = NULL; ValueStorage::getInstance().queryCurrentValue(NAME, elemental); for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) { first = iter->second; DoLog(1) && (Log() << Verbose(1) << "Changing atom " << *first << " to element " << elemental->symbol << "." << endl); first->type = elemental; } return Action::success; } Action::state_ptr AtomChangeElementAction::performUndo(Action::state_ptr _state) { // ParserLoadXyzState *state = assert_cast(_state.get()); return Action::failure; // string newName = state->mol->getName(); // state->mol->setName(state->lastName); // // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); } Action::state_ptr AtomChangeElementAction::performRedo(Action::state_ptr _state){ return Action::failure; } bool AtomChangeElementAction::canUndo() { return false; } bool AtomChangeElementAction::shouldUndo() { return false; } const string AtomChangeElementAction::getName() { return NAME; }