| 1 | /*
 | 
|---|
| 2 |  * ElementDbAction.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: May 9, 2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "Actions/CmdAction/ElementDbAction.hpp"
 | 
|---|
| 9 | #include "CommandLineParser.hpp"
 | 
|---|
| 10 | #include "config.hpp"
 | 
|---|
| 11 | #include "log.hpp"
 | 
|---|
| 12 | #include "periodentafel.hpp"
 | 
|---|
| 13 | #include "verbose.hpp"
 | 
|---|
| 14 | #include "World.hpp"
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <iostream>
 | 
|---|
| 17 | #include <string>
 | 
|---|
| 18 | 
 | 
|---|
| 19 | using namespace std;
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "UIElements/UIFactory.hpp"
 | 
|---|
| 22 | #include "UIElements/Dialog.hpp"
 | 
|---|
| 23 | #include "Actions/MapOfActions.hpp"
 | 
|---|
| 24 | 
 | 
|---|
| 25 | const char CommandLineElementDbAction::NAME[] = "element-db";
 | 
|---|
| 26 | 
 | 
|---|
| 27 | CommandLineElementDbAction::CommandLineElementDbAction() :
 | 
|---|
| 28 |   Action(NAME)
 | 
|---|
| 29 | {}
 | 
|---|
| 30 | 
 | 
|---|
| 31 | CommandLineElementDbAction::~CommandLineElementDbAction()
 | 
|---|
| 32 | {}
 | 
|---|
| 33 | 
 | 
|---|
| 34 | Action::state_ptr CommandLineElementDbAction::performCall() {
 | 
|---|
| 35 |   ostringstream usage;
 | 
|---|
| 36 |   string databasepath;
 | 
|---|
| 37 |   Dialog *dialog = UIFactory::getInstance().makeDialog();
 | 
|---|
| 38 | 
 | 
|---|
| 39 |   // get the path
 | 
|---|
| 40 |   // TODO: Make databasepath a std::string
 | 
|---|
| 41 |   config *configuration = World::getInstance().getConfig();
 | 
|---|
| 42 |   dialog->queryString(NAME, &databasepath, MapOfActions::getInstance().getDescription(NAME));
 | 
|---|
| 43 |   strcpy(configuration->databasepath, databasepath.c_str());
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   if(dialog->display()) {
 | 
|---|
| 46 |     delete dialog;
 | 
|---|
| 47 |   } else {
 | 
|---|
| 48 |     delete dialog;
 | 
|---|
| 49 |   }
 | 
|---|
| 50 | 
 | 
|---|
| 51 |   // load table
 | 
|---|
| 52 |   periodentafel *periode = World::getInstance().getPeriode();
 | 
|---|
| 53 |   if (periode->LoadPeriodentafel(configuration->databasepath)) {
 | 
|---|
| 54 |     DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
 | 
|---|
| 55 |     //periode->Output();
 | 
|---|
| 56 |     return Action::success;
 | 
|---|
| 57 |   } else {
 | 
|---|
| 58 |     DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
 | 
|---|
| 59 |     return Action::failure;
 | 
|---|
| 60 |   }
 | 
|---|
| 61 | 
 | 
|---|
| 62 | }
 | 
|---|
| 63 | 
 | 
|---|
| 64 | Action::state_ptr CommandLineElementDbAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 65 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
 | 
|---|
| 66 | 
 | 
|---|
| 67 |   return Action::failure;
 | 
|---|
| 68 | //  string newName = state->mol->getName();
 | 
|---|
| 69 | //  state->mol->setName(state->lastName);
 | 
|---|
| 70 | //
 | 
|---|
| 71 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
 | 
|---|
| 72 | }
 | 
|---|
| 73 | 
 | 
|---|
| 74 | Action::state_ptr CommandLineElementDbAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 75 |   return Action::failure;
 | 
|---|
| 76 | }
 | 
|---|
| 77 | 
 | 
|---|
| 78 | bool CommandLineElementDbAction::canUndo() {
 | 
|---|
| 79 |   return false;
 | 
|---|
| 80 | }
 | 
|---|
| 81 | 
 | 
|---|
| 82 | bool CommandLineElementDbAction::shouldUndo() {
 | 
|---|
| 83 |   return false;
 | 
|---|
| 84 | }
 | 
|---|
| 85 | 
 | 
|---|
| 86 | const string CommandLineElementDbAction::getName() {
 | 
|---|
| 87 |   return NAME;
 | 
|---|
| 88 | }
 | 
|---|