| [97ebf8] | 1 | /*
|
|---|
| 2 | * BondFileAction.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/BondFileAction.hpp"
|
|---|
| [0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
|---|
| [952f38] | 12 | #include "Helpers/Log.hpp"
|
|---|
| [1a3c26] | 13 | #include "molecule.hpp"
|
|---|
| [952f38] | 14 | #include "Helpers/Verbose.hpp"
|
|---|
| [1a3c26] | 15 | #include "World.hpp"
|
|---|
| [97ebf8] | 16 |
|
|---|
| 17 | #include <iostream>
|
|---|
| 18 | #include <fstream>
|
|---|
| 19 | #include <string>
|
|---|
| 20 |
|
|---|
| 21 | using namespace std;
|
|---|
| 22 |
|
|---|
| 23 | #include "UIElements/UIFactory.hpp"
|
|---|
| 24 | #include "UIElements/Dialog.hpp"
|
|---|
| [861874] | 25 | #include "Actions/ValueStorage.hpp"
|
|---|
| [97ebf8] | 26 |
|
|---|
| 27 |
|
|---|
| 28 | /****** MoleculeBondFileAction *****/
|
|---|
| 29 |
|
|---|
| 30 | // memento to remember the state when undoing
|
|---|
| 31 |
|
|---|
| 32 | //class MoleculeBondFileState : public ActionState {
|
|---|
| 33 | //public:
|
|---|
| 34 | // MoleculeBondFileState(molecule* _mol,std::string _lastName) :
|
|---|
| 35 | // mol(_mol),
|
|---|
| 36 | // lastName(_lastName)
|
|---|
| 37 | // {}
|
|---|
| 38 | // molecule* mol;
|
|---|
| 39 | // std::string lastName;
|
|---|
| 40 | //};
|
|---|
| 41 |
|
|---|
| 42 | const char MoleculeBondFileAction::NAME[] = "bond-file";
|
|---|
| 43 |
|
|---|
| 44 | MoleculeBondFileAction::MoleculeBondFileAction() :
|
|---|
| 45 | Action(NAME)
|
|---|
| 46 | {}
|
|---|
| 47 |
|
|---|
| 48 | MoleculeBondFileAction::~MoleculeBondFileAction()
|
|---|
| 49 | {}
|
|---|
| 50 |
|
|---|
| [1a3c26] | 51 | void MoleculeBondFile(std::string &bondfile) {
|
|---|
| 52 | ValueStorage::getInstance().setCurrentValue(MoleculeBondFileAction::NAME, bondfile);
|
|---|
| 53 | ActionRegistry::getInstance().getActionByName(MoleculeBondFileAction::NAME)->call(Action::NonInteractive);
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| [047878] | 56 | Dialog* MoleculeBondFileAction::fillDialog(Dialog *dialog) {
|
|---|
| 57 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| [eacc3b] | 58 |
|
|---|
| 59 | dialog->queryString(NAME, MapOfActions::getInstance().getDescription(NAME));
|
|---|
| 60 |
|
|---|
| 61 | return dialog;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| [97ebf8] | 64 | Action::state_ptr MoleculeBondFileAction::performCall() {
|
|---|
| 65 | string filename;
|
|---|
| 66 | molecule *mol = NULL;
|
|---|
| 67 |
|
|---|
| [eacc3b] | 68 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
|---|
| [97ebf8] | 69 |
|
|---|
| [eacc3b] | 70 | if(World::getInstance().countSelectedMolecules() == 1) {
|
|---|
| 71 | mol = World::getInstance().beginMoleculeSelection()->second;
|
|---|
| [97ebf8] | 72 | DoLog(0) && (Log() << Verbose(0) << "Parsing bonds from " << filename << "." << endl);
|
|---|
| 73 | ifstream input(filename.c_str());
|
|---|
| 74 | mol->CreateAdjacencyListFromDbondFile(&input);
|
|---|
| 75 | input.close();
|
|---|
| 76 | return Action::success;
|
|---|
| [eacc3b] | 77 | } else
|
|---|
| 78 | return Action::failure;
|
|---|
| [97ebf8] | 79 | }
|
|---|
| 80 |
|
|---|
| 81 | Action::state_ptr MoleculeBondFileAction::performUndo(Action::state_ptr _state) {
|
|---|
| 82 | // MoleculeBondFileState *state = assert_cast<MoleculeBondFileState*>(_state.get());
|
|---|
| 83 |
|
|---|
| 84 | // string newName = state->mol->getName();
|
|---|
| 85 | // state->mol->setName(state->lastName);
|
|---|
| 86 |
|
|---|
| 87 | return Action::failure;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | Action::state_ptr MoleculeBondFileAction::performRedo(Action::state_ptr _state){
|
|---|
| 91 | // Undo and redo have to do the same for this action
|
|---|
| 92 | return performUndo(_state);
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | bool MoleculeBondFileAction::canUndo() {
|
|---|
| 96 | return false;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | bool MoleculeBondFileAction::shouldUndo() {
|
|---|
| 100 | return false;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | const string MoleculeBondFileAction::getName() {
|
|---|
| 104 | return NAME;
|
|---|
| 105 | }
|
|---|