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