| [97ebf8] | 1 | /*
 | 
|---|
 | 2 |  * ElementDbAction.cpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: May 9, 2010
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [bf3817] | 8 | // include config.h
 | 
|---|
 | 9 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 10 | #include <config.h>
 | 
|---|
 | 11 | #endif
 | 
|---|
 | 12 | 
 | 
|---|
| [112b09] | 13 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 14 | 
 | 
|---|
| [97ebf8] | 15 | #include "Actions/CmdAction/ElementDbAction.hpp"
 | 
|---|
| [0430e3] | 16 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| [97ebf8] | 17 | #include "config.hpp"
 | 
|---|
| [952f38] | 18 | #include "Helpers/Log.hpp"
 | 
|---|
| [97ebf8] | 19 | #include "periodentafel.hpp"
 | 
|---|
| [952f38] | 20 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [97ebf8] | 21 | #include "World.hpp"
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | #include <iostream>
 | 
|---|
 | 24 | #include <string>
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | using namespace std;
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 29 | #include "UIElements/Dialog.hpp"
 | 
|---|
| [861874] | 30 | #include "Actions/ValueStorage.hpp"
 | 
|---|
| [97ebf8] | 31 | 
 | 
|---|
 | 32 | const char CommandLineElementDbAction::NAME[] = "element-db";
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 | CommandLineElementDbAction::CommandLineElementDbAction() :
 | 
|---|
 | 35 |   Action(NAME)
 | 
|---|
 | 36 | {}
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 | CommandLineElementDbAction::~CommandLineElementDbAction()
 | 
|---|
 | 39 | {}
 | 
|---|
 | 40 | 
 | 
|---|
| [ecbc9a] | 41 | void CommandElementDb(std::string &databasepath) {
 | 
|---|
 | 42 |   ValueStorage::getInstance().setCurrentValue(CommandLineElementDbAction::NAME, databasepath);
 | 
|---|
 | 43 |   ActionRegistry::getInstance().getActionByName(CommandLineElementDbAction::NAME)->call(Action::NonInteractive);
 | 
|---|
 | 44 | };
 | 
|---|
 | 45 | 
 | 
|---|
| [047878] | 46 | Dialog* CommandLineElementDbAction::fillDialog(Dialog *dialog) {
 | 
|---|
 | 47 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| [a12e8e] | 48 | 
 | 
|---|
 | 49 |   dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 |   return dialog;
 | 
|---|
 | 52 | }
 | 
|---|
 | 53 | 
 | 
|---|
| [97ebf8] | 54 | Action::state_ptr CommandLineElementDbAction::performCall() {
 | 
|---|
 | 55 |   ostringstream usage;
 | 
|---|
 | 56 |   string databasepath;
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 |   // get the path
 | 
|---|
 | 59 |   // TODO: Make databasepath a std::string
 | 
|---|
 | 60 |   config *configuration = World::getInstance().getConfig();
 | 
|---|
| [a12e8e] | 61 |   ValueStorage::getInstance().queryCurrentValue(NAME, databasepath);
 | 
|---|
 | 62 |   strcpy(configuration->databasepath, databasepath.c_str());
 | 
|---|
| [97ebf8] | 63 | 
 | 
|---|
 | 64 |   // load table
 | 
|---|
 | 65 |   periodentafel *periode = World::getInstance().getPeriode();
 | 
|---|
 | 66 |   if (periode->LoadPeriodentafel(configuration->databasepath)) {
 | 
|---|
 | 67 |     DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
 | 
|---|
 | 68 |     //periode->Output();
 | 
|---|
 | 69 |     return Action::success;
 | 
|---|
 | 70 |   } else {
 | 
|---|
 | 71 |     DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
 | 
|---|
 | 72 |     return Action::failure;
 | 
|---|
 | 73 |   }
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | }
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 | Action::state_ptr CommandLineElementDbAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 78 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 |   return Action::failure;
 | 
|---|
 | 81 | //  string newName = state->mol->getName();
 | 
|---|
 | 82 | //  state->mol->setName(state->lastName);
 | 
|---|
 | 83 | //
 | 
|---|
 | 84 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
 | 
|---|
 | 85 | }
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | Action::state_ptr CommandLineElementDbAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 88 |   return Action::failure;
 | 
|---|
 | 89 | }
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 | bool CommandLineElementDbAction::canUndo() {
 | 
|---|
 | 92 |   return false;
 | 
|---|
 | 93 | }
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 | bool CommandLineElementDbAction::shouldUndo() {
 | 
|---|
 | 96 |   return false;
 | 
|---|
 | 97 | }
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 | const string CommandLineElementDbAction::getName() {
 | 
|---|
 | 100 |   return NAME;
 | 
|---|
 | 101 | }
 | 
|---|