1 | /*
|
---|
2 | * BondLengthTableAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/CmdAction/BondLengthTableAction.hpp"
|
---|
11 | #include "config.hpp"
|
---|
12 | #include "log.hpp"
|
---|
13 | #include "verbose.hpp"
|
---|
14 | #include "World.hpp"
|
---|
15 |
|
---|
16 | #include <iostream>
|
---|
17 | #include <string>
|
---|
18 |
|
---|
19 | using namespace std;
|
---|
20 |
|
---|
21 | #include "UIElements/UIFactory.hpp"
|
---|
22 | #include "UIElements/Dialog.hpp"
|
---|
23 | #include "Actions/MapOfActions.hpp"
|
---|
24 |
|
---|
25 | const char CommandLineBondLengthTableAction::NAME[] = "bond-table";
|
---|
26 |
|
---|
27 | CommandLineBondLengthTableAction::CommandLineBondLengthTableAction() :
|
---|
28 | Action(NAME)
|
---|
29 | {}
|
---|
30 |
|
---|
31 | CommandLineBondLengthTableAction::~CommandLineBondLengthTableAction()
|
---|
32 | {}
|
---|
33 |
|
---|
34 | Action::state_ptr CommandLineBondLengthTableAction::performCall() {
|
---|
35 | ostringstream usage;
|
---|
36 | string BondGraphFileName;
|
---|
37 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
38 |
|
---|
39 | config *configuration = World::getInstance().getConfig();
|
---|
40 | dialog->queryString(NAME, &BondGraphFileName, MapOfActions::getInstance().getDescription(NAME));
|
---|
41 |
|
---|
42 | if(dialog->display()) {
|
---|
43 | DoLog(0) && (Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl);
|
---|
44 | delete dialog;
|
---|
45 | } else {
|
---|
46 | delete dialog;
|
---|
47 | return Action::failure;
|
---|
48 | }
|
---|
49 |
|
---|
50 | if (configuration->BG == NULL) {
|
---|
51 | configuration->BG = new BondGraph(configuration->GetIsAngstroem());
|
---|
52 | if ((!BondGraphFileName.empty()) && (configuration->BG->LoadBondLengthTable(BondGraphFileName))) {
|
---|
53 | DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
|
---|
54 | return Action::success;
|
---|
55 | } else {
|
---|
56 | DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
|
---|
57 | return Action::failure;
|
---|
58 | }
|
---|
59 | } else {
|
---|
60 | DoLog(0) && (Log() << Verbose(0) << "Bond length table already present." << endl);
|
---|
61 | return Action::failure;
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | Action::state_ptr CommandLineBondLengthTableAction::performUndo(Action::state_ptr _state) {
|
---|
66 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
67 |
|
---|
68 | return Action::failure;
|
---|
69 | // string newName = state->mol->getName();
|
---|
70 | // state->mol->setName(state->lastName);
|
---|
71 | //
|
---|
72 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
73 | }
|
---|
74 |
|
---|
75 | Action::state_ptr CommandLineBondLengthTableAction::performRedo(Action::state_ptr _state){
|
---|
76 | return Action::failure;
|
---|
77 | }
|
---|
78 |
|
---|
79 | bool CommandLineBondLengthTableAction::canUndo() {
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 |
|
---|
83 | bool CommandLineBondLengthTableAction::shouldUndo() {
|
---|
84 | return false;
|
---|
85 | }
|
---|
86 |
|
---|
87 | const string CommandLineBondLengthTableAction::getName() {
|
---|
88 | return NAME;
|
---|
89 | }
|
---|