[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"
|
---|
| 11 | #include "atom.hpp"
|
---|
| 12 | #include "log.hpp"
|
---|
| 13 | #include "vector.hpp"
|
---|
| 14 | #include "verbose.hpp"
|
---|
| 15 | #include "World.hpp"
|
---|
[84c494] | 16 | #include "Box.hpp"
|
---|
[3dcb1f] | 17 | #include "Matrix.hpp"
|
---|
[97ebf8] | 18 |
|
---|
| 19 | #include <iostream>
|
---|
| 20 | #include <string>
|
---|
| 21 |
|
---|
| 22 | using namespace std;
|
---|
| 23 |
|
---|
| 24 | #include "UIElements/UIFactory.hpp"
|
---|
| 25 | #include "UIElements/Dialog.hpp"
|
---|
[22e780] | 26 | #include "UIElements/ValueStorage.hpp"
|
---|
[97ebf8] | 27 |
|
---|
| 28 | const char WorldScaleBoxAction::NAME[] = "scale-box";
|
---|
| 29 |
|
---|
| 30 | WorldScaleBoxAction::WorldScaleBoxAction() :
|
---|
| 31 | Action(NAME)
|
---|
| 32 | {}
|
---|
| 33 |
|
---|
| 34 | WorldScaleBoxAction::~WorldScaleBoxAction()
|
---|
| 35 | {}
|
---|
| 36 |
|
---|
[22e780] | 37 | Dialog* WorldScaleBoxAction::createDialog() {
|
---|
[97ebf8] | 38 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
[22e780] | 39 |
|
---|
| 40 | dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 41 |
|
---|
| 42 | return dialog;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | Action::state_ptr WorldScaleBoxAction::performCall() {
|
---|
[97ebf8] | 46 | Vector Scaler;
|
---|
| 47 | double x[NDIM];
|
---|
| 48 |
|
---|
[22e780] | 49 | ValueStorage::getInstance().queryCurrentValue(NAME, Scaler);
|
---|
| 50 |
|
---|
| 51 | DoLog(1) && (Log() << Verbose(1) << "Scaling all atomic positions by factor." << endl);
|
---|
| 52 | for (int i=0;i<NDIM;i++)
|
---|
| 53 | x[i] = Scaler[i];
|
---|
| 54 | vector<atom*> AllAtoms = World::getInstance().getAllAtoms();
|
---|
| 55 | for(vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) {
|
---|
| 56 | (*AtomRunner)->x.ScaleAll(x);
|
---|
[97ebf8] | 57 | }
|
---|
[22e780] | 58 |
|
---|
| 59 | Matrix M = World::getInstance().getDomain().getM();
|
---|
| 60 | Matrix scale;
|
---|
| 61 |
|
---|
| 62 | for (int i=0;i<NDIM;i++) {
|
---|
| 63 | scale.at(i,i) = x[i];
|
---|
| 64 | }
|
---|
| 65 | M *= scale;
|
---|
| 66 | World::getInstance().setDomain(M);
|
---|
| 67 |
|
---|
| 68 | return Action::success;
|
---|
[97ebf8] | 69 | }
|
---|
| 70 |
|
---|
| 71 | Action::state_ptr WorldScaleBoxAction::performUndo(Action::state_ptr _state) {
|
---|
| 72 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 73 |
|
---|
| 74 | return Action::failure;
|
---|
| 75 | // string newName = state->mol->getName();
|
---|
| 76 | // state->mol->setName(state->lastName);
|
---|
| 77 | //
|
---|
| 78 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | Action::state_ptr WorldScaleBoxAction::performRedo(Action::state_ptr _state){
|
---|
| 82 | return Action::failure;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | bool WorldScaleBoxAction::canUndo() {
|
---|
| 86 | return false;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | bool WorldScaleBoxAction::shouldUndo() {
|
---|
| 90 | return false;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | const string WorldScaleBoxAction::getName() {
|
---|
| 94 | return NAME;
|
---|
| 95 | }
|
---|