[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 | * AddEmptyBoundaryAction.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: May 8, 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/WorldAction/AddEmptyBoundaryAction.hpp"
|
---|
[0430e3] | 23 | #include "Actions/ActionRegistry.hpp"
|
---|
[97ebf8] | 24 | #include "atom.hpp"
|
---|
[952f38] | 25 | #include "Helpers/Log.hpp"
|
---|
[57f243] | 26 | #include "LinearAlgebra/Vector.hpp"
|
---|
[97ebf8] | 27 | #include "World.hpp"
|
---|
| 28 |
|
---|
| 29 | #include <iostream>
|
---|
| 30 | #include <string>
|
---|
| 31 | #include <vector>
|
---|
| 32 |
|
---|
| 33 | using namespace std;
|
---|
| 34 |
|
---|
| 35 | #include "UIElements/UIFactory.hpp"
|
---|
| 36 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 37 | #include "Actions/ValueStorage.hpp"
|
---|
[97ebf8] | 38 | #include "Helpers/Assert.hpp"
|
---|
| 39 |
|
---|
| 40 | const char WorldAddEmptyBoundaryAction::NAME[] = "boundary";
|
---|
| 41 |
|
---|
| 42 | WorldAddEmptyBoundaryAction::WorldAddEmptyBoundaryAction() :
|
---|
| 43 | Action(NAME)
|
---|
| 44 | {}
|
---|
| 45 |
|
---|
| 46 | WorldAddEmptyBoundaryAction::~WorldAddEmptyBoundaryAction()
|
---|
| 47 | {}
|
---|
| 48 |
|
---|
[a8f6ae] | 49 | void WorldAddEmptyBoundary(Vector &boundary) {
|
---|
| 50 | ValueStorage::getInstance().setCurrentValue(WorldAddEmptyBoundaryAction::NAME, boundary);
|
---|
| 51 | ActionRegistry::getInstance().getActionByName(WorldAddEmptyBoundaryAction::NAME)->call(Action::NonInteractive);
|
---|
| 52 | };
|
---|
| 53 |
|
---|
[0b2ce9] | 54 | void WorldAddEmptyBoundaryAction::getParametersfromValueStorage()
|
---|
| 55 | {};
|
---|
| 56 |
|
---|
[047878] | 57 | Dialog* WorldAddEmptyBoundaryAction::fillDialog(Dialog *dialog) {
|
---|
| 58 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[afd9f3] | 59 |
|
---|
| 60 | dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 61 |
|
---|
| 62 | return dialog;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | Action::state_ptr WorldAddEmptyBoundaryAction::performCall() {
|
---|
[97ebf8] | 66 | Vector boundary;
|
---|
| 67 | Vector Min;
|
---|
| 68 | Vector Max;
|
---|
| 69 | int j=0;
|
---|
| 70 |
|
---|
[afd9f3] | 71 | ValueStorage::getInstance().queryCurrentValue(NAME, boundary);
|
---|
| 72 |
|
---|
| 73 | // get maximum and minimum
|
---|
| 74 | vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
|
---|
| 75 | ASSERT(AllAtoms.size() > 0, "There must be atoms present for AddingEmptyBoundary.");
|
---|
| 76 | vector<atom *>::iterator AtomRunner = AllAtoms.begin();
|
---|
[d74077] | 77 | Min = (*AtomRunner)->getPosition();
|
---|
| 78 | Max = (*AtomRunner)->getPosition();
|
---|
[afd9f3] | 79 | for (; AtomRunner != AllAtoms.end(); ++AtomRunner) {
|
---|
[97ebf8] | 80 | for (int i=0;i<NDIM;i++) {
|
---|
[d74077] | 81 | if ((*AtomRunner)->at(i) > Max[i])
|
---|
| 82 | Max[i] = (*AtomRunner)->at(i);
|
---|
| 83 | if ((*AtomRunner)->at(i) < Min[i])
|
---|
| 84 | Min[i] = (*AtomRunner)->at(i);
|
---|
[97ebf8] | 85 | }
|
---|
| 86 | }
|
---|
[afd9f3] | 87 | // set new box size
|
---|
| 88 | double * const cell_size = new double[6];
|
---|
| 89 | for (j=0;j<6;j++)
|
---|
| 90 | cell_size[j] = 0.;
|
---|
| 91 | j=-1;
|
---|
| 92 | for (int i=0;i<NDIM;i++) {
|
---|
| 93 | j += i+1;
|
---|
| 94 | cell_size[j] = (Max[i]-Min[i]+2.*boundary[i]);
|
---|
| 95 | }
|
---|
| 96 | World::getInstance().setDomain(cell_size);
|
---|
| 97 | delete[] cell_size;
|
---|
| 98 | // translate all atoms, such that Min is aty (0,0,0)
|
---|
| 99 | AtomRunner = AllAtoms.begin();
|
---|
| 100 | for (; AtomRunner != AllAtoms.end(); ++AtomRunner)
|
---|
[d74077] | 101 | *(*AtomRunner) -= Min - boundary;
|
---|
[afd9f3] | 102 | return Action::success;
|
---|
[97ebf8] | 103 | }
|
---|
| 104 |
|
---|
| 105 | Action::state_ptr WorldAddEmptyBoundaryAction::performUndo(Action::state_ptr _state) {
|
---|
| 106 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 107 |
|
---|
| 108 | return Action::failure;
|
---|
| 109 | // string newName = state->mol->getName();
|
---|
| 110 | // state->mol->setName(state->lastName);
|
---|
| 111 | //
|
---|
| 112 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | Action::state_ptr WorldAddEmptyBoundaryAction::performRedo(Action::state_ptr _state){
|
---|
| 116 | return Action::failure;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | bool WorldAddEmptyBoundaryAction::canUndo() {
|
---|
| 120 | return false;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | bool WorldAddEmptyBoundaryAction::shouldUndo() {
|
---|
| 124 | return false;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | const string WorldAddEmptyBoundaryAction::getName() {
|
---|
| 128 | return NAME;
|
---|
| 129 | }
|
---|