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