[97ebf8] | 1 | /*
|
---|
| 2 | * SaveAdjacencyAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 10, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
|
---|
[1a3c26] | 11 | #include "Actions/ActionCalls.hpp"
|
---|
| 12 | #include "bondgraph.hpp"
|
---|
| 13 | #include "config.hpp"
|
---|
| 14 | #include "log.hpp"
|
---|
| 15 | #include "molecule.hpp"
|
---|
| 16 | #include "verbose.hpp"
|
---|
| 17 | #include "World.hpp"
|
---|
| 18 |
|
---|
[97ebf8] | 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"
|
---|
[e58fad1] | 28 | #include "UIElements/ValueStorage.hpp"
|
---|
[97ebf8] | 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 |
|
---|
[1a3c26] | 53 | void MoleculeSaveAdjacency(std::string &adjacencyfile) {
|
---|
| 54 | ValueStorage::getInstance().setCurrentValue(MoleculeSaveAdjacencyAction::NAME, adjacencyfile);
|
---|
| 55 | ActionRegistry::getInstance().getActionByName(MoleculeSaveAdjacencyAction::NAME)->call(Action::NonInteractive);
|
---|
| 56 | };
|
---|
| 57 |
|
---|
[e58fad1] | 58 | Dialog* MoleculeSaveAdjacencyAction::createDialog() {
|
---|
| 59 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 60 |
|
---|
| 61 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 62 |
|
---|
| 63 | return dialog;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[97ebf8] | 66 | Action::state_ptr MoleculeSaveAdjacencyAction::performCall() {
|
---|
| 67 | string filename;
|
---|
| 68 | molecule *mol = NULL;
|
---|
| 69 |
|
---|
[e58fad1] | 70 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
[97ebf8] | 71 |
|
---|
[e58fad1] | 72 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 73 | mol = iter->second;
|
---|
[97ebf8] | 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
|
---|
[35b698] | 77 | mol->StoreAdjacencyToFile(filename);
|
---|
[97ebf8] | 78 | }
|
---|
[e58fad1] | 79 | return Action::success;
|
---|
[97ebf8] | 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 | }
|
---|