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