1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016-2019 EDF R&D
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.alneos.com/ or email : contact@alneos.fr
20 #include "GMSHPlugin_Mesher.hxx"
21 #include "GMSHPlugin_Hypothesis_2D.hxx"
23 #include <SMDS_FaceOfNodes.hxx>
24 #include <SMDS_MeshElement.hxx>
25 #include <SMDS_MeshNode.hxx>
26 #include <SMESHDS_Mesh.hxx>
27 #include <SMESH_Block.hxx>
28 #include <SMESH_Comment.hxx>
29 #include <SMESH_ComputeError.hxx>
30 #include <SMESH_File.hxx>
31 #include <SMESH_Gen_i.hxx>
32 #include <SMESH_Mesh.hxx>
33 #include <SMESH_MesherHelper.hxx>
34 #include <SMESH_subMesh.hxx>
35 #include <utilities.h>
40 #include <BRep_Tool.hxx>
41 #include <Bnd_B3d.hxx>
42 #include <GCPnts_AbscissaPoint.hxx>
43 #include <GeomAdaptor_Curve.hxx>
44 #include <NCollection_Map.hxx>
45 #include <OSD_File.hxx>
46 #include <OSD_Path.hxx>
47 #include <Standard_ErrorHandler.hxx>
48 #include <Standard_ProgramError.hxx>
49 #include <TCollection_AsciiString.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
53 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
54 #include <TopTools_DataMapOfShapeInteger.hxx>
55 #include <TopTools_DataMapOfShapeShape.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TopTools_MapOfShape.hxx>
60 #if GMSH_MAJOR_VERSION >=4
61 #include <GmshGlobal.h>
71 SBoundingBox3d _bounds;
75 //================================================================================
77 * \brief Retrieve ShapeBounds from a compound GEdge
79 //================================================================================
81 bool getBoundsOfShapes( GEdge* gEdge,
82 std::vector< ShapeBounds > & topoEdges )
85 #if GMSH_MAJOR_VERSION >=4
86 for ( size_t i = 0; i < gEdge->_compound.size(); ++i )
88 GEdge* gE = static_cast< GEdge* >( gEdge->_compound[ i ]);
89 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
92 if ( gEdge->geomType() == GEntity::CompoundCurve )
94 std::vector<GEdge*> gEdges = ((GEdgeCompound*)gEdge)->getCompounds();
95 for ( size_t i = 0; i < gEdges.size(); ++i )
97 GEdge* gE = gEdges[ i ];
98 topoEdges.push_back( ShapeBounds{ gE->bounds(), *((TopoDS_Edge*)gE->getNativePtr()) });
102 return topoEdges.size();
105 //================================================================================
107 * \brief Retrieve ShapeBounds from a compound GFace
109 //================================================================================
111 bool getBoundsOfShapes( GFace* gFace,
112 std::vector< ShapeBounds > & topoFaces )
115 #if GMSH_MAJOR_VERSION >=4
116 for ( size_t i = 0; i < gFace->_compound.size(); ++i )
118 GFace* gF = static_cast< GFace* >( gFace->_compound[ i ]);
119 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
122 if ( gFace->geomType() == GEntity::CompoundSurface )
124 std::list<GFace*> gFaces = ((GFaceCompound*)gFace)->getCompounds();
125 for ( std::list<GFace*>::const_iterator itl = gFaces.begin();itl != gFaces.end(); ++itl )
128 topoFaces.push_back( ShapeBounds{ gF->bounds(), *((TopoDS_Face*)gF->getNativePtr()) });
132 return topoFaces.size();
134 //================================================================================
136 * \brief Find a shape whose bounding box includes a given point
138 //================================================================================
140 TopoDS_Shape getShapeAtPoint( const SPoint3& point, const std::vector< ShapeBounds > & shapes )
143 float distmin = std::numeric_limits<float>::max();
144 for ( size_t i = 0; i < shapes.size(); ++i )
146 float dist = GMSHPlugin_Mesher::DistBoundingBox( shapes[i]._bounds, point );
149 shape = shapes[i]._shape;
159 //=============================================================================
163 //=============================================================================
165 GMSHPlugin_Mesher::GMSHPlugin_Mesher (SMESH_Mesh* mesh,
166 const TopoDS_Shape& aShape)
170 // il faudra peut être mettre un truc par defaut si l'utilisateur ne rentre rien en para
171 //defaultParameters();
174 //void GMSHPlugin_Mesher::defaultParameters(){}
176 void GMSHPlugin_Mesher::SetParameters(const GMSHPlugin_Hypothesis* hyp)
180 _algo2d = hyp->Get2DAlgo();
181 _algo3d = hyp->Get3DAlgo();
182 _recomb2DAlgo = hyp->GetRecomb2DAlgo();
183 _recombineAll = hyp->GetRecombineAll();
184 _subdivAlgo = hyp->GetSubdivAlgo();
185 _remeshAlgo = hyp->GetRemeshAlgo();
186 _remeshPara = hyp->GetRemeshPara();
187 _smouthSteps = hyp->GetSmouthSteps();
188 _sizeFactor = hyp->GetSizeFactor();
189 _minSize = hyp->GetMinSize();
190 _maxSize = hyp->GetMaxSize();
191 _secondOrder = hyp->GetSecondOrder();
192 _useIncomplElem = hyp->GetUseIncomplElem();
193 _is2d = hyp->GetIs2d();
194 _compounds = hyp->GetCompoundOnEntries();
201 _recombineAll = false;
209 _secondOrder = false;
210 _useIncomplElem = true;
215 //================================================================================
217 * \brief Set Gmsh Options
219 //================================================================================
221 void GMSHPlugin_Mesher::SetGmshOptions()
223 MESSAGE("GMSHPlugin_Mesher::SetGmshOptions");
225 printf("We chose _algo2d %d \n", _algo2d );
226 printf("We chose _algo3d %d \n", _algo3d );
227 printf("We chose _recomb2DAlgo %d \n", _recomb2DAlgo );
228 printf("We chose _recombineAll %d \n", (_recombineAll)?1:0);
229 printf("We chose _subdivAlgo %d \n", _subdivAlgo );
230 printf("We chose _remeshAlgo %d \n", _remeshAlgo );
231 printf("We chose _remeshPara %d \n", _remeshPara );
232 printf("We chose _smouthSteps %e \n", _smouthSteps );
233 printf("We chose _sizeFactor %e \n", _sizeFactor );
234 printf("We chose _minSize %e \n", _minSize );
235 printf("We chose _maxSize %e \n", _maxSize );
236 printf("We chose _secondOrder %d \n", (_secondOrder)?1:0);
237 printf("We chose _useIncomplElem %d \n", (_useIncomplElem)?1:0);
238 printf("We are in dimension %d \n", (_is2d)?2:3);
241 std::map <int,double> mapAlgo2d;
242 mapAlgo2d[0]=2; mapAlgo2d[1]=1; mapAlgo2d[2]=5; mapAlgo2d[3]=6; mapAlgo2d[4]=8; mapAlgo2d[5]=9;
243 std::map <int,double> mapAlgo3d;
244 mapAlgo3d[0]=1; mapAlgo3d[1]=4; mapAlgo3d[2]=5; mapAlgo3d[3]=6; mapAlgo3d[4]=7; mapAlgo3d[5]=9;
247 ok = GmshSetOption("Mesh", "Algorithm" , mapAlgo2d[_algo2d]) ;
251 ok = GmshSetOption("Mesh", "Algorithm3D" , mapAlgo2d[_algo3d]) ;
254 ok = GmshSetOption("Mesh", "RecombinationAlgorithm" , (double)_recomb2DAlgo) ;
256 ok = GmshSetOption("Mesh", "RecombineAll" , (_recombineAll)?1.:0.) ;
258 ok = GmshSetOption("Mesh", "SubdivisionAlgorithm" , (double)_subdivAlgo) ;
260 ok = GmshSetOption("Mesh", "RemeshAlgorithm" , (double)_remeshAlgo) ;
262 ok = GmshSetOption("Mesh", "RemeshParametrization" , (double)_remeshPara) ;
264 ok = GmshSetOption("Mesh", "Smoothing" , (double)_smouthSteps) ;
266 ok = GmshSetOption("Mesh", "CharacteristicLengthFactor", _sizeFactor) ;
268 ok = GmshSetOption("Mesh", "CharacteristicLengthMin" , _minSize) ;
270 ok = GmshSetOption("Mesh", "CharacteristicLengthMax" , _maxSize) ;
272 ok = GmshSetOption("Mesh", "ElementOrder" , (_secondOrder)?2.:1.) ;
276 ok = GmshSetOption("Mesh", "SecondOrderIncomplete" ,(_useIncomplElem)?1.:0.);
281 //================================================================================
283 * \brief Create and add Compounds into GModel _gModel.
285 //================================================================================
287 void GMSHPlugin_Mesher::CreateGmshCompounds()
289 MESSAGE("GMSHPlugin_Mesher::CreateGmshCompounds");
291 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
293 OCC_Internals* occgeo = _gModel->getOCCInternals();
294 bool toSynchronize = false;
296 for(std::set<std::string>::const_iterator its = _compounds.begin();its != _compounds.end(); ++its )
298 GEOM::GEOM_Object_var aGeomObj;
299 TopoDS_Shape geomShape = TopoDS_Shape();
300 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( (*its).c_str() );
301 SALOMEDS::GenericAttribute_var anAttr;
302 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR"))
304 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
305 CORBA::String_var aVal = anIOR->Value();
306 CORBA::Object_var obj = SMESH_Gen_i::getStudyServant()->ConvertIORToObject(aVal);
307 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
309 if ( !aGeomObj->_is_nil() )
310 geomShape = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
312 TopAbs_ShapeEnum geomType = geomShape.ShapeType();
313 if ( geomType == TopAbs_COMPOUND)// voir s'il ne faut pas mettre une erreur dans le cas contraire
315 MESSAGE("shapeType == TopAbs_COMPOUND");
316 TopoDS_Iterator it(geomShape);
317 TopAbs_ShapeEnum shapeType = it.Value().ShapeType();
318 #if GMSH_MAJOR_VERSION >=4
319 std::vector< std::pair< int, int > > dimTags;
320 for ( ; it.More(); it.Next())
322 const TopoDS_Shape& topoShape = it.Value();
323 ASSERT(topoShape.ShapeType() == shapeType);
324 occgeo->importShapes( &topoShape, false, dimTags );
326 std::vector<int> tags;
327 int dim = ( shapeType == TopAbs_EDGE ) ? 1 : 2;
328 for ( size_t i = 0; i < dimTags.size(); ++i )
330 if ( dimTags[i].first == dim )
331 tags.push_back( dimTags[i].second );
335 _gModel->getGEOInternals()->setCompoundMesh( dim, tags );
336 toSynchronize = true;
340 if (shapeType == TopAbs_EDGE)
342 MESSAGE(" shapeType == TopAbs_EDGE :");
343 int num = _gModel->getNumEdges()+1;
344 Curve *curve = CreateCurve(num, MSH_SEGM_COMPOUND, 1, NULL, NULL, -1, -1, 0., 1.);
345 for ( ; it.More(); it.Next())
347 TopoDS_Shape topoShape = it.Value();
348 ASSERT(topoShape.ShapeType() == shapeType);
349 curve->compound.push_back(occgeo->addEdgeToModel(_gModel, (TopoDS_Edge&)topoShape)->tag());
351 toSynchronize = true;
352 Tree_Add(_gModel->getGEOInternals()->Curves, &curve);
353 //_gModel->importGEOInternals();
356 else if (shapeType == TopAbs_FACE)
358 MESSAGE(" shapeType == TopAbs_FACE :");
359 int num = _gModel->getNumFaces()+1;
360 Surface *surface = CreateSurface(num, MSH_SURF_COMPOUND);
361 for ( ; it.More(); it.Next())
363 TopoDS_Shape topoShape = it.Value();
364 ASSERT(topoShape.ShapeType() == shapeType);
365 surface->compound.push_back(occgeo->addFaceToModel(_gModel, (TopoDS_Face&)topoShape)->tag());
367 toSynchronize = true;
368 Tree_Add(_gModel->getGEOInternals()->Surfaces, &surface);
372 _gModel->getGEOInternals()->synchronize(_gModel);
377 //================================================================================
379 * \brief Write mesh from GModel instance to SMESH instance
381 //================================================================================
383 void GMSHPlugin_Mesher::FillSMesh()
385 SMESHDS_Mesh* meshDS = _mesh->GetMeshDS();
388 for ( GModel::viter it = _gModel->firstVertex(); it != _gModel->lastVertex(); ++it)
390 GVertex *gVertex = *it;
392 // GET topoVertex CORRESPONDING TO gVertex
393 TopoDS_Vertex topoVertex = *((TopoDS_Vertex*)gVertex->getNativePtr());
395 if (gVertex->getVisibility() == 0) // belongs to a compound
397 SMESH_subMesh* sm = _mesh->GetSubMesh(topoVertex);
398 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
402 // FILL SMESH FOR topoVertex
404 for(unsigned int i = 0; i < gVertex->mesh_vertices.size(); i++)
406 MVertex *v = gVertex->mesh_vertices[i];
407 if(v->getIndex() >= 0)
409 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
410 meshDS->SetNodeOnVertex( node, topoVertex );
413 // WE DON'T ADD 0D ELEMENTS because it does not follow the salome meshers philosophy
415 // for(unsigned int i = 0; i < gVertex->getNumMeshElements(); i++)
417 // MElement *e = gVertex->getMeshElement(i);
418 // std::vector<MVertex*> verts;
419 // e->getVertices(verts);
420 // ASSERT(verts.size()==1);
421 // SMDS_Mesh0DElement* zeroDElement = 0;
422 // zeroDElement = meshDS->Add0DElementWithID(verts[0]->getNum(),e->getNum());
423 // meshDS->SetMeshElementOnShape(zeroDElement, topoVertex);
428 for(GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it)
432 // GET topoEdge CORRESPONDING TO gEdge
433 TopoDS_Edge topoEdge;
434 std::vector< ShapeBounds > topoEdges;
436 if ( gEdge->geomType() != GEntity::CompoundCurve )
438 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
439 if (gEdge->getVisibility() == 0) // belongs to a compound
441 SMESH_subMesh* sm = _mesh->GetSubMesh(topoEdge);
442 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
446 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
448 // FILL SMESH FOR topoEdge
450 for ( size_t i = 0; i < gEdge->mesh_vertices.size(); i++ )
452 MVertex *v = gEdge->mesh_vertices[i];
453 if ( v->getIndex() >= 0 )
455 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
458 topoEdge = TopoDS::Edge( getShapeAtPoint( v->point(), topoEdges ));
460 meshDS->SetNodeOnEdge( node, topoEdge );
465 for ( GModel::eiter it = _gModel->firstEdge(); it != _gModel->lastEdge(); ++it )
468 if ( gEdge->getVisibility() == 0) // belongs to a compound
471 TopoDS_Edge topoEdge;
472 std::vector< ShapeBounds > topoEdges;
473 bool isCompound = getBoundsOfShapes( gEdge, topoEdges );
475 topoEdge = *((TopoDS_Edge*)gEdge->getNativePtr());
478 std::vector<MVertex*> verts(3);
479 for ( size_t i = 0; i < gEdge->getNumMeshElements(); i++ )
481 MElement *e = gEdge->getMeshElement(i);
483 e->getVertices(verts);
485 // if a node wasn't set, it is assigned here
486 for ( size_t j = 0; j < verts.size(); j++ )
488 if ( verts[j]->onWhat()->getVisibility() == 0 )
490 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[i]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
491 meshDS->SetNodeOnEdge( node, topoEdge );
492 verts[j]->setEntity(gEdge);
496 SMDS_MeshEdge* edge = 0;
497 switch (verts.size())
500 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
501 verts[1]->getNum(),e->getNum());
504 edge = meshDS->AddEdgeWithID(verts[0]->getNum(),
506 verts[2]->getNum(),e->getNum());
513 topoEdge = TopoDS::Edge( getShapeAtPoint( e->barycenter(), topoEdges ));
515 meshDS->SetMeshElementOnShape( edge, topoEdge );
520 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
524 // GET topoFace CORRESPONDING TO gFace
525 TopoDS_Face topoFace;
526 std::vector< ShapeBounds > topoFaces;
528 if ( gFace->geomType() != GEntity::CompoundSurface )
530 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
531 if (gFace->getVisibility() == 0) // belongs to a compound
533 SMESH_subMesh* sm = _mesh->GetSubMesh(topoFace);
534 sm->SetIsAlwaysComputed(true); // prevent from displaying errors
538 bool isCompound = getBoundsOfShapes( gFace, topoFaces );
540 // FILL SMESH FOR topoFace
542 for ( size_t i = 0; i < gFace->mesh_vertices.size(); i++ )
544 MVertex *v = gFace->mesh_vertices[i];
545 if ( v->getIndex() >= 0 )
547 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
550 topoFace = TopoDS::Face( getShapeAtPoint( v->point(), topoFaces ));
552 meshDS->SetNodeOnFace( node, topoFace );
557 for ( GModel::fiter it = _gModel->firstFace(); it != _gModel->lastFace(); ++it)
561 bool isCompound = ( gFace->geomType() == GEntity::CompoundSurface );
562 if ( !isCompound && gFace->getVisibility() == 0 )
563 continue; // belongs to a compound
565 TopoDS_Face topoFace;
566 std::vector< ShapeBounds > topoFaces;
568 getBoundsOfShapes( gFace, topoFaces );
570 topoFace = *((TopoDS_Face*)gFace->getNativePtr());
573 std::vector<MVertex*> verts;
574 for ( size_t i = 0; i < gFace->getNumMeshElements(); i++ )
576 MElement *e = gFace->getMeshElement(i);
578 e->getVertices(verts);
579 SMDS_MeshFace* face = 0;
581 // if a node wasn't set, it is assigned here
582 for ( size_t j = 0; j < verts.size(); j++)
584 if(verts[j]->onWhat()->getVisibility() == 0)
586 SMDS_MeshNode *node = meshDS->AddNodeWithID(verts[j]->x(),verts[j]->y(),verts[j]->z(),verts[j]->getNum());
587 meshDS->SetNodeOnFace( node, topoFace );
588 verts[i]->setEntity(gFace);
591 switch (verts.size())
594 face = meshDS->AddFaceWithID(verts[0]->getNum(),
596 verts[2]->getNum(),e->getNum());
599 face = meshDS->AddFaceWithID(verts[0]->getNum(),
602 verts[3]->getNum(),e->getNum());
605 face = meshDS->AddFaceWithID(verts[0]->getNum(),
610 verts[5]->getNum(),e->getNum());
613 face = meshDS->AddFaceWithID(verts[0]->getNum(),
620 verts[7]->getNum(),e->getNum());
623 face = meshDS->AddFaceWithID(verts[0]->getNum(),
631 verts[8]->getNum(),e->getNum());
639 topoFace = TopoDS::Face( getShapeAtPoint( e->barycenter(), topoFaces ));
641 meshDS->SetMeshElementOnShape(face, topoFace);
646 for ( GModel::riter it = _gModel->firstRegion(); it != _gModel->lastRegion(); ++it)
648 GRegion *gRegion = *it;
649 if (gRegion->getVisibility() == 0)
652 // GET topoSolid CORRESPONDING TO gRegion
653 TopoDS_Solid topoSolid = *((TopoDS_Solid*)gRegion->getNativePtr());
655 // FILL SMESH FOR topoSolid
658 for(unsigned int i = 0; i < gRegion->mesh_vertices.size(); i++)
660 MVertex *v = gRegion->mesh_vertices[i];
661 if(v->getIndex() >= 0)
663 SMDS_MeshNode *node = meshDS->AddNodeWithID(v->x(),v->y(),v->z(),v->getNum());
664 meshDS->SetNodeInVolume( node, topoSolid );
669 std::vector<MVertex*> verts;
670 for(unsigned int i = 0; i < gRegion->getNumMeshElements(); i++)
672 MElement *e = gRegion->getMeshElement(i);
674 e->getVertices(verts);
675 SMDS_MeshVolume* volume = 0;
676 switch (verts.size()){
678 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
681 verts[3]->getNum(),e->getNum());
684 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
688 verts[4]->getNum(),e->getNum());
691 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
696 verts[4]->getNum(),e->getNum());
699 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
706 verts[5]->getNum(),e->getNum());
709 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
718 verts[9]->getNum(),e->getNum());
721 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
733 verts[9]->getNum(),e->getNum());
735 case 14: // same as case 13, because no pyra14 in smesh
736 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
748 verts[9]->getNum(),e->getNum());
751 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
765 verts[10]->getNum(),e->getNum());
767 case 18: // same as case 15, because no penta18 in smesh
768 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
782 verts[10]->getNum(),e->getNum());
785 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
804 verts[12]->getNum(),e->getNum());
807 volume = meshDS->AddVolumeWithID(verts[0]->getNum(),
840 meshDS->SetMeshElementOnShape(volume, topoSolid);
847 //================================================================================
849 * \brief Find if SPoint point is in SBoundingBox3d bounds
851 //================================================================================
853 float GMSHPlugin_Mesher::DistBoundingBox(const SBoundingBox3d& bounds, const SPoint3& point)
855 SPoint3 min = bounds.min();
856 SPoint3 max = bounds.max();
860 if (point.x() < min.x())
861 x = min.x()-point.x();
862 else if (point.x() > max.x())
863 x = point.x()-max.x();
867 if (point.y() < min.y())
868 y = min.y()-point.y();
869 else if (point.y() > max.y())
870 y = point.y()-max.y();
874 if (point.z() < min.z())
875 z = min.z()-point.z();
876 else if (point.z() > max.z())
877 z = point.z()-max.z();
883 //================================================================================
885 * \brief Reimplemented GmshMessage call. Actions done if errors occurs
886 * during gmsh meshing. We define here what to display and what to do.
888 //================================================================================
889 void GMSHPlugin_Mesher::mymsg::operator()(std::string level, std::string msg)
891 //MESSAGE("level="<< level.c_str() << ", msg=" << msg.c_str()<< "\n");
892 printf("level=%s msg=%s\n", level.c_str(), msg.c_str());
894 if(level == "Fatal" || level == "Error")
896 std::ostringstream oss;
897 if (level == "Fatal")
898 oss << "Fatal error during Generation of Gmsh Mesh\n";
900 oss << "Error during Generation of Gmsh Mesh\n";
901 oss << " " << msg.c_str() << "\n";
902 GEntity *e = _gModel->getCurrentMeshEntity();
905 oss << " error occurred while meshing entity:\n" <<
906 " tag=" << e->tag() << "\n" <<
907 " dimension=" << e->dim() << "\n" <<
908 " native pointer=" << e->getNativePtr();
909 //if(e->geomType() != GEntity::CompoundCurve and e->geomType() != GEntity::CompoundSurface)
911 //SMESH_subMesh *sm = _mesh->GetSubMesh(*((TopoDS_Shape*)e->getNativePtr()));
912 //SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
913 //SMESH_Comment comment;
914 //comment << SMESH_Comment(oss.str);
915 //std::string str = oss.str();
916 //smError.reset( new SMESH_ComputeError( str ));
918 // plutot que de faire de la merde ici, on pourait simplement
919 // remplir une liste pour dire sur quelles entités gmsh se plante
920 // (puis faire le fillsmesh)
921 // puis faire une nouvelle routine qui réécrit les messages d'erreur
922 // probleme : gmsh peut planté en Fatal, dans ce cas pas de fillsmesh
925 if (level == "Fatal")
927 CTX::instance()->lock = 0;
931 printf(oss.str().c_str());
935 //=============================================================================
937 * Here we are going to use the GMSH mesher
939 //=============================================================================
941 bool GMSHPlugin_Mesher::Compute()
943 MESSAGE("GMSHPlugin_Mesher::Compute");
949 _gModel = new GModel();
951 GmshSetMessageHandler(&msg);
952 _gModel->importOCCShape((void*)&_shape);
953 if (_compounds.size() > 0) CreateGmshCompounds();
954 MESSAGE("GModel::Mesh");
957 _gModel->mesh((_is2d)?2:3);
958 #ifdef WITH_SMESH_CANCEL_COMPUTE
962 catch (std::string& str)
970 MESSAGE("Unrecoverable error during Generation of Gmsh Mesh");
975 #if GMSH_MAJOR_VERSION < 4
976 if (_compounds.size() > 0) _gModel->setCompoundVisibility();
982 MESSAGE("GMSHPlugin_Mesher::Compute:End");