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 | * SaveAction.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 "Helpers/Log.hpp"
|
---|
23 | #include "Helpers/Verbose.hpp"
|
---|
24 | #include "Parser/FormatParserStorage.hpp"
|
---|
25 |
|
---|
26 | #include <iostream>
|
---|
27 | #include <string>
|
---|
28 |
|
---|
29 | #include <boost/filesystem/fstream.hpp>
|
---|
30 |
|
---|
31 | using namespace std;
|
---|
32 |
|
---|
33 | #include "SaveAction.hpp"
|
---|
34 |
|
---|
35 | // and construct the stuff
|
---|
36 | #include "SaveAction.def"
|
---|
37 | #include "Action_impl_pre.hpp"
|
---|
38 | /** =========== define the function ====================== */
|
---|
39 | Action::state_ptr MoleculeSaveAction::performCall() {
|
---|
40 | // obtain information
|
---|
41 | getParametersfromValueStorage();
|
---|
42 |
|
---|
43 | DoLog(1) && (Log() << Verbose(1) << "Storing world to file " << params.filename << "." << endl);
|
---|
44 |
|
---|
45 | // extract suffix
|
---|
46 | std::string FilenameSuffix;
|
---|
47 | std::string FilenamePrefix;
|
---|
48 | if (params.filename.has_filename()) {
|
---|
49 | // get suffix
|
---|
50 | FilenameSuffix = params.filename.extension().substr(1); // remove the prefixed "."
|
---|
51 | FilenamePrefix = params.filename.stem();
|
---|
52 | } else {
|
---|
53 | DoeLog(1) && (eLog() << Verbose(1) << "Output file does not have a suffix, cannot recognize format." << endl);
|
---|
54 | return Action::failure;
|
---|
55 | }
|
---|
56 |
|
---|
57 | // store file
|
---|
58 | // parse the file
|
---|
59 | boost::filesystem::ofstream output;
|
---|
60 | output.open(params.filename);
|
---|
61 | if (!output.fail()) {
|
---|
62 | FormatParserStorage::getInstance().saveSelectedMolecules(output, FilenameSuffix);
|
---|
63 | } else {
|
---|
64 | DoeLog(1) && (eLog() << Verbose(1) << "Could not open file " << params.filename << "." << endl);
|
---|
65 | }
|
---|
66 | output.close();
|
---|
67 |
|
---|
68 | return Action::success;
|
---|
69 | }
|
---|
70 |
|
---|
71 | Action::state_ptr MoleculeSaveAction::performUndo(Action::state_ptr _state) {
|
---|
72 | // ParserSaveXyzState *state = assert_cast<ParserSaveXyzState*>(_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 ParserSaveXyzState(state->mol,newName));
|
---|
79 | }
|
---|
80 |
|
---|
81 | Action::state_ptr MoleculeSaveAction::performRedo(Action::state_ptr _state){
|
---|
82 | return Action::failure;
|
---|
83 | // // Undo and redo have to do the same for this action
|
---|
84 | // return performUndo(_state);
|
---|
85 | }
|
---|
86 |
|
---|
87 | bool MoleculeSaveAction::canUndo() {
|
---|
88 | return false;
|
---|
89 | }
|
---|
90 |
|
---|
91 | bool MoleculeSaveAction::shouldUndo() {
|
---|
92 | return false;
|
---|
93 | }
|
---|
94 | /** =========== end of function ====================== */
|
---|