From 39841ffadd1f3ab43217a231183b4bf5d3555a73 Mon Sep 17 00:00:00 2001 From: eap Date: Thu, 11 Aug 2011 11:38:37 +0000 Subject: [PATCH] 0020511: EDF 1101 SMESH : Add CGNS to Mesh Format Supported make CGNS library an optional prerequisite --- adm_local/unix/config_files/check_cgns.m4 | 51 +++++++++++++---------- src/Makefile.am | 10 +++-- src/SMESH/Makefile.am | 6 ++- src/SMESH/SMESH_Mesh.cxx | 14 ++++++- src/SMESHGUI/SMESHGUI.cxx | 8 +++- src/SMESH_I/SMESH_Gen_i.cxx | 9 +++- src/SMESH_I/SMESH_Mesh_i.cxx | 4 ++ 7 files changed, 70 insertions(+), 32 deletions(-) diff --git a/adm_local/unix/config_files/check_cgns.m4 b/adm_local/unix/config_files/check_cgns.m4 index 75f85221e..3fb01001c 100644 --- a/adm_local/unix/config_files/check_cgns.m4 +++ b/adm_local/unix/config_files/check_cgns.m4 @@ -44,32 +44,37 @@ cgns_ok=no LOCAL_INCLUDES="" LOCAL_LIBS="-lcgns $HDF5_LIBS" -if test -z $CGNSHOME -then - AC_MSG_WARN(undefined CGNSHOME variable which specify CGNS library installation directory) - AC_PATH_PROG(BINDIR, cgnsversion) - if test "x$BINDIR" != "x" ; then - CGNSHOME=$BINDIR - CGNSHOME=`echo ${CGNSHOME} | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"` - CGNSHOME=`echo ${CGNSHOME} | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"` - fi -fi -if test ! -z $CGNSHOME -then - LOCAL_INCLUDES="-I$CGNSHOME/include" - if test "x$CGNSHOME" != "x/usr"; then - LOCAL_LIBS="-L$CGNSHOME/lib $LOCAL_LIBS" - fi -fi +if test "x$CGNSHOME" != "xno"; then + if test "x$CGNSHOME" == "xyes"; then + CGNSHOME="" + fi + if test -z $CGNSHOME + then + AC_MSG_WARN(undefined CGNSHOME variable which specify CGNS library installation directory) + AC_PATH_PROG(BINDIR, cgnsversion) + if test "x$BINDIR" != "x" ; then + CGNSHOME=$BINDIR + CGNSHOME=`echo ${CGNSHOME} | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"` + CGNSHOME=`echo ${CGNSHOME} | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"` + fi + fi + if test ! -z $CGNSHOME + then + LOCAL_INCLUDES="-I$CGNSHOME/include" + if test "x$CGNSHOME" != "x/usr"; then + LOCAL_LIBS="-L$CGNSHOME/lib $LOCAL_LIBS" + fi + fi dnl check cgnslib header -CPPFLAGS_old=$CPPFLAGS -CPPFLAGS="$CPPFLAGS $LOCAL_INCLUDES" + CPPFLAGS_old=$CPPFLAGS + CPPFLAGS="$CPPFLAGS $LOCAL_INCLUDES" -AC_CHECK_HEADER(cgnslib.h,cgns_ok=yes ,cgns_ok=no) + AC_CHECK_HEADER(cgnslib.h,cgns_ok=yes ,cgns_ok=no) -CPPFLAGS=$CPPFLAGS_old + CPPFLAGS=$CPPFLAGS_old +fi if test "x$cgns_ok" = "xyes" then @@ -88,11 +93,11 @@ if test "x$cgns_ok" = "xyes" then CGNS_LIBS="$LOCAL_LIBS" CGNS_INCLUDES="$LOCAL_INCLUDES" - #CPPFLAGS="-DWITH_CGNS $CPPFLAGS" + CPPFLAGS="-DWITH_CGNS $CPPFLAGS" fi AC_MSG_RESULT(for CGNS: $cgns_ok) -#AM_CONDITIONAL(WITH_CGNS, [test x"$cgns_ok" = xyes]) +AM_CONDITIONAL(WITH_CGNS, [test x"$cgns_ok" = xyes]) ])dnl diff --git a/src/Makefile.am b/src/Makefile.am index 81302eaf5..0e5088436 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,6 +25,10 @@ # include $(top_srcdir)/adm_local/unix/make_common_starter.am +if WITH_CGNS + DriverCGNS_SUDIR = DriverCGNS +endif + SUBDIRS = \ SMDS \ SMESHDS \ @@ -35,7 +39,7 @@ SUBDIRS = \ DriverDAT \ DriverUNV \ DriverSTL \ - DriverCGNS \ + $(DriverCGNS_SUDIR) \ SMESH \ SMESH_I \ SMESHClient \ @@ -56,6 +60,6 @@ if SMESH_ENABLE_GUI StdMeshersGUI endif -DIST_SUBDIRS = SMDS SMESHDS Controls Driver DriverMED DriverDAT DriverUNV DriverSTL SMESH \ - SMESH_I SMESHClient SMESH_SWIG MEFISTO2 StdMeshers StdMeshers_I OBJECT \ +DIST_SUBDIRS = SMDS SMESHDS Controls Driver DriverMED DriverDAT DriverUNV DriverSTL DriverCGNS \ + SMESH SMESH_I SMESHClient SMESH_SWIG MEFISTO2 StdMeshers StdMeshers_I OBJECT \ SMESHFiltersSelection SMESHGUI PluginUtils SMESH_SWIG_WITHIHM StdMeshersGUI SMESH_PY Tools diff --git a/src/SMESH/Makefile.am b/src/SMESH/Makefile.am index 040c9849f..461b4dc00 100644 --- a/src/SMESH/Makefile.am +++ b/src/SMESH/Makefile.am @@ -87,6 +87,10 @@ libSMESHimpl_la_CPPFLAGS = \ -I$(srcdir)/../SMESHDS \ -I$(srcdir)/../SMESHUtils +if WITH_CGNS + DriverCGNS_LIB = ../DriverCGNS/libMeshDriverCGNS.la +endif + libSMESHimpl_la_LDFLAGS = \ ../SMESHDS/libSMESHDS.la \ ../Controls/libSMESHControls.la \ @@ -94,7 +98,7 @@ libSMESHimpl_la_LDFLAGS = \ ../DriverSTL/libMeshDriverSTL.la \ ../DriverMED/libMeshDriverMED.la \ ../DriverUNV/libMeshDriverUNV.la \ - ../DriverCGNS/libMeshDriverCGNS.la \ + $(DriverCGNS_LIB) \ ../SMESHUtils/libSMESHUtils.la \ $(GEOM_LDFLAGS) -lNMTTools \ $(CAS_LDPATH) -lTKShHealing -lTKPrim -lTKG2d diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 7bc5b7ceb..4e61d614c 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -48,8 +48,10 @@ #include "DriverMED_R_SMESHDS_Mesh.h" #include "DriverUNV_R_SMDS_Mesh.h" #include "DriverSTL_R_SMDS_Mesh.h" +#ifdef WITH_CGNS #include "DriverCGNS_Read.hxx" #include "DriverCGNS_Write.hxx" +#endif #undef _Precision_HeaderFile #include @@ -455,16 +457,20 @@ int SMESH_Mesh::CGNSToMesh(const char* theFileName, const int theMeshIndex, std::string& theMeshName) { + int res = Driver_Mesh::DRS_FAIL; +#ifdef WITH_CGNS + DriverCGNS_Read myReader; myReader.SetMesh(_myMeshDS); myReader.SetFile(theFileName); myReader.SetMeshId(theMeshIndex); - int res = myReader.Perform(); + res = myReader.Perform(); theMeshName = myReader.GetMeshName(); // create groups SynchronizeGroups(); +#endif return res; } @@ -1256,11 +1262,15 @@ void SMESH_Mesh::ExportSTL(const char * file, void SMESH_Mesh::ExportCGNS(const char * file, const SMESHDS_Mesh* meshDS) { + int res = Driver_Mesh::DRS_FAIL; +#ifdef WITH_CGNS DriverCGNS_Write myWriter; myWriter.SetFile( file ); myWriter.SetMesh( const_cast( meshDS )); myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId()); - if ( myWriter.Perform() != Driver_Mesh::DRS_OK ) + res = myWriter.Perform(); +#endif + if ( res != Driver_Mesh::DRS_OK ) throw SALOME_Exception("Export failed"); } diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 32576d437..bfb3d2d30 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -3502,14 +3502,16 @@ void SMESHGUI::initialize( CAM_Application* app ) createMenu( 112, importId, -1 ); createMenu( 113, importId, -1 ); createMenu( 115, importId, -1 ); +#ifdef WITH_CGNS createMenu( 116, importId, -1 ); - +#endif createMenu( 121, exportId, -1 ); createMenu( 122, exportId, -1 ); createMenu( 123, exportId, -1 ); createMenu( 140, exportId, -1 ); // export to STL +#ifdef WITH_CGNS createMenu( 142, exportId, -1 ); // export to CGNS - +#endif createMenu( separator(), fileId, 10 ); createMenu( 33, editId, -1 ); @@ -3810,7 +3812,9 @@ void SMESHGUI::initialize( CAM_Application* app ) createPopupItem( 125, OB, mesh_group, multiple_non_empty ); // EXPORT_MED createPopupItem( 126, OB, mesh_group, only_one_non_empty ); // EXPORT_UNV createPopupItem( 141, OB, mesh_group, only_one_2D ); // EXPORT_STL +#ifdef WITH_CGNS createPopupItem( 143, OB, mesh_group, multiple_non_empty ); // EXPORT_CGNS +#endif createPopupItem( 33, OB, mesh_part + " " + hyp_alg ); // DELETE popupMgr()->insert( separator(), -1, 0 ); diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 3197d7204..887aeacc0 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -100,7 +100,9 @@ #include "DriverMED_W_SMESHDS_Mesh.h" #include "DriverMED_R_SMESHDS_Mesh.h" +#ifdef WITH_CGNS #include "DriverCGNS_Read.hxx" +#endif #include "SALOMEDS_Tool.hxx" #include "SALOME_NamingService.hxx" @@ -1036,6 +1038,9 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName, { Unexpect aCatch(SALOME_SalomeException); + SMESH::mesh_array_var aResult = new SMESH::mesh_array(); + +#ifdef WITH_CGNS // Retrieve nb meshes from the file DriverCGNS_Read myReader; myReader.SetFile( theFileName ); @@ -1043,7 +1048,6 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName, int nbMeshes = myReader.GetNbMeshes(aStatus); theStatus = (SMESH::DriverMED_ReadStatus)aStatus; - SMESH::mesh_array_var aResult = new SMESH::mesh_array(); aResult->length( nbMeshes ); { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups() @@ -1098,6 +1102,9 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName, // Dump creation of groups for ( int i = 0; i < aResult->length(); ++i ) SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups(); +#else + THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR); +#endif return aResult._retn(); } diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 36604c7f8..17b974e3c 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -2784,6 +2784,7 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart, CORBA::Boolean overwrite) throw (SALOME::SALOME_Exception) { +#ifdef WITH_CGNS Unexpect aCatch(SALOME_SalomeException); PrepareForWriting(file,overwrite); @@ -2793,6 +2794,9 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart, TPythonDump() << _this() << ".ExportCGNS( " << meshPart<< ", r'" << file << "', " << overwrite << ")"; +#else + THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR); +#endif } //============================================================================= -- 2.39.2