source: molecuilder/src/Actions/MoleculeAction/BondFileAction.cpp@ 2e06c4

Last change on this file since 2e06c4 was 2e06c4, checked in by Frederik Heber <heber@…>, 15 years ago

Added all commands defined in ParseCommandLineOptions() as Actions.

  • Actions are not yet used, except verbose, version and help.
  • Files are present and included in Makefile.am
  • not unit tests written so far
  • no action has been tested so far (except for MapOfActions)
  • structure introduced to to transition from ParseCommandLineOptions to actions.
  • program name and config file are fixed arguments.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 2.3 KB
Line 
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
14using 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
43const char MoleculeBondFileAction::NAME[] = "bond-file";
44
45MoleculeBondFileAction::MoleculeBondFileAction() :
46 Action(NAME)
47{}
48
49MoleculeBondFileAction::~MoleculeBondFileAction()
50{}
51
52Action::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
72Action::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
81Action::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
86bool MoleculeBondFileAction::canUndo() {
87 return false;
88}
89
90bool MoleculeBondFileAction::shouldUndo() {
91 return false;
92}
93
94const string MoleculeBondFileAction::getName() {
95 return NAME;
96}
Note: See TracBrowser for help on using the repository browser.