[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 |
|
---|
[97ebf8] | 8 | /*
|
---|
| 9 | * SaveAdjacencyAction.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: May 10, 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 |
|
---|
[97ebf8] | 22 | #include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
|
---|
[0430e3] | 23 | #include "Actions/ActionRegistry.hpp"
|
---|
[1a3c26] | 24 | #include "bondgraph.hpp"
|
---|
| 25 | #include "config.hpp"
|
---|
[952f38] | 26 | #include "Helpers/Log.hpp"
|
---|
[1a3c26] | 27 | #include "molecule.hpp"
|
---|
[952f38] | 28 | #include "Helpers/Verbose.hpp"
|
---|
[1a3c26] | 29 | #include "World.hpp"
|
---|
| 30 |
|
---|
[97ebf8] | 31 |
|
---|
| 32 | #include <iostream>
|
---|
| 33 | #include <fstream>
|
---|
| 34 | #include <string>
|
---|
| 35 |
|
---|
| 36 | using namespace std;
|
---|
| 37 |
|
---|
| 38 | #include "UIElements/UIFactory.hpp"
|
---|
| 39 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 40 | #include "Actions/ValueStorage.hpp"
|
---|
[97ebf8] | 41 |
|
---|
| 42 | /****** MoleculeSaveAdjacencyAction *****/
|
---|
| 43 |
|
---|
| 44 | // memento to remember the state when undoing
|
---|
| 45 |
|
---|
| 46 | //class MoleculeSaveAdjacencyState : public ActionState {
|
---|
| 47 | //public:
|
---|
| 48 | // MoleculeSaveAdjacencyState(molecule* _mol,std::string _lastName) :
|
---|
| 49 | // mol(_mol),
|
---|
| 50 | // lastName(_lastName)
|
---|
| 51 | // {}
|
---|
| 52 | // molecule* mol;
|
---|
| 53 | // std::string lastName;
|
---|
| 54 | //};
|
---|
| 55 |
|
---|
| 56 | const char MoleculeSaveAdjacencyAction::NAME[] = "save-adjacency";
|
---|
| 57 |
|
---|
| 58 | MoleculeSaveAdjacencyAction::MoleculeSaveAdjacencyAction() :
|
---|
| 59 | Action(NAME)
|
---|
| 60 | {}
|
---|
| 61 |
|
---|
| 62 | MoleculeSaveAdjacencyAction::~MoleculeSaveAdjacencyAction()
|
---|
| 63 | {}
|
---|
| 64 |
|
---|
[1a3c26] | 65 | void MoleculeSaveAdjacency(std::string &adjacencyfile) {
|
---|
| 66 | ValueStorage::getInstance().setCurrentValue(MoleculeSaveAdjacencyAction::NAME, adjacencyfile);
|
---|
| 67 | ActionRegistry::getInstance().getActionByName(MoleculeSaveAdjacencyAction::NAME)->call(Action::NonInteractive);
|
---|
| 68 | };
|
---|
| 69 |
|
---|
[047878] | 70 | Dialog* MoleculeSaveAdjacencyAction::fillDialog(Dialog *dialog) {
|
---|
| 71 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[e58fad1] | 72 |
|
---|
| 73 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 74 |
|
---|
| 75 | return dialog;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[97ebf8] | 78 | Action::state_ptr MoleculeSaveAdjacencyAction::performCall() {
|
---|
| 79 | string filename;
|
---|
| 80 | molecule *mol = NULL;
|
---|
| 81 |
|
---|
[e58fad1] | 82 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
[97ebf8] | 83 |
|
---|
[e58fad1] | 84 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 85 | mol = iter->second;
|
---|
[97ebf8] | 86 | DoLog(0) && (Log() << Verbose(0) << "Storing adjacency to path " << filename << "." << endl);
|
---|
| 87 | World::getInstance().getConfig()->BG->ConstructBondGraph(mol);
|
---|
| 88 | // TODO: sollte stream nicht filename benutzen, besser fuer unit test
|
---|
[35b698] | 89 | mol->StoreAdjacencyToFile(filename);
|
---|
[97ebf8] | 90 | }
|
---|
[e58fad1] | 91 | return Action::success;
|
---|
[97ebf8] | 92 | }
|
---|
| 93 |
|
---|
| 94 | Action::state_ptr MoleculeSaveAdjacencyAction::performUndo(Action::state_ptr _state) {
|
---|
| 95 | // MoleculeSaveAdjacencyState *state = assert_cast<MoleculeSaveAdjacencyState*>(_state.get());
|
---|
| 96 |
|
---|
| 97 | // string newName = state->mol->getName();
|
---|
| 98 | // state->mol->setName(state->lastName);
|
---|
| 99 |
|
---|
| 100 | return Action::failure;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | Action::state_ptr MoleculeSaveAdjacencyAction::performRedo(Action::state_ptr _state){
|
---|
| 104 | // Undo and redo have to do the same for this action
|
---|
| 105 | return performUndo(_state);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | bool MoleculeSaveAdjacencyAction::canUndo() {
|
---|
| 109 | return false;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | bool MoleculeSaveAdjacencyAction::shouldUndo() {
|
---|
| 113 | return false;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | const string MoleculeSaveAdjacencyAction::getName() {
|
---|
| 117 | return NAME;
|
---|
| 118 | }
|
---|