1 | /*
|
---|
2 | * BondFileAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 10, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Actions/MoleculeAction/BondFileAction.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 "World.hpp"
|
---|
28 |
|
---|
29 | /****** MoleculeBondFileAction *****/
|
---|
30 |
|
---|
31 | // memento to remember the state when undoing
|
---|
32 |
|
---|
33 | //class MoleculeBondFileState : public ActionState {
|
---|
34 | //public:
|
---|
35 | // MoleculeBondFileState(molecule* _mol,std::string _lastName) :
|
---|
36 | // mol(_mol),
|
---|
37 | // lastName(_lastName)
|
---|
38 | // {}
|
---|
39 | // molecule* mol;
|
---|
40 | // std::string lastName;
|
---|
41 | //};
|
---|
42 |
|
---|
43 | const char MoleculeBondFileAction::NAME[] = "bond-file";
|
---|
44 |
|
---|
45 | MoleculeBondFileAction::MoleculeBondFileAction() :
|
---|
46 | Action(NAME)
|
---|
47 | {}
|
---|
48 |
|
---|
49 | MoleculeBondFileAction::~MoleculeBondFileAction()
|
---|
50 | {}
|
---|
51 |
|
---|
52 | Action::state_ptr MoleculeBondFileAction::performCall() {
|
---|
53 | string filename;
|
---|
54 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
55 | molecule *mol = NULL;
|
---|
56 |
|
---|
57 | dialog->queryString(NAME, &filename, MapOfActions::getInstance().getDescription(NAME));
|
---|
58 | dialog->queryMolecule("molecule-by-id", &mol, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
59 |
|
---|
60 | if(dialog->display()) {
|
---|
61 | DoLog(0) && (Log() << Verbose(0) << "Parsing bonds from " << filename << "." << endl);
|
---|
62 | ifstream input(filename.c_str());
|
---|
63 | mol->CreateAdjacencyListFromDbondFile(&input);
|
---|
64 | input.close();
|
---|
65 | delete dialog;
|
---|
66 | return Action::success;
|
---|
67 | }
|
---|
68 | delete dialog;
|
---|
69 | return Action::failure;
|
---|
70 | }
|
---|
71 |
|
---|
72 | Action::state_ptr MoleculeBondFileAction::performUndo(Action::state_ptr _state) {
|
---|
73 | // MoleculeBondFileState *state = assert_cast<MoleculeBondFileState*>(_state.get());
|
---|
74 |
|
---|
75 | // string newName = state->mol->getName();
|
---|
76 | // state->mol->setName(state->lastName);
|
---|
77 |
|
---|
78 | return Action::failure;
|
---|
79 | }
|
---|
80 |
|
---|
81 | Action::state_ptr MoleculeBondFileAction::performRedo(Action::state_ptr _state){
|
---|
82 | // Undo and redo have to do the same for this action
|
---|
83 | return performUndo(_state);
|
---|
84 | }
|
---|
85 |
|
---|
86 | bool MoleculeBondFileAction::canUndo() {
|
---|
87 | return false;
|
---|
88 | }
|
---|
89 |
|
---|
90 | bool MoleculeBondFileAction::shouldUndo() {
|
---|
91 | return false;
|
---|
92 | }
|
---|
93 |
|
---|
94 | const string MoleculeBondFileAction::getName() {
|
---|
95 | return NAME;
|
---|
96 | }
|
---|