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 |
|
---|
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"
|
---|
20 | #include "UIElements/ValueStorage.hpp"
|
---|
21 |
|
---|
22 | #include "log.hpp"
|
---|
23 | #include "molecule.hpp"
|
---|
24 | #include "verbose.hpp"
|
---|
25 | #include "World.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 | Dialog* MoleculeVerletIntegrationAction::createDialog() {
|
---|
51 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
52 |
|
---|
53 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
54 |
|
---|
55 | return dialog;
|
---|
56 | }
|
---|
57 |
|
---|
58 | Action::state_ptr MoleculeVerletIntegrationAction::performCall() {
|
---|
59 | string filename;
|
---|
60 | molecule *mol = NULL;
|
---|
61 |
|
---|
62 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
63 |
|
---|
64 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
65 | mol = iter->second;
|
---|
66 | DoLog(1) && (Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl);
|
---|
67 | // TODO: sollte besser stream nutzen, nicht filename direkt (es sei denn, ist prefix), besser fuer unit test
|
---|
68 | char outputname[MAXSTRINGSIZE];
|
---|
69 | strcpy(outputname, filename.c_str());
|
---|
70 | if (!mol->VerletForceIntegration(outputname, *(World::getInstance().getConfig()), 0))
|
---|
71 | DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
|
---|
72 | else
|
---|
73 | DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
|
---|
74 | }
|
---|
75 | return Action::success;
|
---|
76 | }
|
---|
77 |
|
---|
78 | Action::state_ptr MoleculeVerletIntegrationAction::performUndo(Action::state_ptr _state) {
|
---|
79 | // MoleculeVerletIntegrationState *state = assert_cast<MoleculeVerletIntegrationState*>(_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 MoleculeVerletIntegrationAction::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 MoleculeVerletIntegrationAction::canUndo() {
|
---|
93 | return false;
|
---|
94 | }
|
---|
95 |
|
---|
96 | bool MoleculeVerletIntegrationAction::shouldUndo() {
|
---|
97 | return false;
|
---|
98 | }
|
---|
99 |
|
---|
100 | const string MoleculeVerletIntegrationAction::getName() {
|
---|
101 | return NAME;
|
---|
102 | }
|
---|