| 1 | /* | 
|---|
| 2 | * ElementDbAction.cpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: May 9, 2010 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #include "Helpers/MemDebug.hpp" | 
|---|
| 9 |  | 
|---|
| 10 | #include "Actions/CmdAction/ElementDbAction.hpp" | 
|---|
| 11 | #include "Actions/ActionRegistry.hpp" | 
|---|
| 12 | #include "config.hpp" | 
|---|
| 13 | #include "Helpers/Log.hpp" | 
|---|
| 14 | #include "periodentafel.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 CommandLineElementDbAction::NAME[] = "element-db"; | 
|---|
| 28 |  | 
|---|
| 29 | CommandLineElementDbAction::CommandLineElementDbAction() : | 
|---|
| 30 | Action(NAME) | 
|---|
| 31 | {} | 
|---|
| 32 |  | 
|---|
| 33 | CommandLineElementDbAction::~CommandLineElementDbAction() | 
|---|
| 34 | {} | 
|---|
| 35 |  | 
|---|
| 36 | void CommandElementDb(std::string &databasepath) { | 
|---|
| 37 | ValueStorage::getInstance().setCurrentValue(CommandLineElementDbAction::NAME, databasepath); | 
|---|
| 38 | ActionRegistry::getInstance().getActionByName(CommandLineElementDbAction::NAME)->call(Action::NonInteractive); | 
|---|
| 39 | }; | 
|---|
| 40 |  | 
|---|
| 41 | Dialog* CommandLineElementDbAction::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 CommandLineElementDbAction::performCall() { | 
|---|
| 50 | ostringstream usage; | 
|---|
| 51 | string databasepath; | 
|---|
| 52 |  | 
|---|
| 53 | // get the path | 
|---|
| 54 | // TODO: Make databasepath a std::string | 
|---|
| 55 | config *configuration = World::getInstance().getConfig(); | 
|---|
| 56 | ValueStorage::getInstance().queryCurrentValue(NAME, databasepath); | 
|---|
| 57 | strcpy(configuration->databasepath, databasepath.c_str()); | 
|---|
| 58 |  | 
|---|
| 59 | // load table | 
|---|
| 60 | periodentafel *periode = World::getInstance().getPeriode(); | 
|---|
| 61 | if (periode->LoadPeriodentafel(configuration->databasepath)) { | 
|---|
| 62 | DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl); | 
|---|
| 63 | //periode->Output(); | 
|---|
| 64 | return Action::success; | 
|---|
| 65 | } else { | 
|---|
| 66 | DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl); | 
|---|
| 67 | return Action::failure; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | Action::state_ptr CommandLineElementDbAction::performUndo(Action::state_ptr _state) { | 
|---|
| 73 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get()); | 
|---|
| 74 |  | 
|---|
| 75 | return Action::failure; | 
|---|
| 76 | //  string newName = state->mol->getName(); | 
|---|
| 77 | //  state->mol->setName(state->lastName); | 
|---|
| 78 | // | 
|---|
| 79 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | Action::state_ptr CommandLineElementDbAction::performRedo(Action::state_ptr _state){ | 
|---|
| 83 | return Action::failure; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | bool CommandLineElementDbAction::canUndo() { | 
|---|
| 87 | return false; | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | bool CommandLineElementDbAction::shouldUndo() { | 
|---|
| 91 | return false; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | const string CommandLineElementDbAction::getName() { | 
|---|
| 95 | return NAME; | 
|---|
| 96 | } | 
|---|