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