Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/WorldAction/CenterOnEdgeAction.cpp

    r623e89 r047878  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Actions/WorldAction/CenterOnEdgeAction.hpp"
     11#include "Actions/ActionRegistry.hpp"
    912#include "atom.hpp"
    1013#include "log.hpp"
    1114#include "vector.hpp"
    1215#include "World.hpp"
     16#include "Matrix.hpp"
    1317
    1418#include <iostream>
     
    1923#include "UIElements/UIFactory.hpp"
    2024#include "UIElements/Dialog.hpp"
    21 #include "Actions/MapOfActions.hpp"
     25#include "UIElements/ValueStorage.hpp"
    2226#include "Helpers/Assert.hpp"
    2327
     
    3135{}
    3236
     37void WorldCenterOnEdge() {
     38  ActionRegistry::getInstance().getActionByName(WorldCenterOnEdgeAction::NAME)->call(Action::NonInteractive);
     39};
     40
     41Dialog* WorldCenterOnEdgeAction::fillDialog(Dialog *dialog) {
     42  ASSERT(dialog,"No Dialog given when filling action dialog");
     43
     44  dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
     45
     46  return dialog;
     47}
     48
    3349Action::state_ptr WorldCenterOnEdgeAction::performCall() {
    34   Dialog *dialog = UIFactory::getInstance().makeDialog();
    3550  Vector Min;
    3651  Vector Max;
    37   int j=0;
    3852
    39   dialog->queryEmpty(NAME, MapOfActions::getInstance().getDescription(NAME));
     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();
     57  Min = (*AtomRunner)->x;
     58  Max = (*AtomRunner)->x;
     59  for (; AtomRunner != AllAtoms.end(); ++AtomRunner) {
     60    for (int i=0;i<NDIM;i++) {
     61      if ((*AtomRunner)->x[i] > Max[i])
     62        Max[i] = (*AtomRunner)->x[i];
     63      if ((*AtomRunner)->x[i] < Min[i])
     64        Min[i] = (*AtomRunner)->x[i];
     65    }
     66  }
     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)
     77    (*AtomRunner)->x -= Min;
    4078
    41   if(dialog->display()) {
    42     // get maximum and minimum
    43     vector<atom *> AllAtoms = World::getInstance().getAllAtoms();
    44     ASSERT(AllAtoms.size() > 0, "For CenteronEdge atoms must be present.");
    45     vector<atom *>::iterator AtomRunner = AllAtoms.begin();
    46     Min = (*AtomRunner)->x;
    47     Max = (*AtomRunner)->x;
    48     for (; AtomRunner != AllAtoms.end(); ++AtomRunner) {
    49       for (int i=0;i<NDIM;i++) {
    50         if ((*AtomRunner)->x[i] > Max[i])
    51           Max[i] = (*AtomRunner)->x[i];
    52         if ((*AtomRunner)->x[i] < Min[i])
    53           Min[i] = (*AtomRunner)->x[i];
    54       }
    55     }
    56     // set new box size
    57     double * const cell_size = World::getInstance().getDomain();
    58     for (j=0;j<6;j++)
    59       cell_size[j] = 0.;
    60     j=-1;
    61     for (int i=0;i<NDIM;i++) {
    62       j += i+1;
    63       cell_size[j] = (Max[i]-Min[i]);
    64     }
    65     // translate all atoms, such that Min is aty (0,0,0)
    66     for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner)
    67       (*AtomRunner)->x -= Min;
    68     delete dialog;
    69     return Action::success;
    70   } else {
    71     delete dialog;
    72     return Action::failure;
    73   }
     79  return Action::success;
    7480}
    7581
Note: See TracChangeset for help on using the changeset viewer.