| [97ebf8] | 1 | /*
 | 
|---|
 | 2 |  * SaveAdjacencyAction.cpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: May 10, 2010
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
 | 
|---|
 | 9 | 
 | 
|---|
 | 10 | #include <iostream>
 | 
|---|
 | 11 | #include <fstream>
 | 
|---|
 | 12 | #include <string>
 | 
|---|
 | 13 | 
 | 
|---|
 | 14 | using namespace std;
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 17 | #include "UIElements/Dialog.hpp"
 | 
|---|
 | 18 | #include "Actions/MapOfActions.hpp"
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | #include "atom.hpp"
 | 
|---|
 | 21 | #include "bondgraph.hpp"
 | 
|---|
 | 22 | #include "config.hpp"
 | 
|---|
 | 23 | #include "defs.hpp"
 | 
|---|
 | 24 | #include "log.hpp"
 | 
|---|
 | 25 | #include "molecule.hpp"
 | 
|---|
 | 26 | #include "vector.hpp"
 | 
|---|
 | 27 | #include "verbose.hpp"
 | 
|---|
 | 28 | #include "World.hpp"
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | /****** MoleculeSaveAdjacencyAction *****/
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | // memento to remember the state when undoing
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 | //class MoleculeSaveAdjacencyState : public ActionState {
 | 
|---|
 | 35 | //public:
 | 
|---|
 | 36 | //  MoleculeSaveAdjacencyState(molecule* _mol,std::string _lastName) :
 | 
|---|
 | 37 | //    mol(_mol),
 | 
|---|
 | 38 | //    lastName(_lastName)
 | 
|---|
 | 39 | //  {}
 | 
|---|
 | 40 | //  molecule* mol;
 | 
|---|
 | 41 | //  std::string lastName;
 | 
|---|
 | 42 | //};
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 | const char MoleculeSaveAdjacencyAction::NAME[] = "save-adjacency";
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | MoleculeSaveAdjacencyAction::MoleculeSaveAdjacencyAction() :
 | 
|---|
 | 47 |   Action(NAME)
 | 
|---|
 | 48 | {}
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | MoleculeSaveAdjacencyAction::~MoleculeSaveAdjacencyAction()
 | 
|---|
 | 51 | {}
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | Action::state_ptr MoleculeSaveAdjacencyAction::performCall() {
 | 
|---|
 | 54 |   string filename;
 | 
|---|
 | 55 |   Dialog *dialog = UIFactory::getInstance().makeDialog();
 | 
|---|
 | 56 |   molecule *mol = NULL;
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 |   dialog->queryString(NAME, &filename, MapOfActions::getInstance().getDescription(NAME));
 | 
|---|
 | 59 |   dialog->queryMolecule("molecule-by-id", &mol, MapOfActions::getInstance().getDescription("molecule-by-id"));
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 |   if(dialog->display()) {
 | 
|---|
 | 62 |     DoLog(0) && (Log() << Verbose(0) << "Storing adjacency to path " << filename << "." << endl);
 | 
|---|
 | 63 |     World::getInstance().getConfig()->BG->ConstructBondGraph(mol);
 | 
|---|
 | 64 |     // TODO: sollte stream nicht filename benutzen, besser fuer unit test
 | 
|---|
 | 65 |     char outputname[MAXSTRINGSIZE];
 | 
|---|
 | 66 |     strcpy(outputname, filename.c_str());
 | 
|---|
 | 67 |     mol->StoreAdjacencyToFile(NULL, outputname);
 | 
|---|
 | 68 |     delete dialog;
 | 
|---|
 | 69 |     return Action::success;
 | 
|---|
 | 70 |   }
 | 
|---|
 | 71 |   delete dialog;
 | 
|---|
 | 72 |   return Action::failure;
 | 
|---|
 | 73 | }
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | Action::state_ptr MoleculeSaveAdjacencyAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 76 | //  MoleculeSaveAdjacencyState *state = assert_cast<MoleculeSaveAdjacencyState*>(_state.get());
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | //  string newName = state->mol->getName();
 | 
|---|
 | 79 | //  state->mol->setName(state->lastName);
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 |   return Action::failure;
 | 
|---|
 | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | Action::state_ptr MoleculeSaveAdjacencyAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 85 |   // Undo and redo have to do the same for this action
 | 
|---|
 | 86 |   return performUndo(_state);
 | 
|---|
 | 87 | }
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 | bool MoleculeSaveAdjacencyAction::canUndo() {
 | 
|---|
 | 90 |   return false;
 | 
|---|
 | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | bool MoleculeSaveAdjacencyAction::shouldUndo() {
 | 
|---|
 | 94 |   return false;
 | 
|---|
 | 95 | }
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | const string MoleculeSaveAdjacencyAction::getName() {
 | 
|---|
 | 98 |   return NAME;
 | 
|---|
 | 99 | }
 | 
|---|