[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"
|
---|
| 24 | #include "Actions/MapOfActions.hpp"
|
---|
| 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 |
|
---|
| 36 | Action::state_ptr WorldAddEmptyBoundaryAction::performCall() {
|
---|
| 37 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 38 | Vector boundary;
|
---|
| 39 | Vector Min;
|
---|
| 40 | Vector Max;
|
---|
| 41 | int j=0;
|
---|
| 42 |
|
---|
[84c494] | 43 | dialog->queryVector(NAME, &boundary, false, MapOfActions::getInstance().getDescription(NAME));
|
---|
[97ebf8] | 44 |
|
---|
| 45 | if(dialog->display()) {
|
---|
| 46 | // get maximum and minimum
|
---|
| 47 | vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
|
---|
| 48 | ASSERT(AllAtoms.size() > 0, "There must be atoms present for AddingEmptyBoundary.");
|
---|
| 49 | vector<atom *>::iterator AtomRunner = AllAtoms.begin();
|
---|
| 50 | Min = (*AtomRunner)->x;
|
---|
| 51 | Max = (*AtomRunner)->x;
|
---|
| 52 | for (; AtomRunner != AllAtoms.end(); ++AtomRunner) {
|
---|
| 53 | for (int i=0;i<NDIM;i++) {
|
---|
| 54 | if ((*AtomRunner)->x[i] > Max[i])
|
---|
| 55 | Max[i] = (*AtomRunner)->x[i];
|
---|
| 56 | if ((*AtomRunner)->x[i] < Min[i])
|
---|
| 57 | Min[i] = (*AtomRunner)->x[i];
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | // set new box size
|
---|
[84c494] | 61 | double * const cell_size = new double[6];
|
---|
[97ebf8] | 62 | for (j=0;j<6;j++)
|
---|
| 63 | cell_size[j] = 0.;
|
---|
| 64 | j=-1;
|
---|
| 65 | for (int i=0;i<NDIM;i++) {
|
---|
| 66 | j += i+1;
|
---|
| 67 | cell_size[j] = (Max[i]-Min[i]+2.*boundary[i]);
|
---|
| 68 | }
|
---|
[84c494] | 69 | World::getInstance().setDomain(cell_size);
|
---|
| 70 | delete[] cell_size;
|
---|
[97ebf8] | 71 | // translate all atoms, such that Min is aty (0,0,0)
|
---|
| 72 | AtomRunner = AllAtoms.begin();
|
---|
| 73 | for (; AtomRunner != AllAtoms.end(); ++AtomRunner)
|
---|
[116f37] | 74 | (*AtomRunner)->x -= Min - boundary;
|
---|
[97ebf8] | 75 | delete dialog;
|
---|
| 76 | return Action::success;
|
---|
| 77 | } else {
|
---|
| 78 | delete dialog;
|
---|
| 79 | return Action::failure;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | Action::state_ptr WorldAddEmptyBoundaryAction::performUndo(Action::state_ptr _state) {
|
---|
| 84 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 85 |
|
---|
| 86 | return Action::failure;
|
---|
| 87 | // string newName = state->mol->getName();
|
---|
| 88 | // state->mol->setName(state->lastName);
|
---|
| 89 | //
|
---|
| 90 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | Action::state_ptr WorldAddEmptyBoundaryAction::performRedo(Action::state_ptr _state){
|
---|
| 94 | return Action::failure;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | bool WorldAddEmptyBoundaryAction::canUndo() {
|
---|
| 98 | return false;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | bool WorldAddEmptyBoundaryAction::shouldUndo() {
|
---|
| 102 | return false;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | const string WorldAddEmptyBoundaryAction::getName() {
|
---|
| 106 | return NAME;
|
---|
| 107 | }
|
---|