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