| 1 | /*
|
|---|
| 2 | * SaveAdjacencyAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 10, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| 10 | #include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
|
|---|
| 11 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 12 | #include "bondgraph.hpp"
|
|---|
| 13 | #include "config.hpp"
|
|---|
| 14 | #include "Helpers/Log.hpp"
|
|---|
| 15 | #include "molecule.hpp"
|
|---|
| 16 | #include "Helpers/Verbose.hpp"
|
|---|
| 17 | #include "World.hpp"
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | #include <iostream>
|
|---|
| 21 | #include <fstream>
|
|---|
| 22 | #include <string>
|
|---|
| 23 |
|
|---|
| 24 | using namespace std;
|
|---|
| 25 |
|
|---|
| 26 | #include "UIElements/UIFactory.hpp"
|
|---|
| 27 | #include "UIElements/Dialog.hpp"
|
|---|
| 28 | #include "Actions/ValueStorage.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 | void MoleculeSaveAdjacency(std::string &adjacencyfile) {
|
|---|
| 54 | ValueStorage::getInstance().setCurrentValue(MoleculeSaveAdjacencyAction::NAME, adjacencyfile);
|
|---|
| 55 | ActionRegistry::getInstance().getActionByName(MoleculeSaveAdjacencyAction::NAME)->call(Action::NonInteractive);
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 | Dialog* MoleculeSaveAdjacencyAction::fillDialog(Dialog *dialog) {
|
|---|
| 59 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| 60 |
|
|---|
| 61 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 62 |
|
|---|
| 63 | return dialog;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | Action::state_ptr MoleculeSaveAdjacencyAction::performCall() {
|
|---|
| 67 | string filename;
|
|---|
| 68 | molecule *mol = NULL;
|
|---|
| 69 |
|
|---|
| 70 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
|---|
| 71 |
|
|---|
| 72 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
|---|
| 73 | mol = iter->second;
|
|---|
| 74 | DoLog(0) && (Log() << Verbose(0) << "Storing adjacency to path " << filename << "." << endl);
|
|---|
| 75 | World::getInstance().getConfig()->BG->ConstructBondGraph(mol);
|
|---|
| 76 | // TODO: sollte stream nicht filename benutzen, besser fuer unit test
|
|---|
| 77 | mol->StoreAdjacencyToFile(filename);
|
|---|
| 78 | }
|
|---|
| 79 | return Action::success;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | Action::state_ptr MoleculeSaveAdjacencyAction::performUndo(Action::state_ptr _state) {
|
|---|
| 83 | // MoleculeSaveAdjacencyState *state = assert_cast<MoleculeSaveAdjacencyState*>(_state.get());
|
|---|
| 84 |
|
|---|
| 85 | // string newName = state->mol->getName();
|
|---|
| 86 | // state->mol->setName(state->lastName);
|
|---|
| 87 |
|
|---|
| 88 | return Action::failure;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | Action::state_ptr MoleculeSaveAdjacencyAction::performRedo(Action::state_ptr _state){
|
|---|
| 92 | // Undo and redo have to do the same for this action
|
|---|
| 93 | return performUndo(_state);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | bool MoleculeSaveAdjacencyAction::canUndo() {
|
|---|
| 97 | return false;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | bool MoleculeSaveAdjacencyAction::shouldUndo() {
|
|---|
| 101 | return false;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | const string MoleculeSaveAdjacencyAction::getName() {
|
|---|
| 105 | return NAME;
|
|---|
| 106 | }
|
|---|