[97ebf8] | 1 | /*
|
---|
| 2 | * VerletIntegrationAction.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/VerletIntegrationAction.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 | /****** 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 |
|
---|
[1a3c26] | 50 | void MoleculeVerletIntegration(std::string &forcesfile) {
|
---|
| 51 | ValueStorage::getInstance().setCurrentValue(MoleculeVerletIntegrationAction::NAME, forcesfile);
|
---|
| 52 | ActionRegistry::getInstance().getActionByName(MoleculeVerletIntegrationAction::NAME)->call(Action::NonInteractive);
|
---|
| 53 | };
|
---|
| 54 |
|
---|
[047878] | 55 | Dialog* MoleculeVerletIntegrationAction::fillDialog(Dialog *dialog) {
|
---|
| 56 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[bcd16a] | 57 |
|
---|
| 58 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 59 |
|
---|
| 60 | return dialog;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[97ebf8] | 63 | Action::state_ptr MoleculeVerletIntegrationAction::performCall() {
|
---|
| 64 | string filename;
|
---|
| 65 | molecule *mol = NULL;
|
---|
| 66 |
|
---|
[bcd16a] | 67 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
[97ebf8] | 68 |
|
---|
[bcd16a] | 69 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 70 | mol = iter->second;
|
---|
[97ebf8] | 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());
|
---|
[ef7d30] | 75 | if (!mol->VerletForceIntegration(outputname, *(World::getInstance().getConfig()), 0))
|
---|
[97ebf8] | 76 | DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
|
---|
| 77 | else
|
---|
| 78 | DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
|
---|
| 79 | }
|
---|
[bcd16a] | 80 | return Action::success;
|
---|
[97ebf8] | 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 | }
|
---|