| [97ebf8] | 1 | /*
 | 
|---|
 | 2 |  * ConvexEnvelopeAction.cpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: May 12, 2010
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
 | 
|---|
 | 9 | 
 | 
|---|
 | 10 | #include <iostream>
 | 
|---|
 | 11 | #include <string>
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | using namespace std;
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 16 | #include "UIElements/Dialog.hpp"
 | 
|---|
 | 17 | #include "Actions/MapOfActions.hpp"
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 | #include "atom.hpp"
 | 
|---|
 | 20 | #include "boundary.hpp"
 | 
|---|
 | 21 | #include "linkedcell.hpp"
 | 
|---|
 | 22 | #include "log.hpp"
 | 
|---|
 | 23 | #include "molecule.hpp"
 | 
|---|
 | 24 | #include "verbose.hpp"
 | 
|---|
 | 25 | #include "World.hpp"
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 | /****** TesselationConvexEnvelopeAction *****/
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 | // memento to remember the state when undoing
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | //class TesselationConvexEnvelopeState : public ActionState {
 | 
|---|
 | 32 | //public:
 | 
|---|
 | 33 | //  TesselationConvexEnvelopeState(molecule* _mol,std::string _lastName) :
 | 
|---|
 | 34 | //    mol(_mol),
 | 
|---|
 | 35 | //    lastName(_lastName)
 | 
|---|
 | 36 | //  {}
 | 
|---|
 | 37 | //  molecule* mol;
 | 
|---|
 | 38 | //  std::string lastName;
 | 
|---|
 | 39 | //};
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | const char TesselationConvexEnvelopeAction::NAME[] = "convex-envelope";
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | TesselationConvexEnvelopeAction::TesselationConvexEnvelopeAction() :
 | 
|---|
 | 44 |   Action(NAME)
 | 
|---|
 | 45 | {}
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | TesselationConvexEnvelopeAction::~TesselationConvexEnvelopeAction()
 | 
|---|
 | 48 | {}
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | Action::state_ptr TesselationConvexEnvelopeAction::performCall() {
 | 
|---|
 | 51 |   string filenameConvex;
 | 
|---|
 | 52 |   string filenameNonConvex;
 | 
|---|
 | 53 |   Dialog *dialog = UIFactory::getInstance().makeDialog();
 | 
|---|
 | 54 |   molecule * mol = NULL;
 | 
|---|
 | 55 |   bool Success = false;
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 |   dialog->queryMolecule(NAME, &mol, MapOfActions::getInstance().getDescription(NAME));
 | 
|---|
 | 58 |   dialog->queryString("output", &filenameConvex, MapOfActions::getInstance().getDescription("output"));
 | 
|---|
 | 59 |   dialog->queryString("output", &filenameNonConvex, MapOfActions::getInstance().getDescription("output"));
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 |   if(dialog->display()) {
 | 
|---|
 | 62 |     class Tesselation *TesselStruct = NULL;
 | 
|---|
 | 63 |     const LinkedCell *LCList = NULL;
 | 
|---|
 | 64 |     DoLog(0) && (Log() << Verbose(0) << "Evaluating volume of the convex envelope.");
 | 
|---|
 | 65 |     DoLog(1) && (Log() << Verbose(1) << "Storing tecplot convex data in " << filenameConvex << "." << endl);
 | 
|---|
 | 66 |     DoLog(1) && (Log() << Verbose(1) << "Storing tecplot non-convex data in " << filenameNonConvex << "." << endl);
 | 
|---|
 | 67 |     LCList = new LinkedCell(mol, 100.);
 | 
|---|
 | 68 |     //FindConvexBorder(mol, LCList, argv[argptr]);
 | 
|---|
 | 69 |     // TODO: Beide Funktionen sollten streams anstelle des Filenamen benutzen, besser fuer unit tests
 | 
|---|
 | 70 |     FindNonConvexBorder(mol, TesselStruct, LCList, 50., filenameNonConvex.c_str());
 | 
|---|
 | 71 |     //RemoveAllBoundaryPoints(TesselStruct, mol, argv[argptr]);
 | 
|---|
 | 72 |     ConvexizeNonconvexEnvelope(TesselStruct, mol, filenameConvex.c_str());
 | 
|---|
 | 73 |     delete(TesselStruct);
 | 
|---|
 | 74 |     delete(LCList);
 | 
|---|
 | 75 |     delete dialog;
 | 
|---|
 | 76 |     if (Success)
 | 
|---|
 | 77 |       return Action::success;
 | 
|---|
 | 78 |     else
 | 
|---|
 | 79 |       return Action::failure;
 | 
|---|
 | 80 |   }
 | 
|---|
 | 81 |   delete dialog;
 | 
|---|
 | 82 |   return Action::failure;
 | 
|---|
 | 83 | }
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 | Action::state_ptr TesselationConvexEnvelopeAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 86 | //  TesselationConvexEnvelopeState *state = assert_cast<TesselationConvexEnvelopeState*>(_state.get());
 | 
|---|
 | 87 | 
 | 
|---|
 | 88 | //  string newName = state->mol->getName();
 | 
|---|
 | 89 | //  state->mol->setName(state->lastName);
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 |   return Action::failure;
 | 
|---|
 | 92 | }
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | Action::state_ptr TesselationConvexEnvelopeAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 95 |   // Undo and redo have to do the same for this action
 | 
|---|
 | 96 |   return performUndo(_state);
 | 
|---|
 | 97 | }
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 | bool TesselationConvexEnvelopeAction::canUndo() {
 | 
|---|
 | 100 |   return false;
 | 
|---|
 | 101 | }
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 | bool TesselationConvexEnvelopeAction::shouldUndo() {
 | 
|---|
 | 104 |   return false;
 | 
|---|
 | 105 | }
 | 
|---|
 | 106 | 
 | 
|---|
 | 107 | const string TesselationConvexEnvelopeAction::getName() {
 | 
|---|
 | 108 |   return NAME;
 | 
|---|
 | 109 | }
 | 
|---|