- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/WorldAction/CenterOnEdgeAction.cpp
r623e89 r047878 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 9 8 10 #include "Actions/WorldAction/CenterOnEdgeAction.hpp" 11 #include "Actions/ActionRegistry.hpp" 9 12 #include "atom.hpp" 10 13 #include "log.hpp" 11 14 #include "vector.hpp" 12 15 #include "World.hpp" 16 #include "Matrix.hpp" 13 17 14 18 #include <iostream> … … 19 23 #include "UIElements/UIFactory.hpp" 20 24 #include "UIElements/Dialog.hpp" 21 #include " Actions/MapOfActions.hpp"25 #include "UIElements/ValueStorage.hpp" 22 26 #include "Helpers/Assert.hpp" 23 27 … … 31 35 {} 32 36 37 void WorldCenterOnEdge() { 38 ActionRegistry::getInstance().getActionByName(WorldCenterOnEdgeAction::NAME)->call(Action::NonInteractive); 39 }; 40 41 Dialog* 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 33 49 Action::state_ptr WorldCenterOnEdgeAction::performCall() { 34 Dialog *dialog = UIFactory::getInstance().makeDialog();35 50 Vector Min; 36 51 Vector Max; 37 int j=0;38 52 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; 40 78 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; 74 80 } 75 81
Note:
See TracChangeset
for help on using the changeset viewer.