[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"
|
---|
| 11 | #include "atom.hpp"
|
---|
| 12 | #include "log.hpp"
|
---|
| 13 | #include "vector.hpp"
|
---|
| 14 | #include "World.hpp"
|
---|
| 15 |
|
---|
| 16 | #include <iostream>
|
---|
| 17 | #include <string>
|
---|
| 18 | #include <vector>
|
---|
| 19 |
|
---|
| 20 | using namespace std;
|
---|
| 21 |
|
---|
| 22 | #include "UIElements/UIFactory.hpp"
|
---|
| 23 | #include "UIElements/Dialog.hpp"
|
---|
[afd9f3] | 24 | #include "UIElements/ValueStorage.hpp"
|
---|
[97ebf8] | 25 | #include "Helpers/Assert.hpp"
|
---|
| 26 |
|
---|
| 27 | const char WorldAddEmptyBoundaryAction::NAME[] = "boundary";
|
---|
| 28 |
|
---|
| 29 | WorldAddEmptyBoundaryAction::WorldAddEmptyBoundaryAction() :
|
---|
| 30 | Action(NAME)
|
---|
| 31 | {}
|
---|
| 32 |
|
---|
| 33 | WorldAddEmptyBoundaryAction::~WorldAddEmptyBoundaryAction()
|
---|
| 34 | {}
|
---|
| 35 |
|
---|
[afd9f3] | 36 | Dialog* WorldAddEmptyBoundaryAction::createDialog() {
|
---|
[97ebf8] | 37 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
[afd9f3] | 38 |
|
---|
| 39 | dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 40 |
|
---|
| 41 | return dialog;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | Action::state_ptr WorldAddEmptyBoundaryAction::performCall() {
|
---|
[97ebf8] | 45 | Vector boundary;
|
---|
| 46 | Vector Min;
|
---|
| 47 | Vector Max;
|
---|
| 48 | int j=0;
|
---|
| 49 |
|
---|
[afd9f3] | 50 | ValueStorage::getInstance().queryCurrentValue(NAME, boundary);
|
---|
| 51 |
|
---|
| 52 | // get maximum and minimum
|
---|
| 53 | vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
|
---|
| 54 | ASSERT(AllAtoms.size() > 0, "There must be atoms present for AddingEmptyBoundary.");
|
---|
| 55 | vector<atom *>::iterator AtomRunner = AllAtoms.begin();
|
---|
| 56 | Min = (*AtomRunner)->x;
|
---|
| 57 | Max = (*AtomRunner)->x;
|
---|
| 58 | for (; AtomRunner != AllAtoms.end(); ++AtomRunner) {
|
---|
[97ebf8] | 59 | for (int i=0;i<NDIM;i++) {
|
---|
[afd9f3] | 60 | if ((*AtomRunner)->x[i] > Max[i])
|
---|
| 61 | Max[i] = (*AtomRunner)->x[i];
|
---|
| 62 | if ((*AtomRunner)->x[i] < Min[i])
|
---|
| 63 | Min[i] = (*AtomRunner)->x[i];
|
---|
[97ebf8] | 64 | }
|
---|
| 65 | }
|
---|
[afd9f3] | 66 | // set new box size
|
---|
| 67 | double * const cell_size = new double[6];
|
---|
| 68 | for (j=0;j<6;j++)
|
---|
| 69 | cell_size[j] = 0.;
|
---|
| 70 | j=-1;
|
---|
| 71 | for (int i=0;i<NDIM;i++) {
|
---|
| 72 | j += i+1;
|
---|
| 73 | cell_size[j] = (Max[i]-Min[i]+2.*boundary[i]);
|
---|
| 74 | }
|
---|
| 75 | World::getInstance().setDomain(cell_size);
|
---|
| 76 | delete[] cell_size;
|
---|
| 77 | // translate all atoms, such that Min is aty (0,0,0)
|
---|
| 78 | AtomRunner = AllAtoms.begin();
|
---|
| 79 | for (; AtomRunner != AllAtoms.end(); ++AtomRunner)
|
---|
| 80 | (*AtomRunner)->x -= Min - boundary;
|
---|
| 81 | return Action::success;
|
---|
[97ebf8] | 82 | }
|
---|
| 83 |
|
---|
| 84 | Action::state_ptr WorldAddEmptyBoundaryAction::performUndo(Action::state_ptr _state) {
|
---|
| 85 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 86 |
|
---|
| 87 | return Action::failure;
|
---|
| 88 | // string newName = state->mol->getName();
|
---|
| 89 | // state->mol->setName(state->lastName);
|
---|
| 90 | //
|
---|
| 91 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | Action::state_ptr WorldAddEmptyBoundaryAction::performRedo(Action::state_ptr _state){
|
---|
| 95 | return Action::failure;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | bool WorldAddEmptyBoundaryAction::canUndo() {
|
---|
| 99 | return false;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | bool WorldAddEmptyBoundaryAction::shouldUndo() {
|
---|
| 103 | return false;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | const string WorldAddEmptyBoundaryAction::getName() {
|
---|
| 107 | return NAME;
|
---|
| 108 | }
|
---|