1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * BondLengthTableAction.cpp
|
---|
10 | *
|
---|
11 | * Created on: May 9, 2010
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "Helpers/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "Actions/CommandAction/BondLengthTableAction.hpp"
|
---|
23 | #include "Actions/ActionRegistry.hpp"
|
---|
24 | #include "bondgraph.hpp"
|
---|
25 | #include "config.hpp"
|
---|
26 | #include "Helpers/Log.hpp"
|
---|
27 | #include "Helpers/Verbose.hpp"
|
---|
28 | #include "World.hpp"
|
---|
29 |
|
---|
30 | #include <iostream>
|
---|
31 | #include <string>
|
---|
32 |
|
---|
33 | using namespace std;
|
---|
34 |
|
---|
35 | #include "UIElements/UIFactory.hpp"
|
---|
36 | #include "UIElements/Dialog.hpp"
|
---|
37 | #include "Actions/ValueStorage.hpp"
|
---|
38 |
|
---|
39 | const char CommandBondLengthTableAction::NAME[] = "bond-table";
|
---|
40 |
|
---|
41 | CommandBondLengthTableAction::CommandBondLengthTableAction() :
|
---|
42 | Action(NAME)
|
---|
43 | {}
|
---|
44 |
|
---|
45 | CommandBondLengthTableAction::~CommandBondLengthTableAction()
|
---|
46 | {}
|
---|
47 |
|
---|
48 | void CommandBondLengthTable(std::string &BondGraphFileName) {
|
---|
49 | ValueStorage::getInstance().setCurrentValue(CommandBondLengthTableAction::NAME, BondGraphFileName);
|
---|
50 | ActionRegistry::getInstance().getActionByName(CommandBondLengthTableAction::NAME)->call(Action::NonInteractive);
|
---|
51 | };
|
---|
52 |
|
---|
53 | void CommandBondLengthTableAction::getParametersfromValueStorage()
|
---|
54 | {};
|
---|
55 |
|
---|
56 | Dialog* CommandBondLengthTableAction::fillDialog(Dialog *dialog) {
|
---|
57 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
58 |
|
---|
59 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
60 |
|
---|
61 | return dialog;
|
---|
62 | }
|
---|
63 |
|
---|
64 | Action::state_ptr CommandBondLengthTableAction::performCall() {
|
---|
65 | ostringstream usage;
|
---|
66 | string BondGraphFileName;
|
---|
67 |
|
---|
68 | ValueStorage::getInstance().queryCurrentValue(NAME, BondGraphFileName);
|
---|
69 | DoLog(0) && (Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl);
|
---|
70 | config *configuration = World::getInstance().getConfig();
|
---|
71 | if (configuration->BG == NULL) {
|
---|
72 | configuration->BG = new BondGraph(configuration->GetIsAngstroem());
|
---|
73 | if ((!BondGraphFileName.empty()) && (configuration->BG->LoadBondLengthTable(BondGraphFileName))) {
|
---|
74 | DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
|
---|
75 | return Action::success;
|
---|
76 | } else {
|
---|
77 | DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
|
---|
78 | return Action::failure;
|
---|
79 | }
|
---|
80 | } else {
|
---|
81 | DoLog(0) && (Log() << Verbose(0) << "Bond length table already present." << endl);
|
---|
82 | return Action::failure;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | Action::state_ptr CommandBondLengthTableAction::performUndo(Action::state_ptr _state) {
|
---|
87 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
88 |
|
---|
89 | return Action::failure;
|
---|
90 | // string newName = state->mol->getName();
|
---|
91 | // state->mol->setName(state->lastName);
|
---|
92 | //
|
---|
93 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
94 | }
|
---|
95 |
|
---|
96 | Action::state_ptr CommandBondLengthTableAction::performRedo(Action::state_ptr _state){
|
---|
97 | return Action::failure;
|
---|
98 | }
|
---|
99 |
|
---|
100 | bool CommandBondLengthTableAction::canUndo() {
|
---|
101 | return false;
|
---|
102 | }
|
---|
103 |
|
---|
104 | bool CommandBondLengthTableAction::shouldUndo() {
|
---|
105 | return false;
|
---|
106 | }
|
---|
107 |
|
---|
108 | const string CommandBondLengthTableAction::getName() {
|
---|
109 | return NAME;
|
---|
110 | }
|
---|