-// 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
#include <SMESH_File.hxx>
#include <SMESH_Gen.hxx>
#include <SMESH_Group.hxx>
+#include <SMESH_MGLicenseKeyGen.hxx>
#include <SMESH_Mesh.hxx>
#include <SMESH_MeshEditor.hxx>
#include <SMESH_MesherHelper.hxx>
#include <StdMeshers_FaceSide.hxx>
+#include <StdMeshers_ProjectionUtils.hxx>
#include <StdMeshers_ViscousLayers2D.hxx>
#include <Basics_Utils.hxx>
#include <TopoDS_Wire.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
-#include <gp_XY.hxx>
-#include <gp_XYZ.hxx>
#ifndef WIN32
#include <fenv.h>
#endif
+#include <memory>
+#include <functional>
+
using namespace std;
/* ==================================
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 );
++theNbAttractors;
}
else{
- MESSAGE("Wrong shape type !!")
+ MESSAGE("Wrong shape type !!");
}
}
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;
}
}
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() ));
// 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);
/* 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<integer,std::function<void(integer*)>>;
+
+ 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<const SMDS_MeshNode*> nodes(nv+1);
std::vector<bool> tags(nv+1);
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 )
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()");
else /* you want to stop MG-CADSurf */
{
*interrupt_status = INTERRUPT_STOP;
- return STATUS_ERROR;
+ return STATUS_OK;
}
}
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 );
+}