| [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" | 
|---|
| [a3fded] | 11 | #include "bondgraph.hpp" | 
|---|
| [97ebf8] | 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 "Actions/MapOfActions.hpp" | 
|---|
|  | 25 |  | 
|---|
|  | 26 | const char CommandLineBondLengthTableAction::NAME[] = "bond-table"; | 
|---|
|  | 27 |  | 
|---|
|  | 28 | CommandLineBondLengthTableAction::CommandLineBondLengthTableAction() : | 
|---|
|  | 29 | Action(NAME) | 
|---|
|  | 30 | {} | 
|---|
|  | 31 |  | 
|---|
|  | 32 | CommandLineBondLengthTableAction::~CommandLineBondLengthTableAction() | 
|---|
|  | 33 | {} | 
|---|
|  | 34 |  | 
|---|
|  | 35 | Action::state_ptr CommandLineBondLengthTableAction::performCall() { | 
|---|
|  | 36 | ostringstream usage; | 
|---|
|  | 37 | string BondGraphFileName; | 
|---|
|  | 38 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
|  | 39 |  | 
|---|
|  | 40 | config *configuration = World::getInstance().getConfig(); | 
|---|
|  | 41 | dialog->queryString(NAME, &BondGraphFileName, MapOfActions::getInstance().getDescription(NAME)); | 
|---|
|  | 42 |  | 
|---|
|  | 43 | if(dialog->display()) { | 
|---|
| [39af9f] | 44 | DoLog(0) && (Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl); | 
|---|
| [97ebf8] | 45 | delete dialog; | 
|---|
|  | 46 | } else { | 
|---|
|  | 47 | delete dialog; | 
|---|
| [39af9f] | 48 | return Action::failure; | 
|---|
| [97ebf8] | 49 | } | 
|---|
|  | 50 |  | 
|---|
|  | 51 | if (configuration->BG == NULL) { | 
|---|
|  | 52 | configuration->BG = new BondGraph(configuration->GetIsAngstroem()); | 
|---|
|  | 53 | if ((!BondGraphFileName.empty()) && (configuration->BG->LoadBondLengthTable(BondGraphFileName))) { | 
|---|
|  | 54 | DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl); | 
|---|
|  | 55 | return Action::success; | 
|---|
|  | 56 | } else { | 
|---|
|  | 57 | DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl); | 
|---|
|  | 58 | return Action::failure; | 
|---|
|  | 59 | } | 
|---|
|  | 60 | } else { | 
|---|
|  | 61 | DoLog(0) && (Log() << Verbose(0) << "Bond length table already present." << endl); | 
|---|
|  | 62 | return Action::failure; | 
|---|
|  | 63 | } | 
|---|
|  | 64 | } | 
|---|
|  | 65 |  | 
|---|
|  | 66 | Action::state_ptr CommandLineBondLengthTableAction::performUndo(Action::state_ptr _state) { | 
|---|
|  | 67 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get()); | 
|---|
|  | 68 |  | 
|---|
|  | 69 | return Action::failure; | 
|---|
|  | 70 | //  string newName = state->mol->getName(); | 
|---|
|  | 71 | //  state->mol->setName(state->lastName); | 
|---|
|  | 72 | // | 
|---|
|  | 73 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); | 
|---|
|  | 74 | } | 
|---|
|  | 75 |  | 
|---|
|  | 76 | Action::state_ptr CommandLineBondLengthTableAction::performRedo(Action::state_ptr _state){ | 
|---|
|  | 77 | return Action::failure; | 
|---|
|  | 78 | } | 
|---|
|  | 79 |  | 
|---|
|  | 80 | bool CommandLineBondLengthTableAction::canUndo() { | 
|---|
|  | 81 | return false; | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 | bool CommandLineBondLengthTableAction::shouldUndo() { | 
|---|
|  | 85 | return false; | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 | const string CommandLineBondLengthTableAction::getName() { | 
|---|
|  | 89 | return NAME; | 
|---|
|  | 90 | } | 
|---|