| [b9c847] | 1 | /*
 | 
|---|
 | 2 |  * SetOutputFormatsAction.cpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: May 8, 2010
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 9 | 
 | 
|---|
 | 10 | #include "Actions/WorldAction/SetOutputFormatsAction.hpp"
 | 
|---|
| [0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| [b9c847] | 12 | #include "Parser/ChangeTracker.hpp"
 | 
|---|
 | 13 | #include "Parser/FormatParserStorage.hpp"
 | 
|---|
| [952f38] | 14 | #include "Helpers/Log.hpp"
 | 
|---|
 | 15 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [b9c847] | 16 | #include "World.hpp"
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | #include <iostream>
 | 
|---|
 | 19 | #include <string>
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | using namespace std;
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 24 | #include "UIElements/Dialog.hpp"
 | 
|---|
| [861874] | 25 | #include "Actions/ValueStorage.hpp"
 | 
|---|
| [b9c847] | 26 | 
 | 
|---|
 | 27 | const char WorldSetOutputFormatsAction::NAME[] = "set-output";
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 | WorldSetOutputFormatsAction::WorldSetOutputFormatsAction() :
 | 
|---|
 | 30 |   Action(NAME)
 | 
|---|
 | 31 | {}
 | 
|---|
 | 32 | 
 | 
|---|
 | 33 | WorldSetOutputFormatsAction::~WorldSetOutputFormatsAction()
 | 
|---|
 | 34 | {}
 | 
|---|
 | 35 | 
 | 
|---|
| [a8f6ae] | 36 | void WorldSetOutputFormats(vector<std::string> &FormatList) {
 | 
|---|
 | 37 |   ValueStorage::getInstance().setCurrentValue(WorldSetOutputFormatsAction::NAME, FormatList);
 | 
|---|
 | 38 |   ActionRegistry::getInstance().getActionByName(WorldSetOutputFormatsAction::NAME)->call(Action::NonInteractive);
 | 
|---|
 | 39 | };
 | 
|---|
 | 40 | 
 | 
|---|
| [047878] | 41 | Dialog* WorldSetOutputFormatsAction::fillDialog(Dialog *dialog) {
 | 
|---|
 | 42 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| [ff22c5] | 43 | 
 | 
|---|
 | 44 |   dialog->queryStrings(NAME, ValueStorage::getInstance().getDescription(NAME));
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 |   return dialog;
 | 
|---|
 | 47 | }
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | Action::state_ptr WorldSetOutputFormatsAction::performCall() {
 | 
|---|
| [b9c847] | 50 |   vector<std::string> FormatList;
 | 
|---|
 | 51 | 
 | 
|---|
| [ff22c5] | 52 |   ValueStorage::getInstance().queryCurrentValue(NAME, FormatList);
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 |   for (vector<std::string>::iterator iter = FormatList.begin(); iter != FormatList.end(); ++iter) {
 | 
|---|
 | 55 |     if (*iter == "mpqc") {
 | 
|---|
 | 56 |       FormatParserStorage::getInstance().addMpqc();
 | 
|---|
 | 57 |       DoLog(0) && (Log() << Verbose(0) << "Adding mpqc type to output." << endl);
 | 
|---|
 | 58 |     } else if (*iter == "pcp") {
 | 
|---|
 | 59 |       FormatParserStorage::getInstance().addPcp();
 | 
|---|
 | 60 |       DoLog(0) && (Log() << Verbose(0) << "Adding pcp type to output." << endl);
 | 
|---|
 | 61 |     } else if (*iter == "tremolo") {
 | 
|---|
 | 62 |       FormatParserStorage::getInstance().addTremolo();
 | 
|---|
 | 63 |       DoLog(0) && (Log() << Verbose(0) << "Adding tremolo type to output." << endl);
 | 
|---|
 | 64 |     } else if (*iter == "xyz") {
 | 
|---|
 | 65 |       FormatParserStorage::getInstance().addXyz();
 | 
|---|
 | 66 |       DoLog(0) && (Log() << Verbose(0) << "Adding xyz type to output." << endl);
 | 
|---|
 | 67 |     } else {
 | 
|---|
| [dde125] | 68 |       DoeLog(1) && (eLog() << Verbose(1) << "Unknown format:" << *iter << endl);
 | 
|---|
| [b9c847] | 69 |     }
 | 
|---|
 | 70 |   }
 | 
|---|
| [ff22c5] | 71 |   ChangeTracker::getInstance().saveStatus();
 | 
|---|
 | 72 |   return Action::success;
 | 
|---|
| [b9c847] | 73 | }
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | Action::state_ptr WorldSetOutputFormatsAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 76 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 |   return Action::failure;
 | 
|---|
 | 79 | //  string newName = state->mol->getName();
 | 
|---|
 | 80 | //  state->mol->setName(state->lastName);
 | 
|---|
 | 81 | //
 | 
|---|
 | 82 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
 | 
|---|
 | 83 | }
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 | Action::state_ptr WorldSetOutputFormatsAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 86 |   return Action::failure;
 | 
|---|
 | 87 | }
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 | bool WorldSetOutputFormatsAction::canUndo() {
 | 
|---|
 | 90 |   return false;
 | 
|---|
 | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | bool WorldSetOutputFormatsAction::shouldUndo() {
 | 
|---|
 | 94 |   return false;
 | 
|---|
 | 95 | }
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | const string WorldSetOutputFormatsAction::getName() {
 | 
|---|
 | 98 |   return NAME;
 | 
|---|
 | 99 | }
 | 
|---|