[97ebf8] | 1 | /*
|
---|
| 2 | * ScaleBoxAction.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/ScaleBoxAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[97ebf8] | 12 | #include "atom.hpp"
|
---|
| 13 | #include "log.hpp"
|
---|
| 14 | #include "vector.hpp"
|
---|
| 15 | #include "verbose.hpp"
|
---|
| 16 | #include "World.hpp"
|
---|
[84c494] | 17 | #include "Box.hpp"
|
---|
[3dcb1f] | 18 | #include "Matrix.hpp"
|
---|
[97ebf8] | 19 |
|
---|
| 20 | #include <iostream>
|
---|
| 21 | #include <string>
|
---|
| 22 |
|
---|
| 23 | using namespace std;
|
---|
| 24 |
|
---|
| 25 | #include "UIElements/UIFactory.hpp"
|
---|
| 26 | #include "UIElements/Dialog.hpp"
|
---|
[22e780] | 27 | #include "UIElements/ValueStorage.hpp"
|
---|
[97ebf8] | 28 |
|
---|
| 29 | const char WorldScaleBoxAction::NAME[] = "scale-box";
|
---|
| 30 |
|
---|
| 31 | WorldScaleBoxAction::WorldScaleBoxAction() :
|
---|
| 32 | Action(NAME)
|
---|
| 33 | {}
|
---|
| 34 |
|
---|
| 35 | WorldScaleBoxAction::~WorldScaleBoxAction()
|
---|
| 36 | {}
|
---|
| 37 |
|
---|
[a8f6ae] | 38 | void WorldScaleBox(Vector &Scaler) {
|
---|
| 39 | ValueStorage::getInstance().setCurrentValue(WorldScaleBoxAction::NAME, Scaler);
|
---|
| 40 | ActionRegistry::getInstance().getActionByName(WorldScaleBoxAction::NAME)->call(Action::NonInteractive);
|
---|
| 41 | };
|
---|
| 42 |
|
---|
[047878] | 43 | Dialog* WorldScaleBoxAction::fillDialog(Dialog *dialog) {
|
---|
| 44 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[22e780] | 45 |
|
---|
| 46 | dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 47 |
|
---|
| 48 | return dialog;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | Action::state_ptr WorldScaleBoxAction::performCall() {
|
---|
[97ebf8] | 52 | Vector Scaler;
|
---|
| 53 | double x[NDIM];
|
---|
| 54 |
|
---|
[22e780] | 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)->x.ScaleAll(x);
|
---|
[97ebf8] | 63 | }
|
---|
[22e780] | 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;
|
---|
[97ebf8] | 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 | }
|
---|