#include <StdMeshers_QuadToTriaAdaptor.hxx>
#include <StdMeshers_ViscousLayers2D.hxx>
+#include <SALOMEDS_Tool.hxx>
+
#include <utilities.h>
#include <BRepBuilderAPI_Copy.hxx>
#include <Bnd_B3d.hxx>
#include <NCollection_Map.hxx>
#include <Standard_ErrorHandler.hxx>
+#include <Standard_ProgramError.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopoDS.hxx>
+#include <OSD_File.hxx>
+#include <OSD_Path.hxx>
// Netgen include files
#ifndef OCCGEOMETRY
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"
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
NETGENPlugin_NetgenLibWrapper::NETGENPlugin_NetgenLibWrapper()
{
- Ng_Init();
+ myOutputFile = getOutputFileName();
+ Ng_Init( myOutputFile.c_str() );
_ngMesh = Ng_NewMesh();
}
Ng_DeleteMesh( _ngMesh );
Ng_Exit();
NETGENPlugin_Mesher::RemoveTmpFiles();
+ if( isComputeOk )
+ RemoveOutputFile();
}
//================================================================================
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 );
+}
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
const std::string& pyFile); // debug
private:
+ bool _compute( NETGENPlugin_NetgenLibWrapper* ngLib );
+
SMESH_Mesh* _mesh;
const TopoDS_Shape& _shape;
bool _isVolume;
};
-//================================================================================
-/*!
- * \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