Salome HOME
Merge changes from 'master' branch.
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPluginBuilder.py
index 084b8c7561fd4088285fa7ddb4ccdbadee87350a..19b197b59cd5f4b9695b53792967fb41315b570f 100644 (file)
 # Python API for the MG-CADSurf meshing plug-in module.
 
 from salome.smesh.smesh_algorithm import Mesh_Algorithm
+import GEOM
 
 LIBRARY = "libBLSURFEngine.so"
 
+# ElementType enum
+Triangles, QuadrangleDominant, Quadrangles = 0, 1, 2
+
 # Topology treatment way of MG-CADSurf
 FromCAD, PreProcess, PreProcessPlus, PreCAD = 0,1,2,3
 
@@ -85,8 +89,12 @@ class BLSURF_Algorithm(Mesh_Algorithm):
   def __init__(self, mesh, geom=0):
     Mesh_Algorithm.__init__(self)
     if noBLSURFPlugin:
-      print "Warning: BLSURFPlugin module unavailable"
-    self.Create(mesh, geom, BLSURF, LIBRARY)
+      print("Warning: BLSURFPlugin module unavailable")
+    if mesh.GetMesh().HasShapeToMesh():
+      self.Create(mesh, geom, self.algoType, LIBRARY)
+    else:
+      self.Create(mesh, geom, self.algoType+"_NOGEOM", LIBRARY)
+      mesh.smeshpyD.SetName( self.algo, self.algoType )
     self.params=None
     self.geompyD = mesh.geompyD
     #self.SetPhysicalMesh() - PAL19680
@@ -159,6 +167,7 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     pass
 
   ## Sets maximal allowed ratio between the lengths of two adjacent edges.
+  #  @param toUseGradation to use gradation
   #  @param theVal value of maximal length ratio
   def SetGradation(self, toUseGradation=True, theVal=_gradation):
     if isinstance( toUseGradation, float ): ## backward compatibility
@@ -169,6 +178,7 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     pass
 
   ## Sets maximal allowed ratio between the lengths of two adjacent edges in 3D mesh.
+  #  @param toUseGradation to use gradation
   #  @param theVal value of maximal length ratio
   def SetVolumeGradation(self, toUseGradation=True, theVal=_gradation):
     if self.Parameters().GetGeometricMesh() == 0: theVal = self._volume_gradation
@@ -183,7 +193,7 @@ class BLSURF_Algorithm(Mesh_Algorithm):
   # <li>PreCAD - by pre-processing with PreCAD a CAD model</li></ul>
   def SetTopology(self, way):
     if way != PreCAD and way != FromCAD:
-      print "Warning: topology mode %d is no longer supported. Mode FromCAD is used."%way
+      print("Warning: topology mode %d is no longer supported. Mode FromCAD is used."%way)
       way = FromCAD
     self.Parameters().SetTopology(way)
     pass
@@ -227,6 +237,14 @@ class BLSURF_Algorithm(Mesh_Algorithm):
   def SetJacobianRectification( self, allowRectification ):
     self.Parameters().SetJacobianRectification( allowRectification )
 
+  ## Set use_deprecated_patch_mesher parameter (compatibility with older versions of Meshgems)
+  #  
+  # the use_deprecated_patch_mesher parameter allows to keep the same behaviour than
+  # in salome < 8.3 (meshgems 2.1.11 instead of meshgems >= 2.4.5)
+  #  
+  def SetUseDeprecatedPatchMesher( self, useDeprecatedPatchMesher ):
+    self.Parameters().SetUseDeprecatedPatchMesher( useDeprecatedPatchMesher )
+
   ## Set respect_geometry parameter
   #  
   #  This patch independent option can be deactivated to allow MeshGems-CADSurf
@@ -244,6 +262,13 @@ class BLSURF_Algorithm(Mesh_Algorithm):
   def SetMaxNumberOfPointsPerPatch( self, nb ):
     self.Parameters().SetMaxNumberOfPointsPerPatch( nb )
 
+  ## Set max_number_of_threads parameter
+  #
+  #  Set the maximum of threads to use for multithreading mesh computation
+  #
+  def SetMaxNumberOfThreads( self, nb ):
+    self.Parameters().SetMaxNumberOfThreads( nb )
+
   ## Set respect_geometry parameter
   #  
   #  This patch independent option can be deactivated to allow MeshGems-CADSurf
@@ -344,12 +369,6 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     self.Parameters().SetPreCADMergeEdges(toMergeEdges)
     pass
 
-  ## To remove tiny UV edges.
-  #  @param toRemoveTinyUVEdges "remove_tiny_uv_edges" flag value
-  def SetPreCADRemoveTinyUVEdges(self, toRemoveTinyUVEdges=False):
-    self.Parameters().SetPreCADRemoveTinyUVEdges(toRemoveTinyUVEdges)
-    pass
-
   ## To remove duplicate CAD Faces
   #  @param toRemoveDuplicateCADFaces "remove_duplicate_cad_faces" flag value
   def SetPreCADRemoveDuplicateCADFaces(self, toRemoveDuplicateCADFaces=False):
@@ -493,6 +512,42 @@ class BLSURF_Algorithm(Mesh_Algorithm):
       return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
     pass
 
+  ## Set an enforced vertex on a face given the coordinates of a point.
+  #  The face if found by the application.
+  #  @param x            : x coordinate
+  #  @param y            : y coordinate
+  #  @param z            : z coordinate
+  #  @param vertexName   : name of the enforced vertex
+  #  @param groupName    : name of the group
+  def AddEnforcedVertex(self, x, y, z, vertexName = "", groupName = ""):
+    from salome.smesh.smeshBuilder import AssureGeomPublished
+    if vertexName == "":
+      if groupName == "":
+        return self.Parameters().AddEnforcedVertex(x, y, z)
+      else:
+        return self.Parameters().AddEnforcedVertexWithGroup(x, y, z, groupName)
+      pass
+    else:
+      if groupName == "":
+        return self.Parameters().AddEnforcedVertexNamed(x, y, z, vertexName)
+      else:
+        return self.Parameters().AddEnforcedVertexNamedWithGroup( x, y, z, vertexName, groupName)
+      pass
+    pass
+
+  ## To set an enforced vertex on a face given a GEOM vertex, group or compound.
+  #  The face if found by the application.
+  #  @param theVertex    : GEOM vertex (or group, compound).
+  #  @param groupName    : name of the group
+  def AddEnforcedVertexGeom(self, theVertex, groupName = ""):
+    from salome.smesh.smeshBuilder import AssureGeomPublished
+    AssureGeomPublished( self.mesh, theVertex )
+    if groupName == "":
+      return self.Parameters().AddEnforcedVertexGeom(theVertex)
+    else:
+      return self.Parameters().AddEnforcedVertexGeomWithGroup(theVertex,groupName)
+    pass
+
   ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
   #  @param theFace      : GEOM face (or group, compound) on which to remove the enforced vertex
   #  @param x            : x coordinate
@@ -600,18 +655,30 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     self.Parameters().ClearSizeMaps()
     pass
 
-  ## Sets QuadAllowed flag.
+  ## Sets QuadAllowed flag (DEPRECATED: use SetElementType)
   #  @param toAllow "allow quadrangles" flag value
+  # TODO: to remove in Salome 9
   def SetQuadAllowed(self, toAllow=True):
     self.Parameters().SetQuadAllowed(toAllow)
     pass
 
+  ## Sets elements type
+  #  @param theElementType: 0 (Triangles), 1 (QuadrangleDominant), 2 (Quadrangles)
+  def SetElementType(self, theElementType=Triangles):
+    self.Parameters().SetElementType(theElementType)
+    pass
+
   ## Defines hypothesis having several parameters
   #  @return hypothesis object
   def Parameters(self):
     if not self.params:
-      self.params = self.Hypothesis("MG-CADSurf Parameters", [],
-                                    LIBRARY, UseExisting=0)
+      hypType = "MG-CADSurf Parameters"
+      hasGeom = self.mesh.GetMesh().HasShapeToMesh()
+      if hasGeom:
+        self.params = self.Hypothesis(hypType, [], LIBRARY, UseExisting=0)
+      else:
+        self.params = self.Hypothesis(hypType + "_NOGEOM", [], LIBRARY, UseExisting=0)
+        self.mesh.smeshpyD.SetName( self.params, hypType )
       pass
     return self.params
 
@@ -657,6 +724,36 @@ class BLSURF_Algorithm(Mesh_Algorithm):
         self.Parameters().AddPreCadEdgesPeriodicity(theEdge1, theEdge2)
     pass
 
+  #-----------------------------------------
+  # Hyper-Patches
+  #-----------------------------------------
+  
+  ## Defines hyper-patches. A hyper-patch is a set of adjacent faces meshed as a whole,
+  #  ignoring edges between them
+  #  @param hyperPatchList : list of hyper-patches. A hyper-patch is defined as a list of
+  #         faces or groups of faces. A face can be identified either as a GEOM object or
+  #         a face ID (returned e.g. by geompy.GetSubShapeID( mainShape, subShape )).
+  #         
+  #  Example: cadsurf.SetHyperPatches([[ Face_1, Group_2 ],[ 13, 23 ]])
+  def SetHyperPatches(self, hyperPatchList):
+    hpl = []
+    for patch in hyperPatchList:
+      ids = []
+      for face in patch:
+        if isinstance( face, int ):
+          ids.append( face )
+        elif isinstance( face, GEOM._objref_GEOM_Object):
+          faces = self.mesh.geompyD.SubShapeAll( face, self.mesh.geompyD.ShapeType["FACE"] )
+          for f in faces:
+            ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
+        else:
+          raise TypeError("Face of hyper-patch should be either ID or GEOM_Object, not %s" % type(face))
+        pass
+      hpl.append( ids )
+      pass
+    self.Parameters().SetHyperPatches( hpl )
+    return
+
   #=====================
   # Obsolete methods
   #=====================
@@ -669,7 +766,7 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     """
     Obsolete function. Use SetMinSize.
     """
-    print "Warning: SetPhyMin is obsolete. Please use SetMinSize"
+    print("Warning: SetPhyMin is obsolete. Please use SetMinSize")
     self.SetMinSize(theVal)
     pass
 
@@ -678,7 +775,7 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     """
     Obsolete function. Use SetMaxSize.
     """
-    print "Warning: SetPhyMax is obsolete. Please use SetMaxSize"
+    print("Warning: SetPhyMax is obsolete. Please use SetMaxSize")
     self.SetMaxSize(theVal)
     pass
 
@@ -687,7 +784,7 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     """
     Obsolete function. Use SetAngleMesh.
     """
-    print "Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh"
+    print("Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh")
     self.SetAngleMesh(theVal)
     pass
 
@@ -696,7 +793,7 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     """
     Obsolete function. Use SetAngleMesh.
     """
-    print "Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh"
+    print("Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh")
     self.SetAngleMesh(theVal)
     pass
 
@@ -705,7 +802,7 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     """
     Obsolete function. Use SetMinSize.
     """
-    print "Warning: SetGeoMin is obsolete. Please use SetMinSize"
+    print("Warning: SetGeoMin is obsolete. Please use SetMinSize")
     self.SetMinSize(theVal)
     pass
 
@@ -714,7 +811,7 @@ class BLSURF_Algorithm(Mesh_Algorithm):
     """
     Obsolete function. Use SetMaxSize.
     """
-    print "Warning: SetGeoMax is obsolete. Please use SetMaxSize"
+    print("Warning: SetGeoMax is obsolete. Please use SetMaxSize")
     self.SetMaxSize(theVal)
     pass