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