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 "Actions/ActionRegistry.hpp"
|
---|
12 | #include "bondgraph.hpp"
|
---|
13 | #include "config.hpp"
|
---|
14 | #include "Helpers/Log.hpp"
|
---|
15 | #include "Helpers/Verbose.hpp"
|
---|
16 | #include "World.hpp"
|
---|
17 |
|
---|
18 | #include <iostream>
|
---|
19 | #include <string>
|
---|
20 |
|
---|
21 | using namespace std;
|
---|
22 |
|
---|
23 | #include "UIElements/UIFactory.hpp"
|
---|
24 | #include "UIElements/Dialog.hpp"
|
---|
25 | #include "Actions/ValueStorage.hpp"
|
---|
26 |
|
---|
27 | const char CommandLineBondLengthTableAction::NAME[] = "bond-table";
|
---|
28 |
|
---|
29 | CommandLineBondLengthTableAction::CommandLineBondLengthTableAction() :
|
---|
30 | Action(NAME)
|
---|
31 | {}
|
---|
32 |
|
---|
33 | CommandLineBondLengthTableAction::~CommandLineBondLengthTableAction()
|
---|
34 | {}
|
---|
35 |
|
---|
36 | void CommandBondLengthTable(std::string &BondGraphFileName) {
|
---|
37 | ValueStorage::getInstance().setCurrentValue(CommandLineBondLengthTableAction::NAME, BondGraphFileName);
|
---|
38 | ActionRegistry::getInstance().getActionByName(CommandLineBondLengthTableAction::NAME)->call(Action::NonInteractive);
|
---|
39 | };
|
---|
40 |
|
---|
41 | Dialog* CommandLineBondLengthTableAction::fillDialog(Dialog *dialog) {
|
---|
42 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
43 |
|
---|
44 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
45 |
|
---|
46 | return dialog;
|
---|
47 | }
|
---|
48 |
|
---|
49 | Action::state_ptr CommandLineBondLengthTableAction::performCall() {
|
---|
50 | ostringstream usage;
|
---|
51 | string BondGraphFileName;
|
---|
52 |
|
---|
53 | ValueStorage::getInstance().queryCurrentValue(NAME, BondGraphFileName);
|
---|
54 | DoLog(0) && (Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl);
|
---|
55 | config *configuration = World::getInstance().getConfig();
|
---|
56 | if (configuration->BG == NULL) {
|
---|
57 | configuration->BG = new BondGraph(configuration->GetIsAngstroem());
|
---|
58 | if ((!BondGraphFileName.empty()) && (configuration->BG->LoadBondLengthTable(BondGraphFileName))) {
|
---|
59 | DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
|
---|
60 | return Action::success;
|
---|
61 | } else {
|
---|
62 | DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
|
---|
63 | return Action::failure;
|
---|
64 | }
|
---|
65 | } else {
|
---|
66 | DoLog(0) && (Log() << Verbose(0) << "Bond length table already present." << endl);
|
---|
67 | return Action::failure;
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | Action::state_ptr CommandLineBondLengthTableAction::performUndo(Action::state_ptr _state) {
|
---|
72 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
73 |
|
---|
74 | return Action::failure;
|
---|
75 | // string newName = state->mol->getName();
|
---|
76 | // state->mol->setName(state->lastName);
|
---|
77 | //
|
---|
78 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
79 | }
|
---|
80 |
|
---|
81 | Action::state_ptr CommandLineBondLengthTableAction::performRedo(Action::state_ptr _state){
|
---|
82 | return Action::failure;
|
---|
83 | }
|
---|
84 |
|
---|
85 | bool CommandLineBondLengthTableAction::canUndo() {
|
---|
86 | return false;
|
---|
87 | }
|
---|
88 |
|
---|
89 | bool CommandLineBondLengthTableAction::shouldUndo() {
|
---|
90 | return false;
|
---|
91 | }
|
---|
92 |
|
---|
93 | const string CommandLineBondLengthTableAction::getName() {
|
---|
94 | return NAME;
|
---|
95 | }
|
---|