| [c52e08] | 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 | // gather undo information | 
|---|
|  | 43 | std::stringstream undostream; | 
|---|
|  | 44 | undostream << World::getInstance().getDomain().getConditionNames(); | 
|---|
|  | 45 |  | 
|---|
|  | 46 | // create undo state | 
|---|
|  | 47 | WorldSetBoundaryConditionsState *UndoState = | 
|---|
|  | 48 | new WorldSetBoundaryConditionsState( | 
|---|
|  | 49 | undostream.str(), | 
|---|
|  | 50 | params | 
|---|
|  | 51 | ); | 
|---|
|  | 52 |  | 
|---|
|  | 53 | // set conditions | 
|---|
|  | 54 | World::getInstance().getDomain().setConditions(params.newconditions); | 
|---|
|  | 55 |  | 
|---|
|  | 56 | LOG(0, "STATUS: Boundary conditions are now " << World::getInstance().getDomain().getConditionNames() << "."); | 
|---|
|  | 57 | return Action::state_ptr(UndoState); | 
|---|
|  | 58 | } | 
|---|
|  | 59 |  | 
|---|
|  | 60 | Action::state_ptr WorldSetBoundaryConditionsAction::performUndo(Action::state_ptr _state) { | 
|---|
|  | 61 | WorldSetBoundaryConditionsState *state = assert_cast<WorldSetBoundaryConditionsState*>(_state.get()); | 
|---|
|  | 62 |  | 
|---|
|  | 63 | // set old conditions | 
|---|
|  | 64 | World::getInstance().getDomain().setConditions(state->undostate); | 
|---|
|  | 65 |  | 
|---|
|  | 66 | LOG(0, "STATUS: Boundary conditions are set back to " << World::getInstance().getDomain().getConditionNames() << "."); | 
|---|
|  | 67 | return Action::state_ptr(_state); | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
|  | 70 | Action::state_ptr WorldSetBoundaryConditionsAction::performRedo(Action::state_ptr _state){ | 
|---|
|  | 71 | WorldSetBoundaryConditionsState *state = assert_cast<WorldSetBoundaryConditionsState*>(_state.get()); | 
|---|
|  | 72 |  | 
|---|
|  | 73 | // set again conditions | 
|---|
|  | 74 | World::getInstance().getDomain().setConditions(state->params.newconditions); | 
|---|
|  | 75 |  | 
|---|
|  | 76 | LOG(0, "STATUS: Boundary conditions are again " << World::getInstance().getDomain().getConditionNames() << "."); | 
|---|
|  | 77 | return Action::state_ptr(_state); | 
|---|
|  | 78 | } | 
|---|
|  | 79 |  | 
|---|
|  | 80 | bool WorldSetBoundaryConditionsAction::canUndo() { | 
|---|
|  | 81 | return true; | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 | bool WorldSetBoundaryConditionsAction::shouldUndo() { | 
|---|
|  | 85 | return true; | 
|---|
|  | 86 | } | 
|---|
|  | 87 | /** =========== end of function ====================== */ | 
|---|