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