From 8b381c1692c3ea010fbba687d43fd9d980921860 Mon Sep 17 00:00:00 2001 From: rnv Date: Wed, 27 Feb 2019 15:28:48 +0300 Subject: [PATCH] Porting to gmsh-4.1.4 --- adm_local/cmake_files/FindGMSH.cmake | 4 +- src/GMSHPlugin/GMSHPlugin_Mesher.cxx | 60 +++++++++++++++++++++++++--- src/GMSHPlugin/GMSHPlugin_Mesher.hxx | 10 +++++ 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/adm_local/cmake_files/FindGMSH.cmake b/adm_local/cmake_files/FindGMSH.cmake index 54f346e..a4c6842 100644 --- a/adm_local/cmake_files/FindGMSH.cmake +++ b/adm_local/cmake_files/FindGMSH.cmake @@ -37,8 +37,8 @@ IF(GMSH_ROOT_DIR) LIST(APPEND CMAKE_PREFIX_PATH "${GMSH_ROOT_DIR}") ENDIF(GMSH_ROOT_DIR) -FIND_PATH(GMSH_INCLUDE_DIRS Gmsh.h PATH_SUFFIXES gmsh) -FIND_LIBRARY(GMSH_LIBRARIES NAMES Gmsh) +FIND_PATH(GMSH_INCLUDE_DIRS Gmsh.h gmsh.h PATH_SUFFIXES gmsh) +FIND_LIBRARY(GMSH_LIBRARIES NAMES Gmsh gmsh) INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMSH REQUIRED_VARS GMSH_INCLUDE_DIRS GMSH_LIBRARIES) diff --git a/src/GMSHPlugin/GMSHPlugin_Mesher.cxx b/src/GMSHPlugin/GMSHPlugin_Mesher.cxx index 2d71072..b925bb1 100644 --- a/src/GMSHPlugin/GMSHPlugin_Mesher.cxx +++ b/src/GMSHPlugin/GMSHPlugin_Mesher.cxx @@ -57,6 +57,11 @@ #include #include +#if GMSH_MAJOR_VERSION >=4 +#include +#include +#endif + using namespace std; //============================================================================= @@ -194,6 +199,7 @@ void GMSHPlugin_Mesher::CreateGmshCompounds() SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen(); OCC_Internals* occgeo = _gModel->getOCCInternals(); + bool toSynchronize = false; for(std::set::const_iterator its = _compounds.begin();its != _compounds.end(); ++its ) { @@ -210,13 +216,34 @@ void GMSHPlugin_Mesher::CreateGmshCompounds() } if ( !aGeomObj->_is_nil() ) geomShape = smeshGen_i->GeomObjectToShape( aGeomObj.in() ); - + TopAbs_ShapeEnum geomType = geomShape.ShapeType(); if ( geomType == TopAbs_COMPOUND)// voir s'il ne faut pas mettre une erreur dans le cas contraire { MESSAGE("shapeType == TopAbs_COMPOUND"); TopoDS_Iterator it(geomShape); TopAbs_ShapeEnum shapeType = it.Value().ShapeType(); +#if GMSH_MAJOR_VERSION >=4 + std::vector< std::pair< int, int > > dimTags; + for ( ; it.More(); it.Next()) + { + const TopoDS_Shape& topoShape = it.Value(); + ASSERT(topoShape.ShapeType() == shapeType); + occgeo->importShapes( &topoShape, false, dimTags ); + } + std::vector tags; + int dim = ( shapeType == TopAbs_EDGE ) ? 1 : 2; + for ( size_t i = 0; i < dimTags.size(); ++i ) + { + if ( dimTags[i].first == dim ) + tags.push_back( dimTags[i].second ); + } + if ( !tags.empty() ) + { + _gModel->getGEOInternals()->setCompoundMesh( dim, tags ); + toSynchronize = true; + } +#else // compound of edges if (shapeType == TopAbs_EDGE) { @@ -229,6 +256,7 @@ void GMSHPlugin_Mesher::CreateGmshCompounds() ASSERT(topoShape.ShapeType() == shapeType); curve->compound.push_back(occgeo->addEdgeToModel(_gModel, (TopoDS_Edge&)topoShape)->tag()); } + toSynchronize = true; Tree_Add(_gModel->getGEOInternals()->Curves, &curve); //_gModel->importGEOInternals(); } @@ -244,9 +272,12 @@ void GMSHPlugin_Mesher::CreateGmshCompounds() ASSERT(topoShape.ShapeType() == shapeType); surface->compound.push_back(occgeo->addFaceToModel(_gModel, (TopoDS_Face&)topoShape)->tag()); } + toSynchronize = true; Tree_Add(_gModel->getGEOInternals()->Surfaces, &surface); - _gModel->getGEOInternals()->synchronize(_gModel); } +#endif + if ( toSynchronize ) + _gModel->getGEOInternals()->synchronize(_gModel); } } } @@ -303,7 +334,8 @@ void GMSHPlugin_Mesher::FillSMesh() } // ADD 1D ELEMENTS - for(GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it){ + for(GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it) + { GEdge *gEdge = *it; // GET topoEdge CORRESPONDING TO gEdge (map if compound) @@ -320,6 +352,13 @@ void GMSHPlugin_Mesher::FillSMesh() continue; } } +#if GMSH_MAJOR_VERSION >=4 + for ( size_t i = 0; i < gEdge->_compound.size(); ++i ) + { + GEdge* gE = static_cast< GEdge* >( gEdge->_compound[ i ]); + topoEdges.insert( std::make_pair( gE, *((TopoDS_Edge*)gE->getNativePtr())) ); + } +#else else { // compound case, map construction GEdge/TopoDS_Edge @@ -329,7 +368,8 @@ void GMSHPlugin_Mesher::FillSMesh() topoEdges.insert( pair(*itv,*((TopoDS_Edge*)(*itv)->getNativePtr())) ); } } - +#endif + // FILL SMESH FOR topoEdge //nodes for(unsigned int i = 0; i < gEdge->mesh_vertices.size(); i++) @@ -438,15 +478,23 @@ void GMSHPlugin_Mesher::FillSMesh() continue; } } +#if GMSH_MAJOR_VERSION >=4 + for ( size_t i = 0; i < gFace->_compound.size(); ++i ) + { + GFace* gF = static_cast< GFace* >( gFace->_compound[ i ]); + topoFaces.insert( std::make_pair( gF, *((TopoDS_Face*)gF->getNativePtr())) ); + } +#else else { // compound case, map construction GFace/TopoDS_Face std::list gFaces = ((GFaceCompound*)gFace)->getCompounds(); for(std::list::const_iterator itl = gFaces.begin();itl != gFaces.end(); ++itl) { - topoFaces.insert( pair(*itl,*((TopoDS_Face*)(*itl)->getNativePtr())) ); + topoFaces.insert( std::make_pair( *itl, *((TopoDS_Face*)(*itl)->getNativePtr())) ); } } +#endif // FILL SMESH FOR topoFace //nodes @@ -897,7 +945,9 @@ bool GMSHPlugin_Mesher::Compute() if (!err) { +#if GMSH_MAJOR_VERSION < 4 if (_compounds.size() > 0) _gModel->setCompoundVisibility(); +#endif FillSMesh(); } delete _gModel; diff --git a/src/GMSHPlugin/GMSHPlugin_Mesher.hxx b/src/GMSHPlugin/GMSHPlugin_Mesher.hxx index d047d67..c58ef21 100644 --- a/src/GMSHPlugin/GMSHPlugin_Mesher.hxx +++ b/src/GMSHPlugin/GMSHPlugin_Mesher.hxx @@ -22,13 +22,23 @@ #define _GMSHPlugin_Mesher_HXX_ #include +#include "GmshVersion.h" +#if GMSH_MAJOR_VERSION >=4 +#include "gmsh.h" +#else #include "Gmsh.h" +#endif #include "GmshConfig.h" #include "GModelIO_OCC.h" #include "GModelIO_GEO.h" #include "Geo.h" +#if GMSH_MAJOR_VERSION >=4 +#include "GEdge.h" +#include "GFace.h" +#else #include "GEdgeCompound.h" #include "GFaceCompound.h" +#endif #include "MElement.h" #include "GMSHPlugin_Defs.hxx" -- 2.39.2