| 1 | /*
|
|---|
| 2 | * FillWithMoleculeAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 10, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| 10 | #include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
|
|---|
| 11 |
|
|---|
| 12 | #include <iostream>
|
|---|
| 13 | #include <string>
|
|---|
| 14 |
|
|---|
| 15 | using namespace std;
|
|---|
| 16 |
|
|---|
| 17 | #include "UIElements/UIFactory.hpp"
|
|---|
| 18 | #include "UIElements/Dialog.hpp"
|
|---|
| 19 | #include "Actions/MapOfActions.hpp"
|
|---|
| 20 |
|
|---|
| 21 | #include "atom.hpp"
|
|---|
| 22 | #include "bondgraph.hpp"
|
|---|
| 23 | #include "boundary.hpp"
|
|---|
| 24 | #include "config.hpp"
|
|---|
| 25 | #include "defs.hpp"
|
|---|
| 26 | #include "molecule.hpp"
|
|---|
| 27 | #include "periodentafel.hpp"
|
|---|
| 28 | #include "vector.hpp"
|
|---|
| 29 | #include "verbose.hpp"
|
|---|
| 30 | #include "World.hpp"
|
|---|
| 31 |
|
|---|
| 32 | /****** MoleculeFillWithMoleculeAction *****/
|
|---|
| 33 |
|
|---|
| 34 | // memento to remember the state when undoing
|
|---|
| 35 |
|
|---|
| 36 | //class MoleculeFillWithMoleculeState : public ActionState {
|
|---|
| 37 | //public:
|
|---|
| 38 | // MoleculeFillWithMoleculeState(molecule* _mol,std::string _lastName) :
|
|---|
| 39 | // mol(_mol),
|
|---|
| 40 | // lastName(_lastName)
|
|---|
| 41 | // {}
|
|---|
| 42 | // molecule* mol;
|
|---|
| 43 | // std::string lastName;
|
|---|
| 44 | //};
|
|---|
| 45 |
|
|---|
| 46 | const char MoleculeFillWithMoleculeAction::NAME[] = "fill-molecule";
|
|---|
| 47 |
|
|---|
| 48 | MoleculeFillWithMoleculeAction::MoleculeFillWithMoleculeAction() :
|
|---|
| 49 | Action(NAME)
|
|---|
| 50 | {}
|
|---|
| 51 |
|
|---|
| 52 | MoleculeFillWithMoleculeAction::~MoleculeFillWithMoleculeAction()
|
|---|
| 53 | {}
|
|---|
| 54 |
|
|---|
| 55 | Action::state_ptr MoleculeFillWithMoleculeAction::performCall() {
|
|---|
| 56 | string filename;
|
|---|
| 57 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
|---|
| 58 | Vector distances;
|
|---|
| 59 | Vector lengths;
|
|---|
| 60 | double MaxDistance = -1.;
|
|---|
| 61 | bool DoRotate = false;
|
|---|
| 62 |
|
|---|
| 63 | dialog->queryString(NAME, &filename, MapOfActions::getInstance().getDescription(NAME));
|
|---|
| 64 | dialog->queryVector("distances", &distances, World::getInstance().getDomain(), false, MapOfActions::getInstance().getDescription("distances"));
|
|---|
| 65 | dialog->queryVector("lengths", &lengths, World::getInstance().getDomain(), false, MapOfActions::getInstance().getDescription("lengths"));
|
|---|
| 66 | dialog->queryBoolean("DoRotate", &DoRotate, MapOfActions::getInstance().getDescription("DoRotate"));
|
|---|
| 67 | dialog->queryDouble("MaxDistance", &MaxDistance, MapOfActions::getInstance().getDescription("MaxDistance"));
|
|---|
| 68 |
|
|---|
| 69 | if(dialog->display()) {
|
|---|
| 70 | // construct water molecule
|
|---|
| 71 | molecule *filler = World::getInstance().createMolecule();
|
|---|
| 72 | // if (!filler->AddXYZFile(filename)) {
|
|---|
| 73 | // DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << filename << "." << endl);
|
|---|
| 74 | // }
|
|---|
| 75 | // filler->SetNameFromFilename(filename);
|
|---|
| 76 | molecule *Filling = NULL;
|
|---|
| 77 | atom *first = NULL, *second = NULL, *third = NULL;
|
|---|
| 78 | first = World::getInstance().createAtom();
|
|---|
| 79 | first->type = World::getInstance().getPeriode()->FindElement(1);
|
|---|
| 80 | first->x = Vector(0.441, -0.143, 0.);
|
|---|
| 81 | filler->AddAtom(first);
|
|---|
| 82 | second = World::getInstance().createAtom();
|
|---|
| 83 | second->type = World::getInstance().getPeriode()->FindElement(1);
|
|---|
| 84 | second->x = Vector(-0.464, 1.137, 0.0);
|
|---|
| 85 | filler->AddAtom(second);
|
|---|
| 86 | third = World::getInstance().createAtom();
|
|---|
| 87 | third->type = World::getInstance().getPeriode()->FindElement(8);
|
|---|
| 88 | third->x = Vector(-0.464, 0.177, 0.);
|
|---|
| 89 | filler->AddAtom(third);
|
|---|
| 90 | filler->AddBond(first, third, 1);
|
|---|
| 91 | filler->AddBond(second, third, 1);
|
|---|
| 92 | World::getInstance().getConfig()->BG->ConstructBondGraph(filler);
|
|---|
| 93 | filler->SetNameFromFilename("water");
|
|---|
| 94 | // call routine
|
|---|
| 95 | double distance[NDIM];
|
|---|
| 96 | for (int i=0;i<NDIM;i++)
|
|---|
| 97 | distance[i] = distances[i];
|
|---|
| 98 | Filling = FillBoxWithMolecule(World::getInstance().getMolecules(), filler, *(World::getInstance().getConfig()), MaxDistance, distance, lengths[0], lengths[1], lengths[2], DoRotate);
|
|---|
| 99 | if (Filling != NULL) {
|
|---|
| 100 | Filling->ActiveFlag = false;
|
|---|
| 101 | World::getInstance().getMolecules()->insert(Filling);
|
|---|
| 102 | }
|
|---|
| 103 | World::getInstance().destroyMolecule(filler);
|
|---|
| 104 |
|
|---|
| 105 | delete dialog;
|
|---|
| 106 | return Action::success;
|
|---|
| 107 | }
|
|---|
| 108 | delete dialog;
|
|---|
| 109 | return Action::failure;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | Action::state_ptr MoleculeFillWithMoleculeAction::performUndo(Action::state_ptr _state) {
|
|---|
| 113 | // MoleculeFillWithMoleculeState *state = assert_cast<MoleculeFillWithMoleculeState*>(_state.get());
|
|---|
| 114 |
|
|---|
| 115 | // string newName = state->mol->getName();
|
|---|
| 116 | // state->mol->setName(state->lastName);
|
|---|
| 117 |
|
|---|
| 118 | return Action::failure;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | Action::state_ptr MoleculeFillWithMoleculeAction::performRedo(Action::state_ptr _state){
|
|---|
| 122 | // Undo and redo have to do the same for this action
|
|---|
| 123 | return performUndo(_state);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | bool MoleculeFillWithMoleculeAction::canUndo() {
|
|---|
| 127 | return false;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | bool MoleculeFillWithMoleculeAction::shouldUndo() {
|
|---|
| 131 | return false;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | const string MoleculeFillWithMoleculeAction::getName() {
|
|---|
| 135 | return NAME;
|
|---|
| 136 | }
|
|---|