/* * AddAction.cpp * * Created on: May 9, 2010 * Author: heber */ #include "Actions/AtomAction/AddAction.hpp" #include "CommandLineParser.hpp" #include "atom.hpp" #include "element.hpp" #include "log.hpp" #include "periodentafel.hpp" #include "vector.hpp" #include "verbose.hpp" #include "World.hpp" #include #include using namespace std; #include "UIElements/UIFactory.hpp" #include "UIElements/Dialog.hpp" #include "Actions/MapOfActions.hpp" const char AtomAddAction::NAME[] = "add-atom"; AtomAddAction::AtomAddAction() : Action(NAME) {} AtomAddAction::~AtomAddAction() {} Action::state_ptr AtomAddAction::performCall() { Dialog *dialog = UIFactory::getInstance().makeDialog(); int Z = -1; Vector position; dialog->queryInt(NAME, &Z, MapOfActions::getInstance().getDescription(NAME)); dialog->queryVector("position", &position, World::getInstance().getDomain(), true, MapOfActions::getInstance().getDescription("position")); if(dialog->display()) { delete dialog; atom * first = World::getInstance().createAtom(); first->type = World::getInstance().getPeriode()->FindElement(Z); first->x = position; if (first->type != NULL) { DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << first->type->name << " at " << (first->x) << "." << endl); return Action::success; } else { DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the specified element." << endl); World::getInstance().destroyAtom(first); return Action::failure; } } else { delete dialog; return Action::failure; } } Action::state_ptr AtomAddAction::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 AtomAddAction::performRedo(Action::state_ptr _state){ return Action::failure; } bool AtomAddAction::canUndo() { return false; } bool AtomAddAction::shouldUndo() { return false; } const string AtomAddAction::getName() { return NAME; }