| 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 "Actions/MapOfActions.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include "atom.hpp"
|
|---|
| 23 | #include "log.hpp"
|
|---|
| 24 | #include "molecule.hpp"
|
|---|
| 25 | #include "verbose.hpp"
|
|---|
| 26 | #include "World.hpp"
|
|---|
| 27 |
|
|---|
| 28 | /****** MoleculeVerletIntegrationAction *****/
|
|---|
| 29 |
|
|---|
| 30 | // memento to remember the state when undoing
|
|---|
| 31 |
|
|---|
| 32 | //class MoleculeVerletIntegrationState : public ActionState {
|
|---|
| 33 | //public:
|
|---|
| 34 | // MoleculeVerletIntegrationState(molecule* _mol,std::string _lastName) :
|
|---|
| 35 | // mol(_mol),
|
|---|
| 36 | // lastName(_lastName)
|
|---|
| 37 | // {}
|
|---|
| 38 | // molecule* mol;
|
|---|
| 39 | // std::string lastName;
|
|---|
| 40 | //};
|
|---|
| 41 |
|
|---|
| 42 | const char MoleculeVerletIntegrationAction::NAME[] = "verlet-integrate";
|
|---|
| 43 |
|
|---|
| 44 | MoleculeVerletIntegrationAction::MoleculeVerletIntegrationAction() :
|
|---|
| 45 | Action(NAME)
|
|---|
| 46 | {}
|
|---|
| 47 |
|
|---|
| 48 | MoleculeVerletIntegrationAction::~MoleculeVerletIntegrationAction()
|
|---|
| 49 | {}
|
|---|
| 50 |
|
|---|
| 51 | Action::state_ptr MoleculeVerletIntegrationAction::performCall() {
|
|---|
| 52 | string filename;
|
|---|
| 53 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
|---|
| 54 | molecule *mol = NULL;
|
|---|
| 55 |
|
|---|
| 56 | dialog->queryString(NAME, &filename, MapOfActions::getInstance().getDescription(NAME));
|
|---|
| 57 | dialog->queryMolecule("molecule-by-id", &mol, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
|---|
| 58 |
|
|---|
| 59 | if(dialog->display()) {
|
|---|
| 60 | DoLog(1) && (Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl);
|
|---|
| 61 | // TODO: sollte besser stream nutzen, nicht filename direkt (es sei denn, ist prefix), besser fuer unit test
|
|---|
| 62 | char outputname[MAXSTRINGSIZE];
|
|---|
| 63 | strcpy(outputname, filename.c_str());
|
|---|
| 64 | if (!mol->VerletForceIntegration(outputname, *(World::getInstance().getConfig()), 0))
|
|---|
| 65 | DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
|
|---|
| 66 | else
|
|---|
| 67 | DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
|
|---|
| 68 |
|
|---|
| 69 | delete dialog;
|
|---|
| 70 | return Action::success;
|
|---|
| 71 | }
|
|---|
| 72 | delete dialog;
|
|---|
| 73 | return Action::failure;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | Action::state_ptr MoleculeVerletIntegrationAction::performUndo(Action::state_ptr _state) {
|
|---|
| 77 | // MoleculeVerletIntegrationState *state = assert_cast<MoleculeVerletIntegrationState*>(_state.get());
|
|---|
| 78 |
|
|---|
| 79 | // string newName = state->mol->getName();
|
|---|
| 80 | // state->mol->setName(state->lastName);
|
|---|
| 81 |
|
|---|
| 82 | return Action::failure;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | Action::state_ptr MoleculeVerletIntegrationAction::performRedo(Action::state_ptr _state){
|
|---|
| 86 | // Undo and redo have to do the same for this action
|
|---|
| 87 | return performUndo(_state);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | bool MoleculeVerletIntegrationAction::canUndo() {
|
|---|
| 91 | return false;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | bool MoleculeVerletIntegrationAction::shouldUndo() {
|
|---|
| 95 | return false;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | const string MoleculeVerletIntegrationAction::getName() {
|
|---|
| 99 | return NAME;
|
|---|
| 100 | }
|
|---|