| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | /* | 
|---|
| 9 | * ScaleBoxAction.cpp | 
|---|
| 10 | * | 
|---|
| 11 | *  Created on: May 8, 2010 | 
|---|
| 12 | *      Author: heber | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | // include config.h | 
|---|
| 16 | #ifdef HAVE_CONFIG_H | 
|---|
| 17 | #include <config.h> | 
|---|
| 18 | #endif | 
|---|
| 19 |  | 
|---|
| 20 | #include "Helpers/MemDebug.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | #include "atom.hpp" | 
|---|
| 23 | #include "Helpers/Log.hpp" | 
|---|
| 24 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| 25 | #include "Helpers/Verbose.hpp" | 
|---|
| 26 | #include "World.hpp" | 
|---|
| 27 | #include "Box.hpp" | 
|---|
| 28 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
| 29 |  | 
|---|
| 30 | #include <iostream> | 
|---|
| 31 | #include <string> | 
|---|
| 32 |  | 
|---|
| 33 | using namespace std; | 
|---|
| 34 |  | 
|---|
| 35 | #include "Actions/WorldAction/ScaleBoxAction.hpp" | 
|---|
| 36 |  | 
|---|
| 37 | // and construct the stuff | 
|---|
| 38 | #include "ScaleBoxAction.def" | 
|---|
| 39 | #include "Action_impl_pre.hpp" | 
|---|
| 40 | /** =========== define the function ====================== */ | 
|---|
| 41 | Action::state_ptr WorldScaleBoxAction::performCall() { | 
|---|
| 42 | double x[NDIM]; | 
|---|
| 43 |  | 
|---|
| 44 | // obtain information | 
|---|
| 45 | getParametersfromValueStorage(); | 
|---|
| 46 |  | 
|---|
| 47 | DoLog(1) && (Log() << Verbose(1) << "Scaling all atomic positions by factor." << endl); | 
|---|
| 48 | for (int i=0;i<NDIM;i++) | 
|---|
| 49 | x[i] = params.Scaler[i]; | 
|---|
| 50 | vector<atom*> AllAtoms = World::getInstance().getAllAtoms(); | 
|---|
| 51 | for(vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) { | 
|---|
| 52 | (*AtomRunner)->ScaleAll(x); | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | RealSpaceMatrix M = World::getInstance().getDomain().getM(); | 
|---|
| 56 | RealSpaceMatrix scale; | 
|---|
| 57 |  | 
|---|
| 58 | for (int i=0;i<NDIM;i++) { | 
|---|
| 59 | scale.at(i,i) = x[i]; | 
|---|
| 60 | } | 
|---|
| 61 | M *= scale; | 
|---|
| 62 | World::getInstance().setDomain(M); | 
|---|
| 63 |  | 
|---|
| 64 | return Action::success; | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | Action::state_ptr WorldScaleBoxAction::performUndo(Action::state_ptr _state) { | 
|---|
| 68 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get()); | 
|---|
| 69 |  | 
|---|
| 70 | return Action::failure; | 
|---|
| 71 | //  string newName = state->mol->getName(); | 
|---|
| 72 | //  state->mol->setName(state->lastName); | 
|---|
| 73 | // | 
|---|
| 74 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | Action::state_ptr WorldScaleBoxAction::performRedo(Action::state_ptr _state){ | 
|---|
| 78 | return Action::failure; | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | bool WorldScaleBoxAction::canUndo() { | 
|---|
| 82 | return false; | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | bool WorldScaleBoxAction::shouldUndo() { | 
|---|
| 86 | return false; | 
|---|
| 87 | } | 
|---|
| 88 | /** =========== end of function ====================== */ | 
|---|