[bcf653] | 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 |
|
---|
[03bb99] | 8 | /*
|
---|
| 9 | * SaveXyzAction.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: May 8, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[112b09] | 20 | #include "Helpers/MemDebug.hpp"
|
---|
| 21 |
|
---|
[03bb99] | 22 | #include "Actions/ParserAction/SaveXyzAction.hpp"
|
---|
[0430e3] | 23 | #include "Actions/ActionRegistry.hpp"
|
---|
[03bb99] | 24 | #include "Parser/XyzParser.hpp"
|
---|
[215b89] | 25 | #include "atom.hpp"
|
---|
| 26 | #include "molecule.hpp"
|
---|
[03bb99] | 27 |
|
---|
| 28 | #include <iostream>
|
---|
| 29 | #include <string>
|
---|
| 30 |
|
---|
| 31 | using namespace std;
|
---|
| 32 |
|
---|
| 33 | #include "UIElements/UIFactory.hpp"
|
---|
| 34 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 35 | #include "Actions/ValueStorage.hpp"
|
---|
[03bb99] | 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 |
|
---|
[ecb799] | 52 | const char ParserSaveXyzAction::NAME[] = "SaveXyz";
|
---|
[03bb99] | 53 |
|
---|
| 54 | ParserSaveXyzAction::ParserSaveXyzAction() :
|
---|
| 55 | Action(NAME)
|
---|
| 56 | {}
|
---|
| 57 |
|
---|
| 58 | ParserSaveXyzAction::~ParserSaveXyzAction()
|
---|
| 59 | {}
|
---|
| 60 |
|
---|
[215b89] | 61 | void ParserSaveXyz(std::string &filename) {
|
---|
| 62 | ValueStorage::getInstance().setCurrentValue(ParserSaveXyzAction::NAME, filename);
|
---|
| 63 | ActionRegistry::getInstance().getActionByName(ParserSaveXyzAction::NAME)->call(Action::NonInteractive);
|
---|
| 64 | };
|
---|
| 65 |
|
---|
[0b2ce9] | 66 | void ParserSaveXyzAction::getParametersfromValueStorage()
|
---|
| 67 | {};
|
---|
| 68 |
|
---|
[047878] | 69 | Dialog* ParserSaveXyzAction::fillDialog(Dialog *dialog) {
|
---|
| 70 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[ce8755] | 71 |
|
---|
| 72 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 73 |
|
---|
| 74 | return dialog;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[03bb99] | 77 | Action::state_ptr ParserSaveXyzAction::performCall() {
|
---|
| 78 | string filename;
|
---|
| 79 | XyzParser parser;
|
---|
| 80 |
|
---|
[ce8755] | 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();
|
---|
[03bb99] | 89 | return Action::failure;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[808fd3] | 92 | Action::state_ptr ParserSaveXyzAction::performUndo(Action::state_ptr _state) {
|
---|
[03bb99] | 93 | // ParserSaveXyzState *state = assert_cast<ParserSaveXyzState*>(_state.get());
|
---|
[808fd3] | 94 |
|
---|
| 95 | return Action::failure;
|
---|
[03bb99] | 96 | // string newName = state->mol->getName();
|
---|
| 97 | // state->mol->setName(state->lastName);
|
---|
| 98 | //
|
---|
| 99 | // return Action::state_ptr(new ParserSaveXyzState(state->mol,newName));
|
---|
[808fd3] | 100 | }
|
---|
| 101 |
|
---|
| 102 | Action::state_ptr ParserSaveXyzAction::performRedo(Action::state_ptr _state){
|
---|
| 103 | return Action::failure;
|
---|
[03bb99] | 104 | // // Undo and redo have to do the same for this action
|
---|
| 105 | // return performUndo(_state);
|
---|
[808fd3] | 106 | }
|
---|
[03bb99] | 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 | }
|
---|