| 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 "bondgraph.hpp" | 
|---|
| 12 | #include "config.hpp" | 
|---|
| 13 | #include "log.hpp" | 
|---|
| 14 | #include "verbose.hpp" | 
|---|
| 15 | #include "World.hpp" | 
|---|
| 16 |  | 
|---|
| 17 | #include <iostream> | 
|---|
| 18 | #include <string> | 
|---|
| 19 |  | 
|---|
| 20 | using namespace std; | 
|---|
| 21 |  | 
|---|
| 22 | #include "UIElements/UIFactory.hpp" | 
|---|
| 23 | #include "UIElements/Dialog.hpp" | 
|---|
| 24 | #include "UIElements/ValueStorage.hpp" | 
|---|
| 25 |  | 
|---|
| 26 | const char CommandLineBondLengthTableAction::NAME[] = "bond-table"; | 
|---|
| 27 |  | 
|---|
| 28 | CommandLineBondLengthTableAction::CommandLineBondLengthTableAction() : | 
|---|
| 29 | Action(NAME) | 
|---|
| 30 | {} | 
|---|
| 31 |  | 
|---|
| 32 | CommandLineBondLengthTableAction::~CommandLineBondLengthTableAction() | 
|---|
| 33 | {} | 
|---|
| 34 |  | 
|---|
| 35 | Dialog* CommandLineBondLengthTableAction::createDialog() { | 
|---|
| 36 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
| 37 |  | 
|---|
| 38 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME)); | 
|---|
| 39 |  | 
|---|
| 40 | return dialog; | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 | Action::state_ptr CommandLineBondLengthTableAction::performCall() { | 
|---|
| 44 | ostringstream usage; | 
|---|
| 45 | string BondGraphFileName; | 
|---|
| 46 |  | 
|---|
| 47 | ValueStorage::getInstance().queryCurrentValue(NAME, BondGraphFileName); | 
|---|
| 48 | DoLog(0) && (Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl); | 
|---|
| 49 | config *configuration = World::getInstance().getConfig(); | 
|---|
| 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 | } | 
|---|