[97ebf8] | 1 | /*
|
---|
| 2 | * ElementDbAction.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/ElementDbAction.hpp"
|
---|
| 11 | #include "config.hpp"
|
---|
| 12 | #include "log.hpp"
|
---|
| 13 | #include "periodentafel.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 CommandLineElementDbAction::NAME[] = "element-db";
|
---|
| 27 |
|
---|
| 28 | CommandLineElementDbAction::CommandLineElementDbAction() :
|
---|
| 29 | Action(NAME)
|
---|
| 30 | {}
|
---|
| 31 |
|
---|
| 32 | CommandLineElementDbAction::~CommandLineElementDbAction()
|
---|
| 33 | {}
|
---|
| 34 |
|
---|
| 35 | Action::state_ptr CommandLineElementDbAction::performCall() {
|
---|
| 36 | ostringstream usage;
|
---|
| 37 | string databasepath;
|
---|
| 38 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 39 |
|
---|
| 40 | // get the path
|
---|
| 41 | // TODO: Make databasepath a std::string
|
---|
| 42 | config *configuration = World::getInstance().getConfig();
|
---|
| 43 | dialog->queryString(NAME, &databasepath, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 44 |
|
---|
| 45 | if(dialog->display()) {
|
---|
[198494] | 46 | strcpy(configuration->databasepath, databasepath.c_str());
|
---|
[97ebf8] | 47 | delete dialog;
|
---|
| 48 | } else {
|
---|
| 49 | delete dialog;
|
---|
[198494] | 50 | return Action::failure;
|
---|
[97ebf8] | 51 | }
|
---|
| 52 |
|
---|
| 53 | // load table
|
---|
| 54 | periodentafel *periode = World::getInstance().getPeriode();
|
---|
| 55 | if (periode->LoadPeriodentafel(configuration->databasepath)) {
|
---|
| 56 | DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
|
---|
| 57 | //periode->Output();
|
---|
| 58 | return Action::success;
|
---|
| 59 | } else {
|
---|
| 60 | DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
|
---|
| 61 | return Action::failure;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | Action::state_ptr CommandLineElementDbAction::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 CommandLineElementDbAction::performRedo(Action::state_ptr _state){
|
---|
| 77 | return Action::failure;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | bool CommandLineElementDbAction::canUndo() {
|
---|
| 81 | return false;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | bool CommandLineElementDbAction::shouldUndo() {
|
---|
| 85 | return false;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | const string CommandLineElementDbAction::getName() {
|
---|
| 89 | return NAME;
|
---|
| 90 | }
|
---|