[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"
|
---|
| 11 |
|
---|
| 12 | #include <iostream>
|
---|
| 13 | #include <fstream>
|
---|
| 14 | #include <string>
|
---|
| 15 |
|
---|
| 16 | using namespace std;
|
---|
| 17 |
|
---|
| 18 | #include "UIElements/UIFactory.hpp"
|
---|
| 19 | #include "UIElements/Dialog.hpp"
|
---|
[09cf39] | 20 | #include "UIElements/ValueStorage.hpp"
|
---|
[97ebf8] | 21 |
|
---|
| 22 | #include "log.hpp"
|
---|
| 23 | #include "molecule.hpp"
|
---|
| 24 | #include "verbose.hpp"
|
---|
| 25 | #include "World.hpp"
|
---|
| 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 |
|
---|
[09cf39] | 50 | Dialog* MoleculeSaveTemperatureAction::createDialog() {
|
---|
| 51 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 52 |
|
---|
| 53 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 54 |
|
---|
| 55 | return dialog;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[97ebf8] | 58 | Action::state_ptr MoleculeSaveTemperatureAction::performCall() {
|
---|
| 59 | string filename;
|
---|
| 60 | molecule *mol = NULL;
|
---|
| 61 |
|
---|
[09cf39] | 62 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
[97ebf8] | 63 |
|
---|
[09cf39] | 64 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 65 | mol = iter->second;
|
---|
[97ebf8] | 66 | DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl);
|
---|
| 67 | ofstream output;
|
---|
| 68 | output.open(filename.c_str(), ios::trunc);
|
---|
| 69 | if (output.fail() || !mol->OutputTemperatureFromTrajectories((ofstream * const) &output, 0, mol->MDSteps))
|
---|
| 70 | DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl);
|
---|
| 71 | else
|
---|
| 72 | DoLog(2) && (Log() << Verbose(2) << "File stored." << endl);
|
---|
| 73 | output.close();
|
---|
| 74 | }
|
---|
[09cf39] | 75 | return Action::success;
|
---|
[97ebf8] | 76 | }
|
---|
| 77 |
|
---|
| 78 | Action::state_ptr MoleculeSaveTemperatureAction::performUndo(Action::state_ptr _state) {
|
---|
| 79 | // MoleculeSaveTemperatureState *state = assert_cast<MoleculeSaveTemperatureState*>(_state.get());
|
---|
| 80 |
|
---|
| 81 | // string newName = state->mol->getName();
|
---|
| 82 | // state->mol->setName(state->lastName);
|
---|
| 83 |
|
---|
| 84 | return Action::failure;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | Action::state_ptr MoleculeSaveTemperatureAction::performRedo(Action::state_ptr _state){
|
---|
| 88 | // Undo and redo have to do the same for this action
|
---|
| 89 | return performUndo(_state);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | bool MoleculeSaveTemperatureAction::canUndo() {
|
---|
| 93 | return false;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | bool MoleculeSaveTemperatureAction::shouldUndo() {
|
---|
| 97 | return false;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | const string MoleculeSaveTemperatureAction::getName() {
|
---|
| 101 | return NAME;
|
---|
| 102 | }
|
---|