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