[03bb99] | 1 | /*
|
---|
| 2 | * SaveXyzAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 8, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[bf3817] | 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[112b09] | 13 | #include "Helpers/MemDebug.hpp"
|
---|
| 14 |
|
---|
[03bb99] | 15 | #include "Actions/ParserAction/SaveXyzAction.hpp"
|
---|
[0430e3] | 16 | #include "Actions/ActionRegistry.hpp"
|
---|
[03bb99] | 17 | #include "Parser/XyzParser.hpp"
|
---|
[215b89] | 18 | #include "atom.hpp"
|
---|
| 19 | #include "molecule.hpp"
|
---|
[03bb99] | 20 |
|
---|
| 21 | #include <iostream>
|
---|
| 22 | #include <string>
|
---|
| 23 |
|
---|
| 24 | using namespace std;
|
---|
| 25 |
|
---|
| 26 | #include "UIElements/UIFactory.hpp"
|
---|
| 27 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 28 | #include "Actions/ValueStorage.hpp"
|
---|
[03bb99] | 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 |
|
---|
[ecb799] | 45 | const char ParserSaveXyzAction::NAME[] = "SaveXyz";
|
---|
[03bb99] | 46 |
|
---|
| 47 | ParserSaveXyzAction::ParserSaveXyzAction() :
|
---|
| 48 | Action(NAME)
|
---|
| 49 | {}
|
---|
| 50 |
|
---|
| 51 | ParserSaveXyzAction::~ParserSaveXyzAction()
|
---|
| 52 | {}
|
---|
| 53 |
|
---|
[215b89] | 54 | void ParserSaveXyz(std::string &filename) {
|
---|
| 55 | ValueStorage::getInstance().setCurrentValue(ParserSaveXyzAction::NAME, filename);
|
---|
| 56 | ActionRegistry::getInstance().getActionByName(ParserSaveXyzAction::NAME)->call(Action::NonInteractive);
|
---|
| 57 | };
|
---|
| 58 |
|
---|
[047878] | 59 | Dialog* ParserSaveXyzAction::fillDialog(Dialog *dialog) {
|
---|
| 60 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[ce8755] | 61 |
|
---|
| 62 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 63 |
|
---|
| 64 | return dialog;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[03bb99] | 67 | Action::state_ptr ParserSaveXyzAction::performCall() {
|
---|
| 68 | string filename;
|
---|
| 69 | XyzParser parser;
|
---|
| 70 |
|
---|
[ce8755] | 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();
|
---|
[03bb99] | 79 | return Action::failure;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[808fd3] | 82 | Action::state_ptr ParserSaveXyzAction::performUndo(Action::state_ptr _state) {
|
---|
[03bb99] | 83 | // ParserSaveXyzState *state = assert_cast<ParserSaveXyzState*>(_state.get());
|
---|
[808fd3] | 84 |
|
---|
| 85 | return Action::failure;
|
---|
[03bb99] | 86 | // string newName = state->mol->getName();
|
---|
| 87 | // state->mol->setName(state->lastName);
|
---|
| 88 | //
|
---|
| 89 | // return Action::state_ptr(new ParserSaveXyzState(state->mol,newName));
|
---|
[808fd3] | 90 | }
|
---|
| 91 |
|
---|
| 92 | Action::state_ptr ParserSaveXyzAction::performRedo(Action::state_ptr _state){
|
---|
| 93 | return Action::failure;
|
---|
[03bb99] | 94 | // // Undo and redo have to do the same for this action
|
---|
| 95 | // return performUndo(_state);
|
---|
[808fd3] | 96 | }
|
---|
[03bb99] | 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 | }
|
---|