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