| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
|  | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [97ebf8] | 8 | /* | 
|---|
|  | 9 | * CenterOnEdgeAction.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: May 8, 2010 | 
|---|
|  | 12 | *      Author: heber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
| [bf3817] | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
| [112b09] | 20 | #include "Helpers/MemDebug.hpp" | 
|---|
|  | 21 |  | 
|---|
| [97ebf8] | 22 | #include "Actions/WorldAction/CenterOnEdgeAction.hpp" | 
|---|
| [0430e3] | 23 | #include "Actions/ActionRegistry.hpp" | 
|---|
| [97ebf8] | 24 | #include "atom.hpp" | 
|---|
| [952f38] | 25 | #include "Helpers/Log.hpp" | 
|---|
| [57f243] | 26 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| [97ebf8] | 27 | #include "World.hpp" | 
|---|
| [57f243] | 28 | #include "LinearAlgebra/Matrix.hpp" | 
|---|
| [97ebf8] | 29 |  | 
|---|
|  | 30 | #include <iostream> | 
|---|
|  | 31 | #include <string> | 
|---|
|  | 32 |  | 
|---|
|  | 33 | using namespace std; | 
|---|
|  | 34 |  | 
|---|
|  | 35 | #include "UIElements/UIFactory.hpp" | 
|---|
|  | 36 | #include "UIElements/Dialog.hpp" | 
|---|
| [861874] | 37 | #include "Actions/ValueStorage.hpp" | 
|---|
| [97ebf8] | 38 | #include "Helpers/Assert.hpp" | 
|---|
|  | 39 |  | 
|---|
|  | 40 | const char WorldCenterOnEdgeAction::NAME[] = "center-edge"; | 
|---|
|  | 41 |  | 
|---|
|  | 42 | WorldCenterOnEdgeAction::WorldCenterOnEdgeAction() : | 
|---|
|  | 43 | Action(NAME) | 
|---|
|  | 44 | {} | 
|---|
|  | 45 |  | 
|---|
|  | 46 | WorldCenterOnEdgeAction::~WorldCenterOnEdgeAction() | 
|---|
|  | 47 | {} | 
|---|
|  | 48 |  | 
|---|
| [a8f6ae] | 49 | void WorldCenterOnEdge() { | 
|---|
|  | 50 | ActionRegistry::getInstance().getActionByName(WorldCenterOnEdgeAction::NAME)->call(Action::NonInteractive); | 
|---|
|  | 51 | }; | 
|---|
|  | 52 |  | 
|---|
| [047878] | 53 | Dialog* WorldCenterOnEdgeAction::fillDialog(Dialog *dialog) { | 
|---|
|  | 54 | ASSERT(dialog,"No Dialog given when filling action dialog"); | 
|---|
| [1ba67d] | 55 |  | 
|---|
|  | 56 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME)); | 
|---|
|  | 57 |  | 
|---|
|  | 58 | return dialog; | 
|---|
|  | 59 | } | 
|---|
|  | 60 |  | 
|---|
|  | 61 | Action::state_ptr WorldCenterOnEdgeAction::performCall() { | 
|---|
| [97ebf8] | 62 | Vector Min; | 
|---|
|  | 63 | Vector Max; | 
|---|
|  | 64 |  | 
|---|
| [1ba67d] | 65 | // get maximum and minimum | 
|---|
|  | 66 | vector<atom *> AllAtoms = World::getInstance().getAllAtoms(); | 
|---|
|  | 67 | ASSERT(AllAtoms.size() > 0, "For CenteronEdge atoms must be present."); | 
|---|
|  | 68 | vector<atom *>::iterator AtomRunner = AllAtoms.begin(); | 
|---|
| [d74077] | 69 | Min = (*AtomRunner)->getPosition(); | 
|---|
|  | 70 | Max = (*AtomRunner)->getPosition(); | 
|---|
| [1ba67d] | 71 | for (; AtomRunner != AllAtoms.end(); ++AtomRunner) { | 
|---|
| [97ebf8] | 72 | for (int i=0;i<NDIM;i++) { | 
|---|
| [d74077] | 73 | if ((*AtomRunner)->at(i) > Max[i]) | 
|---|
|  | 74 | Max[i] = (*AtomRunner)->at(i); | 
|---|
|  | 75 | if ((*AtomRunner)->at(i) < Min[i]) | 
|---|
|  | 76 | Min[i] = (*AtomRunner)->at(i); | 
|---|
| [97ebf8] | 77 | } | 
|---|
|  | 78 | } | 
|---|
| [1ba67d] | 79 | // set new box size | 
|---|
|  | 80 | Matrix domain; | 
|---|
|  | 81 | for (int i=0;i<NDIM;i++) { | 
|---|
|  | 82 | double tmp = Max[i]-Min[i]; | 
|---|
|  | 83 | tmp = fabs(tmp)>=1. ? tmp : 1.0; | 
|---|
|  | 84 | domain.at(i,i) = tmp; | 
|---|
|  | 85 | } | 
|---|
|  | 86 | World::getInstance().setDomain(domain); | 
|---|
|  | 87 | // translate all atoms, such that Min is aty (0,0,0) | 
|---|
|  | 88 | for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) | 
|---|
| [d74077] | 89 | *(*AtomRunner) -= Min; | 
|---|
| [1ba67d] | 90 |  | 
|---|
|  | 91 | return Action::success; | 
|---|
| [97ebf8] | 92 | } | 
|---|
|  | 93 |  | 
|---|
|  | 94 | Action::state_ptr WorldCenterOnEdgeAction::performUndo(Action::state_ptr _state) { | 
|---|
|  | 95 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get()); | 
|---|
|  | 96 |  | 
|---|
|  | 97 | return Action::failure; | 
|---|
|  | 98 | //  string newName = state->mol->getName(); | 
|---|
|  | 99 | //  state->mol->setName(state->lastName); | 
|---|
|  | 100 | // | 
|---|
|  | 101 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | Action::state_ptr WorldCenterOnEdgeAction::performRedo(Action::state_ptr _state){ | 
|---|
|  | 105 | return Action::failure; | 
|---|
|  | 106 | } | 
|---|
|  | 107 |  | 
|---|
|  | 108 | bool WorldCenterOnEdgeAction::canUndo() { | 
|---|
|  | 109 | return false; | 
|---|
|  | 110 | } | 
|---|
|  | 111 |  | 
|---|
|  | 112 | bool WorldCenterOnEdgeAction::shouldUndo() { | 
|---|
|  | 113 | return false; | 
|---|
|  | 114 | } | 
|---|
|  | 115 |  | 
|---|
|  | 116 | const string WorldCenterOnEdgeAction::getName() { | 
|---|
|  | 117 | return NAME; | 
|---|
|  | 118 | } | 
|---|