[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"
|
---|
| 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"
|
---|
[eacc3b] | 20 | #include "UIElements/ValueStorage.hpp"
|
---|
[97ebf8] | 21 |
|
---|
| 22 | #include "log.hpp"
|
---|
| 23 | #include "molecule.hpp"
|
---|
[eacc3b] | 24 | #include "verbose.hpp"
|
---|
[97ebf8] | 25 | #include "World.hpp"
|
---|
| 26 |
|
---|
| 27 | /****** MoleculeBondFileAction *****/
|
---|
| 28 |
|
---|
| 29 | // memento to remember the state when undoing
|
---|
| 30 |
|
---|
| 31 | //class MoleculeBondFileState : public ActionState {
|
---|
| 32 | //public:
|
---|
| 33 | // MoleculeBondFileState(molecule* _mol,std::string _lastName) :
|
---|
| 34 | // mol(_mol),
|
---|
| 35 | // lastName(_lastName)
|
---|
| 36 | // {}
|
---|
| 37 | // molecule* mol;
|
---|
| 38 | // std::string lastName;
|
---|
| 39 | //};
|
---|
| 40 |
|
---|
| 41 | const char MoleculeBondFileAction::NAME[] = "bond-file";
|
---|
| 42 |
|
---|
| 43 | MoleculeBondFileAction::MoleculeBondFileAction() :
|
---|
| 44 | Action(NAME)
|
---|
| 45 | {}
|
---|
| 46 |
|
---|
| 47 | MoleculeBondFileAction::~MoleculeBondFileAction()
|
---|
| 48 | {}
|
---|
| 49 |
|
---|
[eacc3b] | 50 | Dialog* MoleculeBondFileAction::createDialog() {
|
---|
| 51 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 52 |
|
---|
| 53 | dialog->queryString(NAME, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 54 |
|
---|
| 55 | return dialog;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 |
|
---|
[97ebf8] | 59 | Action::state_ptr MoleculeBondFileAction::performCall() {
|
---|
| 60 | string filename;
|
---|
| 61 | molecule *mol = NULL;
|
---|
| 62 |
|
---|
[eacc3b] | 63 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
[97ebf8] | 64 |
|
---|
[eacc3b] | 65 | if(World::getInstance().countSelectedMolecules() == 1) {
|
---|
| 66 | mol = World::getInstance().beginMoleculeSelection()->second;
|
---|
[97ebf8] | 67 | DoLog(0) && (Log() << Verbose(0) << "Parsing bonds from " << filename << "." << endl);
|
---|
| 68 | ifstream input(filename.c_str());
|
---|
| 69 | mol->CreateAdjacencyListFromDbondFile(&input);
|
---|
| 70 | input.close();
|
---|
| 71 | return Action::success;
|
---|
[eacc3b] | 72 | } else
|
---|
| 73 | return Action::failure;
|
---|
[97ebf8] | 74 | }
|
---|
| 75 |
|
---|
| 76 | Action::state_ptr MoleculeBondFileAction::performUndo(Action::state_ptr _state) {
|
---|
| 77 | // MoleculeBondFileState *state = assert_cast<MoleculeBondFileState*>(_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 MoleculeBondFileAction::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 MoleculeBondFileAction::canUndo() {
|
---|
| 91 | return false;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | bool MoleculeBondFileAction::shouldUndo() {
|
---|
| 95 | return false;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | const string MoleculeBondFileAction::getName() {
|
---|
| 99 | return NAME;
|
---|
| 100 | }
|
---|