| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010-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 | * OutputAction.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 "CodePatterns/MemDebug.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | #include "Parser/FormatParserStorage.hpp" | 
|---|
| 23 | #include "CodePatterns/Log.hpp" | 
|---|
| 24 | #include "CodePatterns/Verbose.hpp" | 
|---|
| 25 | #include "World.hpp" | 
|---|
| 26 |  | 
|---|
| 27 | #include <iostream> | 
|---|
| 28 | #include <string> | 
|---|
| 29 |  | 
|---|
| 30 | #include <boost/filesystem/fstream.hpp> | 
|---|
| 31 |  | 
|---|
| 32 | #include "Actions/WorldAction/OutputAction.hpp" | 
|---|
| 33 |  | 
|---|
| 34 | using namespace MoleCuilder; | 
|---|
| 35 |  | 
|---|
| 36 | // and construct the stuff | 
|---|
| 37 | #include "OutputAction.def" | 
|---|
| 38 | #include "Action_impl_pre.hpp" | 
|---|
| 39 | /** =========== define the function ====================== */ | 
|---|
| 40 | Action::state_ptr WorldOutputAction::performCall() { | 
|---|
| 41 | // obtain information | 
|---|
| 42 | getParametersfromValueStorage(); | 
|---|
| 43 |  | 
|---|
| 44 | LOG(1, "Storing world to file " << params.filename << "."); | 
|---|
| 45 |  | 
|---|
| 46 | // extract suffix | 
|---|
| 47 | std::string FilenameSuffix; | 
|---|
| 48 | std::string FilenamePrefix; | 
|---|
| 49 | if (params.filename.has_filename()) { | 
|---|
| 50 | // get suffix | 
|---|
| 51 | #if BOOST_VERSION >= 104600 | 
|---|
| 52 | FilenameSuffix = params.filename.extension().string().substr(1); // remove the prefixed "." | 
|---|
| 53 | FilenamePrefix = params.filename.stem().string(); | 
|---|
| 54 | #else | 
|---|
| 55 | FilenameSuffix = params.filename.extension().substr(1); // remove the prefixed "." | 
|---|
| 56 | FilenamePrefix = params.filename.stem(); | 
|---|
| 57 | #endif | 
|---|
| 58 | } else { | 
|---|
| 59 | ELOG(1, "Output file does not have a suffix, cannot recognize format."); | 
|---|
| 60 | return Action::failure; | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | // store file | 
|---|
| 64 | // parse the file | 
|---|
| 65 | boost::filesystem::ofstream output; | 
|---|
| 66 | output.open(params.filename); | 
|---|
| 67 | if (!output.fail()) { | 
|---|
| 68 | FormatParserStorage::getInstance().saveWorld(output, FilenameSuffix); | 
|---|
| 69 | } else { | 
|---|
| 70 | ELOG(1, "Could not open file " << params.filename << "."); | 
|---|
| 71 | } | 
|---|
| 72 | output.close(); | 
|---|
| 73 |  | 
|---|
| 74 | return Action::success; | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | Action::state_ptr WorldOutputAction::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 WorldOutputAction::performRedo(Action::state_ptr _state){ | 
|---|
| 88 | return Action::failure; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | bool WorldOutputAction::canUndo() { | 
|---|
| 92 | return false; | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 | bool WorldOutputAction::shouldUndo() { | 
|---|
| 96 | return false; | 
|---|
| 97 | } | 
|---|
| 98 | /** =========== end of function ====================== */ | 
|---|