X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FBLSURFPlugin%2FBLSURFPlugin_BLSURF.cxx;h=94e8065769ef2d2afaf6da97c51990370d6a739c;hb=ce134533bb9155786bb02b76e6a63b4efae4f0d0;hp=e47c490c954f1095aed332128c14e4ed8f62c1b2;hpb=69bb2d888bb5829a78bb05e68d63aeee86a597a7;p=plugins%2Fblsurfplugin.git diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index e47c490..94e8065 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2021 CEA/DEN, EDF R&D +// Copyright (C) 2007-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -40,10 +40,12 @@ extern "C"{ #include #include #include +#include #include #include #include #include +#include #include #include @@ -90,13 +92,14 @@ extern "C"{ #include #include #include -#include -#include #ifndef WIN32 #include #endif +#include +#include + using namespace std; /* ================================== @@ -512,12 +515,45 @@ TopoDS_Shape BLSURFPlugin_BLSURF::entryToShape(std::string entry) return S; } +// Check if a point is already on the shape. +// if faceShape is defined, we use it +// else we use the sub-shape of the mesh +bool _doVertexAlreadyExists(const TopoDS_Face& faceShape, + const gp_Pnt& aPnt) +{ + // If the point is already on the shape, no need to add it + TopExp_Explorer ex; + TopoDS_Shape shapeToCheckVertices(faceShape); + bool alreadyExists(false); + if (faceShape.IsNull()) + shapeToCheckVertices = theHelper->GetSubShape(); + for (ex.Init(shapeToCheckVertices, TopAbs_VERTEX); ex.More(); ex.Next()) + { + TopoDS_Vertex vertex = TopoDS::Vertex(ex.Current()); + double tol = BRep_Tool::Tolerance( vertex ); + gp_Pnt p = BRep_Tool::Pnt(vertex); + if ( p.IsEqual( aPnt, tol)) + { + MESSAGE("The enforced vertex is already on the shape => No need to add it."); + alreadyExists = true; + break; + } + } + return alreadyExists; +} + void _createEnforcedVertexOnFace(TopoDS_Face faceShape, const gp_Pnt& aPnt, - BLSURFPlugin_Hypothesis::TEnfVertex *enfVertex) + BLSURFPlugin_Hypothesis::TEnfVertex *enfVertex, + bool checkVertexAlreadyExists=true) { BLSURFPlugin_Hypothesis::TEnfVertexCoords enf_coords, coords, s_coords; + // checkVertexAlreadyExists only for non internal vertices. + // For them we set checkVertexAlreadyExists=false as we do have to add them + if (checkVertexAlreadyExists && _doVertexAlreadyExists(faceShape, aPnt)) + return; + // Find the face and get the (u,v) values of the enforced vertex on the face BLSURFPlugin_BLSURF::projectionPoint projPnt = BLSURFPlugin_BLSURF::getProjectionPoint( faceShape, aPnt, /*allowStateON=*/true ); @@ -1309,7 +1345,7 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, ++theNbAttractors; } else{ - MESSAGE("Wrong shape type !!") + MESSAGE("Wrong shape type !!"); } } @@ -1369,7 +1405,8 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp, enfVertex->geomEntry = ""; enfVertex->grpName = grpName; enfVertex->vertex = TopoDS::Vertex( exp_face.Current() ); - _createEnforcedVertexOnFace( TopoDS::Face(exp.Current()), aPnt, enfVertex); + _createEnforcedVertexOnFace( TopoDS::Face(exp.Current()), aPnt, enfVertex, + /*checkVertexAlreadyExists*/false); HasSizeMapOnFace = true; } } @@ -1759,7 +1796,7 @@ namespace TSeg2EdgeMap seg2EdgeMap; TopoDS_Iterator edgeIt( wire ); - for ( int iSeg = 1; edgeIt.More(); edgeIt.Next(), ++iSeg ) + for ( size_t iSeg = 1; edgeIt.More() && iSeg < nodesOfVertices.size(); edgeIt.Next(), ++iSeg ) { SMESH_TLink link( nodesOfVertices[ iSeg-1 ], nodesOfVertices[ iSeg ]); TopoDS_Edge edge( TopoDS::Edge( edgeIt.Value() )); @@ -2528,6 +2565,9 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh& aMesh, // set_param(css, "global_physical_size", val_to_string( minFaceSize * 0.5 ).c_str()); // set_param(css, "max_size", val_to_string( minFaceSize * 5 ).c_str()); } + std::string errorTxt; + if ( !SMESHUtils_MGLicenseKeyGen::SignCAD( c, errorTxt )) + return error( "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt ); // Use the original dcad cadsurf_set_dcad(css, dcad); @@ -2625,18 +2665,22 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh& aMesh, /* retrieve mesh data (see meshgems/mesh.h) */ integer nv, ne, nt, nq, vtx[4], tag, nb_tag; - integer *evedg, *evtri, *evquad, *tags_buff, type; + integer type; real xyz[3]; mesh_get_vertex_count (msh, &nv); mesh_get_edge_count (msh, &ne); mesh_get_triangle_count (msh, &nt); mesh_get_quadrangle_count(msh, &nq); + + using deleted_unique_ptr = std::unique_ptr>; + + deleted_unique_ptr evedg_var((integer *)mesh_calloc_generic_buffer(msh), [](integer *ptr) { free(ptr); }); + deleted_unique_ptr evtri_var((integer *)mesh_calloc_generic_buffer(msh), [](integer *ptr) { free(ptr); }); + deleted_unique_ptr evquad_var((integer *)mesh_calloc_generic_buffer(msh), [](integer *ptr) { free(ptr); }); + deleted_unique_ptr tags_buff_var((integer*)mesh_calloc_generic_buffer(msh), [](integer *ptr) { free(ptr); }); - evedg = (integer *)mesh_calloc_generic_buffer(msh); - evtri = (integer *)mesh_calloc_generic_buffer(msh); - evquad = (integer *)mesh_calloc_generic_buffer(msh); - tags_buff = (integer*)mesh_calloc_generic_buffer(msh); + integer *evedg(evedg_var.get()),*evtri(evtri_var.get()),*evquad(evquad_var.get()),*tags_buff(tags_buff_var.get()); std::vector nodes(nv+1); std::vector tags(nv+1); @@ -2958,6 +3002,14 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh& aMesh, error(_comment); } + // Set event listeners + if ( _hypothesis ) + for ( int iF = 1; iF <= fmap.Size(); ++iF ) + { + const TopoDS_Shape& face = fmap( iF ); + SetEventListener( aMesh.GetSubMesh( face )); + } + // Issue 0019864. On DebianSarge, FE signals do not obey to OSD::SetSignal(false) #ifndef WIN32 if ( oldFEFlags > 0 ) @@ -3061,6 +3113,11 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelpe meshgems_mesh_set_quadrangle_vertices( msh, iQ++, nodeIDs ); } + std::string errorTxt; + + if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( msh, "cadsurf", errorTxt )) + return error( "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt ); + ret = cadsurf_set_mesh(css, msh); if ( ret != STATUS_OK ) return error("Pb in cadsurf_set_mesh()"); @@ -3481,7 +3538,7 @@ status_t interrupt_cb(integer *interrupt_status, void *user_data) else /* you want to stop MG-CADSurf */ { *interrupt_status = INTERRUPT_STOP; - return STATUS_ERROR; + return STATUS_OK; } } @@ -3663,3 +3720,52 @@ void BLSURFPlugin_BLSURF::FillEntryToShape( const BLSURFPlugin_Hypothesis* entryToShape.insert({ entry, shape }); } } + +//================================================================================ +/*! + * \brief Sets event listener to submeshes if enforced mesh is defined + * \param subMesh - submesh where algo is set + * + * This method is called when a submesh gets HYP_OK algo_state. + * After being set, event listener is notified on each event of a submesh. + * By default none listener is set + */ +//================================================================================ + +void BLSURFPlugin_BLSURF::SetEventListener(SMESH_subMesh* faceSubMesh) +{ + if ( !_hypothesis ) + return; + + for ( const BLSURFPlugin_Hypothesis::EnforcedMesh& enfMesh : _hypothesis->GetEnforcedMeshes() ) + { + SMESH_Mesh* mesh1D; + _hypothesis->GetEnforcedSegments( enfMesh, mesh1D ); + if ( !mesh1D ) + continue; + + TopExp_Explorer edgeExp( mesh1D->GetShapeToMesh(), TopAbs_EDGE ); + if ( edgeExp.More() ) + StdMeshers_ProjectionUtils::SetEventListener( faceSubMesh, + edgeExp.Current(), + mesh1D ); + // StdMeshers_ProjectionUtils::SetEventListener( faceSubMesh, + // mesh1D->GetShapeToMesh(), + // mesh1D ); + } + return; +} + +//================================================================================ +/*! + * \brief Allow algo to do something after persistent restoration + * \param subMesh - restored submesh + * + * This method is called only if a submesh has HYP_OK algo_state. + */ +//================================================================================ + +void BLSURFPlugin_BLSURF::SubmeshRestored(SMESH_subMesh* subMesh) +{ + SetEventListener( subMesh ); +}