[97ebf8] | 1 | /*
|
---|
| 2 | * SaveTemperatureAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 10, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/MoleculeAction/SaveTemperatureAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[952f38] | 12 | #include "Helpers/Log.hpp"
|
---|
[1a3c26] | 13 | #include "molecule.hpp"
|
---|
[952f38] | 14 | #include "Helpers/Verbose.hpp"
|
---|
[1a3c26] | 15 | #include "World.hpp"
|
---|
[97ebf8] | 16 |
|
---|
| 17 | #include <iostream>
|
---|
| 18 | #include <fstream>
|
---|
| 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"
|
---|
[97ebf8] | 26 |
|
---|
| 27 | /****** MoleculeSaveTemperatureAction *****/
|
---|
| 28 |
|
---|
| 29 | // memento to remember the state when undoing
|
---|
| 30 |
|
---|
| 31 | //class MoleculeSaveTemperatureState : public ActionState {
|
---|
| 32 | //public:
|
---|
| 33 | // MoleculeSaveTemperatureState(molecule* _mol,std::string _lastName) :
|
---|
| 34 | // mol(_mol),
|
---|
| 35 | // lastName(_lastName)
|
---|
| 36 | // {}
|
---|
| 37 | // molecule* mol;
|
---|
| 38 | // std::string lastName;
|
---|
| 39 | //};
|
---|
| 40 |
|
---|
| 41 | const char MoleculeSaveTemperatureAction::NAME[] = "save-temperature";
|
---|
| 42 |
|
---|
| 43 | MoleculeSaveTemperatureAction::MoleculeSaveTemperatureAction() :
|
---|
| 44 | Action(NAME)
|
---|
| 45 | {}
|
---|
| 46 |
|
---|
| 47 | MoleculeSaveTemperatureAction::~MoleculeSaveTemperatureAction()
|
---|
| 48 | {}
|
---|
| 49 |
|
---|
[1a3c26] | 50 | void MoleculeSaveTemperature(std::string &temperaturefile) {
|
---|
| 51 | ValueStorage::getInstance().setCurrentValue(MoleculeSaveTemperatureAction::NAME, temperaturefile);
|
---|
| 52 | ActionRegistry::getInstance().getActionByName(MoleculeSaveTemperatureAction::NAME)->call(Action::NonInteractive);
|
---|
| 53 | };
|
---|
| 54 |
|
---|
[047878] | 55 | Dialog* MoleculeSaveTemperatureAction::fillDialog(Dialog *dialog) {
|
---|
| 56 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[09cf39] | 57 |
|
---|
| 58 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 59 |
|
---|
| 60 | return dialog;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[97ebf8] | 63 | Action::state_ptr MoleculeSaveTemperatureAction::performCall() {
|
---|
| 64 | string filename;
|
---|
| 65 | molecule *mol = NULL;
|
---|
| 66 |
|
---|
[09cf39] | 67 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
[97ebf8] | 68 |
|
---|
[09cf39] | 69 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 70 | mol = iter->second;
|
---|
[97ebf8] | 71 | DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl);
|
---|
| 72 | ofstream output;
|
---|
| 73 | output.open(filename.c_str(), ios::trunc);
|
---|
| 74 | if (output.fail() || !mol->OutputTemperatureFromTrajectories((ofstream * const) &output, 0, mol->MDSteps))
|
---|
| 75 | DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl);
|
---|
| 76 | else
|
---|
| 77 | DoLog(2) && (Log() << Verbose(2) << "File stored." << endl);
|
---|
| 78 | output.close();
|
---|
| 79 | }
|
---|
[09cf39] | 80 | return Action::success;
|
---|
[97ebf8] | 81 | }
|
---|
| 82 |
|
---|
| 83 | Action::state_ptr MoleculeSaveTemperatureAction::performUndo(Action::state_ptr _state) {
|
---|
| 84 | // MoleculeSaveTemperatureState *state = assert_cast<MoleculeSaveTemperatureState*>(_state.get());
|
---|
| 85 |
|
---|
| 86 | // string newName = state->mol->getName();
|
---|
| 87 | // state->mol->setName(state->lastName);
|
---|
| 88 |
|
---|
| 89 | return Action::failure;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | Action::state_ptr MoleculeSaveTemperatureAction::performRedo(Action::state_ptr _state){
|
---|
| 93 | // Undo and redo have to do the same for this action
|
---|
| 94 | return performUndo(_state);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | bool MoleculeSaveTemperatureAction::canUndo() {
|
---|
| 98 | return false;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | bool MoleculeSaveTemperatureAction::shouldUndo() {
|
---|
| 102 | return false;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | const string MoleculeSaveTemperatureAction::getName() {
|
---|
| 106 | return NAME;
|
---|
| 107 | }
|
---|