From: akl Date: Fri, 31 May 2013 08:47:45 +0000 (+0000) Subject: Implementation of 0022170: [CEA 704] Redirect NETGEN outup in a log file. X-Git-Tag: V7_3_0a1~48 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=28e6f61a7eaf0cf7355a6c2066f22fb91b668e44;p=plugins%2Fnetgenplugin.git Implementation of 0022170: [CEA 704] Redirect NETGEN outup in a log file. Output of 'netgen' is redirected to temporary file. --- diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx index c6bfbd5..63f6c3c 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.cxx @@ -46,6 +46,8 @@ #include #include +#include + #include #include @@ -53,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +64,8 @@ #include #include #include +#include +#include // Netgen include files #ifndef OCCGEOMETRY @@ -2050,8 +2055,14 @@ namespace bool NETGENPlugin_Mesher::Compute() { - NETGENPlugin_NetgenLibWrapper ngLib; + NETGENPlugin_NetgenLibWrapper aNgLib; + +// Internal method is needed to get result of computation + return aNgLib.isComputeOk = _compute( &aNgLib ); +} +bool NETGENPlugin_Mesher::_compute( NETGENPlugin_NetgenLibWrapper* ngLib ) +{ netgen::MeshingParameters& mparams = netgen::mparam; MESSAGE("Compute with:\n" " max size = " << mparams.maxh << "\n" @@ -2142,7 +2153,7 @@ bool NETGENPlugin_Mesher::Compute() err = 0; //- MESHCONST_ANALYSE isn't so important step if ( !ngMesh ) return false; - ngLib.setMesh(( Ng_Mesh*) ngMesh ); + ngLib->setMesh(( Ng_Mesh*) ngMesh ); ngMesh->ClearFaceDescriptors(); // we make descriptors our-self @@ -3457,7 +3468,8 @@ SMESH_Mesh& NETGENPlugin_Internals::getMesh() const NETGENPlugin_NetgenLibWrapper::NETGENPlugin_NetgenLibWrapper() { - Ng_Init(); + myOutputFile = getOutputFileName(); + Ng_Init( myOutputFile.c_str() ); _ngMesh = Ng_NewMesh(); } @@ -3472,6 +3484,8 @@ NETGENPlugin_NetgenLibWrapper::~NETGENPlugin_NetgenLibWrapper() Ng_DeleteMesh( _ngMesh ); Ng_Exit(); NETGENPlugin_Mesher::RemoveTmpFiles(); + if( isComputeOk ) + RemoveOutputFile(); } //================================================================================ @@ -3486,3 +3500,40 @@ void NETGENPlugin_NetgenLibWrapper::setMesh( Ng_Mesh* mesh ) Ng_DeleteMesh( _ngMesh ); _ngMesh = mesh; } + +//================================================================================ +/*! + * \brief Return a unique file name + */ +//================================================================================ + +std::string NETGENPlugin_NetgenLibWrapper::getOutputFileName() +{ + std::string aTmpDir = SALOMEDS_Tool::GetTmpDir(); + + TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str(); + aGenericName += "NETGEN_"; + aGenericName += getpid(); + aGenericName += "_"; + aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString()); + aGenericName += ".out"; + + return aGenericName.ToCString(); +} + +//================================================================================ +/*! + * \brief Remove file with netgen output + */ +//================================================================================ + +void NETGENPlugin_NetgenLibWrapper::RemoveOutputFile() +{ + string tmpDir = SALOMEDS_Tool::GetDirFromPath( myOutputFile ); + SALOMEDS::ListOfFileNames_var aFiles = new SALOMEDS::ListOfFileNames; + aFiles->length(1); + std::string aFileName = SALOMEDS_Tool::GetNameFromPath( myOutputFile ) + ".out"; + aFiles[0] = aFileName.c_str(); + + SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.c_str(), aFiles.in(), true ); +} diff --git a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx index 6038e7f..f7bc370 100644 --- a/src/NETGENPlugin/NETGENPlugin_Mesher.hxx +++ b/src/NETGENPlugin/NETGENPlugin_Mesher.hxx @@ -72,6 +72,25 @@ struct NETGENPlugin_ngMeshInfo void restoreLocalH ( netgen::Mesh* ngMesh); }; +//================================================================================ +/*! + * \brief It correctly initializes netgen library at constructor and + * correctly finishes using netgen library at destructor + */ +//================================================================================ + +struct NETGENPLUGIN_EXPORT NETGENPlugin_NetgenLibWrapper +{ + std::string myOutputFile; + bool isComputeOk; + nglib::Ng_Mesh * _ngMesh; + NETGENPlugin_NetgenLibWrapper(); + ~NETGENPlugin_NetgenLibWrapper(); + void setMesh( nglib::Ng_Mesh* mesh ); + std::string getOutputFileName(); + void RemoveOutputFile(); +}; + //============================================================================= /*! * \brief This class calls the NETGEN mesher of OCC geometry @@ -150,6 +169,8 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Mesher const std::string& pyFile); // debug private: + bool _compute( NETGENPlugin_NetgenLibWrapper* ngLib ); + SMESH_Mesh* _mesh; const TopoDS_Shape& _shape; bool _isVolume; @@ -230,19 +251,4 @@ public: }; -//================================================================================ -/*! - * \brief It correctly initializes netgen library at constructor and - * correctly finishes using netgen library at destructor - */ -//================================================================================ - -struct NETGENPLUGIN_EXPORT NETGENPlugin_NetgenLibWrapper -{ - nglib::Ng_Mesh * _ngMesh; - NETGENPlugin_NetgenLibWrapper(); - ~NETGENPlugin_NetgenLibWrapper(); - void setMesh( nglib::Ng_Mesh* mesh ); -}; - #endif