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