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