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 | * SaveXyzAction.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 "Actions/ParserAction/SaveXyzAction.hpp"
|
---|
23 | #include "Actions/ActionRegistry.hpp"
|
---|
24 | #include "Parser/XyzParser.hpp"
|
---|
25 | #include "atom.hpp"
|
---|
26 | #include "molecule.hpp"
|
---|
27 |
|
---|
28 | #include <iostream>
|
---|
29 | #include <string>
|
---|
30 |
|
---|
31 | using namespace std;
|
---|
32 |
|
---|
33 | #include "UIElements/UIFactory.hpp"
|
---|
34 | #include "UIElements/Dialog.hpp"
|
---|
35 | #include "Actions/ValueStorage.hpp"
|
---|
36 |
|
---|
37 |
|
---|
38 | /****** ParserSaveXyzAction *****/
|
---|
39 |
|
---|
40 | //// memento to remember the state when undoing
|
---|
41 | //
|
---|
42 | //class ParserSaveXyzState : public ActionState {
|
---|
43 | //public:
|
---|
44 | // ParserSaveXyzState(molecule* _mol,std::string _lastName) :
|
---|
45 | // mol(_mol),
|
---|
46 | // lastName(_lastName)
|
---|
47 | // {}
|
---|
48 | // molecule* mol;
|
---|
49 | // std::string lastName;
|
---|
50 | //};
|
---|
51 |
|
---|
52 | const char ParserSaveXyzAction::NAME[] = "SaveXyz";
|
---|
53 |
|
---|
54 | ParserSaveXyzAction::ParserSaveXyzAction() :
|
---|
55 | Action(NAME)
|
---|
56 | {}
|
---|
57 |
|
---|
58 | ParserSaveXyzAction::~ParserSaveXyzAction()
|
---|
59 | {}
|
---|
60 |
|
---|
61 | void ParserSaveXyz(std::string &filename) {
|
---|
62 | ValueStorage::getInstance().setCurrentValue(ParserSaveXyzAction::NAME, filename);
|
---|
63 | ActionRegistry::getInstance().getActionByName(ParserSaveXyzAction::NAME)->call(Action::NonInteractive);
|
---|
64 | };
|
---|
65 |
|
---|
66 | void ParserSaveXyzAction::getParametersfromValueStorage()
|
---|
67 | {};
|
---|
68 |
|
---|
69 | Dialog* ParserSaveXyzAction::fillDialog(Dialog *dialog) {
|
---|
70 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
71 |
|
---|
72 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
73 |
|
---|
74 | return dialog;
|
---|
75 | }
|
---|
76 |
|
---|
77 | Action::state_ptr ParserSaveXyzAction::performCall() {
|
---|
78 | string filename;
|
---|
79 | XyzParser parser;
|
---|
80 |
|
---|
81 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
82 |
|
---|
83 | // store xyz file
|
---|
84 | ofstream output;
|
---|
85 | output.open(filename.c_str());
|
---|
86 | if (!output.fail())
|
---|
87 | parser.save(&output);
|
---|
88 | output.close();
|
---|
89 | return Action::failure;
|
---|
90 | }
|
---|
91 |
|
---|
92 | Action::state_ptr ParserSaveXyzAction::performUndo(Action::state_ptr _state) {
|
---|
93 | // ParserSaveXyzState *state = assert_cast<ParserSaveXyzState*>(_state.get());
|
---|
94 |
|
---|
95 | return Action::failure;
|
---|
96 | // string newName = state->mol->getName();
|
---|
97 | // state->mol->setName(state->lastName);
|
---|
98 | //
|
---|
99 | // return Action::state_ptr(new ParserSaveXyzState(state->mol,newName));
|
---|
100 | }
|
---|
101 |
|
---|
102 | Action::state_ptr ParserSaveXyzAction::performRedo(Action::state_ptr _state){
|
---|
103 | return Action::failure;
|
---|
104 | // // Undo and redo have to do the same for this action
|
---|
105 | // return performUndo(_state);
|
---|
106 | }
|
---|
107 |
|
---|
108 | bool ParserSaveXyzAction::canUndo() {
|
---|
109 | return false;
|
---|
110 | }
|
---|
111 |
|
---|
112 | bool ParserSaveXyzAction::shouldUndo() {
|
---|
113 | return false;
|
---|
114 | }
|
---|
115 |
|
---|
116 | const string ParserSaveXyzAction::getName() {
|
---|
117 | return NAME;
|
---|
118 | }
|
---|