- ## Removes all nodes and elements
- # @param refresh if @c True, Object browser is automatically updated (when running in GUI)
- # @ingroup l2_construct
- def Clear(self, refresh=False):
- self.mesh.Clear()
- if ( salome.sg.hasDesktop() and
- salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() ) ):
- smeshgui = salome.ImportComponentGUI("SMESH")
- smeshgui.Init(self.mesh.GetStudyId())
- smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
- if refresh: salome.sg.updateObjBrowser(1)
-
- ## Removes all nodes and elements of indicated shape
- # @param refresh if @c True, Object browser is automatically updated (when running in GUI)
- # @param geomId the ID of a sub-shape to remove elements on
- # @ingroup l2_construct
- def ClearSubMesh(self, geomId, refresh=False):
- self.mesh.ClearSubMesh(geomId)
- if salome.sg.hasDesktop():
- smeshgui = salome.ImportComponentGUI("SMESH")
- smeshgui.Init(self.mesh.GetStudyId())
- smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
- if refresh: salome.sg.updateObjBrowser(1)
-
- ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron
- # @param fineness [0.0,1.0] defines mesh fineness
- # @return True or False
- # @ingroup l3_algos_basic
- def AutomaticTetrahedralization(self, fineness=0):
- dim = self.MeshDimension()
- # assign hypotheses
- self.RemoveGlobalHypotheses()
- self.Segment().AutomaticLength(fineness)
- if dim > 1 :
- self.Triangle().LengthFromEdges()
- pass
- if dim > 2 :
+ def GetSubShapeName(self, subShapeID ):
+ """
+ Return a name of a sub-shape by its ID.
+ Possible variants (for *subShapeID* == 3):
+
+ - **"Face_12"** - published sub-shape
+ - **FACE #3** - not published sub-shape
+ - **sub-shape #3** - invalid sub-shape ID
+ - **#3** - error in this function
+
+ Parameters:
+ subShapeID: a unique ID of a sub-shape
+
+ Returns:
+ a string describing the sub-shape
+
+ """
+
+ if not self.mesh.HasShapeToMesh():
+ return ""
+ try:
+ shapeText = ""
+ mainIOR = salome.orb.object_to_string( self.GetShape() )
+ s = salome.myStudy
+ mainSO = s.FindObjectIOR(mainIOR)
+ if mainSO:
+ if subShapeID == 1:
+ shapeText = '"%s"' % mainSO.GetName()
+ subIt = s.NewChildIterator(mainSO)
+ while subIt.More():
+ subSO = subIt.Value()
+ subIt.Next()
+ obj = subSO.GetObject()
+ if not obj: continue
+ go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
+ if not go: continue
+ try:
+ ids = self.geompyD.GetSubShapeID( self.GetShape(), go )
+ except:
+ continue
+ if ids == subShapeID:
+ shapeText = '"%s"' % subSO.GetName()
+ break
+ if not shapeText:
+ shape = self.geompyD.GetSubShape( self.GetShape(), [subShapeID])
+ if shape:
+ shapeText = '%s #%s' % (shape.GetShapeType(), subShapeID)
+ else:
+ shapeText = 'sub-shape #%s' % (subShapeID)
+ except:
+ shapeText = "#%s" % (subShapeID)
+ return shapeText
+
+ def GetFailedShapes(self, publish=False):
+ """
+ Return a list of sub-shapes meshing of which failed, grouped into GEOM groups by
+ error of an algorithm
+
+ Parameters:
+ publish: if *True*, the returned groups will be published in the study
+
+ Returns:
+ a list of GEOM groups each named after a failed algorithm
+ """
+
+
+ algo2shapes = {}
+ computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, self.GetShape() )
+ for err in computeErrors:
+ shape = self.geompyD.GetSubShape( self.GetShape(), [err.subShapeID])
+ if not shape: continue
+ if err.algoName in algo2shapes:
+ algo2shapes[ err.algoName ].append( shape )
+ else:
+ algo2shapes[ err.algoName ] = [ shape ]
+ pass
+
+ groups = []
+ for algoName, shapes in list(algo2shapes.items()):
+ while shapes:
+ groupType = self.smeshpyD.EnumToLong( shapes[0].GetShapeType() )
+ otherTypeShapes = []
+ sameTypeShapes = []
+ group = self.geompyD.CreateGroup( self.geom, groupType )
+ for shape in shapes:
+ if shape.GetShapeType() == shapes[0].GetShapeType():
+ sameTypeShapes.append( shape )
+ else:
+ otherTypeShapes.append( shape )
+ self.geompyD.UnionList( group, sameTypeShapes )
+ if otherTypeShapes:
+ group.SetName( "%s %s" % ( algoName, shapes[0].GetShapeType() ))
+ else:
+ group.SetName( algoName )
+ groups.append( group )
+ shapes = otherTypeShapes
+ pass
+ if publish:
+ for group in groups:
+ self.geompyD.addToStudyInFather( self.geom, group, group.GetName() )
+ return groups
+
+ def GetMeshOrder(self):
+ """
+ Return sub-mesh objects list in meshing order
+
+ Returns:
+ list of lists of :class:`sub-meshes <SMESH.SMESH_subMesh>`
+ """
+
+ return self.mesh.GetMeshOrder()
+
+ def SetMeshOrder(self, submeshes):
+ """
+ Set priority of sub-meshes. It works in two ways:
+
+ * For sub-meshes with assigned algorithms of same dimension generating mesh of
+ *several dimensions*, it sets the order in which the sub-meshes are computed.
+ * For the rest sub-meshes, it sets the order in which the sub-meshes are checked
+ when looking for meshing parameters to apply to a sub-shape. To impose the
+ order in which sub-meshes with uni-dimensional algorithms are computed,
+ call **submesh.Compute()** in a desired order.
+
+ Parameters:
+ submeshes: list of lists of :class:`sub-meshes <SMESH.SMESH_subMesh>`
+ """
+
+ return self.mesh.SetMeshOrder(submeshes)
+
+ def Clear(self, refresh=False):
+ """
+ Remove all nodes and elements generated on geometry. Imported elements remain.
+
+ Parameters:
+ refresh: if *True*, Object browser is automatically updated (when running in GUI)
+ """
+
+ self.mesh.Clear()
+ if ( salome.sg.hasDesktop() ):
+ if refresh: salome.sg.updateObjBrowser()
+
+ def ClearSubMesh(self, geomId, refresh=False):
+ """
+ Remove all nodes and elements of indicated shape
+
+ Parameters:
+ geomId: the ID of a sub-shape to remove elements on
+ refresh: if *True*, Object browser is automatically updated (when running in GUI)
+ """
+
+ self.mesh.ClearSubMesh(geomId)
+ if salome.sg.hasDesktop():
+ if refresh: salome.sg.updateObjBrowser()
+
+ def AutomaticTetrahedralization(self, fineness=0):
+ """
+ Compute a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron
+
+ Parameters:
+ fineness: [0.0,1.0] defines mesh fineness
+
+ Returns:
+ True or False
+ """
+
+ dim = self.MeshDimension()
+ # assign hypotheses
+ self.RemoveGlobalHypotheses()
+ self.Segment().AutomaticLength(fineness)
+ if dim > 1 :
+ self.Triangle().LengthFromEdges()
+ pass
+ if dim > 2 :