1 | /*
|
---|
2 | * VerletIntegrationAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 10, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/MoleculeAction/VerletIntegrationAction.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 | /****** MoleculeVerletIntegrationAction *****/
|
---|
28 |
|
---|
29 | // memento to remember the state when undoing
|
---|
30 |
|
---|
31 | //class MoleculeVerletIntegrationState : public ActionState {
|
---|
32 | //public:
|
---|
33 | // MoleculeVerletIntegrationState(molecule* _mol,std::string _lastName) :
|
---|
34 | // mol(_mol),
|
---|
35 | // lastName(_lastName)
|
---|
36 | // {}
|
---|
37 | // molecule* mol;
|
---|
38 | // std::string lastName;
|
---|
39 | //};
|
---|
40 |
|
---|
41 | const char MoleculeVerletIntegrationAction::NAME[] = "verlet-integrate";
|
---|
42 |
|
---|
43 | MoleculeVerletIntegrationAction::MoleculeVerletIntegrationAction() :
|
---|
44 | Action(NAME)
|
---|
45 | {}
|
---|
46 |
|
---|
47 | MoleculeVerletIntegrationAction::~MoleculeVerletIntegrationAction()
|
---|
48 | {}
|
---|
49 |
|
---|
50 | void MoleculeVerletIntegration(std::string &forcesfile) {
|
---|
51 | ValueStorage::getInstance().setCurrentValue(MoleculeVerletIntegrationAction::NAME, forcesfile);
|
---|
52 | ActionRegistry::getInstance().getActionByName(MoleculeVerletIntegrationAction::NAME)->call(Action::NonInteractive);
|
---|
53 | };
|
---|
54 |
|
---|
55 | Dialog* MoleculeVerletIntegrationAction::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 MoleculeVerletIntegrationAction::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) << "Parsing forces file and Verlet integrating." << endl);
|
---|
72 | // TODO: sollte besser stream nutzen, nicht filename direkt (es sei denn, ist prefix), besser fuer unit test
|
---|
73 | char outputname[MAXSTRINGSIZE];
|
---|
74 | strcpy(outputname, filename.c_str());
|
---|
75 | if (!mol->VerletForceIntegration(outputname, *(World::getInstance().getConfig()), 0))
|
---|
76 | DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
|
---|
77 | else
|
---|
78 | DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
|
---|
79 | }
|
---|
80 | return Action::success;
|
---|
81 | }
|
---|
82 |
|
---|
83 | Action::state_ptr MoleculeVerletIntegrationAction::performUndo(Action::state_ptr _state) {
|
---|
84 | // MoleculeVerletIntegrationState *state = assert_cast<MoleculeVerletIntegrationState*>(_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 MoleculeVerletIntegrationAction::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 MoleculeVerletIntegrationAction::canUndo() {
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 |
|
---|
101 | bool MoleculeVerletIntegrationAction::shouldUndo() {
|
---|
102 | return false;
|
---|
103 | }
|
---|
104 |
|
---|
105 | const string MoleculeVerletIntegrationAction::getName() {
|
---|
106 | return NAME;
|
---|
107 | }
|
---|