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 | * SetTremoloAtomdataAction.cpp
|
---|
10 | *
|
---|
11 | * Created on: Aug 9, 2011
|
---|
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/TremoloParser.hpp"
|
---|
23 | #include "Parser/FormatParserStorage.hpp"
|
---|
24 | #include "CodePatterns/Log.hpp"
|
---|
25 | #include "CodePatterns/Verbose.hpp"
|
---|
26 |
|
---|
27 | #include <iostream>
|
---|
28 | #include <string>
|
---|
29 |
|
---|
30 | #include <boost/filesystem/fstream.hpp>
|
---|
31 |
|
---|
32 | #include "SetTremoloAtomdataAction.hpp"
|
---|
33 |
|
---|
34 | using namespace MoleCuilder;
|
---|
35 |
|
---|
36 | // and construct the stuff
|
---|
37 | #include "SetTremoloAtomdataAction.def"
|
---|
38 | #include "Action_impl_pre.hpp"
|
---|
39 | /** =========== define the function ====================== */
|
---|
40 | Action::state_ptr ParserSetTremoloAtomdataAction::performCall() {
|
---|
41 | FormatParser<tremolo> &parser = FormatParserStorage::getInstance().getParser<tremolo>();
|
---|
42 |
|
---|
43 | LOG(1, "Setting Tremolo's ATOMDATA to: '" << params.atomdata_string.get() << "'");
|
---|
44 |
|
---|
45 | const std::string old_atomdata = parser.getAtomData();
|
---|
46 |
|
---|
47 | if (params.atomdata_reset.get())
|
---|
48 | parser.resetAtomData(params.atomdata_string.get());
|
---|
49 | else
|
---|
50 | parser.setAtomData(params.atomdata_string.get());
|
---|
51 |
|
---|
52 | return Action::state_ptr(new ParserSetTremoloAtomdataState(old_atomdata, params));
|
---|
53 | }
|
---|
54 |
|
---|
55 | Action::state_ptr ParserSetTremoloAtomdataAction::performUndo(Action::state_ptr _state) {
|
---|
56 | ParserSetTremoloAtomdataState *state = assert_cast<ParserSetTremoloAtomdataState*>(_state.get());
|
---|
57 |
|
---|
58 | FormatParser<tremolo> &parser = FormatParserStorage::getInstance().getParser<tremolo>();
|
---|
59 | LOG(1, "INFO: Reverting to 'ATOMDATA " << state->old_atomdata << "'.");
|
---|
60 | parser.resetAtomData(state->old_atomdata);
|
---|
61 |
|
---|
62 | return Action::state_ptr(_state);
|
---|
63 | }
|
---|
64 |
|
---|
65 | Action::state_ptr ParserSetTremoloAtomdataAction::performRedo(Action::state_ptr _state){
|
---|
66 | ParserSetTremoloAtomdataState *state = assert_cast<ParserSetTremoloAtomdataState*>(_state.get());
|
---|
67 |
|
---|
68 | FormatParser<tremolo> &parser = FormatParserStorage::getInstance().getParser<tremolo>();
|
---|
69 |
|
---|
70 | if (state->params.atomdata_reset.get())
|
---|
71 | parser.resetAtomData(state->params.atomdata_string.get());
|
---|
72 | else
|
---|
73 | parser.setAtomData(state->params.atomdata_string.get());
|
---|
74 |
|
---|
75 | return Action::state_ptr(_state);
|
---|
76 | }
|
---|
77 |
|
---|
78 | bool ParserSetTremoloAtomdataAction::canUndo() {
|
---|
79 | return true;
|
---|
80 | }
|
---|
81 |
|
---|
82 | bool ParserSetTremoloAtomdataAction::shouldUndo() {
|
---|
83 | return true;
|
---|
84 | }
|
---|
85 | /** =========== end of function ====================== */
|
---|