Salome HOME
Fix TypeError: unorderable types: EnumItem() < EnumItem()
[modules/smesh.git] / src / SMESH_SWIG / smeshBuilder.py
index cb3244dafa69a9146da5fb28d63bf045bd3a2f88..19724b28569918f1b05d1bb47ef570f91a5c9abc 100644 (file)
@@ -90,7 +90,7 @@ from   salome.smesh.smesh_algorithm import Mesh_Algorithm
 import SALOME
 import SALOMEDS
 import os
-import collections
+import inspect
 
 ## Private class used to workaround a problem that sometimes isinstance(m, Mesh) returns False
 #
@@ -124,7 +124,7 @@ def ParseParameters(*args):
     Parameters = ""
     hasVariables = False
     varModifFun=None
-    if args and isinstance( args[-1], collections.Callable):
+    if args and callable(args[-1]):
         args, varModifFun = args[:-1], args[-1]
     for parameter in args:
 
@@ -219,31 +219,31 @@ def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh):
         pass
     reason = ""
     if hasattr( status, "__getitem__" ):
-        status,reason = status[0],status[1]
-    if status == HYP_UNKNOWN_FATAL :
+        status, reason = status[0]._v, status[1]
+    if status == HYP_UNKNOWN_FATAL._v:
         reason = "for unknown reason"
-    elif status == HYP_INCOMPATIBLE :
+    elif status == HYP_INCOMPATIBLE._v:
         reason = "this hypothesis mismatches the algorithm"
-    elif status == HYP_NOTCONFORM :
+    elif status == HYP_NOTCONFORM._v:
         reason = "a non-conform mesh would be built"
-    elif status == HYP_ALREADY_EXIST :
+    elif status == HYP_ALREADY_EXIST._v:
         if isAlgo: return # it does not influence anything
         reason = hypType + " of the same dimension is already assigned to this shape"
-    elif status == HYP_BAD_DIM :
+    elif status == HYP_BAD_DIM._v:
         reason = hypType + " mismatches the shape"
-    elif status == HYP_CONCURENT :
+    elif status == HYP_CONCURENT._v:
         reason = "there are concurrent hypotheses on sub-shapes"
-    elif status == HYP_BAD_SUBSHAPE :
+    elif status == HYP_BAD_SUBSHAPE._v:
         reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
-    elif status == HYP_BAD_GEOMETRY:
+    elif status == HYP_BAD_GEOMETRY._v:
         reason = "the algorithm is not applicable to this geometry"
-    elif status == HYP_HIDDEN_ALGO:
+    elif status == HYP_HIDDEN_ALGO._v:
         reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
-    elif status == HYP_HIDING_ALGO:
+    elif status == HYP_HIDING_ALGO._v:
         reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
-    elif status == HYP_NEED_SHAPE:
+    elif status == HYP_NEED_SHAPE._v:
         reason = "algorithm can't work without shape"
-    elif status == HYP_INCOMPAT_HYPS:
+    elif status == HYP_INCOMPAT_HYPS._v:
         pass
     else:
         return
@@ -254,7 +254,7 @@ def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh):
             meshName = GetName( mesh )
             if meshName and meshName != NO_NAME:
                 where = '"%s" shape in "%s" mesh ' % ( geomName, meshName )
-    if status < HYP_UNKNOWN_FATAL and where:
+    if status < HYP_UNKNOWN_FATAL._v and where:
         print('"%s" was assigned to %s but %s' %( hypName, where, reason ))
     elif where:
         print('"%s" was not assigned to %s : %s' %( hypName, where, reason ))
@@ -989,7 +989,7 @@ class smeshBuilder(SMESH._objref_SMESH_Gen):
             if not meth_name.startswith("Get") and \
                not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
                 method = getattr ( hyp.__class__, meth_name )
-                if isinstance(method, collections.Callable):
+                if callable(method):
                     setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
 
         return hyp
@@ -1223,8 +1223,8 @@ class Mesh(metaclass=MeshMeta):
     #  @param name Study name of the mesh
     #  @ingroup l2_construct
     def __init__(self, smeshpyD, geompyD, obj=0, name=0):
-        self.smeshpyD=smeshpyD
-        self.geompyD=geompyD
+        self.smeshpyD = smeshpyD
+        self.geompyD = geompyD
         if obj is None:
             obj = 0
         objHasName = False
@@ -1484,18 +1484,18 @@ class Mesh(metaclass=MeshMeta):
                 name = err.algoName
                 if len(name) == 0:
                     reason = '%s %sD algorithm is missing' % (glob, dim)
-                elif err.state == HYP_MISSING:
+                elif err.state._v == HYP_MISSING._v:
                     reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
                               % (glob, dim, name, dim))
-                elif err.state == HYP_NOTCONFORM:
+                elif err.state._v == HYP_NOTCONFORM._v:
                     reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
-                elif err.state == HYP_BAD_PARAMETER:
+                elif err.state._v == HYP_BAD_PARAMETER._v:
                     reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
                               % ( glob, dim, name ))
-                elif err.state == HYP_BAD_GEOMETRY:
+                elif err.state._v == HYP_BAD_GEOMETRY._v:
                     reason = ('%s %sD algorithm "%s" is assigned to mismatching'
                               'geometry' % ( glob, dim, name ))
-                elif err.state == HYP_HIDDEN_ALGO:
+                elif err.state._v == HYP_HIDDEN_ALGO._v:
                     reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
                               'algorithm of upper dimension generating %sD mesh'
                               % ( glob, dim, name, glob, dim ))
@@ -1719,7 +1719,7 @@ class Mesh(metaclass=MeshMeta):
             AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
             status = self.mesh.AddHypothesis(geom, hyp)
         else:
-            status = HYP_BAD_GEOMETRY,""
+            status = HYP_BAD_GEOMETRY, ""
         hyp_name = GetName( hyp )
         geom_name = ""
         if geom:
@@ -4561,10 +4561,12 @@ class Mesh(metaclass=MeshMeta):
     #  @param NodesToKeep nodes to keep in the mesh: a list of groups, sub-meshes or node IDs.
     #         If @a NodesToKeep does not include a node to keep for some group to merge,
     #         then the first node in the group is kept.
+    #  @param AvoidMakingHoles prevent merging nodes which cause removal of elements becoming
+    #         invalid
     #  @ingroup l2_modif_trsf
-    def MergeNodes (self, GroupsOfNodes, NodesToKeep=[]):
+    def MergeNodes (self, GroupsOfNodes, NodesToKeep=[], AvoidMakingHoles=False):
         # NodesToKeep are converted to SMESH_IDSource in meshEditor.MergeNodes()
-        self.editor.MergeNodes(GroupsOfNodes,NodesToKeep)
+        self.editor.MergeNodes( GroupsOfNodes, NodesToKeep, AvoidMakingHoles )
 
     ## Find the elements built on the same nodes.
     #  @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
@@ -5046,8 +5048,8 @@ class Mesh(metaclass=MeshMeta):
 #  with old dump scripts which call SMESH_Mesh directly and not via smeshBuilder.Mesh
 #
 class meshProxy(SMESH._objref_SMESH_Mesh):
-    def __init__(self):
-        SMESH._objref_SMESH_Mesh.__init__(self)
+    def __init__(self, *args):
+        SMESH._objref_SMESH_Mesh.__init__(self, *args)
     def __deepcopy__(self, memo=None):
         new = self.__class__()
         return new
@@ -5062,8 +5064,8 @@ omniORB.registerObjref(SMESH._objref_SMESH_Mesh._NP_RepositoryId, meshProxy)
 ## Private class wrapping SMESH.SMESH_SubMesh in order to add Compute()
 #
 class submeshProxy(SMESH._objref_SMESH_subMesh):
-    def __init__(self):
-        SMESH._objref_SMESH_subMesh.__init__(self)
+    def __init__(self, *args):
+        SMESH._objref_SMESH_subMesh.__init__(self, *args)
         self.mesh = None
     def __deepcopy__(self, memo=None):
         new = self.__class__()
@@ -5099,8 +5101,8 @@ omniORB.registerObjref(SMESH._objref_SMESH_subMesh._NP_RepositoryId, submeshProx
 #  smeshBuilder.Mesh
 #
 class meshEditor(SMESH._objref_SMESH_MeshEditor):
-    def __init__(self):
-        SMESH._objref_SMESH_MeshEditor.__init__(self)
+    def __init__(self, *args):
+        SMESH._objref_SMESH_MeshEditor.__init__(self, *args)
         self.mesh = None
     def __getattr__(self, name ): # method called if an attribute not found
         if not self.mesh:         # look for name() method in Mesh class
@@ -5120,17 +5122,18 @@ class meshEditor(SMESH._objref_SMESH_MeshEditor):
     def FindCoincidentNodesOnPart(self,*args): # a 3d arg added (SeparateCornerAndMediumNodes)
         if len( args ) == 2: args += False,
         return SMESH._objref_SMESH_MeshEditor.FindCoincidentNodesOnPart( self, *args )
-    def MergeNodes(self,*args): # a 2nd arg added (NodesToKeep)
+    def MergeNodes(self,*args): # 2 args added (NodesToKeep,AvoidMakingHoles)
         if len( args ) == 1:
-            return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], [] )
+            return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], [], False )
         NodesToKeep = args[1]
+        AvoidMakingHoles = args[2] if len( args ) == 3 else False
         unRegister  = genObjUnRegister()
         if NodesToKeep:
             if isinstance( NodesToKeep, list ) and isinstance( NodesToKeep[0], int ):
                 NodesToKeep = self.MakeIDSource( NodesToKeep, SMESH.NODE )
             if not isinstance( NodesToKeep, list ):
                 NodesToKeep = [ NodesToKeep ]
-        return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], NodesToKeep )
+        return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], NodesToKeep, AvoidMakingHoles )
     pass
 omniORB.registerObjref(SMESH._objref_SMESH_MeshEditor._NP_RepositoryId, meshEditor)
 
@@ -5176,8 +5179,8 @@ class algoCreator:
 
     # Store a python class of algorithm
     def add(self, algoClass):
-        if type( algoClass ).__name__ == 'classobj' and \
-           hasattr( algoClass, "algoType"):
+        if inspect.isclass(algoClass) and \
+           hasattr(algoClass, "algoType"):
             self.algoTypeToClass[ algoClass.algoType ] = algoClass
             if not self.defaultAlgoType and \
                hasattr( algoClass, "isDefault") and algoClass.isDefault:
@@ -5283,7 +5286,7 @@ for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
         if k[0] == '_': continue
         algo = getattr( plugin, k )
         #print "             algo:", str(algo)
-        if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
+        if inspect.isclass(algo) and hasattr(algo, "meshMethod"):
             #print "                     meshMethod:" , str(algo.meshMethod)
             if not hasattr( Mesh, algo.meshMethod ):
                 setattr( Mesh, algo.meshMethod, algoCreator() )