| 1 | /*
|
|---|
| 2 | * SaveXyzAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 8, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| 10 | #include "Actions/ParserAction/SaveXyzAction.hpp"
|
|---|
| 11 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 12 | #include "Parser/XyzParser.hpp"
|
|---|
| 13 | #include "atom.hpp"
|
|---|
| 14 | #include "molecule.hpp"
|
|---|
| 15 |
|
|---|
| 16 | #include <iostream>
|
|---|
| 17 | #include <string>
|
|---|
| 18 |
|
|---|
| 19 | using namespace std;
|
|---|
| 20 |
|
|---|
| 21 | #include "UIElements/UIFactory.hpp"
|
|---|
| 22 | #include "UIElements/Dialog.hpp"
|
|---|
| 23 | #include "Actions/ValueStorage.hpp"
|
|---|
| 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 |
|
|---|
| 40 | const char ParserSaveXyzAction::NAME[] = "SaveXyz";
|
|---|
| 41 |
|
|---|
| 42 | ParserSaveXyzAction::ParserSaveXyzAction() :
|
|---|
| 43 | Action(NAME)
|
|---|
| 44 | {}
|
|---|
| 45 |
|
|---|
| 46 | ParserSaveXyzAction::~ParserSaveXyzAction()
|
|---|
| 47 | {}
|
|---|
| 48 |
|
|---|
| 49 | void ParserSaveXyz(std::string &filename) {
|
|---|
| 50 | ValueStorage::getInstance().setCurrentValue(ParserSaveXyzAction::NAME, filename);
|
|---|
| 51 | ActionRegistry::getInstance().getActionByName(ParserSaveXyzAction::NAME)->call(Action::NonInteractive);
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | Dialog* ParserSaveXyzAction::fillDialog(Dialog *dialog) {
|
|---|
| 55 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| 56 |
|
|---|
| 57 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 58 |
|
|---|
| 59 | return dialog;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | Action::state_ptr ParserSaveXyzAction::performCall() {
|
|---|
| 63 | string filename;
|
|---|
| 64 | XyzParser parser;
|
|---|
| 65 |
|
|---|
| 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();
|
|---|
| 74 | return Action::failure;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | Action::state_ptr ParserSaveXyzAction::performUndo(Action::state_ptr _state) {
|
|---|
| 78 | // ParserSaveXyzState *state = assert_cast<ParserSaveXyzState*>(_state.get());
|
|---|
| 79 |
|
|---|
| 80 | return Action::failure;
|
|---|
| 81 | // string newName = state->mol->getName();
|
|---|
| 82 | // state->mol->setName(state->lastName);
|
|---|
| 83 | //
|
|---|
| 84 | // return Action::state_ptr(new ParserSaveXyzState(state->mol,newName));
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | Action::state_ptr ParserSaveXyzAction::performRedo(Action::state_ptr _state){
|
|---|
| 88 | return Action::failure;
|
|---|
| 89 | // // Undo and redo have to do the same for this action
|
|---|
| 90 | // return performUndo(_state);
|
|---|
| 91 | }
|
|---|
| 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 | }
|
|---|