Salome HOME
IPAL53870: Dump study script creates an excess sub-mesh
[modules/smesh.git] / src / SMESH_SWIG / StdMeshersBuilder.py
index 054bd7e7e11b96652aa6515650e35f4c8e61e308..afcd449fb9ec38766601d1929ad9dcdbb52230bd 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -21,6 +21,8 @@
 # @package StdMeshersBuilder
 # Python API for the standard meshing plug-in module.
 
+LIBRARY = "libStdMeshersEngine.so"
+
 from salome.smesh.smesh_algorithm import Mesh_Algorithm
 import StdMeshers
 
@@ -42,9 +44,14 @@ Hexa        = "Hexa_3D"
 QUADRANGLE  = "Quadrangle_2D"
 ## Algorithm type: Radial Quadrangle 1D-2D algorithm, see StdMeshersBuilder_RadialQuadrangle1D2D
 RADIAL_QUAD = "RadialQuadrangle_1D2D"
+## Algorithm type: Quadrangle (Medial Axis Projection) 1D-2D algorithm, see StdMeshersBuilder_QuadMA_1D2D
+QUAD_MA_PROJ = "QuadFromMedialAxis_1D2D"
+## Algorithm type: Polygon Per Face 2D algorithm, see StdMeshersBuilder_PolygonPerFace
+POLYGON     = "PolygonPerFace_2D"
 
-# import items of enum QuadType
+# import items of enums
 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
+for e in StdMeshers.VLExtrusionMethod._items: exec('%s = StdMeshers.%s'%(e,e))
 
 #----------------------
 # Algorithms
@@ -63,7 +70,7 @@ class StdMeshersBuilder_Segment(Mesh_Algorithm):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = REGULAR
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = True
@@ -143,7 +150,7 @@ class StdMeshersBuilder_Segment(Mesh_Algorithm):
             reversedEdges, UseExisting = [], reversedEdges
         entry = self.MainShapeEntry()
         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
-        if s == []:
+        if not s:
             hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
                                   UseExisting=UseExisting,
                                   CompareMethod=self._compareNumberOfSegments)
@@ -151,7 +158,6 @@ class StdMeshersBuilder_Segment(Mesh_Algorithm):
             hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
                                   UseExisting=UseExisting,
                                   CompareMethod=self._compareNumberOfSegments)
-            hyp.SetDistrType( 1 )
             hyp.SetScaleFactor(s)
         hyp.SetNumberOfSegments(n)
         hyp.SetReversedEdges( reversedEdgeInd )
@@ -183,23 +189,20 @@ class StdMeshersBuilder_Segment(Mesh_Algorithm):
     #  @param minSize defines the minimal allowed segment length
     #  @param maxSize defines the maximal allowed segment length
     #  @param deflection defines the maximal allowed distance from a segment to an edge
-    #  @param grading defines how much size of adjacent elements can differ
     #  @param UseExisting if ==true - searches for an existing hypothesis created with
     #                     the same parameters, else (default) - creates a new one
     #  @return an instance of StdMeshers_Adaptive1D hypothesis
     #  @ingroup l3_hypos_1dhyps
-    def Adaptive(self, minSize, maxSize, deflection, grading, UseExisting=False):
+    def Adaptive(self, minSize, maxSize, deflection, UseExisting=False):
         from salome.smesh.smeshBuilder import IsEqual
         compFun = lambda hyp, args: ( IsEqual(hyp.GetMinSize(), args[0]) and \
                                       IsEqual(hyp.GetMaxSize(), args[1]) and \
-                                      IsEqual(hyp.GetDeflection(), args[2]) and \
-                                      IsEqual(hyp.GetGrading(), args[3]))
-        hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection, grading],
+                                      IsEqual(hyp.GetDeflection(), args[2]))
+        hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection],
                               UseExisting=UseExisting, CompareMethod=compFun)
         hyp.SetMinSize(minSize)
         hyp.SetMaxSize(maxSize)
         hyp.SetDeflection(deflection)
-        hyp.SetGrading(grading)
         return hyp
 
     ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with a length
@@ -260,7 +263,7 @@ class StdMeshersBuilder_Segment(Mesh_Algorithm):
     # on curve from 0 to 1 (additionally it is neecessary to check
     # orientation of edges and create list of reversed edges if it is
     # needed) and sets numbers of segments between given points (default
-    # values are equals 1
+    # values are 1)
     #  @param points defines the list of parameters on curve
     #  @param nbSegs defines the list of numbers of segments
     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
@@ -378,6 +381,7 @@ class StdMeshersBuilder_Segment(Mesh_Algorithm):
             pass
         # 0D algorithm
         if self.geom is None:
+            self.geom = store_geom
             raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
         from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
         AssureGeomPublished( self.mesh, self.geom )
@@ -388,7 +392,7 @@ class StdMeshersBuilder_Segment(Mesh_Algorithm):
             algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
             pass
         status = self.mesh.mesh.AddHypothesis(self.geom, algo)
-        TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
+        TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True, self.mesh)
         #
         from salome.smesh.smeshBuilder import IsEqual
         comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
@@ -425,7 +429,7 @@ class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = COMPOSITE
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = False
@@ -458,9 +462,6 @@ class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
     algoType   = PYTHON
     ## doc string of the method
     #  @internal
-    docHelper  = "Creates tetrahedron 3D algorithm for solids"
-    ## doc string of the method
-    #  @internal
     docHelper  = "Creates segment 1D algorithm for edges"
 
     ## Private constructor.
@@ -501,7 +502,7 @@ class StdMeshersBuilder_Triangle_MEFISTO(Mesh_Algorithm):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = MEFISTO
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = True
@@ -555,7 +556,7 @@ class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = QUADRANGLE
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = True
@@ -702,7 +703,7 @@ class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = Hexa
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = True
@@ -734,7 +735,7 @@ class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = "Projection_1D"
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = True
@@ -792,7 +793,7 @@ class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = "Projection_2D"
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = True
@@ -833,12 +834,13 @@ class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
             from salome.smesh.smeshBuilder import AssureGeomPublished
             AssureGeomPublished( self.mesh, geom )
         hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
-                              UseExisting=0)
+                              UseExisting=0, toAdd=False)
         # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
         hyp.SetSourceFace( face )
         hyp.SetSourceMesh( mesh )
         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
+        self.mesh.AddHypothesis(hyp, self.geom)
         return hyp
 
     pass # end of StdMeshersBuilder_Projection2D class
@@ -858,7 +860,7 @@ class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
     algoType   = "Projection_1D2D"
     ## doc string of the method
     #  @internal
-    docHelper  = "Creates projection 1D-2D algorithm for edges and faces"
+    docHelper  = "Creates projection 1D-2D algorithm for faces"
 
     ## Private constructor.
     #  @param mesh parent mesh object algorithm is assigned to
@@ -962,10 +964,8 @@ class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
         shape = geom
         if not shape:
             shape = mesh.geom
-        from salome.geom import geomBuilder
-        nbSolids = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SOLID"] ))
-        nbShells = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SHELL"] ))
-        if nbSolids == 0 or nbSolids == nbShells:
+        isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
+        if not isRadial:
             self.Create(mesh, geom, "Prism_3D")
             pass
         else:
@@ -1039,11 +1039,10 @@ class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
         if self.algoType != "RadialPrism_3D":
             print "Prism_3D algorith doesn't support any hyposesis"
             return None
-        if s == []:
+        if not s:
             hyp = self.OwnHypothesis("NumberOfSegments", [n])
         else:
             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
-            hyp.SetDistrType( 1 )
             hyp.SetScaleFactor(s)
         hyp.SetNumberOfSegments(n)
         return hyp
@@ -1102,8 +1101,7 @@ class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
 
     pass # end of StdMeshersBuilder_Prism3D class
 
-## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
-#  depending on geometry
+## Defines Radial Prism 3D algorithm
 # 
 #  It is created by calling smeshBuilder.Mesh.Prism(geom=0)
 #
@@ -1118,7 +1116,7 @@ class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
     algoType   = "RadialPrism_3D"
     ## doc string of the method
     #  @internal
-    docHelper  = "Creates prism 3D algorithm for volumes"
+    docHelper  = "Creates Raial Prism 3D algorithm for volumes"
 
     ## Private constructor.
     #  @param mesh parent mesh object algorithm is assigned to
@@ -1135,30 +1133,12 @@ class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
         self.nbLayers = None
         return
 
-## Defines a Radial Quadrangle 1D-2D algorithm
+## Base class for algorithms supporting radial distribution hypotheses
 # 
-#  It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
-#
-#  @ingroup l2_algos_radialq
-class StdMeshersBuilder_RadialQuadrangle1D2D(Mesh_Algorithm):
+class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
 
-    ## name of the dynamic method in smeshBuilder.Mesh class
-    #  @internal
-    meshMethod = "Quadrangle"
-    ## type of algorithm used with helper function in smeshBuilder.Mesh class
-    #  @internal
-    algoType   = RADIAL_QUAD
-    ## doc string of the method
-    #  @internal
-    docHelper  = "Creates quadrangle 1D-2D algorithm for triangular faces"
-
-    ## Private constructor.
-    #  @param mesh parent mesh object algorithm is assigned to
-    #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
-    #              if it is @c 0 (default), the algorithm is assigned to the main shape
-    def __init__(self, mesh, geom=0):
+    def __init__(self):
         Mesh_Algorithm.__init__(self)
-        self.Create(mesh, geom, self.algoType)
 
         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
         self.nbLayers = None
@@ -1261,6 +1241,96 @@ class StdMeshersBuilder_RadialQuadrangle1D2D(Mesh_Algorithm):
 
     pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
 
+## Defines a Radial Quadrangle 1D-2D algorithm
+# 
+#  It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
+#
+#  @ingroup l2_algos_radialq
+class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
+
+    ## name of the dynamic method in smeshBuilder.Mesh class
+    #  @internal
+    meshMethod = "Quadrangle"
+    ## type of algorithm used with helper function in smeshBuilder.Mesh class
+    #  @internal
+    algoType   = RADIAL_QUAD
+    ## doc string of the method
+    #  @internal
+    docHelper  = "Creates quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
+
+    ## Private constructor.
+    #  @param mesh parent mesh object algorithm is assigned to
+    #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
+    #              if it is @c 0 (default), the algorithm is assigned to the main shape
+    def __init__(self, mesh, geom=0):
+        StdMeshersBuilder_RadialAlgorithm.__init__(self)
+        self.Create(mesh, geom, self.algoType)
+
+        self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
+        self.nbLayers = None
+        pass
+
+
+## Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm
+# 
+#  It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
+#
+#  @ingroup l2_algos_quad_ma
+class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
+
+    ## name of the dynamic method in smeshBuilder.Mesh class
+    #  @internal
+    meshMethod = "Quadrangle"
+    ## type of algorithm used with helper function in smeshBuilder.Mesh class
+    #  @internal
+    algoType   = QUAD_MA_PROJ
+    ## doc string of the method
+    #  @internal
+    docHelper  = "Creates quadrangle 1D-2D algorithm for faces"
+
+    ## Private constructor.
+    #  @param mesh parent mesh object algorithm is assigned to
+    #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
+    #              if it is @c 0 (default), the algorithm is assigned to the main shape
+    def __init__(self, mesh, geom=0):
+        StdMeshersBuilder_RadialAlgorithm.__init__(self)
+        self.Create(mesh, geom, self.algoType)
+        pass
+
+    pass
+
+## Defines a Polygon Per Face 2D algorithm
+# 
+#  It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
+#
+#  @ingroup l2_algos_quad_ma
+class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
+
+    ## name of the dynamic method in smeshBuilder.Mesh class
+    #  @internal
+    meshMethod = "Polygon"
+    ## type of algorithm used with helper function in smeshBuilder.Mesh class
+    #  @internal
+    algoType   = POLYGON
+    ## flag pointing whether this algorithm should be used by default in dynamic method
+    #  of smeshBuilder.Mesh class
+    #  @internal
+    isDefault  = True
+    ## doc string of the method
+    #  @internal
+    docHelper  = "Creates polygon 2D algorithm for faces"
+
+    ## Private constructor.
+    #  @param mesh parent mesh object algorithm is assigned to
+    #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
+    #              if it is @c 0 (default), the algorithm is assigned to the main shape
+    def __init__(self, mesh, geom=0):
+        Mesh_Algorithm.__init__(self)
+        self.Create(mesh, geom, self.algoType)
+        pass
+
+    pass
+
 ## Defines a Use Existing Elements 1D algorithm
 #
 #  It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
@@ -1274,7 +1344,7 @@ class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = "Import_1D"
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = True
@@ -1324,13 +1394,13 @@ class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = "Import_1D2D"
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = True
     ## doc string of the method
     #  @internal
-    docHelper  = "Creates 1D-2D algorithm for edges/faces with reusing of existing mesh elements"
+    docHelper  = "Creates 1D-2D algorithm for faces with reusing of existing mesh elements"
 
     ## Private constructor.
     #  @param mesh parent mesh object algorithm is assigned to
@@ -1348,15 +1418,16 @@ class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
     #  @param UseExisting if ==true - searches for the existing hypothesis created with
     #                     the same parameters, else (default) - creates a new one
     def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
-        for group in groups:
-            from salome.smesh.smeshBuilder import AssureGeomPublished
-            AssureGeomPublished( self.mesh, group )
+        import SMESH
         compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
                                       hyp.GetCopySourceMesh() == args[1], args[2] )
         hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
-                              UseExisting=UseExisting, CompareMethod=compFun)
+                              UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
+        if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
+            groups = [groups]
         hyp.SetSourceFaces(groups)
         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
+        self.mesh.AddHypothesis(hyp, self.geom)
         return hyp
 
     pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
@@ -1374,13 +1445,13 @@ class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
     ## type of algorithm used with helper function in smeshBuilder.Mesh class
     #  @internal
     algoType   = "Cartesian_3D"
-    ## flag pointing either this algorithm should be used by default in dynamic method
+    ## flag pointing whether this algorithm should be used by default in dynamic method
     #  of smeshBuilder.Mesh class
     #  @internal
     isDefault  = True
     ## doc string of the method
     #  @internal
-    docHelper  = "Creates body fitting 3D algorithm for volumes"
+    docHelper  = "Creates Body Fitting 3D algorithm for volumes"
 
     ## Private constructor.
     #  @param mesh parent mesh object algorithm is assigned to
@@ -1510,7 +1581,7 @@ class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
     algoType   = "UseExisting_1D"
     ## doc string of the method
     #  @internal
-    docHelper  = "Creates 1D algorithm for edges with reusing of existing mesh elements"
+    docHelper  = "Creates 1D algorithm allowing batch meshing of edges"
 
     ## Private constructor.
     #  @param mesh parent mesh object algorithm is assigned to
@@ -1538,7 +1609,7 @@ class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
     algoType   = "UseExisting_2D"
     ## doc string of the method
     #  @internal
-    docHelper  = "Creates 2D algorithm for faces with reusing of existing mesh elements"
+    docHelper  = "Creates 2D algorithm allowing batch meshing of faces"
 
     ## Private constructor.
     #  @param mesh parent mesh object algorithm is assigned to