[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"
|
---|
| 11 | #include "atom.hpp"
|
---|
| 12 | #include "log.hpp"
|
---|
| 13 | #include "vector.hpp"
|
---|
| 14 | #include "World.hpp"
|
---|
| 15 |
|
---|
| 16 | #include <iostream>
|
---|
| 17 | #include <string>
|
---|
| 18 |
|
---|
| 19 | using namespace std;
|
---|
| 20 |
|
---|
| 21 | #include "UIElements/UIFactory.hpp"
|
---|
| 22 | #include "UIElements/Dialog.hpp"
|
---|
| 23 | #include "Actions/MapOfActions.hpp"
|
---|
| 24 | #include "Helpers/Assert.hpp"
|
---|
| 25 |
|
---|
| 26 | const char WorldCenterOnEdgeAction::NAME[] = "center-edge";
|
---|
| 27 |
|
---|
| 28 | WorldCenterOnEdgeAction::WorldCenterOnEdgeAction() :
|
---|
| 29 | Action(NAME)
|
---|
| 30 | {}
|
---|
| 31 |
|
---|
| 32 | WorldCenterOnEdgeAction::~WorldCenterOnEdgeAction()
|
---|
| 33 | {}
|
---|
| 34 |
|
---|
| 35 | Action::state_ptr WorldCenterOnEdgeAction::performCall() {
|
---|
| 36 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 37 | Vector Min;
|
---|
| 38 | Vector Max;
|
---|
| 39 | int j=0;
|
---|
| 40 |
|
---|
| 41 | dialog->queryEmpty(NAME, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 42 |
|
---|
| 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 | // translate all atoms, such that Min is aty (0,0,0)
|
---|
| 68 | for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner)
|
---|
| 69 | (*AtomRunner)->x -= Min;
|
---|
| 70 | delete dialog;
|
---|
| 71 | return Action::success;
|
---|
| 72 | } else {
|
---|
| 73 | delete dialog;
|
---|
| 74 | return Action::failure;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | Action::state_ptr WorldCenterOnEdgeAction::performUndo(Action::state_ptr _state) {
|
---|
| 79 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 80 |
|
---|
| 81 | return Action::failure;
|
---|
| 82 | // string newName = state->mol->getName();
|
---|
| 83 | // state->mol->setName(state->lastName);
|
---|
| 84 | //
|
---|
| 85 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | Action::state_ptr WorldCenterOnEdgeAction::performRedo(Action::state_ptr _state){
|
---|
| 89 | return Action::failure;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | bool WorldCenterOnEdgeAction::canUndo() {
|
---|
| 93 | return false;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | bool WorldCenterOnEdgeAction::shouldUndo() {
|
---|
| 97 | return false;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | const string WorldCenterOnEdgeAction::getName() {
|
---|
| 101 | return NAME;
|
---|
| 102 | }
|
---|