- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Actions/WorldAction/CenterOnEdgeAction.cpp ¶
rb9c847 r0430e3 9 9 10 10 #include "Actions/WorldAction/CenterOnEdgeAction.hpp" 11 #include "Actions/ActionRegistry.hpp" 11 12 #include "atom.hpp" 12 13 #include "log.hpp" 13 14 #include "vector.hpp" 14 15 #include "World.hpp" 16 #include "Matrix.hpp" 15 17 16 18 #include <iostream> … … 21 23 #include "UIElements/UIFactory.hpp" 22 24 #include "UIElements/Dialog.hpp" 23 #include " Actions/MapOfActions.hpp"25 #include "UIElements/ValueStorage.hpp" 24 26 #include "Helpers/Assert.hpp" 25 27 … … 33 35 {} 34 36 37 void WorldCenterOnEdge() { 38 ActionRegistry::getInstance().getActionByName(WorldCenterOnEdgeAction::NAME)->call(Action::NonInteractive); 39 }; 40 41 Dialog* WorldCenterOnEdgeAction::createDialog() { 42 Dialog *dialog = UIFactory::getInstance().makeDialog(); 43 44 dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME)); 45 46 return dialog; 47 } 48 35 49 Action::state_ptr WorldCenterOnEdgeAction::performCall() { 36 Dialog *dialog = UIFactory::getInstance().makeDialog();37 50 Vector Min; 38 51 Vector Max; 39 int j=0;40 52 41 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; 42 78 43 if(dialog->display()) { 44 // get maximum and minimum 45 vector<atom *> AllAtoms = World::getInstance().getAllAtoms(); 46 ASSERT(AllAtoms.size() > 0, "For CenteronEdge atoms must be present."); 47 vector<atom *>::iterator AtomRunner = AllAtoms.begin(); 48 Min = (*AtomRunner)->x; 49 Max = (*AtomRunner)->x; 50 for (; AtomRunner != AllAtoms.end(); ++AtomRunner) { 51 for (int i=0;i<NDIM;i++) { 52 if ((*AtomRunner)->x[i] > Max[i]) 53 Max[i] = (*AtomRunner)->x[i]; 54 if ((*AtomRunner)->x[i] < Min[i]) 55 Min[i] = (*AtomRunner)->x[i]; 56 } 57 } 58 // set new box size 59 double * const cell_size = World::getInstance().getDomain(); 60 for (j=0;j<6;j++) 61 cell_size[j] = 0.; 62 j=-1; 63 for (int i=0;i<NDIM;i++) { 64 j += i+1; 65 cell_size[j] = (Max[i]-Min[i]); 66 } 67 World::getInstance().setDomain(cell_size); 68 // translate all atoms, such that Min is aty (0,0,0) 69 for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) 70 (*AtomRunner)->x -= Min; 71 delete dialog; 72 return Action::success; 73 } else { 74 delete dialog; 75 return Action::failure; 76 } 79 return Action::success; 77 80 } 78 81
Note:
See TracChangeset
for help on using the changeset viewer.