| [97ebf8] | 1 | /*
|
|---|
| 2 | * SaveBondsAction.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/SaveBondsAction.hpp"
|
|---|
| [0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
|---|
| [1a3c26] | 12 | #include "bondgraph.hpp"
|
|---|
| 13 | #include "config.hpp"
|
|---|
| [952f38] | 14 | #include "Helpers/Log.hpp"
|
|---|
| [1a3c26] | 15 | #include "molecule.hpp"
|
|---|
| [952f38] | 16 | #include "Helpers/Verbose.hpp"
|
|---|
| [1a3c26] | 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"
|
|---|
| [861874] | 28 | #include "Actions/ValueStorage.hpp"
|
|---|
| [97ebf8] | 29 |
|
|---|
| 30 | /****** MoleculeSaveBondsAction *****/
|
|---|
| 31 |
|
|---|
| 32 | // memento to remember the state when undoing
|
|---|
| 33 |
|
|---|
| 34 | //class MoleculeSaveBondsState : public ActionState {
|
|---|
| 35 | //public:
|
|---|
| 36 | // MoleculeSaveBondsState(molecule* _mol,std::string _lastName) :
|
|---|
| 37 | // mol(_mol),
|
|---|
| 38 | // lastName(_lastName)
|
|---|
| 39 | // {}
|
|---|
| 40 | // molecule* mol;
|
|---|
| 41 | // std::string lastName;
|
|---|
| 42 | //};
|
|---|
| 43 |
|
|---|
| 44 | const char MoleculeSaveBondsAction::NAME[] = "save-bonds";
|
|---|
| 45 |
|
|---|
| 46 | MoleculeSaveBondsAction::MoleculeSaveBondsAction() :
|
|---|
| 47 | Action(NAME)
|
|---|
| 48 | {}
|
|---|
| 49 |
|
|---|
| 50 | MoleculeSaveBondsAction::~MoleculeSaveBondsAction()
|
|---|
| 51 | {}
|
|---|
| 52 |
|
|---|
| [1a3c26] | 53 | void MoleculeSaveBonds(std::string &bondsfile) {
|
|---|
| 54 | ValueStorage::getInstance().setCurrentValue(MoleculeSaveBondsAction::NAME, bondsfile);
|
|---|
| 55 | ActionRegistry::getInstance().getActionByName(MoleculeSaveBondsAction::NAME)->call(Action::NonInteractive);
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| [047878] | 58 | Dialog* MoleculeSaveBondsAction::fillDialog(Dialog *dialog) {
|
|---|
| 59 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| [fdf198] | 60 |
|
|---|
| 61 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| [5b5c4d] | 62 |
|
|---|
| 63 | return dialog;
|
|---|
| [fdf198] | 64 | }
|
|---|
| 65 |
|
|---|
| [97ebf8] | 66 | Action::state_ptr MoleculeSaveBondsAction::performCall() {
|
|---|
| 67 | string filename;
|
|---|
| 68 | molecule *mol = NULL;
|
|---|
| 69 |
|
|---|
| [fdf198] | 70 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
|---|
| [97ebf8] | 71 |
|
|---|
| [fdf198] | 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 bonds to path " << filename << "." << endl);
|
|---|
| 75 | World::getInstance().getConfig()->BG->ConstructBondGraph(mol);
|
|---|
| [35b698] | 76 | // TODO: sollte stream, nicht filenamen direkt nutzen, besser fuer unit tests
|
|---|
| 77 | mol->StoreBondsToFile(filename);
|
|---|
| [97ebf8] | 78 | }
|
|---|
| [fdf198] | 79 | return Action::success;
|
|---|
| [97ebf8] | 80 | }
|
|---|
| 81 |
|
|---|
| 82 | Action::state_ptr MoleculeSaveBondsAction::performUndo(Action::state_ptr _state) {
|
|---|
| 83 | // MoleculeSaveBondsState *state = assert_cast<MoleculeSaveBondsState*>(_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 MoleculeSaveBondsAction::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 MoleculeSaveBondsAction::canUndo() {
|
|---|
| 97 | return false;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | bool MoleculeSaveBondsAction::shouldUndo() {
|
|---|
| 101 | return false;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | const string MoleculeSaveBondsAction::getName() {
|
|---|
| 105 | return NAME;
|
|---|
| 106 | }
|
|---|