Salome HOME
23303: [EDF 12024] Filter for nodes connectivity
[modules/smesh.git] / src / SMESH_SWIG / smeshBuilder.py
index 67e3c71b3433800884b11ef396e1aa66d4ea9b8c..e257a4d6bb3e836c0c2b4c79908a3735dcd65918 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2015  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
@@ -32,7 +32,6 @@
 ##   @{
 ##     @defgroup l3_algos_basic   Basic meshing algorithms
 ##     @defgroup l3_algos_proj    Projection Algorithms
-##     @defgroup l3_algos_radialp Radial Prism
 ##     @defgroup l3_algos_segmarv Segments around Vertex
 ##     @defgroup l3_algos_3dextr  3D extrusion meshing algorithm
 
 ##   @defgroup l2_modif_trsf     Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging)
 ##   @defgroup l2_modif_movenode Moving nodes
 ##   @defgroup l2_modif_throughp Mesh through point
-##   @defgroup l2_modif_invdiag  Diagonal inversion of elements
 ##   @defgroup l2_modif_unitetri Uniting triangles
-##   @defgroup l2_modif_changori Changing orientation of elements
 ##   @defgroup l2_modif_cutquadr Cutting elements
+##   @defgroup l2_modif_changori Changing orientation of elements
 ##   @defgroup l2_modif_smooth   Smoothing
 ##   @defgroup l2_modif_extrurev Extrusion and Revolution
 ##   @defgroup l2_modif_patterns Pattern mapping
@@ -252,7 +250,7 @@ def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh):
         if mesh:
             meshName = GetName( mesh )
             if meshName and meshName != NO_NAME:
-                where = '"%s" in "%s"' % ( geomName, meshName )
+                where = '"%s" shape in "%s" mesh ' % ( geomName, meshName )
     if status < HYP_UNKNOWN_FATAL and where:
         print '"%s" was assigned to %s but %s' %( hypName, where, reason )
     elif where:
@@ -310,9 +308,9 @@ engine = None
 doLcc = False
 created = False
 
-## This class allows to create, load or manipulate meshes
-#  It has a set of methods to create load or copy meshes, to combine several meshes.
-#  It also has methods to get infos on meshes.
+## This class allows to create, load or manipulate meshes.
+#  It has a set of methods to create, load or copy meshes, to combine several meshes, etc.
+#  It also has methods to get infos and measure meshes.
 class smeshBuilder(object, SMESH._objref_SMESH_Gen):
 
     # MirrorType enumeration
@@ -614,6 +612,7 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen):
     #  @param allGroups forces creation of groups corresponding to every input mesh
     #  @param name name of a new mesh
     #  @return an instance of Mesh class
+    #  @ingroup l2_compounds
     def Concatenate( self, meshes, uniteIdenticalGroups,
                      mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
                      name = ""):
@@ -965,6 +964,10 @@ class smeshBuilder(object, SMESH._objref_SMESH_Gen):
             functor = aFilterMgr.CreateLength()
         elif theCriterion == FT_Length2D:
             functor = aFilterMgr.CreateLength2D()
+        elif theCriterion == FT_NodeConnectivityNumber:
+            functor = aFilterMgr.CreateNodeConnectivityNumber()
+        elif theCriterion == FT_BallDiameter:
+            functor = aFilterMgr.CreateBallDiameter()
         else:
             print "Error: given parameter is not numerical functor type."
         aFilterMgr.UnRegister()
@@ -1162,7 +1165,7 @@ omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
 #    import salome
 #    salome.salome_init()
 #    from salome.smesh import smeshBuilder
-#    smesh = smeshBuilder.New(theStudy)
+#    smesh = smeshBuilder.New(salome.myStudy)
 #  \endcode
 #  @param  study     SALOME study, generally obtained by salome.myStudy.
 #  @param  instance  CORBA proxy of SMESH Engine. If None, the default Engine is used.
@@ -1177,7 +1180,7 @@ def New( study, instance=None):
         import salome
         salome.salome_init()
         from salome.smesh import smeshBuilder
-        smesh = smeshBuilder.New(theStudy)
+        smesh = smeshBuilder.New(salome.myStudy)
 
     Parameters:
         study     SALOME study, generally obtained by salome.myStudy.
@@ -1498,13 +1501,20 @@ class Mesh:
                 print allReasons
             pass
         if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
-            smeshgui = salome.ImportComponentGUI("SMESH")
-            smeshgui.Init(self.mesh.GetStudyId())
-            smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
-            if refresh: salome.sg.updateObjBrowser(1)
-            pass
+            if not isinstance( refresh, list): # not a call from subMesh.Compute()
+                smeshgui = salome.ImportComponentGUI("SMESH")
+                smeshgui.Init(self.mesh.GetStudyId())
+                smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
+                if refresh: salome.sg.updateObjBrowser(1)
+
         return ok
 
+    ## Return a list of error messages (SMESH.ComputeError) of the last Compute()
+    def GetComputeErrors(self, shape=0 ):
+        if shape == 0:
+            shape = self.mesh.GetShapeToMesh()
+        return self.smeshpyD.GetComputeErrors( self.mesh, shape )
+
     ## Return a name of a sub-shape by its ID
     #  @param subShapeID a unique ID of a sub-shape
     #  @return a string describing the sub-shape; possible variants:
@@ -1593,13 +1603,13 @@ class Mesh:
         return groups
 
     ## Return sub-mesh objects list in meshing order
-    #  @return list of list of sub-meshes
+    #  @return list of lists of sub-meshes
     #  @ingroup l2_construct
     def GetMeshOrder(self):
         return self.mesh.GetMeshOrder()
 
     ## Set order in which concurrent sub-meshes sould be meshed
-    #  @param submeshes list of sub-meshes
+    #  @param submeshes list of lists of sub-meshes
     #  @ingroup l2_construct
     def SetMeshOrder(self, submeshes):
         return self.mesh.SetMeshOrder(submeshes)
@@ -2153,7 +2163,7 @@ class Mesh:
 
     ##
     #  Create a standalone group of entities basing on nodes of other groups.
-    #  \param groups - list of groups, sub-meshes or filters, of any type.
+    #  \param groups - list of reference groups, sub-meshes or filters, of any type.
     #  \param elemType - a type of elements to include to the new group; either of 
     #         (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
     #  \param name - a name of the new group.
@@ -2165,7 +2175,10 @@ class Mesh:
     #         - SMESH.AT_LEAST_ONE - include if one or more node is common,
     #         - SMEHS.MAJORITY - include if half of nodes or more are common.
     #  \param underlyingOnly - if \c True (default), an element is included to the
-    #         new group provided that it is based on nodes of one element of \a groups.
+    #         new group provided that it is based on nodes of an element of \a groups;
+    #         in this case the reference \a groups are supposed to be of higher dimension
+    #         than \a elemType, which can be useful for example to get all faces lying on
+    #         volumes of the reference \a groups.
     #  @return an instance of SMESH_Group
     #  @ingroup l2_grps_operon
     def CreateDimGroup(self, groups, elemType, name,
@@ -2176,7 +2189,7 @@ class Mesh:
 
 
     ## Convert group on geom into standalone group
-    #  @ingroup l2_grps_delete
+    #  @ingroup l2_grps_edit
     def ConvertToStandalone(self, group):
         return self.mesh.ConvertToStandalone(group)
 
@@ -3073,7 +3086,7 @@ class Mesh:
     #  @param NodeID1  the ID of the first node
     #  @param NodeID2  the ID of the second node
     #  @return false if proper faces were not found
-    #  @ingroup l2_modif_invdiag
+    #  @ingroup l2_modif_cutquadr
     def InverseDiag(self, NodeID1, NodeID2):
         return self.editor.InverseDiag(NodeID1, NodeID2)
 
@@ -3812,17 +3825,27 @@ class Mesh:
                                          NbOfSteps, Tolerance, MakeGroups, TotalAngle)
 
     ## Generates new elements by extrusion of the given elements and nodes
-    #  @param nodes nodes to extrude: a list including ids, groups, sub-meshes or a mesh
-    #  @param edges edges to extrude: a list including ids, groups, sub-meshes or a mesh
-    #  @param faces faces to extrude: a list including ids, groups, sub-meshes or a mesh
+    #  @param nodes nodes to extrude: a list including ids, groups, sub-meshes or a mesh
+    #  @param edges edges to extrude: a list including ids, groups, sub-meshes or a mesh
+    #  @param faces faces to extrude: a list including ids, groups, sub-meshes or a mesh
     #  @param StepVector vector or DirStruct or 3 vector components, defining
     #         the direction and value of extrusion for one step (the total extrusion
     #         length will be NbOfSteps * ||StepVector||)
     #  @param NbOfSteps the number of steps
     #  @param MakeGroups forces the generation of new groups from existing ones
+    #  @param scaleFactors optional scale factors to apply during extrusion
+    #  @param linearVariation if @c True, scaleFactors are spread over all @a scaleFactors,
+    #         else scaleFactors[i] is applied to nodes at the i-th extrusion step
+    #  @param basePoint optional scaling center; if not provided, a gravity center of
+    #         nodes and elements being extruded is used as the scaling center.
+    #         It can be either
+    #         - a list of tree components of the point or
+    #         - a node ID or
+    #         - a GEOM point
     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
     #  @ingroup l2_modif_extrurev
-    def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False):
+    def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False,
+                              scaleFactors=[], linearVariation=False, basePoint=[] ):
         unRegister = genObjUnRegister()
         nodes = self._getIdSourceList( nodes, SMESH.NODE, unRegister )
         edges = self._getIdSourceList( edges, SMESH.EDGE, unRegister )
@@ -3833,12 +3856,22 @@ class Mesh:
         if isinstance( StepVector, list ):
             StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
 
+        if isinstance( basePoint, int):
+            xyz = self.GetNodeXYZ( basePoint )
+            if not xyz:
+                raise RuntimeError, "Invalid node ID: %s" % basePoint
+            basePoint = xyz
+        if isinstance( basePoint, geomBuilder.GEOM._objref_GEOM_Object ):
+            basePoint = self.geompyD.PointCoordinates( basePoint )
+
         NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
         Parameters = StepVector.PS.parameters + var_separator + Parameters
         self.mesh.SetParameters(Parameters)
 
         return self.editor.ExtrusionSweepObjects( nodes, edges, faces,
-                                                  StepVector, NbOfSteps, MakeGroups)
+                                                  StepVector, NbOfSteps,
+                                                  scaleFactors, linearVariation, basePoint,
+                                                  MakeGroups)
 
 
     ## Generates new elements by extrusion of the elements with given ids
@@ -4973,7 +5006,7 @@ class Mesh:
     pass # end of Mesh class
 
 
-## class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility
+## Class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility
 #  with old dump scripts which call SMESH_Mesh directly and not via smeshBuilder.Mesh
 #
 class meshProxy(SMESH._objref_SMESH_Mesh):
@@ -4989,7 +5022,40 @@ class meshProxy(SMESH._objref_SMESH_Mesh):
     pass
 omniORB.registerObjref(SMESH._objref_SMESH_Mesh._NP_RepositoryId, meshProxy)
 
-## class used to compensate change of CORBA API of SMESH_MeshEditor for backward compatibility
+
+## Class wrapping SMESH_SubMesh in order to add Compute()
+#
+class submeshProxy(SMESH._objref_SMESH_subMesh):
+    def __init__(self):
+        SMESH._objref_SMESH_subMesh.__init__(self)
+        self.mesh = None
+    def __deepcopy__(self, memo=None):
+        new = self.__class__()
+        return new
+
+    ## Computes the sub-mesh and returns the status of the computation
+    #  @param refresh if @c True, Object browser is automatically updated (when running in GUI)
+    #  @return True or False
+    #  @ingroup l2_construct
+    def Compute(self,refresh=False):
+        if not self.mesh:
+            self.mesh = Mesh( smeshBuilder(), None, self.GetMesh())
+
+        ok = self.mesh.Compute( self.GetSubShape(),refresh=[] )
+
+        if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
+            smeshgui = salome.ImportComponentGUI("SMESH")
+            smeshgui.Init(self.mesh.GetStudyId())
+            smeshgui.SetMeshIcon( salome.ObjectToID( self ), ok, (self.GetNumberOfElements()==0) )
+            if refresh: salome.sg.updateObjBrowser(1)
+            pass
+
+        return ok
+    pass
+omniORB.registerObjref(SMESH._objref_SMESH_subMesh._NP_RepositoryId, submeshProxy)
+
+
+## Class used to compensate change of CORBA API of SMESH_MeshEditor for backward compatibility
 #  with old dump scripts which call SMESH_MeshEditor directly and not via smeshBuilder.Mesh
 #
 class meshEditor(SMESH._objref_SMESH_MeshEditor):
@@ -5101,7 +5167,7 @@ class algoCreator:
         raise RuntimeError, "No class found for algo type %s" % algoType
         return None
 
-# Private class used to substitute and store variable parameters of hypotheses.
+## Private class used to substitute and store variable parameters of hypotheses.
 #
 class hypMethodWrapper:
     def __init__(self, hyp, method):
@@ -5132,7 +5198,8 @@ class hypMethodWrapper:
         return result
     pass
 
-# A helper class that call UnRegister() of SALOME.GenericObj'es stored in it
+## A helper class that call UnRegister() of SALOME.GenericObj'es stored in it
+#
 class genObjUnRegister:
 
     def __init__(self, genObj=None):
@@ -5153,6 +5220,9 @@ class genObjUnRegister:
             if genObj and hasattr( genObj, "UnRegister" ):
                 genObj.UnRegister()
 
+
+## Bind methods creating mesher plug-ins to the Mesh class
+#
 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
     #
     #print "pluginName: ", pluginName