Salome HOME
0020716: EDF 1229 SMESH : Improvement of reversed edges dialog box
[modules/smesh.git] / src / SMESH_SWIG / smeshDC.py
index 2ec2d34e5a99ba18bf249c44ec485d8192be19f2..b02092b41722505f2f3a152093b574cd2d9e1eff 100644 (file)
@@ -509,6 +509,26 @@ def AssureGeomPublished(mesh, geom, name=''):
         mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
     return
 
+## Return the first vertex of a geomertical edge by ignoring orienation
+def FirstVertexOnCurve(edge):
+    from geompy import SubShapeAll, ShapeType, KindOfShape, PointCoordinates
+    vv = SubShapeAll( edge, ShapeType["VERTEX"])
+    if not vv:
+        raise TypeError, "Given object has no vertices"
+    if len( vv ) == 1: return vv[0]
+    info = KindOfShape(edge)
+    xyz = info[1:4] # coords of the first vertex
+    xyz1  = PointCoordinates( vv[0] )
+    xyz2  = PointCoordinates( vv[1] )
+    dist1, dist2 = 0,0
+    for i in range(3):
+        dist1 += abs( xyz[i] - xyz1[i] )
+        dist2 += abs( xyz[i] - xyz2[i] )
+    if dist1 < dist2:
+        return vv[0]
+    else:
+        return vv[1]
+
 # end of l1_auxiliary
 ## @}
 
@@ -796,6 +816,8 @@ class smeshDC(SMESH._objref_SMESH_Gen):
                      UnaryOp=FT_Undefined,
                      BinaryOp=FT_Undefined,
                      Tolerance=1e-07):
+        if not CritType in SMESH.FunctorType._items:
+            raise TypeError, "CritType should be of SMESH.FunctorType"
         aCriterion = self.GetEmptyCriterion()
         aCriterion.TypeOfElement = elementType
         aCriterion.Type = self.EnumToLong(CritType)
@@ -851,6 +873,7 @@ class smeshDC(SMESH._objref_SMESH_Gen):
             # Checks the treshold
             try:
                 aCriterion.Threshold = self.EnumToLong(aTreshold)
+                assert( aTreshold in SMESH.GeometryType._items )
             except:
                 if isinstance(aTreshold, int):
                     aCriterion.Threshold = aTreshold
@@ -4568,6 +4591,42 @@ class Mesh_Algorithm:
         hyp.SetIgnoreFaces(ignoreFaces)
         return hyp
 
+    ## Transform a list of ether edges or tuples (edge 1st_vertex_of_edge)
+    #  into a list acceptable to SetReversedEdges() of some 1D hypotheses
+    #  @ingroupl3_hypos_1dhyps
+    def ReversedEdgeIndices(self, reverseList):
+        resList = []
+        geompy = self.mesh.geompyD
+        for i in reverseList:
+            if isinstance( i, int ):
+                s = geompy.SubShapes(self.mesh.geom, [i])[0]
+                if s.GetShapeType() != geompyDC.GEOM.EDGE:
+                    raise TypeError, "Not EDGE index given"
+                resList.append( i )
+            elif isinstance( i, geompyDC.GEOM._objref_GEOM_Object ):
+                if i.GetShapeType() != geompyDC.GEOM.EDGE:
+                    raise TypeError, "Not an EDGE given"
+                resList.append( geompy.GetSubShapeID(self.mesh.geom, i ))
+            elif len( i ) > 1:
+                e = i[0]
+                v = i[1]
+                if not isinstance( e, geompyDC.GEOM._objref_GEOM_Object ) or \
+                   not isinstance( v, geompyDC.GEOM._objref_GEOM_Object ):
+                    raise TypeError, "A list item must be a tuple (edge 1st_vertex_of_edge)"
+                if v.GetShapeType() == geompyDC.GEOM.EDGE and \
+                   e.GetShapeType() == geompyDC.GEOM.VERTEX:
+                    v,e = e,v
+                if e.GetShapeType() != geompyDC.GEOM.EDGE or \
+                   v.GetShapeType() != geompyDC.GEOM.VERTEX:
+                    raise TypeError, "A list item must be a tuple (edge 1st_vertex_of_edge)"
+                vFirst = FirstVertexOnCurve( e )
+                tol    = geompy.Tolerance( vFirst )[-1]
+                if geompy.MinDistance( v, vFirst ) > 1.5*tol:
+                    resList.append( geompy.GetSubShapeID(self.mesh.geom, e ))
+            else:
+                raise TypeError, "Item must be either an edge or tuple (edge 1st_vertex_of_edge)"
+        return resList
+
 # Public class: Mesh_Segment
 # --------------------------
 
@@ -4640,7 +4699,8 @@ class Mesh_Segment(Mesh_Algorithm):
     ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
     #  @param n for the number of segments that cut an edge
     #  @param s for the scale factor (optional)
-    #  @param reversedEdges is a list of edges to mesh using reversed orientation
+    #  @param reversedEdges is a list of edges to mesh using reversed orientation.
+    #                       A list item can also be a tuple (edge 1st_vertex_of_edge)
     #  @param UseExisting if ==true - searches for an existing hypothesis created with
     #                     the same parameters, else (default) - create a new one
     #  @return an instance of StdMeshers_NumberOfSegments hypothesis
@@ -4649,20 +4709,19 @@ class Mesh_Segment(Mesh_Algorithm):
         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
             reversedEdges, UseExisting = [], reversedEdges
         entry = self.MainShapeEntry()
-        if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
-            reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
+        reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
         if s == []:
-            hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdges, entry],
+            hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
                                   UseExisting=UseExisting,
                                   CompareMethod=self.CompareNumberOfSegments)
         else:
-            hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdges, entry],
+            hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
                                   UseExisting=UseExisting,
                                   CompareMethod=self.CompareNumberOfSegments)
             hyp.SetDistrType( 1 )
             hyp.SetScaleFactor(s)
         hyp.SetNumberOfSegments(n)
-        hyp.SetReversedEdges( reversedEdges )
+        hyp.SetReversedEdges( reversedEdgeInd )
         hyp.SetObjectEntry( entry )
         return hyp
 
@@ -4685,7 +4744,8 @@ class Mesh_Segment(Mesh_Algorithm):
     ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
     #  @param start defines the length of the first segment
     #  @param end   defines the length of the last  segment
-    #  @param reversedEdges is a list of edges to mesh using reversed orientation
+    #  @param reversedEdges is a list of edges to mesh using reversed orientation.
+    #                       A list item can also be a tuple (edge 1st_vertex_of_edge)
     #  @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_Arithmetic1D hypothesis
@@ -4693,15 +4753,14 @@ class Mesh_Segment(Mesh_Algorithm):
     def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
             reversedEdges, UseExisting = [], reversedEdges
-        if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
-            reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
+        reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
         entry = self.MainShapeEntry()
-        hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdges, entry],
+        hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
                               UseExisting=UseExisting,
                               CompareMethod=self.CompareArithmetic1D)
         hyp.SetStartLength(start)
         hyp.SetEndLength(end)
-        hyp.SetReversedEdges( reversedEdges )
+        hyp.SetReversedEdges( reversedEdgeInd )
         hyp.SetObjectEntry( entry )
         return hyp
 
@@ -4723,7 +4782,8 @@ class Mesh_Segment(Mesh_Algorithm):
     # values are equals 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
+    #  @param reversedEdges is a list of edges to mesh using reversed orientation.
+    #                       A list item can also be a tuple (edge 1st_vertex_of_edge)
     #  @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_Arithmetic1D hypothesis
@@ -4731,15 +4791,14 @@ class Mesh_Segment(Mesh_Algorithm):
     def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
             reversedEdges, UseExisting = [], reversedEdges
-        if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
-            reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
+        reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
         entry = self.MainShapeEntry()
-        hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdges, entry],
+        hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
                               UseExisting=UseExisting,
                               CompareMethod=self.CompareFixedPoints1D)
         hyp.SetPoints(points)
         hyp.SetNbSegments(nbSegs)
-        hyp.SetReversedEdges(reversedEdges)
+        hyp.SetReversedEdges(reversedEdgeInd)
         hyp.SetObjectEntry(entry)
         return hyp
 
@@ -4759,7 +4818,8 @@ class Mesh_Segment(Mesh_Algorithm):
     ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
     #  @param start defines the length of the first segment
     #  @param end   defines the length of the last  segment
-    #  @param reversedEdges is a list of edges to mesh using reversed orientation
+    #  @param reversedEdges is a list of edges to mesh using reversed orientation.
+    #                       A list item can also be a tuple (edge 1st_vertex_of_edge)
     #  @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_StartEndLength hypothesis
@@ -4767,15 +4827,14 @@ class Mesh_Segment(Mesh_Algorithm):
     def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
             reversedEdges, UseExisting = [], reversedEdges
-        if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
-            reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
+        reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
         entry = self.MainShapeEntry()
-        hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdges, entry],
+        hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
                               UseExisting=UseExisting,
                               CompareMethod=self.CompareStartEndLength)
         hyp.SetStartLength(start)
         hyp.SetEndLength(end)
-        hyp.SetReversedEdges( reversedEdges )
+        hyp.SetReversedEdges( reversedEdgeInd )
         hyp.SetObjectEntry( entry )
         return hyp
 
@@ -5135,11 +5194,14 @@ class Mesh_Triangle(Mesh_Algorithm):
             self.params.SetOptionValue(optionName,level)
 
     ## Sets advanced PreCAD option value.
+    #  Keyword arguments:
+    #  optionName: name of the option
+    #  optionValue: value of the option
     #  @ingroup l3_hypos_blsurf
-    def SetPreCADOptionValue(self, optionName, level):
+    def SetPreCADOptionValue(self, optionName, optionValue):
         if self.Parameters():
             #  Parameter of BLSURF algo
-            self.params.SetPreCADOptionValue(optionName,level)
+            self.params.SetPreCADOptionValue(optionName,optionValue)
 
     ## Sets GMF file for export at computation
     #  @ingroup l3_hypos_blsurf
@@ -5199,75 +5261,38 @@ class Mesh_Triangle(Mesh_Algorithm):
     #  @param x            : x coordinate
     #  @param y            : y coordinate
     #  @param z            : z coordinate
-    #  @ingroup l3_hypos_blsurf
-    def SetEnforcedVertex(self, theFace, x, y, z):
-        if self.Parameters():
-            #  Parameter of BLSURF algo
-            AssureGeomPublished( self.mesh, theFace )
-            return self.params.SetEnforcedVertex(theFace, x, y, z)
-
-    ## To set an enforced vertex as SetEnforcedVertex. The created enforced vertex is identified by a name.
-    #  @param theFace      : GEOM face (or group, compound) on which to define an enforced vertex
-    #  @param x            : x coordinate
-    #  @param y            : y coordinate
-    #  @param z            : z coordinate
     #  @param vertexName   : name of the enforced vertex
-    #  @ingroup l3_hypos_blsurf
-    def SetEnforcedVertexNamed(self, theFace, x, y, z, vertexName):
-        if self.Parameters():
-            #  Parameter of BLSURF algo
-            AssureGeomPublished( self.mesh, theFace )
-            return self.params.SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
-
-    ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
-    #  @param theFace      : GEOM face (or group, compound) on which to define an enforced vertex
-    #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
-    #  @ingroup l3_hypos_blsurf
-    def SetEnforcedVertexGeom(self, theFace, theVertex):
-        if self.Parameters():
-            #  Parameter of BLSURF algo
-            AssureGeomPublished( self.mesh, theFace )
-            AssureGeomPublished( self.mesh, theVertex )
-            return self.params.SetEnforcedVertexGeom(theFace, theVertex)
-
-    ## To set an enforced vertex as SetEnforcedVertex and add it in the group "groupName".
-    #  @param theFace      : GEOM face (or group, compound) on which to define an enforced vertex
-    #  @param x            : x coordinate
-    #  @param y            : y coordinate
-    #  @param z            : z coordinate
     #  @param groupName    : name of the group
     #  @ingroup l3_hypos_blsurf
-    def SetEnforcedVertexWithGroup(self, theFace, x, y, z, groupName):
+    def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
         if self.Parameters():
             #  Parameter of BLSURF algo
             AssureGeomPublished( self.mesh, theFace )
-            return self.params.SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
-
-    ## To set an enforced vertex as SetEnforcedVertexNamed and add it in the group "groupName".
-    #  @param theFace      : GEOM face (or group, compound) on which to define an enforced vertex
-    #  @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
-    #  @ingroup l3_hypos_blsurf
-    def SetEnforcedVertexNamedWithGroup(self, theFace, x, y, z, vertexName, groupName):
-        if self.Parameters():
-            #  Parameter of BLSURF algo
-            AssureGeomPublished( self.mesh, theFace )
-            return self.params.SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
+            if vertexName == "":
+              if groupName == "":
+                return self.params.SetEnforcedVertex(theFace, x, y, z)
+              else:
+                return self.params.SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
+            else:
+              if groupName == "":
+                return self.params.SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
+              else:
+                return self.params.SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
 
-    ## To set an enforced vertex as SetEnforcedVertexGeom and add it in the group "groupName".
+    ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
     #  @param theFace      : GEOM face (or group, compound) on which to define an enforced vertex
     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
     #  @param groupName    : name of the group
     #  @ingroup l3_hypos_blsurf
-    def SetEnforcedVertexGeomWithGroup(self, theFace, theVertex, groupName):
+    def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
         if self.Parameters():
             #  Parameter of BLSURF algo
             AssureGeomPublished( self.mesh, theFace )
             AssureGeomPublished( self.mesh, theVertex )
-            return self.params.SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
+            if groupName == "":
+              return self.params.SetEnforcedVertexGeom(theFace, theVertex)
+            else:
+              return self.params.SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
 
     ## 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
@@ -5844,80 +5869,79 @@ class Mesh_Tetrahedron(Mesh_Algorithm):
             self.params.SetToRemoveCentralPoint(toRemove)
 
     ## To set an enforced vertex.
+    #  @param x            : x coordinate
+    #  @param y            : y coordinate
+    #  @param z            : z coordinate
+    #  @param size         : size of 1D element around enforced vertex
+    #  @param vertexName   : name of the enforced vertex
+    #  @param groupName    : name of the group
     #  @ingroup l3_hypos_ghs3dh
-    def SetEnforcedVertex(self, x, y, z, size):
-        #  Advanced parameter of GHS3D
-        if self.Parameters():
-            return self.params.SetEnforcedVertex(x, y, z, size)
-
-    ## To set an enforced vertex and add it in the group "groupName".
-    #  Only on meshes w/o geometry
-    #  @ingroup l3_hypos_ghs3dh
-    def SetEnforcedVertexWithGroup(self, x, y, z, size, groupName):
-        #  Advanced parameter of GHS3D
-        if self.Parameters():
-            return self.params.SetEnforcedVertexWithGroup(x, y, z, size,groupName)
-
-    ## To remove an enforced vertex.
-    #  @ingroup l3_hypos_ghs3dh
-    def RemoveEnforcedVertex(self, x, y, z):
+    def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
         #  Advanced parameter of GHS3D
         if self.Parameters():
-            return self.params.RemoveEnforcedVertex(x, y, z)
+          if vertexName == "":
+            if groupName == "":
+              return self.params.SetEnforcedVertex(x, y, z, size)
+            else:
+              return self.params.SetEnforcedVertexWithGroup(x, y, z, size, groupName)
+          else:
+            if groupName == "":
+              return self.params.SetEnforcedVertexNamed(x, y, z, size, vertexName)
+            else:
+              return self.params.SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
 
     ## To set an enforced vertex given a GEOM vertex, group or compound.
+    #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
+    #  @param size         : size of 1D element around enforced vertex
+    #  @param groupName    : name of the group
     #  @ingroup l3_hypos_ghs3dh
-    def SetEnforcedVertexGeom(self, theVertex, size):
+    def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
         AssureGeomPublished( self.mesh, theVertex )
         #  Advanced parameter of GHS3D
         if self.Parameters():
+          if groupName == "":
             return self.params.SetEnforcedVertexGeom(theVertex, size)
+          else:
+            return self.params.SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
 
-    ## To set an enforced vertex given a GEOM vertex, group or compound
-    #  and add it in the group "groupName".
-    #  Only on meshes w/o geometry
+    ## To remove an enforced vertex.
+    #  @param x            : x coordinate
+    #  @param y            : y coordinate
+    #  @param z            : z coordinate
     #  @ingroup l3_hypos_ghs3dh
-    def SetEnforcedVertexGeomWithGroup(self, theVertex, size, groupName):
-        AssureGeomPublished( self.mesh, theVertex )
+    def RemoveEnforcedVertex(self, x, y, z):
         #  Advanced parameter of GHS3D
         if self.Parameters():
-            return self.params.SetEnforcedVertexGeomWithGroup(theVertex, size,groupName)
+          return self.params.RemoveEnforcedVertex(x, y, z)
 
     ## To remove an enforced vertex given a GEOM vertex, group or compound.
+    #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
     #  @ingroup l3_hypos_ghs3dh
     def RemoveEnforcedVertexGeom(self, theVertex):
         AssureGeomPublished( self.mesh, theVertex )
         #  Advanced parameter of GHS3D
         if self.Parameters():
-            return self.params.RemoveEnforcedVertexGeom(theVertex)
-
-    ## To set an enforced mesh.
-    #  @ingroup l3_hypos_ghs3dh
-    def SetEnforcedMesh(self, theSource, elementType):
-        #  Advanced parameter of GHS3D
-        if self.Parameters():
-            return self.params.SetEnforcedMesh(theSource, elementType)
-
-    ## To set an enforced mesh and add the enforced elements in the group "groupName".
-    #  @ingroup l3_hypos_ghs3dh
-    def SetEnforcedMeshWithGroup(self, theSource, elementType, groupName):
-        #  Advanced parameter of GHS3D
-        if self.Parameters():
-            return self.params.SetEnforcedMeshWithGroup(theSource, elementType, groupName)
-
-    ## To set an enforced mesh with given size.
-    #  @ingroup l3_hypos_ghs3dh
-    def SetEnforcedMeshSize(self, theSource, elementType, size):
-        #  Advanced parameter of GHS3D
-        if self.Parameters():
-            return self.params.SetEnforcedMeshSize(theSource, elementType, size)
+          return self.params.RemoveEnforcedVertexGeom(theVertex)
 
     ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
+    #  @param theSource    : source mesh which provides constraint elements/nodes
+    #  @param elementType  : SMESH.ElementType (NODE, EDGE or FACE)
+    #  @param size         : size of elements around enforced elements. Unused if -1.
+    #  @param groupName    : group in which enforced elements will be added. Unused if "".
     #  @ingroup l3_hypos_ghs3dh
-    def SetEnforcedMeshSizeWithGroup(self, theSource, elementType, size, groupName):
+    def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
         #  Advanced parameter of GHS3D
         if self.Parameters():
-            return self.params.SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
+          if size >= 0:
+            if groupName != "":
+              return self.params.SetEnforcedMesh(theSource, elementType)
+            else:
+              return self.params.SetEnforcedMeshWithGroup(theSource, elementType, groupName)
+          else:
+            if groupName != "":
+              return self.params.SetEnforcedMeshSize(theSource, elementType, size)
+            else:
+              return self.params.SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
 
     ## Sets command line option as text.
     #  @ingroup l3_hypos_ghs3dh