[97ebf8] | 1 | /*
|
---|
| 2 | * ElementDbAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Actions/CmdAction/ElementDbAction.hpp"
|
---|
| 9 | #include "config.hpp"
|
---|
| 10 | #include "log.hpp"
|
---|
| 11 | #include "periodentafel.hpp"
|
---|
| 12 | #include "verbose.hpp"
|
---|
| 13 | #include "World.hpp"
|
---|
| 14 |
|
---|
| 15 | #include <iostream>
|
---|
| 16 | #include <string>
|
---|
| 17 |
|
---|
| 18 | using namespace std;
|
---|
| 19 |
|
---|
| 20 | #include "UIElements/UIFactory.hpp"
|
---|
| 21 | #include "UIElements/Dialog.hpp"
|
---|
| 22 | #include "Actions/MapOfActions.hpp"
|
---|
| 23 |
|
---|
| 24 | const char CommandLineElementDbAction::NAME[] = "element-db";
|
---|
| 25 |
|
---|
| 26 | CommandLineElementDbAction::CommandLineElementDbAction() :
|
---|
| 27 | Action(NAME)
|
---|
| 28 | {}
|
---|
| 29 |
|
---|
| 30 | CommandLineElementDbAction::~CommandLineElementDbAction()
|
---|
| 31 | {}
|
---|
| 32 |
|
---|
| 33 | Action::state_ptr CommandLineElementDbAction::performCall() {
|
---|
| 34 | ostringstream usage;
|
---|
| 35 | string databasepath;
|
---|
| 36 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 37 |
|
---|
| 38 | // get the path
|
---|
| 39 | // TODO: Make databasepath a std::string
|
---|
| 40 | config *configuration = World::getInstance().getConfig();
|
---|
| 41 | dialog->queryString(NAME, &databasepath, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 42 |
|
---|
| 43 | if(dialog->display()) {
|
---|
[198494] | 44 | strcpy(configuration->databasepath, databasepath.c_str());
|
---|
[97ebf8] | 45 | delete dialog;
|
---|
| 46 | } else {
|
---|
| 47 | delete dialog;
|
---|
[198494] | 48 | return Action::failure;
|
---|
[97ebf8] | 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 | }
|
---|