Salome HOME
updated copyright message
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_EnforcedMesh1D.cxx
index 923bdfaef076ccba11c4c67be5a8d5b367f9284b..3f3abde0155961eb4550733fe91bb53c3b9705bc 100644 (file)
@@ -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
@@ -101,8 +101,6 @@ namespace
    *  \param [in] braNodes - nodes of the branch
    *  \param [in] nodeIndex - index of a node of the branch
    *  \param [inout] mesh - mesh holding the nodes and segments
-   * 
-   * 
    */
   //================================================================================
 
@@ -145,7 +143,8 @@ BLSURFPlugin_EnforcedMesh1D::BLSURFPlugin_EnforcedMesh1D( SMESH_MesherHelper&
   : _mesh ( helper.GetMesh() ),
     _shape( helper.GetSubShape() ),
     _helper( *_mesh ),
-    _isQuadratic( helper.GetIsQuadratic() )
+    _isQuadratic( helper.GetIsQuadratic() ),
+    _nodeTag0( 0 )
 {
   if ( !hyp || !_mesh || hyp->GetEnforcedMeshes().empty() )
     return;
@@ -170,10 +169,10 @@ BLSURFPlugin_EnforcedMesh1D::BLSURFPlugin_EnforcedMesh1D( SMESH_MesherHelper&
     splitSelfIntersectingSegments( face );
   }
 
-  for ( TEdge2Nodes::Iterator e2nn( _nodesOnEdge ); e2nn.More(); e2nn.Next() )
-  {
-    splitEdgeByNodes( e2nn.Key(), e2nn.Value() );
-  }
+  // for ( TEdge2Nodes::Iterator e2nn( _nodesOnEdge ); e2nn.More(); e2nn.Next() )
+  // {
+  //   splitEdgeByNodes( e2nn.Key(), e2nn.Value() );
+  // }
 }
 
 //================================================================================
@@ -238,9 +237,47 @@ BLSURFPlugin_EnforcedMesh1D::~BLSURFPlugin_EnforcedMesh1D()
   return;
 }
 
+//================================================================================
+/*!
+ * \brief Add a vertex on EDGE
+ */
+//================================================================================
+
+void BLSURFPlugin_EnforcedMesh1D::AddVertexOnEdge( const double* theXYZ )
+{
+  // setup predicates to find the supporting EDGE
+  setupPredicates( _shape );
+
+  SMESHDS_Mesh*         meshDS = _mesh->GetMeshDS();
+  const SMDS_MeshNode* nodeOnE = meshDS->AddNode( theXYZ[0], theXYZ[1], theXYZ[2] );
+
+  // check if enfNode is on VERTEX
+  bool toRemove = true;
+  TopoDS_Vertex vertex;
+  TopoDS_Edge   edge;
+  if ( _onVertexPredicate->IsSatisfy( nodeOnE, &vertex ))
+  {
+    toRemove = SMESH_Algo::VertexNode( vertex, meshDS );
+    if ( !toRemove )
+      meshDS->SetNodeOnVertex( nodeOnE, vertex );
+  }
+  // find the EDGE supporting theXYZ
+  else if ( _onEdgePredicate->IsSatisfy( nodeOnE, &edge ))
+  {
+    gp_Pnt pnt( theXYZ[0], theXYZ[1], theXYZ[2] );
+    toRemove = findNodeOnEdge( pnt, edge );
+    if ( !toRemove )
+      addNodeOnEdge( nodeOnE, edge );
+  }
+
+  if ( toRemove )
+    meshDS->RemoveFreeNode( nodeOnE, /*submesh=*/nullptr, /*fromGroup=*/false );
+}
+
 //================================================================================
 /*!
  * \brief Return EDGEs resulted from division of FACE boundary by enforced segments
+ *        and enforced vertices
  *  \param [in] edge - possibly divided EDGE
  *  \param [out] splits - split EDGEs
  *  \return bool - true if the EDGE is split
@@ -251,6 +288,15 @@ bool BLSURFPlugin_EnforcedMesh1D::GetSplitsOfEdge( const TopoDS_Edge&
                                                    std::vector< TopoDS_Edge > & splits,
                                                    TopTools_IndexedMapOfShape & edgeTags )
 {
+  if ( _nodesOnEdge.IsBound( edge )) // divide the EDGE
+  {
+    splitEdgeByNodes( edge, _nodesOnEdge( edge ));
+
+    _nodesOnEdge.UnBind( edge );
+  }
+
+  // return splits
+
   std::vector< TopoDS_Edge > * splitsInMap = _edgeSplitsOfEdge.ChangeSeek( edge );
   if ( !splitsInMap )
     return false;
@@ -288,7 +334,7 @@ copyEnforcedMesh( const BLSURFPlugin_Hypothesis::EnforcedMesh& theEnfMesh,
   SMESH_Mesh* mesh1D;
   SMDS_ElemIteratorPtr segIt = theHyp->GetEnforcedSegments( theEnfMesh, mesh1D );
   if ( !segIt->more() )
-    return;
+    throw SALOME_Exception("No edges in an enforced mesh");
 
   // setup predicates to detect nodes on FACE boundary
   setupPredicates( theShape );