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