[97ebf8] | 1 | /*
|
---|
| 2 | * SaveBondsAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 10, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Actions/MoleculeAction/SaveBondsAction.hpp"
|
---|
| 9 |
|
---|
| 10 | #include <iostream>
|
---|
| 11 | #include <fstream>
|
---|
| 12 | #include <string>
|
---|
| 13 |
|
---|
| 14 | using namespace std;
|
---|
| 15 |
|
---|
| 16 | #include "UIElements/UIFactory.hpp"
|
---|
| 17 | #include "UIElements/Dialog.hpp"
|
---|
| 18 | #include "Actions/MapOfActions.hpp"
|
---|
| 19 |
|
---|
| 20 | #include "atom.hpp"
|
---|
| 21 | #include "bondgraph.hpp"
|
---|
| 22 | #include "config.hpp"
|
---|
| 23 | #include "defs.hpp"
|
---|
| 24 | #include "log.hpp"
|
---|
| 25 | #include "molecule.hpp"
|
---|
| 26 | #include "vector.hpp"
|
---|
| 27 | #include "verbose.hpp"
|
---|
| 28 | #include "World.hpp"
|
---|
| 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 |
|
---|
| 53 | Action::state_ptr MoleculeSaveBondsAction::performCall() {
|
---|
| 54 | string filename;
|
---|
| 55 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 56 | molecule *mol = NULL;
|
---|
| 57 |
|
---|
| 58 | dialog->queryString(NAME, &filename, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 59 | dialog->queryMolecule("molecule-by-id", &mol, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
| 60 |
|
---|
| 61 | if(dialog->display()) {
|
---|
| 62 | DoLog(0) && (Log() << Verbose(0) << "Storing bonds to path " << filename << "." << endl);
|
---|
| 63 | World::getInstance().getConfig()->BG->ConstructBondGraph(mol);
|
---|
| 64 | // TODO: sollte stream, nicht filenamen direkt nutzen, beser fuer unit tests
|
---|
| 65 | char outputname[MAXSTRINGSIZE];
|
---|
| 66 | strcpy(outputname, filename.c_str());
|
---|
| 67 | mol->StoreBondsToFile(NULL, outputname);
|
---|
| 68 | delete dialog;
|
---|
| 69 | return Action::success;
|
---|
| 70 | }
|
---|
| 71 | delete dialog;
|
---|
| 72 | return Action::failure;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | Action::state_ptr MoleculeSaveBondsAction::performUndo(Action::state_ptr _state) {
|
---|
| 76 | // MoleculeSaveBondsState *state = assert_cast<MoleculeSaveBondsState*>(_state.get());
|
---|
| 77 |
|
---|
| 78 | // string newName = state->mol->getName();
|
---|
| 79 | // state->mol->setName(state->lastName);
|
---|
| 80 |
|
---|
| 81 | return Action::failure;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | Action::state_ptr MoleculeSaveBondsAction::performRedo(Action::state_ptr _state){
|
---|
| 85 | // Undo and redo have to do the same for this action
|
---|
| 86 | return performUndo(_state);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | bool MoleculeSaveBondsAction::canUndo() {
|
---|
| 90 | return false;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | bool MoleculeSaveBondsAction::shouldUndo() {
|
---|
| 94 | return false;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | const string MoleculeSaveBondsAction::getName() {
|
---|
| 98 | return NAME;
|
---|
| 99 | }
|
---|