| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2012 University of Bonn. All rights reserved.
 | 
|---|
| 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | /*
 | 
|---|
| 9 |  * SetBoundaryConditionsAction.cpp
 | 
|---|
| 10 |  *
 | 
|---|
| 11 |  *  Created on: Jan 2, 2012
 | 
|---|
| 12 |  *      Author: heber
 | 
|---|
| 13 |  */
 | 
|---|
| 14 | 
 | 
|---|
| 15 | // include config.h
 | 
|---|
| 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 17 | #include <config.h>
 | 
|---|
| 18 | #endif
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include <sstream>
 | 
|---|
| 23 | #include <vector>
 | 
|---|
| 24 | 
 | 
|---|
| 25 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 26 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| 27 | #include "Box.hpp"
 | 
|---|
| 28 | #include "World.hpp"
 | 
|---|
| 29 | 
 | 
|---|
| 30 | #include <iostream>
 | 
|---|
| 31 | #include <string>
 | 
|---|
| 32 | 
 | 
|---|
| 33 | #include "Actions/WorldAction/SetBoundaryConditionsAction.hpp"
 | 
|---|
| 34 | 
 | 
|---|
| 35 | using namespace MoleCuilder;
 | 
|---|
| 36 | 
 | 
|---|
| 37 | // and construct the stuff
 | 
|---|
| 38 | #include "SetBoundaryConditionsAction.def"
 | 
|---|
| 39 | #include "Action_impl_pre.hpp"
 | 
|---|
| 40 | /** =========== define the function ====================== */
 | 
|---|
| 41 | Action::state_ptr WorldSetBoundaryConditionsAction::performCall() {
 | 
|---|
| 42 |   // obtain information
 | 
|---|
| 43 |   getParametersfromValueStorage();
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   // gather undo information
 | 
|---|
| 46 |   std::stringstream undostream;
 | 
|---|
| 47 |   undostream << World::getInstance().getDomain().getConditionNames();
 | 
|---|
| 48 | 
 | 
|---|
| 49 |   // create undo state
 | 
|---|
| 50 |   WorldSetBoundaryConditionsState *UndoState =
 | 
|---|
| 51 |       new WorldSetBoundaryConditionsState(
 | 
|---|
| 52 |           undostream.str(),
 | 
|---|
| 53 |           params
 | 
|---|
| 54 |           );
 | 
|---|
| 55 | 
 | 
|---|
| 56 |   // set conditions
 | 
|---|
| 57 |   World::getInstance().getDomain().setConditions(params.newconditions);
 | 
|---|
| 58 | 
 | 
|---|
| 59 |   LOG(0, "STATUS: Boundary conditions are now " << World::getInstance().getDomain().getConditionNames() << ".");
 | 
|---|
| 60 |   return Action::state_ptr(UndoState);
 | 
|---|
| 61 | }
 | 
|---|
| 62 | 
 | 
|---|
| 63 | Action::state_ptr WorldSetBoundaryConditionsAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 64 |   WorldSetBoundaryConditionsState *state = assert_cast<WorldSetBoundaryConditionsState*>(_state.get());
 | 
|---|
| 65 | 
 | 
|---|
| 66 |   // set old conditions
 | 
|---|
| 67 |   World::getInstance().getDomain().setConditions(state->undostate);
 | 
|---|
| 68 | 
 | 
|---|
| 69 |   LOG(0, "STATUS: Boundary conditions are set back to " << World::getInstance().getDomain().getConditionNames() << ".");
 | 
|---|
| 70 |   return Action::state_ptr(_state);
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | Action::state_ptr WorldSetBoundaryConditionsAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 74 |   WorldSetBoundaryConditionsState *state = assert_cast<WorldSetBoundaryConditionsState*>(_state.get());
 | 
|---|
| 75 | 
 | 
|---|
| 76 |   // set again conditions
 | 
|---|
| 77 |   World::getInstance().getDomain().setConditions(state->params.newconditions);
 | 
|---|
| 78 | 
 | 
|---|
| 79 |   LOG(0, "STATUS: Boundary conditions are again " << World::getInstance().getDomain().getConditionNames() << ".");
 | 
|---|
| 80 |   return Action::state_ptr(_state);
 | 
|---|
| 81 | }
 | 
|---|
| 82 | 
 | 
|---|
| 83 | bool WorldSetBoundaryConditionsAction::canUndo() {
 | 
|---|
| 84 |   return true;
 | 
|---|
| 85 | }
 | 
|---|
| 86 | 
 | 
|---|
| 87 | bool WorldSetBoundaryConditionsAction::shouldUndo() {
 | 
|---|
| 88 |   return true;
 | 
|---|
| 89 | }
 | 
|---|
| 90 | /** =========== end of function ====================== */
 | 
|---|