| [97ebf8] | 1 | /* | 
|---|
|  | 2 | * BondLengthTableAction.cpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: May 9, 2010 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [112b09] | 8 | #include "Helpers/MemDebug.hpp" | 
|---|
|  | 9 |  | 
|---|
| [97ebf8] | 10 | #include "Actions/CmdAction/BondLengthTableAction.hpp" | 
|---|
| [0430e3] | 11 | #include "Actions/ActionRegistry.hpp" | 
|---|
| [a3fded] | 12 | #include "bondgraph.hpp" | 
|---|
| [97ebf8] | 13 | #include "config.hpp" | 
|---|
|  | 14 | #include "log.hpp" | 
|---|
|  | 15 | #include "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" | 
|---|
| [bb2b2c] | 25 | #include "UIElements/ValueStorage.hpp" | 
|---|
| [97ebf8] | 26 |  | 
|---|
|  | 27 | const char CommandLineBondLengthTableAction::NAME[] = "bond-table"; | 
|---|
|  | 28 |  | 
|---|
|  | 29 | CommandLineBondLengthTableAction::CommandLineBondLengthTableAction() : | 
|---|
|  | 30 | Action(NAME) | 
|---|
|  | 31 | {} | 
|---|
|  | 32 |  | 
|---|
|  | 33 | CommandLineBondLengthTableAction::~CommandLineBondLengthTableAction() | 
|---|
|  | 34 | {} | 
|---|
|  | 35 |  | 
|---|
| [ecbc9a] | 36 | void CommandBondLengthTable(std::string &BondGraphFileName) { | 
|---|
|  | 37 | ValueStorage::getInstance().setCurrentValue(CommandLineBondLengthTableAction::NAME, BondGraphFileName); | 
|---|
|  | 38 | ActionRegistry::getInstance().getActionByName(CommandLineBondLengthTableAction::NAME)->call(Action::NonInteractive); | 
|---|
|  | 39 | }; | 
|---|
|  | 40 |  | 
|---|
| [bb2b2c] | 41 | Dialog* CommandLineBondLengthTableAction::createDialog() { | 
|---|
|  | 42 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
|  | 43 |  | 
|---|
|  | 44 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME)); | 
|---|
|  | 45 |  | 
|---|
|  | 46 | return dialog; | 
|---|
|  | 47 | } | 
|---|
|  | 48 |  | 
|---|
| [97ebf8] | 49 | Action::state_ptr CommandLineBondLengthTableAction::performCall() { | 
|---|
|  | 50 | ostringstream usage; | 
|---|
|  | 51 | string BondGraphFileName; | 
|---|
|  | 52 |  | 
|---|
| [bb2b2c] | 53 | ValueStorage::getInstance().queryCurrentValue(NAME, BondGraphFileName); | 
|---|
|  | 54 | DoLog(0) && (Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl); | 
|---|
| [97ebf8] | 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 | } | 
|---|