/* * FillWithMoleculeAction.cpp * * Created on: May 10, 2010 * Author: heber */ #include "Helpers/MemDebug.hpp" #include "Actions/MoleculeAction/FillWithMoleculeAction.hpp" #include #include using namespace std; #include "UIElements/UIFactory.hpp" #include "UIElements/Dialog.hpp" #include "UIElements/ValueStorage.hpp" #include "atom.hpp" #include "bondgraph.hpp" #include "boundary.hpp" #include "config.hpp" #include "molecule.hpp" #include "verbose.hpp" #include "World.hpp" /****** MoleculeFillWithMoleculeAction *****/ // memento to remember the state when undoing //class MoleculeFillWithMoleculeState : public ActionState { //public: // MoleculeFillWithMoleculeState(molecule* _mol,std::string _lastName) : // mol(_mol), // lastName(_lastName) // {} // molecule* mol; // std::string lastName; //}; const char MoleculeFillWithMoleculeAction::NAME[] = "fill-molecule"; MoleculeFillWithMoleculeAction::MoleculeFillWithMoleculeAction() : Action(NAME) {} MoleculeFillWithMoleculeAction::~MoleculeFillWithMoleculeAction() {} Dialog* MoleculeFillWithMoleculeAction::createDialog() { Dialog *dialog = UIFactory::getInstance().makeDialog(); dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME)); dialog->queryVector("distances", false, ValueStorage::getInstance().getDescription("distances")); dialog->queryVector("lengths", false, ValueStorage::getInstance().getDescription("lengths")); dialog->queryBoolean("DoRotate", ValueStorage::getInstance().getDescription("DoRotate")); dialog->queryDouble("MaxDistance", ValueStorage::getInstance().getDescription("MaxDistance")); return dialog; } Action::state_ptr MoleculeFillWithMoleculeAction::performCall() { string filename; Vector distances; Vector lengths; double MaxDistance = -1.; bool DoRotate = false; ValueStorage::getInstance().queryCurrentValue(NAME, filename); ValueStorage::getInstance().queryCurrentValue("distances", distances); ValueStorage::getInstance().queryCurrentValue("lengths", lengths); ValueStorage::getInstance().queryCurrentValue("DoRotate", DoRotate); ValueStorage::getInstance().queryCurrentValue("MaxDistance", MaxDistance); DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules, lengths(" << lengths[0] << "," << lengths[1] << "," << lengths[2] << "), distances (" << distances[0] << "," << distances[1] << "," << distances[2] << "), MaxDistance " << MaxDistance << ", DoRotate " << DoRotate << "." << endl); // construct water molecule molecule *filler = World::getInstance().createMolecule(); if (!filler->AddXYZFile(filename)) { DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << filename << "." << endl); } filler->SetNameFromFilename(filename.c_str()); molecule *Filling = NULL; // atom *first = NULL, *second = NULL, *third = NULL; // first = World::getInstance().createAtom(); // first->type = World::getInstance().getPeriode()->FindElement(1); // first->x = Vector(0.441, -0.143, 0.); // filler->AddAtom(first); // second = World::getInstance().createAtom(); // second->type = World::getInstance().getPeriode()->FindElement(1); // second->x = Vector(-0.464, 1.137, 0.0); // filler->AddAtom(second); // third = World::getInstance().createAtom(); // third->type = World::getInstance().getPeriode()->FindElement(8); // third->x = Vector(-0.464, 0.177, 0.); // filler->AddAtom(third); // filler->AddBond(first, third, 1); // filler->AddBond(second, third, 1); World::getInstance().getConfig()->BG->ConstructBondGraph(filler); // filler->SetNameFromFilename("water"); // call routine double distance[NDIM]; for (int i=0;iActiveFlag = false; World::getInstance().getMolecules()->insert(Filling); } for (molecule::iterator iter = filler->begin(); !filler->empty(); iter = filler->begin()) { atom *Walker = *iter; filler->erase(iter); World::getInstance().destroyAtom(Walker); } World::getInstance().destroyMolecule(filler); return Action::success; } Action::state_ptr MoleculeFillWithMoleculeAction::performUndo(Action::state_ptr _state) { // MoleculeFillWithMoleculeState *state = assert_cast(_state.get()); // string newName = state->mol->getName(); // state->mol->setName(state->lastName); return Action::failure; } Action::state_ptr MoleculeFillWithMoleculeAction::performRedo(Action::state_ptr _state){ // Undo and redo have to do the same for this action return performUndo(_state); } bool MoleculeFillWithMoleculeAction::canUndo() { return false; } bool MoleculeFillWithMoleculeAction::shouldUndo() { return false; } const string MoleculeFillWithMoleculeAction::getName() { return NAME; }