| 1 | /*
|
|---|
| 2 | * ElementDbAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 9, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | // include config.h
|
|---|
| 9 | #ifdef HAVE_CONFIG_H
|
|---|
| 10 | #include <config.h>
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| 13 | #include "Helpers/MemDebug.hpp"
|
|---|
| 14 |
|
|---|
| 15 | #include "Actions/CmdAction/ElementDbAction.hpp"
|
|---|
| 16 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 17 | #include "config.hpp"
|
|---|
| 18 | #include "Helpers/Log.hpp"
|
|---|
| 19 | #include "periodentafel.hpp"
|
|---|
| 20 | #include "Helpers/Verbose.hpp"
|
|---|
| 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"
|
|---|
| 30 | #include "Actions/ValueStorage.hpp"
|
|---|
| 31 |
|
|---|
| 32 | const char CommandLineElementDbAction::NAME[] = "element-db";
|
|---|
| 33 |
|
|---|
| 34 | CommandLineElementDbAction::CommandLineElementDbAction() :
|
|---|
| 35 | Action(NAME)
|
|---|
| 36 | {}
|
|---|
| 37 |
|
|---|
| 38 | CommandLineElementDbAction::~CommandLineElementDbAction()
|
|---|
| 39 | {}
|
|---|
| 40 |
|
|---|
| 41 | void CommandElementDb(std::string &databasepath) {
|
|---|
| 42 | ValueStorage::getInstance().setCurrentValue(CommandLineElementDbAction::NAME, databasepath);
|
|---|
| 43 | ActionRegistry::getInstance().getActionByName(CommandLineElementDbAction::NAME)->call(Action::NonInteractive);
|
|---|
| 44 | };
|
|---|
| 45 |
|
|---|
| 46 | Dialog* CommandLineElementDbAction::fillDialog(Dialog *dialog) {
|
|---|
| 47 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| 48 |
|
|---|
| 49 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 50 |
|
|---|
| 51 | return dialog;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 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();
|
|---|
| 61 | ValueStorage::getInstance().queryCurrentValue(NAME, databasepath);
|
|---|
| 62 | strcpy(configuration->databasepath, databasepath.c_str());
|
|---|
| 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 | }
|
|---|