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