| [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 |  | 
|---|
| [047878] | 66 | Dialog* ParserSaveXyzAction::fillDialog(Dialog *dialog) { | 
|---|
|  | 67 | ASSERT(dialog,"No Dialog given when filling action dialog"); | 
|---|
| [ce8755] | 68 |  | 
|---|
|  | 69 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME)); | 
|---|
|  | 70 |  | 
|---|
|  | 71 | return dialog; | 
|---|
|  | 72 | } | 
|---|
|  | 73 |  | 
|---|
| [03bb99] | 74 | Action::state_ptr ParserSaveXyzAction::performCall() { | 
|---|
|  | 75 | string filename; | 
|---|
|  | 76 | XyzParser parser; | 
|---|
|  | 77 |  | 
|---|
| [ce8755] | 78 | ValueStorage::getInstance().queryCurrentValue(NAME, filename); | 
|---|
|  | 79 |  | 
|---|
|  | 80 | // store xyz file | 
|---|
|  | 81 | ofstream output; | 
|---|
|  | 82 | output.open(filename.c_str()); | 
|---|
|  | 83 | if (!output.fail()) | 
|---|
|  | 84 | parser.save(&output); | 
|---|
|  | 85 | output.close(); | 
|---|
| [03bb99] | 86 | return Action::failure; | 
|---|
|  | 87 | } | 
|---|
|  | 88 |  | 
|---|
| [808fd3] | 89 | Action::state_ptr ParserSaveXyzAction::performUndo(Action::state_ptr _state) { | 
|---|
| [03bb99] | 90 | //  ParserSaveXyzState *state = assert_cast<ParserSaveXyzState*>(_state.get()); | 
|---|
| [808fd3] | 91 |  | 
|---|
|  | 92 | return Action::failure; | 
|---|
| [03bb99] | 93 | //  string newName = state->mol->getName(); | 
|---|
|  | 94 | //  state->mol->setName(state->lastName); | 
|---|
|  | 95 | // | 
|---|
|  | 96 | //  return Action::state_ptr(new ParserSaveXyzState(state->mol,newName)); | 
|---|
| [808fd3] | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 | Action::state_ptr ParserSaveXyzAction::performRedo(Action::state_ptr _state){ | 
|---|
|  | 100 | return Action::failure; | 
|---|
| [03bb99] | 101 | //  // Undo and redo have to do the same for this action | 
|---|
|  | 102 | //  return performUndo(_state); | 
|---|
| [808fd3] | 103 | } | 
|---|
| [03bb99] | 104 |  | 
|---|
|  | 105 | bool ParserSaveXyzAction::canUndo() { | 
|---|
|  | 106 | return false; | 
|---|
|  | 107 | } | 
|---|
|  | 108 |  | 
|---|
|  | 109 | bool ParserSaveXyzAction::shouldUndo() { | 
|---|
|  | 110 | return false; | 
|---|
|  | 111 | } | 
|---|
|  | 112 |  | 
|---|
|  | 113 | const string ParserSaveXyzAction::getName() { | 
|---|
|  | 114 | return NAME; | 
|---|
|  | 115 | } | 
|---|