| [97ebf8] | 1 | /*
 | 
|---|
 | 2 |  * CenterOnEdgeAction.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/CenterOnEdgeAction.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"
 | 
|---|
| [57f243] | 16 | #include "LinearAlgebra/Matrix.hpp"
 | 
|---|
| [97ebf8] | 17 | 
 | 
|---|
 | 18 | #include <iostream>
 | 
|---|
 | 19 | #include <string>
 | 
|---|
 | 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 WorldCenterOnEdgeAction::NAME[] = "center-edge";
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | WorldCenterOnEdgeAction::WorldCenterOnEdgeAction() :
 | 
|---|
 | 31 |   Action(NAME)
 | 
|---|
 | 32 | {}
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 | WorldCenterOnEdgeAction::~WorldCenterOnEdgeAction()
 | 
|---|
 | 35 | {}
 | 
|---|
 | 36 | 
 | 
|---|
| [a8f6ae] | 37 | void WorldCenterOnEdge() {
 | 
|---|
 | 38 |   ActionRegistry::getInstance().getActionByName(WorldCenterOnEdgeAction::NAME)->call(Action::NonInteractive);
 | 
|---|
 | 39 | };
 | 
|---|
 | 40 | 
 | 
|---|
| [047878] | 41 | Dialog* WorldCenterOnEdgeAction::fillDialog(Dialog *dialog) {
 | 
|---|
 | 42 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| [1ba67d] | 43 | 
 | 
|---|
 | 44 |   dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 |   return dialog;
 | 
|---|
 | 47 | }
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | Action::state_ptr WorldCenterOnEdgeAction::performCall() {
 | 
|---|
| [97ebf8] | 50 |   Vector Min;
 | 
|---|
 | 51 |   Vector Max;
 | 
|---|
 | 52 | 
 | 
|---|
| [1ba67d] | 53 |   // get maximum and minimum
 | 
|---|
 | 54 |   vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
 | 
|---|
 | 55 |   ASSERT(AllAtoms.size() > 0, "For CenteronEdge atoms must be present.");
 | 
|---|
 | 56 |   vector<atom *>::iterator AtomRunner = AllAtoms.begin();
 | 
|---|
| [d74077] | 57 |   Min = (*AtomRunner)->getPosition();
 | 
|---|
 | 58 |   Max = (*AtomRunner)->getPosition();
 | 
|---|
| [1ba67d] | 59 |   for (; AtomRunner != AllAtoms.end(); ++AtomRunner) {
 | 
|---|
| [97ebf8] | 60 |     for (int i=0;i<NDIM;i++) {
 | 
|---|
| [d74077] | 61 |       if ((*AtomRunner)->at(i) > Max[i])
 | 
|---|
 | 62 |         Max[i] = (*AtomRunner)->at(i);
 | 
|---|
 | 63 |       if ((*AtomRunner)->at(i) < Min[i])
 | 
|---|
 | 64 |         Min[i] = (*AtomRunner)->at(i);
 | 
|---|
| [97ebf8] | 65 |     }
 | 
|---|
 | 66 |   }
 | 
|---|
| [1ba67d] | 67 |   // set new box size
 | 
|---|
 | 68 |   Matrix domain;
 | 
|---|
 | 69 |   for (int i=0;i<NDIM;i++) {
 | 
|---|
 | 70 |     double tmp = Max[i]-Min[i];
 | 
|---|
 | 71 |     tmp = fabs(tmp)>=1. ? tmp : 1.0;
 | 
|---|
 | 72 |     domain.at(i,i) = tmp;
 | 
|---|
 | 73 |   }
 | 
|---|
 | 74 |   World::getInstance().setDomain(domain);
 | 
|---|
 | 75 |   // translate all atoms, such that Min is aty (0,0,0)
 | 
|---|
 | 76 |   for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner)
 | 
|---|
| [d74077] | 77 |     *(*AtomRunner) -= Min;
 | 
|---|
| [1ba67d] | 78 | 
 | 
|---|
 | 79 |   return Action::success;
 | 
|---|
| [97ebf8] | 80 | }
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 | Action::state_ptr WorldCenterOnEdgeAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 83 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 |   return Action::failure;
 | 
|---|
 | 86 | //  string newName = state->mol->getName();
 | 
|---|
 | 87 | //  state->mol->setName(state->lastName);
 | 
|---|
 | 88 | //
 | 
|---|
 | 89 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
 | 
|---|
 | 90 | }
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 | Action::state_ptr WorldCenterOnEdgeAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 93 |   return Action::failure;
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | bool WorldCenterOnEdgeAction::canUndo() {
 | 
|---|
 | 97 |   return false;
 | 
|---|
 | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | bool WorldCenterOnEdgeAction::shouldUndo() {
 | 
|---|
 | 101 |   return false;
 | 
|---|
 | 102 | }
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 | const string WorldCenterOnEdgeAction::getName() {
 | 
|---|
 | 105 |   return NAME;
 | 
|---|
 | 106 | }
 | 
|---|