1 | /*
|
---|
2 | * ScaleBoxAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 8, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/WorldAction/ScaleBoxAction.hpp"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "atom.hpp"
|
---|
13 | #include "Helpers/Log.hpp"
|
---|
14 | #include "LinearAlgebra/Vector.hpp"
|
---|
15 | #include "Helpers/Verbose.hpp"
|
---|
16 | #include "World.hpp"
|
---|
17 | #include "Box.hpp"
|
---|
18 | #include "LinearAlgebra/Matrix.hpp"
|
---|
19 |
|
---|
20 | #include <iostream>
|
---|
21 | #include <string>
|
---|
22 |
|
---|
23 | using namespace std;
|
---|
24 |
|
---|
25 | #include "UIElements/UIFactory.hpp"
|
---|
26 | #include "UIElements/Dialog.hpp"
|
---|
27 | #include "Actions/ValueStorage.hpp"
|
---|
28 |
|
---|
29 | const char WorldScaleBoxAction::NAME[] = "scale-box";
|
---|
30 |
|
---|
31 | WorldScaleBoxAction::WorldScaleBoxAction() :
|
---|
32 | Action(NAME)
|
---|
33 | {}
|
---|
34 |
|
---|
35 | WorldScaleBoxAction::~WorldScaleBoxAction()
|
---|
36 | {}
|
---|
37 |
|
---|
38 | void WorldScaleBox(Vector &Scaler) {
|
---|
39 | ValueStorage::getInstance().setCurrentValue(WorldScaleBoxAction::NAME, Scaler);
|
---|
40 | ActionRegistry::getInstance().getActionByName(WorldScaleBoxAction::NAME)->call(Action::NonInteractive);
|
---|
41 | };
|
---|
42 |
|
---|
43 | Dialog* WorldScaleBoxAction::fillDialog(Dialog *dialog) {
|
---|
44 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
45 |
|
---|
46 | dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
|
---|
47 |
|
---|
48 | return dialog;
|
---|
49 | }
|
---|
50 |
|
---|
51 | Action::state_ptr WorldScaleBoxAction::performCall() {
|
---|
52 | Vector Scaler;
|
---|
53 | double x[NDIM];
|
---|
54 |
|
---|
55 | ValueStorage::getInstance().queryCurrentValue(NAME, Scaler);
|
---|
56 |
|
---|
57 | DoLog(1) && (Log() << Verbose(1) << "Scaling all atomic positions by factor." << endl);
|
---|
58 | for (int i=0;i<NDIM;i++)
|
---|
59 | x[i] = Scaler[i];
|
---|
60 | vector<atom*> AllAtoms = World::getInstance().getAllAtoms();
|
---|
61 | for(vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) {
|
---|
62 | (*AtomRunner)->ScaleAll(x);
|
---|
63 | }
|
---|
64 |
|
---|
65 | Matrix M = World::getInstance().getDomain().getM();
|
---|
66 | Matrix scale;
|
---|
67 |
|
---|
68 | for (int i=0;i<NDIM;i++) {
|
---|
69 | scale.at(i,i) = x[i];
|
---|
70 | }
|
---|
71 | M *= scale;
|
---|
72 | World::getInstance().setDomain(M);
|
---|
73 |
|
---|
74 | return Action::success;
|
---|
75 | }
|
---|
76 |
|
---|
77 | Action::state_ptr WorldScaleBoxAction::performUndo(Action::state_ptr _state) {
|
---|
78 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
79 |
|
---|
80 | return Action::failure;
|
---|
81 | // string newName = state->mol->getName();
|
---|
82 | // state->mol->setName(state->lastName);
|
---|
83 | //
|
---|
84 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
85 | }
|
---|
86 |
|
---|
87 | Action::state_ptr WorldScaleBoxAction::performRedo(Action::state_ptr _state){
|
---|
88 | return Action::failure;
|
---|
89 | }
|
---|
90 |
|
---|
91 | bool WorldScaleBoxAction::canUndo() {
|
---|
92 | return false;
|
---|
93 | }
|
---|
94 |
|
---|
95 | bool WorldScaleBoxAction::shouldUndo() {
|
---|
96 | return false;
|
---|
97 | }
|
---|
98 |
|
---|
99 | const string WorldScaleBoxAction::getName() {
|
---|
100 | return NAME;
|
---|
101 | }
|
---|