1 | /*
|
---|
2 | * SaveTemperatureAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 10, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/MoleculeAction/SaveTemperatureAction.hpp"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "Helpers/Log.hpp"
|
---|
13 | #include "molecule.hpp"
|
---|
14 | #include "Helpers/Verbose.hpp"
|
---|
15 | #include "World.hpp"
|
---|
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"
|
---|
25 | #include "Actions/ValueStorage.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 |
|
---|
50 | void MoleculeSaveTemperature(std::string &temperaturefile) {
|
---|
51 | ValueStorage::getInstance().setCurrentValue(MoleculeSaveTemperatureAction::NAME, temperaturefile);
|
---|
52 | ActionRegistry::getInstance().getActionByName(MoleculeSaveTemperatureAction::NAME)->call(Action::NonInteractive);
|
---|
53 | };
|
---|
54 |
|
---|
55 | Dialog* MoleculeSaveTemperatureAction::fillDialog(Dialog *dialog) {
|
---|
56 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
57 |
|
---|
58 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
59 |
|
---|
60 | return dialog;
|
---|
61 | }
|
---|
62 |
|
---|
63 | Action::state_ptr MoleculeSaveTemperatureAction::performCall() {
|
---|
64 | string filename;
|
---|
65 | molecule *mol = NULL;
|
---|
66 |
|
---|
67 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
68 |
|
---|
69 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
70 | mol = iter->second;
|
---|
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 | }
|
---|
80 | return Action::success;
|
---|
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 | }
|
---|