1 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 # File : smeshBuilder.py
20 # Author : Francis KLOSS, OCC
24 from salome.geom import geomBuilder
26 import SMESH # This is necessary for back compatibility
28 from salome.smesh.smesh_algorithm import Mesh_Algorithm
35 """Private class used to workaround a problem that sometimes isinstance(m, Mesh) returns False
37 def __instancecheck__(cls, inst):
38 """Implement isinstance(inst, cls)."""
39 return any(cls.__subclasscheck__(c)
40 for c in {type(inst), inst.__class__})
42 def __subclasscheck__(cls, sub):
43 """Implement issubclass(sub, cls)."""
44 return type.__subclasscheck__(cls, sub) or (cls.__name__ == sub.__name__ and cls.__module__ == sub.__module__)
46 def DegreesToRadians(AngleInDegrees):
47 """Convert an angle from degrees to radians
50 return AngleInDegrees * pi / 180.0
52 import salome_notebook
53 notebook = salome_notebook.notebook
54 # Salome notebook variable separator
57 def ParseParameters(*args):
59 Return list of variable values from salome notebook.
60 The last argument, if is callable, is used to modify values got from notebook
66 if args and callable( args[-1] ):
67 args, varModifFun = args[:-1], args[-1]
68 for parameter in args:
70 Parameters += str(parameter) + var_separator
72 if isinstance(parameter,str):
73 # check if there is an inexistent variable name
74 if not notebook.isVariable(parameter):
75 raise ValueError, "Variable with name '" + parameter + "' doesn't exist!!!"
76 parameter = notebook.get(parameter)
79 parameter = varModifFun(parameter)
82 Result.append(parameter)
85 Parameters = Parameters[:-1]
86 Result.append( Parameters )
87 Result.append( hasVariables )
90 def ParseAngles(*args):
92 Parse parameters while converting variables to radians
94 return ParseParameters( *( args + (DegreesToRadians, )))
96 def __initPointStruct(point,*args):
98 Substitute PointStruct.__init__() to create SMESH.PointStruct using notebook variables.
99 Parameters are stored in PointStruct.parameters attribute
101 point.x, point.y, point.z, point.parameters,hasVars = ParseParameters(*args)
103 SMESH.PointStruct.__init__ = __initPointStruct
105 def __initAxisStruct(ax,*args):
107 Substitute AxisStruct.__init__() to create SMESH.AxisStruct using notebook variables.
108 Parameters are stored in AxisStruct.parameters attribute
112 "Bad nb args (%s) passed in SMESH.AxisStruct(x,y,z,dx,dy,dz)"%(len( args ))
113 ax.x, ax.y, ax.z, ax.vx, ax.vy, ax.vz, ax.parameters,hasVars = ParseParameters(*args)
115 SMESH.AxisStruct.__init__ = __initAxisStruct
117 smeshPrecisionConfusion = 1.e-07
118 def IsEqual(val1, val2, tol=smeshPrecisionConfusion):
119 """Compare real values using smeshPrecisionConfusion as tolerance
121 if abs(val1 - val2) < tol:
129 Return a name of an object
136 if isinstance(obj, SALOMEDS._objref_SObject):
140 ior = salome.orb.object_to_string(obj)
145 studies = salome.myStudyManager.GetOpenStudies()
146 for sname in studies:
147 s = salome.myStudyManager.GetStudyByName(sname)
149 sobj = s.FindObjectIOR(ior)
150 if not sobj: continue
151 return sobj.GetName()
152 if hasattr(obj, "GetName"):
153 # unknown CORBA object, having GetName() method
156 # unknown CORBA object, no GetName() method
159 if hasattr(obj, "GetName"):
160 # unknown non-CORBA object, having GetName() method
163 raise RuntimeError, "Null or invalid object"
165 def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh):
167 Print error message if a hypothesis was not assigned.
170 hypType = "algorithm"
172 hypType = "hypothesis"
175 if hasattr( status, "__getitem__" ):
176 status,reason = status[0],status[1]
177 if status == HYP_UNKNOWN_FATAL :
178 reason = "for unknown reason"
179 elif status == HYP_INCOMPATIBLE :
180 reason = "this hypothesis mismatches the algorithm"
181 elif status == HYP_NOTCONFORM :
182 reason = "a non-conform mesh would be built"
183 elif status == HYP_ALREADY_EXIST :
184 if isAlgo: return # it does not influence anything
185 reason = hypType + " of the same dimension is already assigned to this shape"
186 elif status == HYP_BAD_DIM :
187 reason = hypType + " mismatches the shape"
188 elif status == HYP_CONCURRENT :
189 reason = "there are concurrent hypotheses on sub-shapes"
190 elif status == HYP_BAD_SUBSHAPE :
191 reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
192 elif status == HYP_BAD_GEOMETRY:
193 reason = "the algorithm is not applicable to this geometry"
194 elif status == HYP_HIDDEN_ALGO:
195 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
196 elif status == HYP_HIDING_ALGO:
197 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
198 elif status == HYP_NEED_SHAPE:
199 reason = "algorithm can't work without shape"
200 elif status == HYP_INCOMPAT_HYPS:
206 where = '"%s"' % geomName
208 meshName = GetName( mesh )
209 if meshName and meshName != NO_NAME:
210 where = '"%s" shape in "%s" mesh ' % ( geomName, meshName )
211 if status < HYP_UNKNOWN_FATAL and where:
212 print '"%s" was assigned to %s but %s' %( hypName, where, reason )
214 print '"%s" was not assigned to %s : %s' %( hypName, where, reason )
216 print '"%s" was not assigned : %s' %( hypName, reason )
219 def AssureGeomPublished(mesh, geom, name=''):
221 Private method. Add geom (sub-shape of the main shape) into the study if not yet there
223 if not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
225 if not geom.GetStudyEntry() and \
226 mesh.smeshpyD.GetCurrentStudy():
228 studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
229 if studyID != mesh.geompyD.myStudyId:
230 mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
232 if not name and geom.GetShapeType() != geomBuilder.GEOM.COMPOUND:
233 # for all groups SubShapeName() return "Compound_-1"
234 name = mesh.geompyD.SubShapeName(geom, mesh.geom)
236 name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
238 mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
241 def FirstVertexOnCurve(mesh, edge):
244 the first vertex of a geometrical edge by ignoring orientation
246 vv = mesh.geompyD.SubShapeAll( edge, geomBuilder.geomBuilder.ShapeType["VERTEX"])
248 raise TypeError, "Given object has no vertices"
249 if len( vv ) == 1: return vv[0]
250 v0 = mesh.geompyD.MakeVertexOnCurve(edge,0.)
251 xyz = mesh.geompyD.PointCoordinates( v0 ) # coords of the first vertex
252 xyz1 = mesh.geompyD.PointCoordinates( vv[0] )
253 xyz2 = mesh.geompyD.PointCoordinates( vv[1] )
256 dist1 += abs( xyz[i] - xyz1[i] )
257 dist2 += abs( xyz[i] - xyz2[i] )
266 smeshInst is a singleton
272 class smeshBuilder(object, SMESH._objref_SMESH_Gen):
274 This class allows to create, load or manipulate meshes.
275 It has a set of methods to create, load or copy meshes, to combine several meshes, etc.
276 It also has methods to get infos and measure meshes.
279 # MirrorType enumeration
280 POINT = SMESH_MeshEditor.POINT
281 AXIS = SMESH_MeshEditor.AXIS
282 PLANE = SMESH_MeshEditor.PLANE
284 # Smooth_Method enumeration
285 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
286 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
288 PrecisionConfusion = smeshPrecisionConfusion
290 # TopAbs_State enumeration
291 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
293 # Methods of splitting a hexahedron into tetrahedra
294 Hex_5Tet, Hex_6Tet, Hex_24Tet, Hex_2Prisms, Hex_4Prisms = 1, 2, 3, 1, 2
300 #print "==== __new__", engine, smeshInst, doLcc
302 if smeshInst is None:
303 # smesh engine is either retrieved from engine, or created
305 # Following test avoids a recursive loop
307 if smeshInst is not None:
308 # smesh engine not created: existing engine found
312 # FindOrLoadComponent called:
313 # 1. CORBA resolution of server
314 # 2. the __new__ method is called again
315 #print "==== smeshInst = lcc.FindOrLoadComponent ", engine, smeshInst, doLcc
316 smeshInst = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
318 # FindOrLoadComponent not called
319 if smeshInst is None:
320 # smeshBuilder instance is created from lcc.FindOrLoadComponent
321 #print "==== smeshInst = super(smeshBuilder,cls).__new__(cls) ", engine, smeshInst, doLcc
322 smeshInst = super(smeshBuilder,cls).__new__(cls)
324 # smesh engine not created: existing engine found
325 #print "==== existing ", engine, smeshInst, doLcc
327 #print "====1 ", smeshInst
330 #print "====2 ", smeshInst
335 #print "--------------- smeshbuilder __init__ ---", created
338 SMESH._objref_SMESH_Gen.__init__(self)
340 def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
342 Dump component to the Python script.
343 This method overrides IDL function to allow default values for the parameters.
346 return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
348 def SetDumpPythonHistorical(self, isHistorical):
350 Set mode of DumpPython(), *historical* or *snapshot*.
351 In the *historical* mode, the Python Dump script includes all commands
352 performed by SMESH engine. In the *snapshot* mode, commands
353 relating to objects removed from the Study are excluded from the script
354 as well as commands not influencing the current state of meshes
357 if isHistorical: val = "true"
359 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
361 def init_smesh(self,theStudy,geompyD = None):
363 Set the current study and Geometry component
367 self.SetCurrentStudy(theStudy,geompyD)
370 notebook.myStudy = theStudy
372 def Mesh(self, obj=0, name=0):
374 Create a mesh. This mesh can be either
376 * an empty mesh not bound to geometry, if *obj* == 0
377 * an empty mesh bound to geometry, if *obj* is GEOM.GEOM_Object
378 * a mesh wrapping a :class:`CORBA mesh <SMESH.SMESH_Mesh>` given as *obj* parameter.
383 1. a :class:`CORBA mesh <SMESH.SMESH_Mesh>` got by calling e.g.
386 salome.myStudy.FindObjectID("0:1:2:3").GetObject()
388 2. a geometrical object for meshing
390 name: the name for the new mesh.
393 an instance of class :class:`Mesh`.
396 if isinstance(obj,str):
398 return Mesh(self,self.geompyD,obj,name)
400 def EnumToLong(self,theItem):
402 Return a long value from enumeration
407 def ColorToString(self,c):
409 Convert SALOMEDS.Color to string.
410 To be used with filters.
413 c: color value (SALOMEDS.Color)
416 a string representation of the color.
420 if isinstance(c, SALOMEDS.Color):
421 val = "%s;%s;%s" % (c.R, c.G, c.B)
422 elif isinstance(c, str):
425 raise ValueError, "Color value should be of string or SALOMEDS.Color type"
428 def GetPointStruct(self,theVertex):
430 Get :class:`SMESH.PointStruct` from vertex
433 theVertex (GEOM.GEOM_Object): vertex
436 :class:`SMESH.PointStruct`
439 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
440 return PointStruct(x,y,z)
442 def GetDirStruct(self,theVector):
444 Get :class:`SMESH.DirStruct` from vector
447 theVector (GEOM.GEOM_Object): vector
450 :class:`SMESH.DirStruct`
453 vertices = self.geompyD.SubShapeAll( theVector, geomBuilder.geomBuilder.ShapeType["VERTEX"] )
454 if(len(vertices) != 2):
455 print "Error: vector object is incorrect."
457 p1 = self.geompyD.PointCoordinates(vertices[0])
458 p2 = self.geompyD.PointCoordinates(vertices[1])
459 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
460 dirst = DirStruct(pnt)
463 def MakeDirStruct(self,x,y,z):
465 Make :class:`SMESH.DirStruct` from a triplet of floats
468 x,y,z (float): vector components
471 :class:`SMESH.DirStruct`
474 pnt = PointStruct(x,y,z)
475 return DirStruct(pnt)
477 def GetAxisStruct(self,theObj):
479 Get :class:`SMESH.AxisStruct` from a geometrical object
482 theObj (GEOM.GEOM_Object): line or plane
485 :class:`SMESH.AxisStruct`
488 edges = self.geompyD.SubShapeAll( theObj, geomBuilder.geomBuilder.ShapeType["EDGE"] )
491 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
492 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
493 vertex1 = self.geompyD.PointCoordinates(vertex1)
494 vertex2 = self.geompyD.PointCoordinates(vertex2)
495 vertex3 = self.geompyD.PointCoordinates(vertex3)
496 vertex4 = self.geompyD.PointCoordinates(vertex4)
497 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
498 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
499 normal = [ v1[1]*v2[2]-v2[1]*v1[2], v1[2]*v2[0]-v2[2]*v1[0], v1[0]*v2[1]-v2[0]*v1[1] ]
500 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
501 axis._mirrorType = SMESH.SMESH_MeshEditor.PLANE
502 elif len(edges) == 1:
503 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
504 p1 = self.geompyD.PointCoordinates( vertex1 )
505 p2 = self.geompyD.PointCoordinates( vertex2 )
506 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
507 axis._mirrorType = SMESH.SMESH_MeshEditor.AXIS
508 elif theObj.GetShapeType() == GEOM.VERTEX:
509 x,y,z = self.geompyD.PointCoordinates( theObj )
510 axis = AxisStruct( x,y,z, 1,0,0,)
511 axis._mirrorType = SMESH.SMESH_MeshEditor.POINT
514 # From SMESH_Gen interface:
515 # ------------------------
517 def SetName(self, obj, name):
519 Set the given name to an object
522 obj: the object to rename
523 name: a new object name
526 if isinstance( obj, Mesh ):
528 elif isinstance( obj, Mesh_Algorithm ):
529 obj = obj.GetAlgorithm()
530 ior = salome.orb.object_to_string(obj)
531 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
533 def SetEmbeddedMode( self,theMode ):
538 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
540 def IsEmbeddedMode(self):
545 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
547 def SetCurrentStudy( self, theStudy, geompyD = None ):
549 Set the current study. Calling SetCurrentStudy( None ) allows to
550 switch **off** automatic pubilishing in the Study of mesh objects.
554 from salome.geom import geomBuilder
555 geompyD = geomBuilder.geom
558 self.SetGeomEngine(geompyD)
559 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
562 notebook = salome_notebook.NoteBook( theStudy )
564 notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
566 sb = theStudy.NewBuilder()
567 sc = theStudy.FindComponent("SMESH")
568 if sc: sb.LoadWith(sc, self)
572 def GetCurrentStudy(self):
574 Get the current study
577 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
579 def CreateMeshesFromUNV( self,theFileName ):
581 Create a Mesh object importing data from the given UNV file
584 an instance of class :class:`Mesh`
587 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
588 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
591 def CreateMeshesFromMED( self,theFileName ):
593 Create a Mesh object(s) importing data from the given MED file
596 a tuple ( list of class :class:`Mesh` instances,
597 :class:`SMESH.DriverMED_ReadStatus` )
600 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
601 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
602 return aMeshes, aStatus
604 def CreateMeshesFromSAUV( self,theFileName ):
606 Create a Mesh object(s) importing data from the given SAUV file
609 a tuple ( list of class :class:`Mesh` instances, :class:`SMESH.DriverMED_ReadStatus` )
612 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
613 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
614 return aMeshes, aStatus
616 def CreateMeshesFromSTL( self, theFileName ):
618 Create a Mesh object importing data from the given STL file
621 an instance of class :class:`Mesh`
624 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
625 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
628 def CreateMeshesFromCGNS( self, theFileName ):
630 Create Mesh objects importing data from the given CGNS file
633 a tuple ( list of class :class:`Mesh` instances, :class:`SMESH.DriverMED_ReadStatus` )
636 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
637 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
638 return aMeshes, aStatus
640 def CreateMeshesFromGMF( self, theFileName ):
642 Create a Mesh object importing data from the given GMF file.
643 GMF files must have .mesh extension for the ASCII format and .meshb for
647 ( an instance of class :class:`Mesh`, :class:`SMESH.ComputeError` )
650 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
653 if error.comment: print "*** CreateMeshesFromGMF() errors:\n", error.comment
654 return Mesh(self, self.geompyD, aSmeshMesh), error
656 def Concatenate( self, meshes, uniteIdenticalGroups,
657 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
660 Concatenate the given meshes into one mesh. All groups of input meshes will be
661 present in the new mesh.
664 meshes: :class:`meshes, sub-meshes, groups or filters <SMESH.SMESH_IDSource>` to combine into one mesh
665 uniteIdenticalGroups: if True, groups with same names are united, else they are renamed
666 mergeNodesAndElements: if True, equal nodes and elements are merged
667 mergeTolerance: tolerance for merging nodes
668 allGroups: forces creation of groups corresponding to every input mesh
669 name: name of a new mesh
672 an instance of class :class:`Mesh`
675 if not meshes: return None
676 for i,m in enumerate(meshes):
677 if isinstance(m, Mesh):
678 meshes[i] = m.GetMesh()
679 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
680 meshes[0].SetParameters(Parameters)
682 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
683 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
685 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
686 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
687 aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
690 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
692 Create a mesh by copying a part of another mesh.
695 meshPart: a part of mesh to copy, either
696 :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`.
697 To copy nodes or elements not forming any mesh object,
698 pass result of :meth:`Mesh.GetIDSource` as *meshPart*
699 meshName: a name of the new mesh
700 toCopyGroups: to create in the new mesh groups the copied elements belongs to
701 toKeepIDs: to preserve order of the copied elements or not
704 an instance of class :class:`Mesh`
707 if (isinstance( meshPart, Mesh )):
708 meshPart = meshPart.GetMesh()
709 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
710 return Mesh(self, self.geompyD, mesh)
712 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
714 Return IDs of sub-shapes
717 theMainObject (GEOM.GEOM_Object): a shape
718 theListOfSubObjects: sub-shapes (list of GEOM.GEOM_Object)
720 the list of integer values
723 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
725 def GetPattern(self):
727 Create a pattern mapper.
730 an instance of :class:`SMESH.SMESH_Pattern`
732 :ref:`Example of Patterns usage <tui_pattern_mapping>`
735 return SMESH._objref_SMESH_Gen.GetPattern(self)
737 def SetBoundaryBoxSegmentation(self, nbSegments):
739 Set number of segments per diagonal of boundary box of geometry, by which
740 default segment length of appropriate 1D hypotheses is defined in GUI.
744 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
746 # Filtering. Auxiliary functions:
747 # ------------------------------
749 def GetEmptyCriterion(self):
751 Create an empty criterion
754 :class:`SMESH.Filter.Criterion`
757 Type = self.EnumToLong(FT_Undefined)
758 Compare = self.EnumToLong(FT_Undefined)
762 UnaryOp = self.EnumToLong(FT_Undefined)
763 BinaryOp = self.EnumToLong(FT_Undefined)
766 Precision = -1 ##@1e-07
767 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
768 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
770 def GetCriterion(self,elementType,
772 Compare = FT_EqualTo,
774 UnaryOp=FT_Undefined,
775 BinaryOp=FT_Undefined,
778 Create a criterion by the given parameters
779 Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
782 elementType: the :class:`type of elements <SMESH.ElementType>` (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
783 CritType: the type of criterion :class:`SMESH.FunctorType` (SMESH.FT_Taper, SMESH.FT_Area, etc.).
784 Note that the items starting from FT_LessThan are not suitable for *CritType*.
785 Compare: belongs to {SMESH.FT_LessThan, SMESH.FT_MoreThan, SMESH.FT_EqualTo}
786 Threshold: the threshold value (range of ids as string, shape, numeric)
787 UnaryOp: SMESH.FT_LogicalNOT or SMESH.FT_Undefined
788 BinaryOp: a binary logical operation SMESH.FT_LogicalAND, SMESH.FT_LogicalOR or
790 Tolerance: the tolerance used by SMESH.FT_BelongToGeom, SMESH.FT_BelongToSurface,
791 SMESH.FT_LyingOnGeom, SMESH.FT_CoplanarFaces criteria
794 :class:`SMESH.Filter.Criterion`
796 Example: :ref:`combining_filters`
799 if not CritType in SMESH.FunctorType._items:
800 raise TypeError, "CritType should be of SMESH.FunctorType"
801 aCriterion = self.GetEmptyCriterion()
802 aCriterion.TypeOfElement = elementType
803 aCriterion.Type = self.EnumToLong(CritType)
804 aCriterion.Tolerance = Tolerance
806 aThreshold = Threshold
808 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
809 aCriterion.Compare = self.EnumToLong(Compare)
810 elif Compare == "=" or Compare == "==":
811 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
813 aCriterion.Compare = self.EnumToLong(FT_LessThan)
815 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
816 elif Compare != FT_Undefined:
817 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
820 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
821 FT_BelongToCylinder, FT_LyingOnGeom]:
822 # Check that Threshold is GEOM object
823 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object):
824 aCriterion.ThresholdStr = GetName(aThreshold)
825 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
826 if not aCriterion.ThresholdID:
827 name = aCriterion.ThresholdStr
829 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
830 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
831 # or a name of GEOM object
832 elif isinstance( aThreshold, str ):
833 aCriterion.ThresholdStr = aThreshold
835 raise TypeError, "The Threshold should be a shape."
836 if isinstance(UnaryOp,float):
837 aCriterion.Tolerance = UnaryOp
838 UnaryOp = FT_Undefined
840 elif CritType == FT_BelongToMeshGroup:
841 # Check that Threshold is a group
842 if isinstance(aThreshold, SMESH._objref_SMESH_GroupBase):
843 if aThreshold.GetType() != elementType:
844 raise ValueError, "Group type mismatches Element type"
845 aCriterion.ThresholdStr = aThreshold.GetName()
846 aCriterion.ThresholdID = salome.orb.object_to_string( aThreshold )
847 study = self.GetCurrentStudy()
849 so = study.FindObjectIOR( aCriterion.ThresholdID )
853 aCriterion.ThresholdID = entry
855 raise TypeError, "The Threshold should be a Mesh Group"
856 elif CritType == FT_RangeOfIds:
857 # Check that Threshold is string
858 if isinstance(aThreshold, str):
859 aCriterion.ThresholdStr = aThreshold
861 raise TypeError, "The Threshold should be a string."
862 elif CritType == FT_CoplanarFaces:
863 # Check the Threshold
864 if isinstance(aThreshold, int):
865 aCriterion.ThresholdID = str(aThreshold)
866 elif isinstance(aThreshold, str):
869 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
870 aCriterion.ThresholdID = aThreshold
873 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
874 elif CritType == FT_ConnectedElements:
875 # Check the Threshold
876 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object): # shape
877 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
878 if not aCriterion.ThresholdID:
879 name = aThreshold.GetName()
881 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
882 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
883 elif isinstance(aThreshold, int): # node id
884 aCriterion.Threshold = aThreshold
885 elif isinstance(aThreshold, list): # 3 point coordinates
886 if len( aThreshold ) < 3:
887 raise ValueError, "too few point coordinates, must be 3"
888 aCriterion.ThresholdStr = " ".join( [str(c) for c in aThreshold[:3]] )
889 elif isinstance(aThreshold, str):
890 if aThreshold.isdigit():
891 aCriterion.Threshold = aThreshold # node id
893 aCriterion.ThresholdStr = aThreshold # hope that it's point coordinates
896 "The Threshold should either a VERTEX, or a node ID, "\
897 "or a list of point coordinates and not '%s'"%aThreshold
898 elif CritType == FT_ElemGeomType:
899 # Check the Threshold
901 aCriterion.Threshold = self.EnumToLong(aThreshold)
902 assert( aThreshold in SMESH.GeometryType._items )
904 if isinstance(aThreshold, int):
905 aCriterion.Threshold = aThreshold
907 raise TypeError, "The Threshold should be an integer or SMESH.GeometryType."
910 elif CritType == FT_EntityType:
911 # Check the Threshold
913 aCriterion.Threshold = self.EnumToLong(aThreshold)
914 assert( aThreshold in SMESH.EntityType._items )
916 if isinstance(aThreshold, int):
917 aCriterion.Threshold = aThreshold
919 raise TypeError, "The Threshold should be an integer or SMESH.EntityType."
923 elif CritType == FT_GroupColor:
924 # Check the Threshold
926 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
928 raise TypeError, "The threshold value should be of SALOMEDS.Color type"
930 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
931 FT_LinearOrQuadratic, FT_BadOrientedVolume,
932 FT_BareBorderFace, FT_BareBorderVolume,
933 FT_OverConstrainedFace, FT_OverConstrainedVolume,
934 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
935 # At this point the Threshold is unnecessary
936 if aThreshold == FT_LogicalNOT:
937 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
938 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
939 aCriterion.BinaryOp = aThreshold
943 aThreshold = float(aThreshold)
944 aCriterion.Threshold = aThreshold
946 raise TypeError, "The Threshold should be a number."
949 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
950 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
952 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
953 aCriterion.BinaryOp = self.EnumToLong(Threshold)
955 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
956 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
958 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
959 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
963 def GetFilter(self,elementType,
964 CritType=FT_Undefined,
967 UnaryOp=FT_Undefined,
971 Create a filter with the given parameters
974 elementType: the :class:`type of elements <SMESH.ElementType>` (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
975 CritType: the :class:`type of criterion <SMESH.FunctorType>` (SMESH.FT_Taper, SMESH.FT_Area, etc.).
976 Note that the items starting from FT_LessThan are not suitable for CritType.
977 Compare: belongs to {SMESH.FT_LessThan, SMESH.FT_MoreThan, SMESH.FT_EqualTo}
978 Threshold: the threshold value (range of ids as string, shape, numeric)
979 UnaryOp: SMESH.FT_LogicalNOT or SMESH.FT_Undefined
980 Tolerance: the tolerance used by SMESH.FT_BelongToGeom, SMESH.FT_BelongToSurface,
981 SMESH.FT_LyingOnGeom, SMESH.FT_CoplanarFaces and SMESH.FT_EqualNodes criteria
982 mesh: the mesh to initialize the filter with
985 :class:`SMESH.Filter`
988 See :doc:`Filters usage examples <tui_filters>`
991 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
992 aFilterMgr = self.CreateFilterManager()
993 aFilter = aFilterMgr.CreateFilter()
995 aCriteria.append(aCriterion)
996 aFilter.SetCriteria(aCriteria)
998 if isinstance( mesh, Mesh ): aFilter.SetMesh( mesh.GetMesh() )
999 else : aFilter.SetMesh( mesh )
1000 aFilterMgr.UnRegister()
1003 def GetFilterFromCriteria(self,criteria, binOp=SMESH.FT_LogicalAND):
1005 Create a filter from criteria
1008 criteria: a list of :class:`SMESH.Filter.Criterion`
1009 binOp: binary operator used when binary operator of criteria is undefined
1012 :class:`SMESH.Filter`
1015 See :doc:`Filters usage examples <tui_filters>`
1018 for i in range( len( criteria ) - 1 ):
1019 if criteria[i].BinaryOp == self.EnumToLong( SMESH.FT_Undefined ):
1020 criteria[i].BinaryOp = self.EnumToLong( binOp )
1021 aFilterMgr = self.CreateFilterManager()
1022 aFilter = aFilterMgr.CreateFilter()
1023 aFilter.SetCriteria(criteria)
1024 aFilterMgr.UnRegister()
1027 def GetFunctor(self,theCriterion):
1029 Create a numerical functor by its type
1032 theCriterion (SMESH.FunctorType): functor type.
1033 Note that not all items correspond to numerical functors.
1036 :class:`SMESH.NumericalFunctor`
1039 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
1041 aFilterMgr = self.CreateFilterManager()
1043 if theCriterion == FT_AspectRatio:
1044 functor = aFilterMgr.CreateAspectRatio()
1045 elif theCriterion == FT_AspectRatio3D:
1046 functor = aFilterMgr.CreateAspectRatio3D()
1047 elif theCriterion == FT_Warping:
1048 functor = aFilterMgr.CreateWarping()
1049 elif theCriterion == FT_MinimumAngle:
1050 functor = aFilterMgr.CreateMinimumAngle()
1051 elif theCriterion == FT_Taper:
1052 functor = aFilterMgr.CreateTaper()
1053 elif theCriterion == FT_Skew:
1054 functor = aFilterMgr.CreateSkew()
1055 elif theCriterion == FT_Area:
1056 functor = aFilterMgr.CreateArea()
1057 elif theCriterion == FT_Volume3D:
1058 functor = aFilterMgr.CreateVolume3D()
1059 elif theCriterion == FT_MaxElementLength2D:
1060 functor = aFilterMgr.CreateMaxElementLength2D()
1061 elif theCriterion == FT_MaxElementLength3D:
1062 functor = aFilterMgr.CreateMaxElementLength3D()
1063 elif theCriterion == FT_MultiConnection:
1064 functor = aFilterMgr.CreateMultiConnection()
1065 elif theCriterion == FT_MultiConnection2D:
1066 functor = aFilterMgr.CreateMultiConnection2D()
1067 elif theCriterion == FT_Length:
1068 functor = aFilterMgr.CreateLength()
1069 elif theCriterion == FT_Length2D:
1070 functor = aFilterMgr.CreateLength2D()
1071 elif theCriterion == FT_Deflection2D:
1072 functor = aFilterMgr.CreateDeflection2D()
1073 elif theCriterion == FT_NodeConnectivityNumber:
1074 functor = aFilterMgr.CreateNodeConnectivityNumber()
1075 elif theCriterion == FT_BallDiameter:
1076 functor = aFilterMgr.CreateBallDiameter()
1078 print "Error: given parameter is not numerical functor type."
1079 aFilterMgr.UnRegister()
1082 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
1087 theHType (string): mesh hypothesis type
1088 theLibName (string): mesh plug-in library name
1091 created hypothesis instance
1093 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
1095 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
1098 # wrap hypothesis methods
1099 for meth_name in dir( hyp.__class__ ):
1100 if not meth_name.startswith("Get") and \
1101 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
1102 method = getattr ( hyp.__class__, meth_name )
1103 if callable(method):
1104 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
1108 def GetMeshInfo(self, obj):
1110 Get the mesh statistic.
1111 Use :meth:`smeshBuilder.EnumToLong` to get an integer from
1112 an item of :class:`SMESH.EntityType`.
1115 dictionary { :class:`SMESH.EntityType` - "count of elements" }
1118 if isinstance( obj, Mesh ):
1121 if hasattr(obj, "GetMeshInfo"):
1122 values = obj.GetMeshInfo()
1123 for i in range(SMESH.Entity_Last._v):
1124 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
1128 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
1130 Get minimum distance between two objects
1132 * If *src2* is None, and *id2* = 0, distance from *src1* / *id1* to the origin is computed.
1133 * If *src2* is None, and *id2* != 0, it is assumed that both *id1* and *id2* belong to *src1*.
1136 src1 (SMESH.SMESH_IDSource): first source object
1137 src2 (SMESH.SMESH_IDSource): second source object
1138 id1 (int): node/element id from the first source
1139 id2 (int): node/element id from the second (or first) source
1140 isElem1 (boolean): *True* if *id1* is element id, *False* if it is node id
1141 isElem2 (boolean): *True* if *id2* is element id, *False* if it is node id
1144 minimum distance value
1147 :meth:`GetMinDistance`
1150 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
1154 result = result.value
1157 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
1159 Get :class:`SMESH.Measure` structure specifying minimum distance data between two objects
1161 * If *src2* is None, and *id2* = 0, distance from *src1* / *id1* to the origin is computed.
1162 * If *src2* is None, and *id2* != 0, it is assumed that both *id1* and *id2* belong to *src1*.
1165 src1 (SMESH.SMESH_IDSource): first source object
1166 src2 (SMESH.SMESH_IDSource): second source object
1167 id1 (int): node/element id from the first source
1168 id2 (int): node/element id from the second (or first) source
1169 isElem1 (boolean): *True* if **id1** is element id, *False* if it is node id
1170 isElem2 (boolean): *True* if **id2** is element id, *False* if it is node id
1173 :class:`SMESH.Measure` structure or None if input data is invalid
1178 if isinstance(src1, Mesh): src1 = src1.mesh
1179 if isinstance(src2, Mesh): src2 = src2.mesh
1180 if src2 is None and id2 != 0: src2 = src1
1181 if not hasattr(src1, "_narrow"): return None
1182 src1 = src1._narrow(SMESH.SMESH_IDSource)
1183 if not src1: return None
1184 unRegister = genObjUnRegister()
1187 e = m.GetMeshEditor()
1189 src1 = e.MakeIDSource([id1], SMESH.FACE)
1191 src1 = e.MakeIDSource([id1], SMESH.NODE)
1192 unRegister.set( src1 )
1194 if hasattr(src2, "_narrow"):
1195 src2 = src2._narrow(SMESH.SMESH_IDSource)
1196 if src2 and id2 != 0:
1198 e = m.GetMeshEditor()
1200 src2 = e.MakeIDSource([id2], SMESH.FACE)
1202 src2 = e.MakeIDSource([id2], SMESH.NODE)
1203 unRegister.set( src2 )
1206 aMeasurements = self.CreateMeasurements()
1207 unRegister.set( aMeasurements )
1208 result = aMeasurements.MinDistance(src1, src2)
1211 def BoundingBox(self, objects):
1213 Get bounding box of the specified object(s)
1216 objects (SMESH.SMESH_IDSource): single source object or list of source objects
1219 tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
1222 :meth:`GetBoundingBox`
1225 result = self.GetBoundingBox(objects)
1229 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
1232 def GetBoundingBox(self, objects):
1234 Get :class:`SMESH.Measure` structure specifying bounding box data of the specified object(s)
1237 objects (SMESH.SMESH_IDSource): single source object or list of source objects
1240 :class:`SMESH.Measure` structure
1246 if isinstance(objects, tuple):
1247 objects = list(objects)
1248 if not isinstance(objects, list):
1252 if isinstance(o, Mesh):
1253 srclist.append(o.mesh)
1254 elif hasattr(o, "_narrow"):
1255 src = o._narrow(SMESH.SMESH_IDSource)
1256 if src: srclist.append(src)
1259 aMeasurements = self.CreateMeasurements()
1260 result = aMeasurements.BoundingBox(srclist)
1261 aMeasurements.UnRegister()
1264 def GetLength(self, obj):
1266 Get sum of lengths of all 1D elements in the mesh object.
1269 obj: :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
1272 sum of lengths of all 1D elements
1275 if isinstance(obj, Mesh): obj = obj.mesh
1276 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1277 aMeasurements = self.CreateMeasurements()
1278 value = aMeasurements.Length(obj)
1279 aMeasurements.UnRegister()
1282 def GetArea(self, obj):
1284 Get sum of areas of all 2D elements in the mesh object.
1287 obj: :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
1290 sum of areas of all 2D elements
1293 if isinstance(obj, Mesh): obj = obj.mesh
1294 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1295 aMeasurements = self.CreateMeasurements()
1296 value = aMeasurements.Area(obj)
1297 aMeasurements.UnRegister()
1300 def GetVolume(self, obj):
1302 Get sum of volumes of all 3D elements in the mesh object.
1305 obj: :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
1308 sum of volumes of all 3D elements
1311 if isinstance(obj, Mesh): obj = obj.mesh
1312 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1313 aMeasurements = self.CreateMeasurements()
1314 value = aMeasurements.Volume(obj)
1315 aMeasurements.UnRegister()
1318 def GetGravityCenter(self, obj):
1320 Get gravity center of all nodes of the mesh object.
1323 obj: :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
1326 Three components of the gravity center (x,y,z)
1328 if isinstance(obj, Mesh): obj = obj.mesh
1329 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1330 aMeasurements = self.CreateMeasurements()
1331 pointStruct = aMeasurements.GravityCenter(obj)
1332 aMeasurements.UnRegister()
1333 return pointStruct.x, pointStruct.y, pointStruct.z
1335 pass # end of class smeshBuilder
1338 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
1339 """Registering the new proxy for SMESH.SMESH_Gen"""
1342 def New( study, instance=None, instanceGeom=None):
1344 Create a new smeshBuilder instance. The smeshBuilder class provides the Python
1345 interface to create or load meshes.
1350 salome.salome_init()
1351 from salome.smesh import smeshBuilder
1352 smesh = smeshBuilder.New(salome.myStudy)
1355 study: SALOME study, generally obtained by salome.myStudy.
1356 instance: CORBA proxy of SMESH Engine. If None, the default Engine is used.
1357 instanceGeom: CORBA proxy of GEOM Engine. If None, the default Engine is used.
1359 :class:`smeshBuilder` instance
1367 smeshInst = smeshBuilder()
1368 assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__
1369 smeshInst.init_smesh(study, instanceGeom)
1373 # Public class: Mesh
1374 # ==================
1378 This class allows defining and managing a mesh.
1379 It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1380 It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1381 new nodes and elements and by changing the existing entities), to get information
1382 about a mesh and to export a mesh in different formats.
1384 __metaclass__ = MeshMeta
1390 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1394 Create a mesh on the shape *obj* (or an empty mesh if *obj* is equal to 0) and
1395 sets the GUI name of this mesh to *name*.
1398 smeshpyD: an instance of smeshBuilder class
1399 geompyD: an instance of geomBuilder class
1400 obj: Shape to be meshed or :class:`SMESH.SMESH_Mesh` object
1401 name: Study name of the mesh
1404 self.smeshpyD=smeshpyD
1405 self.geompyD=geompyD
1410 if isinstance(obj, geomBuilder.GEOM._objref_GEOM_Object):
1413 # publish geom of mesh (issue 0021122)
1414 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
1416 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
1417 if studyID != geompyD.myStudyId:
1418 geompyD.init_geom( smeshpyD.GetCurrentStudy())
1421 geo_name = name + " shape"
1423 geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1424 geompyD.addToStudy( self.geom, geo_name )
1425 self.SetMesh( self.smeshpyD.CreateMesh(self.geom) )
1427 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1430 self.SetMesh( self.smeshpyD.CreateEmptyMesh() )
1432 self.smeshpyD.SetName(self.mesh, name)
1434 self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1437 self.geom = self.mesh.GetShapeToMesh()
1439 self.editor = self.mesh.GetMeshEditor()
1440 self.functors = [None] * SMESH.FT_Undefined._v
1442 # set self to algoCreator's
1443 for attrName in dir(self):
1444 attr = getattr( self, attrName )
1445 if isinstance( attr, algoCreator ):
1446 setattr( self, attrName, attr.copy( self ))
1453 Destructor. Clean-up resources
1456 #self.mesh.UnRegister()
1460 def SetMesh(self, theMesh):
1462 Initialize the Mesh object from an instance of :class:`SMESH.SMESH_Mesh` interface
1465 theMesh: a :class:`SMESH.SMESH_Mesh` object
1469 # do not call Register() as this prevents mesh servant deletion at closing study
1470 #if self.mesh: self.mesh.UnRegister()
1473 #self.mesh.Register()
1474 self.geom = self.mesh.GetShapeToMesh()
1479 Return the mesh, that is an encapsulated instance of :class:`SMESH.SMESH_Mesh` interface
1482 a :class:`SMESH.SMESH_Mesh` object
1489 Get the name of the mesh
1492 the name of the mesh as a string
1495 name = GetName(self.GetMesh())
1498 def SetName(self, name):
1500 Set a name to the mesh
1503 name: a new name of the mesh
1506 self.smeshpyD.SetName(self.GetMesh(), name)
1508 def GetSubMesh(self, geom, name):
1510 Get a sub-mesh object associated to a *geom* geometrical object.
1513 geom: a geometrical object (shape)
1514 name: a name for the sub-mesh in the Object Browser
1517 an object of type :class:`SMESH.SMESH_subMesh`, representing a part of mesh,
1518 which lies on the given shape
1521 A sub-mesh is implicitly created when a sub-shape is specified at
1522 creating an algorithm, for example::
1524 algo1D = mesh.Segment(geom=Edge_1)
1526 creates a sub-mesh on *Edge_1* and assign Wire Discretization algorithm to it.
1527 The created sub-mesh can be retrieved from the algorithm::
1529 submesh = algo1D.GetSubMesh()
1532 AssureGeomPublished( self, geom, name )
1533 submesh = self.mesh.GetSubMesh( geom, name )
1538 Return the shape associated to the mesh
1546 def SetShape(self, geom):
1548 Associate the given shape to the mesh (entails the recreation of the mesh)
1551 geom: the shape to be meshed (GEOM_Object)
1554 self.mesh = self.smeshpyD.CreateMesh(geom)
1558 Load mesh from the study after opening the study
1562 def IsReadyToCompute(self, theSubObject):
1564 Return true if the hypotheses are defined well
1567 theSubObject: a sub-shape of a mesh shape
1573 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1575 def GetAlgoState(self, theSubObject):
1577 Return errors of hypotheses definition.
1578 The list of errors is empty if everything is OK.
1581 theSubObject: a sub-shape of a mesh shape
1587 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1589 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1591 Return a geometrical object on which the given element was built.
1592 The returned geometrical object, if not nil, is either found in the
1593 study or published by this method with the given name
1596 theElementID: the id of the mesh element
1597 theGeomName: the user-defined name of the geometrical object
1600 GEOM.GEOM_Object instance
1603 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1605 def MeshDimension(self):
1607 Return the mesh dimension depending on the dimension of the underlying shape
1608 or, if the mesh is not based on any shape, basing on deimension of elements
1611 mesh dimension as an integer value [0,3]
1614 if self.mesh.HasShapeToMesh():
1615 shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
1616 if len( shells ) > 0 :
1618 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1620 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1625 if self.NbVolumes() > 0: return 3
1626 if self.NbFaces() > 0: return 2
1627 if self.NbEdges() > 0: return 1
1630 def Evaluate(self, geom=0):
1632 Evaluate size of prospective mesh on a shape
1635 a list where i-th element is a number of elements of i-th :class:`SMESH.EntityType`.
1636 To know predicted number of e.g. edges, inquire it this way::
1638 Evaluate()[ smesh.EnumToLong( SMESH.Entity_Edge )]
1641 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1643 geom = self.mesh.GetShapeToMesh()
1646 return self.smeshpyD.Evaluate(self.mesh, geom)
1649 def Compute(self, geom=0, discardModifs=False, refresh=False):
1651 Compute the mesh and return the status of the computation
1654 geom: geomtrical shape on which mesh data should be computed
1655 discardModifs: if True and the mesh has been edited since
1656 a last total re-compute and that may prevent successful partial re-compute,
1657 then the mesh is cleaned before Compute()
1658 refresh: if *True*, Object Browser is automatically updated (when running in GUI)
1664 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1666 geom = self.mesh.GetShapeToMesh()
1671 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1673 ok = self.smeshpyD.Compute(self.mesh, geom)
1674 except SALOME.SALOME_Exception, ex:
1675 print "Mesh computation failed, exception caught:"
1676 print " ", ex.details.text
1679 print "Mesh computation failed, exception caught:"
1680 traceback.print_exc()
1684 # Treat compute errors
1685 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1687 for err in computeErrors:
1688 if self.mesh.HasShapeToMesh():
1689 shapeText = " on %s" % self.GetSubShapeName( err.subShapeID )
1691 stdErrors = ["OK", #COMPERR_OK
1692 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1693 "std::exception", #COMPERR_STD_EXCEPTION
1694 "OCC exception", #COMPERR_OCC_EXCEPTION
1695 "..", #COMPERR_SLM_EXCEPTION
1696 "Unknown exception", #COMPERR_EXCEPTION
1697 "Memory allocation problem", #COMPERR_MEMORY_PB
1698 "Algorithm failed", #COMPERR_ALGO_FAILED
1699 "Unexpected geometry", #COMPERR_BAD_SHAPE
1700 "Warning", #COMPERR_WARNING
1701 "Computation cancelled",#COMPERR_CANCELED
1702 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1704 if err.code < len(stdErrors): errText = stdErrors[err.code]
1706 errText = "code %s" % -err.code
1707 if errText: errText += ". "
1708 errText += err.comment
1709 if allReasons: allReasons += "\n"
1711 allReasons += '- "%s"%s - %s' %(err.algoName, shapeText, errText)
1713 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1717 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1719 if err.isGlobalAlgo:
1727 reason = '%s %sD algorithm is missing' % (glob, dim)
1728 elif err.state == HYP_MISSING:
1729 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1730 % (glob, dim, name, dim))
1731 elif err.state == HYP_NOTCONFORM:
1732 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1733 elif err.state == HYP_BAD_PARAMETER:
1734 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1735 % ( glob, dim, name ))
1736 elif err.state == HYP_BAD_GEOMETRY:
1737 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1738 'geometry' % ( glob, dim, name ))
1739 elif err.state == HYP_HIDDEN_ALGO:
1740 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1741 'algorithm of upper dimension generating %sD mesh'
1742 % ( glob, dim, name, glob, dim ))
1744 reason = ("For unknown reason. "
1745 "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1747 if allReasons: allReasons += "\n"
1748 allReasons += "- " + reason
1750 if not ok or allReasons != "":
1751 msg = '"' + GetName(self.mesh) + '"'
1752 if ok: msg += " has been computed with warnings"
1753 else: msg += " has not been computed"
1754 if allReasons != "": msg += ":"
1759 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1760 if not isinstance( refresh, list): # not a call from subMesh.Compute()
1761 smeshgui = salome.ImportComponentGUI("SMESH")
1762 smeshgui.Init(self.mesh.GetStudyId())
1763 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1764 if refresh: salome.sg.updateObjBrowser(True)
1768 def GetComputeErrors(self, shape=0 ):
1770 Return a list of error messages (:class:`SMESH.ComputeError`) of the last :meth:`Compute`
1774 shape = self.mesh.GetShapeToMesh()
1775 return self.smeshpyD.GetComputeErrors( self.mesh, shape )
1777 def GetSubShapeName(self, subShapeID ):
1779 Return a name of a sub-shape by its ID.
1780 Possible variants (for *subShapeID* == 3):
1782 - **"Face_12"** - published sub-shape
1783 - **FACE #3** - not published sub-shape
1784 - **sub-shape #3** - invalid sub-shape ID
1785 - **#3** - error in this function
1788 subShapeID: a unique ID of a sub-shape
1791 a string describing the sub-shape
1795 if not self.mesh.HasShapeToMesh():
1799 mainIOR = salome.orb.object_to_string( self.GetShape() )
1800 for sname in salome.myStudyManager.GetOpenStudies():
1801 s = salome.myStudyManager.GetStudyByName(sname)
1803 mainSO = s.FindObjectIOR(mainIOR)
1804 if not mainSO: continue
1806 shapeText = '"%s"' % mainSO.GetName()
1807 subIt = s.NewChildIterator(mainSO)
1809 subSO = subIt.Value()
1811 obj = subSO.GetObject()
1812 if not obj: continue
1813 go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
1816 ids = self.geompyD.GetSubShapeID( self.GetShape(), go )
1819 if ids == subShapeID:
1820 shapeText = '"%s"' % subSO.GetName()
1823 shape = self.geompyD.GetSubShape( self.GetShape(), [subShapeID])
1825 shapeText = '%s #%s' % (shape.GetShapeType(), subShapeID)
1827 shapeText = 'sub-shape #%s' % (subShapeID)
1829 shapeText = "#%s" % (subShapeID)
1832 def GetFailedShapes(self, publish=False):
1834 Return a list of sub-shapes meshing of which failed, grouped into GEOM groups by
1835 error of an algorithm
1838 publish: if *True*, the returned groups will be published in the study
1841 a list of GEOM groups each named after a failed algorithm
1846 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, self.GetShape() )
1847 for err in computeErrors:
1848 shape = self.geompyD.GetSubShape( self.GetShape(), [err.subShapeID])
1849 if not shape: continue
1850 if err.algoName in algo2shapes:
1851 algo2shapes[ err.algoName ].append( shape )
1853 algo2shapes[ err.algoName ] = [ shape ]
1857 for algoName, shapes in algo2shapes.items():
1859 groupType = self.smeshpyD.EnumToLong( shapes[0].GetShapeType() )
1860 otherTypeShapes = []
1862 group = self.geompyD.CreateGroup( self.geom, groupType )
1863 for shape in shapes:
1864 if shape.GetShapeType() == shapes[0].GetShapeType():
1865 sameTypeShapes.append( shape )
1867 otherTypeShapes.append( shape )
1868 self.geompyD.UnionList( group, sameTypeShapes )
1870 group.SetName( "%s %s" % ( algoName, shapes[0].GetShapeType() ))
1872 group.SetName( algoName )
1873 groups.append( group )
1874 shapes = otherTypeShapes
1877 for group in groups:
1878 self.geompyD.addToStudyInFather( self.geom, group, group.GetName() )
1881 def GetMeshOrder(self):
1883 Return sub-mesh objects list in meshing order
1886 list of lists of :class:`sub-meshes <SMESH.SMESH_subMesh>`
1889 return self.mesh.GetMeshOrder()
1891 def SetMeshOrder(self, submeshes):
1893 Set order in which concurrent sub-meshes should be meshed
1896 submeshes: list of lists of :class:`sub-meshes <SMESH.SMESH_subMesh>`
1899 return self.mesh.SetMeshOrder(submeshes)
1901 def Clear(self, refresh=False):
1903 Remove all nodes and elements generated on geometry. Imported elements remain.
1906 refresh: if *True*, Object browser is automatically updated (when running in GUI)
1910 if ( salome.sg.hasDesktop() and
1911 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() ) ):
1912 smeshgui = salome.ImportComponentGUI("SMESH")
1913 smeshgui.Init(self.mesh.GetStudyId())
1914 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1915 if refresh: salome.sg.updateObjBrowser(True)
1917 def ClearSubMesh(self, geomId, refresh=False):
1919 Remove all nodes and elements of indicated shape
1922 geomId: the ID of a sub-shape to remove elements on
1923 refresh: if *True*, Object browser is automatically updated (when running in GUI)
1926 self.mesh.ClearSubMesh(geomId)
1927 if salome.sg.hasDesktop():
1928 smeshgui = salome.ImportComponentGUI("SMESH")
1929 smeshgui.Init(self.mesh.GetStudyId())
1930 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1931 if refresh: salome.sg.updateObjBrowser(True)
1933 def AutomaticTetrahedralization(self, fineness=0):
1935 Compute a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron
1938 fineness: [0.0,1.0] defines mesh fineness
1944 dim = self.MeshDimension()
1946 self.RemoveGlobalHypotheses()
1947 self.Segment().AutomaticLength(fineness)
1949 self.Triangle().LengthFromEdges()
1954 return self.Compute()
1956 def AutomaticHexahedralization(self, fineness=0):
1958 Compute an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1961 fineness: [0.0, 1.0] defines mesh fineness
1967 dim = self.MeshDimension()
1968 # assign the hypotheses
1969 self.RemoveGlobalHypotheses()
1970 self.Segment().AutomaticLength(fineness)
1977 return self.Compute()
1979 def AddHypothesis(self, hyp, geom=0):
1984 hyp: a hypothesis to assign
1985 geom: a subhape of mesh geometry
1988 :class:`SMESH.Hypothesis_Status`
1991 if isinstance( hyp, geomBuilder.GEOM._objref_GEOM_Object ):
1992 hyp, geom = geom, hyp
1993 if isinstance( hyp, Mesh_Algorithm ):
1994 hyp = hyp.GetAlgorithm()
1999 geom = self.mesh.GetShapeToMesh()
2002 if self.mesh.HasShapeToMesh():
2003 hyp_type = hyp.GetName()
2004 lib_name = hyp.GetLibName()
2005 # checkAll = ( not geom.IsSame( self.mesh.GetShapeToMesh() ))
2006 # if checkAll and geom:
2007 # checkAll = geom.GetType() == 37
2009 isApplicable = self.smeshpyD.IsApplicable(hyp_type, lib_name, geom, checkAll)
2011 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
2012 status = self.mesh.AddHypothesis(geom, hyp)
2014 status = HYP_BAD_GEOMETRY,""
2015 hyp_name = GetName( hyp )
2018 geom_name = geom.GetName()
2019 isAlgo = hyp._narrow( SMESH_Algo )
2020 TreatHypoStatus( status, hyp_name, geom_name, isAlgo, self )
2023 def IsUsedHypothesis(self, hyp, geom):
2025 Return True if an algorithm or hypothesis is assigned to a given shape
2028 hyp: an algorithm or hypothesis to check
2029 geom: a subhape of mesh geometry
2035 if not hyp: # or not geom
2037 if isinstance( hyp, Mesh_Algorithm ):
2038 hyp = hyp.GetAlgorithm()
2040 hyps = self.GetHypothesisList(geom)
2042 if h.GetId() == hyp.GetId():
2046 def RemoveHypothesis(self, hyp, geom=0):
2048 Unassign a hypothesis
2051 hyp (SMESH.SMESH_Hypothesis): a hypothesis to unassign
2052 geom (GEOM.GEOM_Object): a sub-shape of mesh geometry
2055 :class:`SMESH.Hypothesis_Status`
2060 if isinstance( hyp, Mesh_Algorithm ):
2061 hyp = hyp.GetAlgorithm()
2067 if self.IsUsedHypothesis( hyp, shape ):
2068 return self.mesh.RemoveHypothesis( shape, hyp )
2069 hypName = GetName( hyp )
2070 geoName = GetName( shape )
2071 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
2074 def GetHypothesisList(self, geom):
2076 Get the list of hypotheses added on a geometry
2079 geom (GEOM.GEOM_Object): a sub-shape of mesh geometry
2082 the sequence of :class:`SMESH.SMESH_Hypothesis`
2085 return self.mesh.GetHypothesisList( geom )
2087 def RemoveGlobalHypotheses(self):
2089 Remove all global hypotheses
2092 current_hyps = self.mesh.GetHypothesisList( self.geom )
2093 for hyp in current_hyps:
2094 self.mesh.RemoveHypothesis( self.geom, hyp )
2098 def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
2099 overwrite=1, meshPart=None, autoDimension=True, fields=[], geomAssocFields=''):
2101 Export the mesh in a file in MED format
2102 allowing to overwrite the file if it exists or add the exported data to its contents
2106 auto_groups: boolean parameter for creating/not creating
2107 the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
2108 the typical use is auto_groups=False.
2109 version: MED format version (MED_V2_1 or MED_V2_2,
2110 the latter meaning any current version). The parameter is
2111 obsolete since MED_V2_1 is no longer supported.
2112 overwrite: boolean parameter for overwriting/not overwriting the file
2113 meshPart: a part of mesh (:class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`) to export instead of the mesh
2114 autoDimension: if *True* (default), a space dimension of a MED mesh can be either
2116 - 1D if all mesh nodes lie on OX coordinate axis, or
2117 - 2D if all mesh nodes lie on XOY coordinate plane, or
2118 - 3D in the rest cases.
2120 If *autoDimension* is *False*, the space dimension is always 3.
2121 fields: list of GEOM fields defined on the shape to mesh.
2122 geomAssocFields: each character of this string means a need to export a
2123 corresponding field; correspondence between fields and characters is following:
2124 - 'v' stands for "_vertices _" field;
2125 - 'e' stands for "_edges _" field;
2126 - 'f' stands for "_faces _" field;
2127 - 's' stands for "_solids _" field.
2130 if meshPart or fields or geomAssocFields:
2131 unRegister = genObjUnRegister()
2132 if isinstance( meshPart, list ):
2133 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
2134 unRegister.set( meshPart )
2135 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension,
2136 fields, geomAssocFields)
2138 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
2140 def ExportSAUV(self, f, auto_groups=0):
2142 Export the mesh in a file in SAUV format
2147 auto_groups: boolean parameter for creating/not creating
2148 the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
2149 the typical use is auto_groups=False.
2152 self.mesh.ExportSAUV(f, auto_groups)
2154 def ExportDAT(self, f, meshPart=None):
2156 Export the mesh in a file in DAT format
2160 meshPart: a part of mesh (:class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`) to export instead of the mesh
2164 unRegister = genObjUnRegister()
2165 if isinstance( meshPart, list ):
2166 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
2167 unRegister.set( meshPart )
2168 self.mesh.ExportPartToDAT( meshPart, f )
2170 self.mesh.ExportDAT(f)
2172 def ExportUNV(self, f, meshPart=None):
2174 Export the mesh in a file in UNV format
2178 meshPart: a part of mesh (:class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`) to export instead of the mesh
2182 unRegister = genObjUnRegister()
2183 if isinstance( meshPart, list ):
2184 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
2185 unRegister.set( meshPart )
2186 self.mesh.ExportPartToUNV( meshPart, f )
2188 self.mesh.ExportUNV(f)
2190 def ExportSTL(self, f, ascii=1, meshPart=None):
2192 Export the mesh in a file in STL format
2196 ascii: defines the file encoding
2197 meshPart: a part of mesh (:class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`) to export instead of the mesh
2201 unRegister = genObjUnRegister()
2202 if isinstance( meshPart, list ):
2203 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
2204 unRegister.set( meshPart )
2205 self.mesh.ExportPartToSTL( meshPart, f, ascii )
2207 self.mesh.ExportSTL(f, ascii)
2209 def ExportCGNS(self, f, overwrite=1, meshPart=None, groupElemsByType=False):
2211 Export the mesh in a file in CGNS format
2215 overwrite: boolean parameter for overwriting/not overwriting the file
2216 meshPart: a part of mesh (:class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`) to export instead of the mesh
2217 groupElemsByType: if True all elements of same entity type are exported at ones,
2218 else elements are exported in order of their IDs which can cause creation
2219 of multiple cgns sections
2222 unRegister = genObjUnRegister()
2223 if isinstance( meshPart, list ):
2224 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
2225 unRegister.set( meshPart )
2226 if isinstance( meshPart, Mesh ):
2227 meshPart = meshPart.mesh
2229 meshPart = self.mesh
2230 self.mesh.ExportCGNS(meshPart, f, overwrite, groupElemsByType)
2232 def ExportGMF(self, f, meshPart=None):
2234 Export the mesh in a file in GMF format.
2235 GMF files must have .mesh extension for the ASCII format and .meshb for
2236 the bynary format. Other extensions are not allowed.
2240 meshPart: a part of mesh (:class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`) to export instead of the mesh
2243 unRegister = genObjUnRegister()
2244 if isinstance( meshPart, list ):
2245 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
2246 unRegister.set( meshPart )
2247 if isinstance( meshPart, Mesh ):
2248 meshPart = meshPart.mesh
2250 meshPart = self.mesh
2251 self.mesh.ExportGMF(meshPart, f, True)
2253 def ExportToMED(self, f, version=MED_V2_2, opt=0, overwrite=1, autoDimension=True):
2255 Deprecated, used only for compatibility! Please, use :meth:`ExportMED` method instead.
2256 Export the mesh in a file in MED format
2257 allowing to overwrite the file if it exists or add the exported data to its contents
2261 version: MED format version (MED_V2_1 or MED_V2_2,
2262 the latter meaning any current version). The parameter is
2263 obsolete since MED_V2_1 is no longer supported.
2264 opt: boolean parameter for creating/not creating
2265 the groups Group_On_All_Nodes, Group_On_All_Faces, ...
2266 overwrite: boolean parameter for overwriting/not overwriting the file
2267 autoDimension: if *True* (default), a space dimension of a MED mesh can be either
2269 - 1D if all mesh nodes lie on OX coordinate axis, or
2270 - 2D if all mesh nodes lie on XOY coordinate plane, or
2271 - 3D in the rest cases.
2273 If **autoDimension** is *False*, the space dimension is always 3.
2276 self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension)
2278 # Operations with groups:
2279 # ----------------------
2281 def CreateEmptyGroup(self, elementType, name):
2283 Create an empty mesh group
2286 elementType: the :class:`type <SMESH.ElementType>` of elements in the group;
2287 either of (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
2288 name: the name of the mesh group
2291 :class:`SMESH.SMESH_Group`
2294 return self.mesh.CreateGroup(elementType, name)
2296 def Group(self, grp, name=""):
2298 Create a mesh group based on the geometric object *grp*
2299 and give it a *name*.
2300 If *name* is not defined the name of the geometric group is used
2303 Works like :meth:`GroupOnGeom`.
2306 grp: a geometric group, a vertex, an edge, a face or a solid
2307 name: the name of the mesh group
2310 :class:`SMESH.SMESH_GroupOnGeom`
2313 return self.GroupOnGeom(grp, name)
2315 def GroupOnGeom(self, grp, name="", typ=None):
2317 Create a mesh group based on the geometrical object *grp*
2319 if *name* is not defined the name of the geometric group is used
2322 grp: a geometrical group, a vertex, an edge, a face or a solid
2323 name: the name of the mesh group
2324 typ: the type of elements in the group; either of
2325 (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME). If not set, it is
2326 automatically detected by the type of the geometry
2329 :class:`SMESH.SMESH_GroupOnGeom`
2332 AssureGeomPublished( self, grp, name )
2334 name = grp.GetName()
2336 typ = self._groupTypeFromShape( grp )
2337 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
2339 def _groupTypeFromShape( self, shape ):
2341 Pivate method to get a type of group on geometry
2343 tgeo = str(shape.GetShapeType())
2344 if tgeo == "VERTEX":
2346 elif tgeo == "EDGE":
2348 elif tgeo == "FACE" or tgeo == "SHELL":
2350 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
2352 elif tgeo == "COMPOUND":
2353 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
2355 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
2356 return self._groupTypeFromShape( sub[0] )
2359 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
2362 def GroupOnFilter(self, typ, name, filter):
2364 Create a mesh group with given *name* based on the *filter* which
2365 is a special type of group dynamically updating it's contents during
2369 typ: the type of elements in the group; either of
2370 (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
2371 name: the name of the mesh group
2372 filter (SMESH.Filter): the filter defining group contents
2375 :class:`SMESH.SMESH_GroupOnFilter`
2378 return self.mesh.CreateGroupFromFilter(typ, name, filter)
2380 def MakeGroupByIds(self, groupName, elementType, elemIDs):
2382 Create a mesh group by the given ids of elements
2385 groupName: the name of the mesh group
2386 elementType: the type of elements in the group; either of
2387 (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
2388 elemIDs: either the list of ids, :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
2391 :class:`SMESH.SMESH_Group`
2394 group = self.mesh.CreateGroup(elementType, groupName)
2395 if isinstance( elemIDs, Mesh ):
2396 elemIDs = elemIDs.GetMesh()
2397 if hasattr( elemIDs, "GetIDs" ):
2398 if hasattr( elemIDs, "SetMesh" ):
2399 elemIDs.SetMesh( self.GetMesh() )
2400 group.AddFrom( elemIDs )
2408 CritType=FT_Undefined,
2411 UnaryOp=FT_Undefined,
2414 Create a mesh group by the given conditions
2417 groupName: the name of the mesh group
2418 elementType (SMESH.ElementType): the type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
2419 CritType (SMESH.FunctorType): the type of criterion (SMESH.FT_Taper, SMESH.FT_Area, etc.).
2420 Note that the items starting from FT_LessThan are not suitable for CritType.
2421 Compare (SMESH.FunctorType): belongs to {SMESH.FT_LessThan, SMESH.FT_MoreThan, SMESH.FT_EqualTo}
2422 Threshold: the threshold value (range of ids as string, shape, numeric, depending on *CritType*)
2423 UnaryOp (SMESH.FunctorType): SMESH.FT_LogicalNOT or SMESH.FT_Undefined
2424 Tolerance (float): the tolerance used by SMESH.FT_BelongToGeom, SMESH.FT_BelongToSurface,
2425 SMESH.FT_LyingOnGeom, SMESH.FT_CoplanarFaces criteria
2428 :class:`SMESH.SMESH_GroupOnFilter`
2431 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
2432 group = self.MakeGroupByCriterion(groupName, aCriterion)
2435 def MakeGroupByCriterion(self, groupName, Criterion):
2437 Create a mesh group by the given criterion
2440 groupName: the name of the mesh group
2441 Criterion: the instance of :class:`SMESH.Filter.Criterion` class
2444 :class:`SMESH.SMESH_GroupOnFilter`
2447 :meth:`smeshBuilder.GetCriterion`
2450 return self.MakeGroupByCriteria( groupName, [Criterion] )
2452 def MakeGroupByCriteria(self, groupName, theCriteria, binOp=SMESH.FT_LogicalAND):
2454 Create a mesh group by the given criteria (list of :class:`SMESH.Filter.Criterion`)
2457 groupName: the name of the mesh group
2458 theCriteria: the list of :class:`SMESH.Filter.Criterion`
2459 binOp: binary operator (SMESH.FT_LogicalAND or SMESH.FT_LogicalOR ) used when binary operator of criteria is undefined
2462 :class:`SMESH.SMESH_GroupOnFilter`
2465 :meth:`smeshBuilder.GetCriterion`
2468 aFilter = self.smeshpyD.GetFilterFromCriteria( theCriteria, binOp )
2469 group = self.MakeGroupByFilter(groupName, aFilter)
2472 def MakeGroupByFilter(self, groupName, theFilter):
2474 Create a mesh group by the given filter
2477 groupName (string): the name of the mesh group
2478 theFilter (SMESH.Filter): the filter
2481 :class:`SMESH.SMESH_GroupOnFilter`
2484 :meth:`smeshBuilder.GetFilter`
2487 #group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
2488 #theFilter.SetMesh( self.mesh )
2489 #group.AddFrom( theFilter )
2490 group = self.GroupOnFilter( theFilter.GetElementType(), groupName, theFilter )
2493 def RemoveGroup(self, group):
2498 group (SMESH.SMESH_GroupBase): group to remove
2501 self.mesh.RemoveGroup(group)
2503 def RemoveGroupWithContents(self, group):
2505 Remove a group with its contents
2508 group (SMESH.SMESH_GroupBase): group to remove
2511 self.mesh.RemoveGroupWithContents(group)
2513 def GetGroups(self, elemType = SMESH.ALL):
2515 Get the list of groups existing in the mesh in the order
2516 of creation (starting from the oldest one)
2519 elemType (SMESH.ElementType): type of elements the groups contain;
2520 by default groups of elements of all types are returned
2523 a sequence of :class:`SMESH.SMESH_GroupBase`
2526 groups = self.mesh.GetGroups()
2527 if elemType == SMESH.ALL:
2531 if g.GetType() == elemType:
2532 typedGroups.append( g )
2539 Get the number of groups existing in the mesh
2542 the quantity of groups as an integer value
2545 return self.mesh.NbGroups()
2547 def GetGroupNames(self):
2549 Get the list of names of groups existing in the mesh
2555 groups = self.GetGroups()
2557 for group in groups:
2558 names.append(group.GetName())
2561 def GetGroupByName(self, name, elemType = None):
2563 Find groups by name and type
2566 name (string): name of the group of interest
2567 elemType (SMESH.ElementType): type of elements the groups contain;
2568 by default one group of any type is returned;
2569 if elemType == SMESH.ALL then all groups of any type are returned
2572 a list of :class:`SMESH.SMESH_GroupBase`
2576 for group in self.GetGroups():
2577 if group.GetName() == name:
2578 if elemType is None:
2580 if ( elemType == SMESH.ALL or
2581 group.GetType() == elemType ):
2582 groups.append( group )
2585 def UnionGroups(self, group1, group2, name):
2587 Produce a union of two groups.
2588 A new group is created. All mesh elements that are
2589 present in the initial groups are added to the new one
2592 group1 (SMESH.SMESH_GroupBase): a group
2593 group2 (SMESH.SMESH_GroupBase): another group
2596 instance of :class:`SMESH.SMESH_Group`
2599 return self.mesh.UnionGroups(group1, group2, name)
2601 def UnionListOfGroups(self, groups, name):
2603 Produce a union list of groups.
2604 New group is created. All mesh elements that are present in
2605 initial groups are added to the new one
2608 groups: list of :class:`SMESH.SMESH_GroupBase`
2611 instance of :class:`SMESH.SMESH_Group`
2614 return self.mesh.UnionListOfGroups(groups, name)
2616 def IntersectGroups(self, group1, group2, name):
2618 Prodice an intersection of two groups.
2619 A new group is created. All mesh elements that are common
2620 for the two initial groups are added to the new one.
2623 group1 (SMESH.SMESH_GroupBase): a group
2624 group2 (SMESH.SMESH_GroupBase): another group
2627 instance of :class:`SMESH.SMESH_Group`
2630 return self.mesh.IntersectGroups(group1, group2, name)
2632 def IntersectListOfGroups(self, groups, name):
2634 Produce an intersection of groups.
2635 New group is created. All mesh elements that are present in all
2636 initial groups simultaneously are added to the new one
2639 groups: a list of :class:`SMESH.SMESH_GroupBase`
2642 instance of :class:`SMESH.SMESH_Group`
2645 return self.mesh.IntersectListOfGroups(groups, name)
2647 def CutGroups(self, main_group, tool_group, name):
2649 Produce a cut of two groups.
2650 A new group is created. All mesh elements that are present in
2651 the main group but are not present in the tool group are added to the new one
2654 main_group (SMESH.SMESH_GroupBase): a group to cut from
2655 tool_group (SMESH.SMESH_GroupBase): a group to cut by
2658 an instance of :class:`SMESH.SMESH_Group`
2661 return self.mesh.CutGroups(main_group, tool_group, name)
2663 def CutListOfGroups(self, main_groups, tool_groups, name):
2665 Produce a cut of groups.
2666 A new group is created. All mesh elements that are present in main groups
2667 but do not present in tool groups are added to the new one
2670 main_group: groups to cut from (list of :class:`SMESH.SMESH_GroupBase`)
2671 tool_group: groups to cut by (list of :class:`SMESH.SMESH_GroupBase`)
2674 an instance of :class:`SMESH.SMESH_Group`
2677 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
2679 def CreateDimGroup(self, groups, elemType, name,
2680 nbCommonNodes = SMESH.ALL_NODES, underlyingOnly = True):
2682 Create a standalone group of entities basing on nodes of other groups.
2685 groups: list of reference :class:`sub-meshes, groups or filters <SMESH.SMESH_IDSource>`, of any type.
2686 elemType: a type of elements to include to the new group; either of
2687 (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
2688 name: a name of the new group.
2689 nbCommonNodes: a criterion of inclusion of an element to the new group
2690 basing on number of element nodes common with reference *groups*.
2691 Meaning of possible values are:
2693 - SMESH.ALL_NODES - include if all nodes are common,
2694 - SMESH.MAIN - include if all corner nodes are common (meaningful for a quadratic mesh),
2695 - SMESH.AT_LEAST_ONE - include if one or more node is common,
2696 - SMEHS.MAJORITY - include if half of nodes or more are common.
2697 underlyingOnly: if *True* (default), an element is included to the
2698 new group provided that it is based on nodes of an element of *groups*;
2699 in this case the reference *groups* are supposed to be of higher dimension
2700 than *elemType*, which can be useful for example to get all faces lying on
2701 volumes of the reference *groups*.
2704 an instance of :class:`SMESH.SMESH_Group`
2707 if isinstance( groups, SMESH._objref_SMESH_IDSource ):
2709 return self.mesh.CreateDimGroup(groups, elemType, name, nbCommonNodes, underlyingOnly)
2712 def ConvertToStandalone(self, group):
2714 Convert group on geom into standalone group
2717 return self.mesh.ConvertToStandalone(group)
2719 # Get some info about mesh:
2720 # ------------------------
2722 def GetLog(self, clearAfterGet):
2724 Return the log of nodes and elements added or removed
2725 since the previous clear of the log.
2728 clearAfterGet: log is emptied after Get (safe if concurrents access)
2731 list of SMESH.log_block structures { commandType, number, coords, indexes }
2734 return self.mesh.GetLog(clearAfterGet)
2738 Clear the log of nodes and elements added or removed since the previous
2739 clear. Must be used immediately after :meth:`GetLog` if clearAfterGet is false.
2742 self.mesh.ClearLog()
2744 def SetAutoColor(self, theAutoColor):
2746 Toggle auto color mode on the object.
2747 If switched on, a default color of a new group in Create Group dialog is chosen randomly.
2750 theAutoColor (boolean): the flag which toggles auto color mode.
2753 self.mesh.SetAutoColor(theAutoColor)
2755 def GetAutoColor(self):
2757 Get flag of object auto color mode.
2763 return self.mesh.GetAutoColor()
2770 integer value, which is the internal Id of the mesh
2773 return self.mesh.GetId()
2775 def GetStudyId(self):
2780 integer value, which is the study Id of the mesh
2783 return self.mesh.GetStudyId()
2785 def HasDuplicatedGroupNamesMED(self):
2787 Check the group names for duplications.
2788 Consider the maximum group name length stored in MED file.
2794 return self.mesh.HasDuplicatedGroupNamesMED()
2796 def GetMeshEditor(self):
2798 Obtain the mesh editor tool
2801 an instance of :class:`SMESH.SMESH_MeshEditor`
2806 def GetIDSource(self, ids, elemType = SMESH.ALL):
2808 Wrap a list of IDs of elements or nodes into :class:`SMESH.SMESH_IDSource` which
2809 can be passed as argument to a method accepting :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
2813 elemType: type of elements; this parameter is used to distinguish
2814 IDs of nodes from IDs of elements; by default ids are treated as
2815 IDs of elements; use SMESH.NODE if ids are IDs of nodes.
2818 an instance of :class:`SMESH.SMESH_IDSource`
2821 call UnRegister() for the returned object as soon as it is no more useful::
2823 idSrc = mesh.GetIDSource( [1,3,5], SMESH.NODE )
2824 mesh.DoSomething( idSrc )
2828 if isinstance( ids, int ):
2830 return self.editor.MakeIDSource(ids, elemType)
2833 # Get information about mesh contents:
2834 # ------------------------------------
2836 def GetMeshInfo(self, obj = None):
2838 Get the mesh statistic.
2839 Use :meth:`smeshBuilder.EnumToLong` to get an integer from
2840 an item of :class:`SMESH.EntityType`.
2843 dictionary { :class:`SMESH.EntityType` - "count of elements" }
2846 if not obj: obj = self.mesh
2847 return self.smeshpyD.GetMeshInfo(obj)
2851 Return the number of nodes in the mesh
2857 return self.mesh.NbNodes()
2859 def NbElements(self):
2861 Return the number of elements in the mesh
2867 return self.mesh.NbElements()
2869 def Nb0DElements(self):
2871 Return the number of 0d elements in the mesh
2877 return self.mesh.Nb0DElements()
2881 Return the number of ball discrete elements in the mesh
2887 return self.mesh.NbBalls()
2891 Return the number of edges in the mesh
2897 return self.mesh.NbEdges()
2899 def NbEdgesOfOrder(self, elementOrder):
2901 Return the number of edges with the given order in the mesh
2904 elementOrder: the order of elements
2905 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
2911 return self.mesh.NbEdgesOfOrder(elementOrder)
2915 Return the number of faces in the mesh
2921 return self.mesh.NbFaces()
2923 def NbFacesOfOrder(self, elementOrder):
2925 Return the number of faces with the given order in the mesh
2928 elementOrder: the order of elements
2929 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
2935 return self.mesh.NbFacesOfOrder(elementOrder)
2937 def NbTriangles(self):
2939 Return the number of triangles in the mesh
2945 return self.mesh.NbTriangles()
2947 def NbTrianglesOfOrder(self, elementOrder):
2949 Return the number of triangles with the given order in the mesh
2952 elementOrder: is the order of elements
2953 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
2959 return self.mesh.NbTrianglesOfOrder(elementOrder)
2961 def NbBiQuadTriangles(self):
2963 Return the number of biquadratic triangles in the mesh
2969 return self.mesh.NbBiQuadTriangles()
2971 def NbQuadrangles(self):
2973 Return the number of quadrangles in the mesh
2979 return self.mesh.NbQuadrangles()
2981 def NbQuadranglesOfOrder(self, elementOrder):
2983 Return the number of quadrangles with the given order in the mesh
2986 elementOrder: the order of elements
2987 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
2993 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2995 def NbBiQuadQuadrangles(self):
2997 Return the number of biquadratic quadrangles in the mesh
3003 return self.mesh.NbBiQuadQuadrangles()
3005 def NbPolygons(self, elementOrder = SMESH.ORDER_ANY):
3007 Return the number of polygons of given order in the mesh
3010 elementOrder: the order of elements
3011 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
3017 return self.mesh.NbPolygonsOfOrder(elementOrder)
3019 def NbVolumes(self):
3021 Return the number of volumes in the mesh
3027 return self.mesh.NbVolumes()
3030 def NbVolumesOfOrder(self, elementOrder):
3032 Return the number of volumes with the given order in the mesh
3035 elementOrder: the order of elements
3036 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
3042 return self.mesh.NbVolumesOfOrder(elementOrder)
3046 Return the number of tetrahedrons in the mesh
3052 return self.mesh.NbTetras()
3054 def NbTetrasOfOrder(self, elementOrder):
3056 Return the number of tetrahedrons with the given order in the mesh
3059 elementOrder: the order of elements
3060 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
3066 return self.mesh.NbTetrasOfOrder(elementOrder)
3070 Return the number of hexahedrons in the mesh
3076 return self.mesh.NbHexas()
3078 def NbHexasOfOrder(self, elementOrder):
3080 Return the number of hexahedrons with the given order in the mesh
3083 elementOrder: the order of elements
3084 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
3090 return self.mesh.NbHexasOfOrder(elementOrder)
3092 def NbTriQuadraticHexas(self):
3094 Return the number of triquadratic hexahedrons in the mesh
3100 return self.mesh.NbTriQuadraticHexas()
3102 def NbPyramids(self):
3104 Return the number of pyramids in the mesh
3110 return self.mesh.NbPyramids()
3112 def NbPyramidsOfOrder(self, elementOrder):
3114 Return the number of pyramids with the given order in the mesh
3117 elementOrder: the order of elements
3118 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
3124 return self.mesh.NbPyramidsOfOrder(elementOrder)
3128 Return the number of prisms in the mesh
3134 return self.mesh.NbPrisms()
3136 def NbPrismsOfOrder(self, elementOrder):
3138 Return the number of prisms with the given order in the mesh
3141 elementOrder: the order of elements
3142 (SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC)
3148 return self.mesh.NbPrismsOfOrder(elementOrder)
3150 def NbHexagonalPrisms(self):
3152 Return the number of hexagonal prisms in the mesh
3158 return self.mesh.NbHexagonalPrisms()
3160 def NbPolyhedrons(self):
3162 Return the number of polyhedrons in the mesh
3168 return self.mesh.NbPolyhedrons()
3170 def NbSubMesh(self):
3172 Return the number of submeshes in the mesh
3178 return self.mesh.NbSubMesh()
3180 def GetElementsId(self):
3182 Return the list of all mesh elements IDs
3185 the list of integer values
3188 :meth:`GetElementsByType`
3191 return self.mesh.GetElementsId()
3193 def GetElementsByType(self, elementType):
3195 Return the list of IDs of mesh elements with the given type
3198 elementType (SMESH.ElementType): the required type of elements
3201 list of integer values
3204 return self.mesh.GetElementsByType(elementType)
3206 def GetNodesId(self):
3208 Return the list of mesh nodes IDs
3211 the list of integer values
3214 return self.mesh.GetNodesId()
3216 # Get the information about mesh elements:
3217 # ------------------------------------
3219 def GetElementType(self, id, iselem=True):
3221 Return the type of mesh element or node
3224 the value from :class:`SMESH.ElementType` enumeration.
3225 Return SMESH.ALL if element or node with the given ID does not exist
3228 return self.mesh.GetElementType(id, iselem)
3230 def GetElementGeomType(self, id):
3232 Return the geometric type of mesh element
3235 the value from :class:`SMESH.EntityType` enumeration.
3238 return self.mesh.GetElementGeomType(id)
3240 def GetElementShape(self, id):
3242 Return the shape type of mesh element
3245 the value from :class:`SMESH.GeometryType` enumeration.
3248 return self.mesh.GetElementShape(id)
3250 def GetSubMeshElementsId(self, Shape):
3252 Return the list of sub-mesh elements IDs
3255 Shape (GEOM.GEOM_Object): a geom object (sub-shape).
3256 *Shape* must be the sub-shape of the :meth:`main shape <GetShape>`
3259 list of integer values
3262 if isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object):
3263 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
3266 return self.mesh.GetSubMeshElementsId(ShapeID)
3268 def GetSubMeshNodesId(self, Shape, all):
3270 Return the list of sub-mesh nodes IDs
3273 Shape: a geom object (sub-shape).
3274 *Shape* must be the sub-shape of a :meth:`GetShape`
3275 all: If True, gives all nodes of sub-mesh elements, otherwise gives only sub-mesh nodes
3278 list of integer values
3281 if isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object):
3282 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
3285 return self.mesh.GetSubMeshNodesId(ShapeID, all)
3287 def GetSubMeshElementType(self, Shape):
3289 Return type of elements on given shape
3292 Shape: a geom object (sub-shape).
3293 *Shape* must be a sub-shape of a ShapeToMesh()
3296 :class:`SMESH.ElementType`
3299 if isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object):
3300 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
3303 return self.mesh.GetSubMeshElementType(ShapeID)
3307 Get the mesh description
3313 return self.mesh.Dump()
3316 # Get the information about nodes and elements of a mesh by its IDs:
3317 # -----------------------------------------------------------
3319 def GetNodeXYZ(self, id):
3321 Get XYZ coordinates of a node.
3322 If there is no node for the given ID - return an empty list
3325 list of float values
3328 return self.mesh.GetNodeXYZ(id)
3330 def GetNodeInverseElements(self, id):
3332 Return list of IDs of inverse elements for the given node.
3333 If there is no node for the given ID - return an empty list
3336 list of integer values
3339 return self.mesh.GetNodeInverseElements(id)
3341 def GetNodePosition(self,NodeID):
3343 Return the position of a node on the shape
3346 :class:`SMESH.NodePosition`
3349 return self.mesh.GetNodePosition(NodeID)
3351 def GetElementPosition(self,ElemID):
3353 Return the position of an element on the shape
3356 :class:`SMESH.ElementPosition`
3359 return self.mesh.GetElementPosition(ElemID)
3361 def GetShapeID(self, id):
3363 Return the ID of the shape, on which the given node was generated.
3366 an integer value > 0 or -1 if there is no node for the given
3367 ID or the node is not assigned to any geometry
3370 return self.mesh.GetShapeID(id)
3372 def GetShapeIDForElem(self,id):
3374 Return the ID of the shape, on which the given element was generated.
3377 an integer value > 0 or -1 if there is no element for the given
3378 ID or the element is not assigned to any geometry
3381 return self.mesh.GetShapeIDForElem(id)
3383 def GetElemNbNodes(self, id):
3385 Return the number of nodes of the given element
3388 an integer value > 0 or -1 if there is no element for the given ID
3391 return self.mesh.GetElemNbNodes(id)
3393 def GetElemNode(self, id, index):
3395 Return the node ID the given (zero based) index for the given element.
3397 * If there is no element for the given ID - return -1.
3398 * If there is no node for the given index - return -2.
3401 id (int): element ID
3402 index (int): node index within the element
3405 an integer value (ID)
3408 :meth:`GetElemNodes`
3411 return self.mesh.GetElemNode(id, index)
3413 def GetElemNodes(self, id):
3415 Return the IDs of nodes of the given element
3418 a list of integer values
3421 return self.mesh.GetElemNodes(id)
3423 def IsMediumNode(self, elementID, nodeID):
3425 Return true if the given node is the medium node in the given quadratic element
3428 return self.mesh.IsMediumNode(elementID, nodeID)
3430 def IsMediumNodeOfAnyElem(self, nodeID, elementType = SMESH.ALL ):
3432 Return true if the given node is the medium node in one of quadratic elements
3435 nodeID: ID of the node
3436 elementType: the type of elements to check a state of the node, either of
3437 (SMESH.ALL, SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
3440 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
3442 def ElemNbEdges(self, id):
3444 Return the number of edges for the given element
3447 return self.mesh.ElemNbEdges(id)
3449 def ElemNbFaces(self, id):
3451 Return the number of faces for the given element
3454 return self.mesh.ElemNbFaces(id)
3456 def GetElemFaceNodes(self,elemId, faceIndex):
3458 Return nodes of given face (counted from zero) for given volumic element.
3461 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
3463 def GetFaceNormal(self, faceId, normalized=False):
3465 Return three components of normal of given mesh face
3466 (or an empty array in KO case)
3469 return self.mesh.GetFaceNormal(faceId,normalized)
3471 def FindElementByNodes(self, nodes):
3473 Return an element based on all given nodes.
3476 return self.mesh.FindElementByNodes(nodes)
3478 def GetElementsByNodes(self, nodes, elemType=SMESH.ALL):
3480 Return elements including all given nodes.
3483 return self.mesh.GetElementsByNodes( nodes, elemType )
3485 def IsPoly(self, id):
3487 Return true if the given element is a polygon
3490 return self.mesh.IsPoly(id)
3492 def IsQuadratic(self, id):
3494 Return true if the given element is quadratic
3497 return self.mesh.IsQuadratic(id)
3499 def GetBallDiameter(self, id):
3501 Return diameter of a ball discrete element or zero in case of an invalid *id*
3504 return self.mesh.GetBallDiameter(id)
3506 def BaryCenter(self, id):
3508 Return XYZ coordinates of the barycenter of the given element.
3509 If there is no element for the given ID - return an empty list
3512 a list of three double values
3515 return self.mesh.BaryCenter(id)
3517 def GetIdsFromFilter(self, theFilter):
3519 Pass mesh elements through the given filter and return IDs of fitting elements
3522 theFilter: :class:`SMESH.Filter`
3528 :meth:`SMESH.Filter.GetIDs`
3531 theFilter.SetMesh( self.mesh )
3532 return theFilter.GetIDs()
3534 # Get mesh measurements information:
3535 # ------------------------------------
3537 def GetFreeBorders(self):
3539 Verify whether a 2D mesh element has free edges (edges connected to one face only).
3540 Return a list of special structures (borders).
3543 a list of :class:`SMESH.FreeEdges.Border`
3546 aFilterMgr = self.smeshpyD.CreateFilterManager()
3547 aPredicate = aFilterMgr.CreateFreeEdges()
3548 aPredicate.SetMesh(self.mesh)
3549 aBorders = aPredicate.GetBorders()
3550 aFilterMgr.UnRegister()
3553 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
3555 Get minimum distance between two nodes, elements or distance to the origin
3558 id1: first node/element id
3559 id2: second node/element id (if 0, distance from *id1* to the origin is computed)
3560 isElem1: *True* if *id1* is element id, *False* if it is node id
3561 isElem2: *True* if *id2* is element id, *False* if it is node id
3564 minimum distance value **GetMinDistance()**
3567 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
3568 return aMeasure.value
3570 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
3572 Get :class:`SMESH.Measure` structure specifying minimum distance data between two objects
3575 id1: first node/element id
3576 id2: second node/element id (if 0, distance from *id1* to the origin is computed)
3577 isElem1: *True* if *id1* is element id, *False* if it is node id
3578 isElem2: *True* if *id2* is element id, *False* if it is node id
3581 :class:`SMESH.Measure` structure
3587 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
3589 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
3592 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
3594 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
3599 aMeasurements = self.smeshpyD.CreateMeasurements()
3600 aMeasure = aMeasurements.MinDistance(id1, id2)
3601 genObjUnRegister([aMeasurements,id1, id2])
3604 def BoundingBox(self, objects=None, isElem=False):
3606 Get bounding box of the specified object(s)
3609 objects: single :class:`source object <SMESH.SMESH_IDSource>` or list of source objects or list of nodes/elements IDs
3610 isElem: if *objects* is a list of IDs, *True* value in this parameters specifies that *objects* are elements,
3611 *False* specifies that *objects* are nodes
3614 tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
3617 :meth:`GetBoundingBox()`
3620 result = self.GetBoundingBox(objects, isElem)
3624 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
3627 def GetBoundingBox(self, objects=None, isElem=False):
3629 Get :class:`SMESH.Measure` structure specifying bounding box data of the specified object(s)
3632 objects: single :class:`source object <SMESH.SMESH_IDSource>` or list of source objects or list of nodes/elements IDs
3633 isElem: if *objects* is a list of IDs, True means that *objects* are elements,
3634 False means that *objects* are nodes
3637 :class:`SMESH.Measure` structure
3640 :meth:`BoundingBox()`
3644 objects = [self.mesh]
3645 elif isinstance(objects, tuple):
3646 objects = list(objects)
3647 if not isinstance(objects, list):
3649 if len(objects) > 0 and isinstance(objects[0], int):
3652 unRegister = genObjUnRegister()
3654 if isinstance(o, Mesh):
3655 srclist.append(o.mesh)
3656 elif hasattr(o, "_narrow"):
3657 src = o._narrow(SMESH.SMESH_IDSource)
3658 if src: srclist.append(src)
3660 elif isinstance(o, list):
3662 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
3664 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
3665 unRegister.set( srclist[-1] )
3668 aMeasurements = self.smeshpyD.CreateMeasurements()
3669 unRegister.set( aMeasurements )
3670 aMeasure = aMeasurements.BoundingBox(srclist)
3673 # Mesh edition (SMESH_MeshEditor functionality):
3674 # ---------------------------------------------
3676 def RemoveElements(self, IDsOfElements):
3678 Remove the elements from the mesh by ids
3681 IDsOfElements: is a list of ids of elements to remove
3687 return self.editor.RemoveElements(IDsOfElements)
3689 def RemoveNodes(self, IDsOfNodes):
3691 Remove nodes from mesh by ids
3694 IDsOfNodes: is a list of ids of nodes to remove
3700 return self.editor.RemoveNodes(IDsOfNodes)
3702 def RemoveOrphanNodes(self):
3704 Remove all orphan (free) nodes from mesh
3707 number of the removed nodes
3710 return self.editor.RemoveOrphanNodes()
3712 def AddNode(self, x, y, z):
3714 Add a node to the mesh by coordinates
3720 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
3721 if hasVars: self.mesh.SetParameters(Parameters)
3722 return self.editor.AddNode( x, y, z)
3724 def Add0DElement( self, IDOfNode, DuplicateElements=True ):
3726 Create a 0D element on a node with given number.
3729 IDOfNode: the ID of node for creation of the element.
3730 DuplicateElements: to add one more 0D element to a node or not
3733 ID of the new 0D element
3736 return self.editor.Add0DElement( IDOfNode, DuplicateElements )
3738 def Add0DElementsToAllNodes(self, theObject, theGroupName="", DuplicateElements=False):
3740 Create 0D elements on all nodes of the given elements except those
3741 nodes on which a 0D element already exists.
3744 theObject: an object on whose nodes 0D elements will be created.
3745 It can be list of element IDs, :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
3746 theGroupName: optional name of a group to add 0D elements created
3747 and/or found on nodes of *theObject*.
3748 DuplicateElements: to add one more 0D element to a node or not
3751 an object (a new group or a temporary :class:`SMESH.SMESH_IDSource`) holding
3752 IDs of new and/or found 0D elements. IDs of 0D elements
3753 can be retrieved from the returned object by
3754 calling :meth:`GetIDs() <SMESH.SMESH_IDSource.GetIDs>`
3757 unRegister = genObjUnRegister()
3758 if isinstance( theObject, Mesh ):
3759 theObject = theObject.GetMesh()
3760 elif isinstance( theObject, list ):
3761 theObject = self.GetIDSource( theObject, SMESH.ALL )
3762 unRegister.set( theObject )
3763 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName, DuplicateElements )
3765 def AddBall(self, IDOfNode, diameter):
3767 Create a ball element on a node with given ID.
3770 IDOfNode: the ID of node for creation of the element.
3771 diameter: the bal diameter.
3774 ID of the new ball element
3777 return self.editor.AddBall( IDOfNode, diameter )
3779 def AddEdge(self, IDsOfNodes):
3781 Create a linear or quadratic edge (this is determined
3782 by the number of given nodes).
3785 IDsOfNodes: list of node IDs for creation of the element.
3786 The order of nodes in this list should correspond to
3787 the :ref:`connectivity convention <connectivity_page>`.
3793 return self.editor.AddEdge(IDsOfNodes)
3795 def AddFace(self, IDsOfNodes):
3797 Create a linear or quadratic face (this is determined
3798 by the number of given nodes).
3801 IDsOfNodes: list of node IDs for creation of the element.
3802 The order of nodes in this list should correspond to
3803 the :ref:`connectivity convention <connectivity_page>`.
3809 return self.editor.AddFace(IDsOfNodes)
3811 def AddPolygonalFace(self, IdsOfNodes):
3813 Add a polygonal face defined by a list of node IDs
3816 IdsOfNodes: the list of node IDs for creation of the element.
3822 return self.editor.AddPolygonalFace(IdsOfNodes)
3824 def AddQuadPolygonalFace(self, IdsOfNodes):
3826 Add a quadratic polygonal face defined by a list of node IDs
3829 IdsOfNodes: the list of node IDs for creation of the element;
3830 corner nodes follow first.
3836 return self.editor.AddQuadPolygonalFace(IdsOfNodes)
3838 def AddVolume(self, IDsOfNodes):
3840 Create both simple and quadratic volume (this is determined
3841 by the number of given nodes).
3844 IDsOfNodes: list of node IDs for creation of the element.
3845 The order of nodes in this list should correspond to
3846 the :ref:`connectivity convention <connectivity_page>`.
3849 ID of the new volumic element
3852 return self.editor.AddVolume(IDsOfNodes)
3854 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
3856 Create a volume of many faces, giving nodes for each face.
3859 IdsOfNodes: list of node IDs for volume creation, face by face.
3860 Quantities: list of integer values, Quantities[i]
3861 gives the quantity of nodes in face number i.
3864 ID of the new volumic element
3867 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
3869 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
3871 Create a volume of many faces, giving the IDs of the existing faces.
3874 The created volume will refer only to the nodes
3875 of the given faces, not to the faces themselves.
3878 IdsOfFaces: the list of face IDs for volume creation.
3881 ID of the new volumic element
3884 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
3887 def SetNodeOnVertex(self, NodeID, Vertex):
3889 Binds a node to a vertex
3893 Vertex: a vertex (GEOM.GEOM_Object) or vertex ID
3896 True if succeed else raises an exception
3899 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
3900 VertexID = self.geompyD.GetSubShapeID( self.geom, Vertex )
3904 self.editor.SetNodeOnVertex(NodeID, VertexID)
3905 except SALOME.SALOME_Exception, inst:
3906 raise ValueError, inst.details.text
3910 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
3912 Stores the node position on an edge
3916 Edge: an edge (GEOM.GEOM_Object) or edge ID
3917 paramOnEdge: a parameter on the edge where the node is located
3920 True if succeed else raises an exception
3923 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
3924 EdgeID = self.geompyD.GetSubShapeID( self.geom, Edge )
3928 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
3929 except SALOME.SALOME_Exception, inst:
3930 raise ValueError, inst.details.text
3933 def SetNodeOnFace(self, NodeID, Face, u, v):
3935 Stores node position on a face
3939 Face: a face (GEOM.GEOM_Object) or face ID
3940 u: U parameter on the face where the node is located
3941 v: V parameter on the face where the node is located
3944 True if succeed else raises an exception
3947 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
3948 FaceID = self.geompyD.GetSubShapeID( self.geom, Face )
3952 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
3953 except SALOME.SALOME_Exception, inst:
3954 raise ValueError, inst.details.text
3957 def SetNodeInVolume(self, NodeID, Solid):
3959 Binds a node to a solid
3963 Solid: a solid (GEOM.GEOM_Object) or solid ID
3966 True if succeed else raises an exception
3969 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
3970 SolidID = self.geompyD.GetSubShapeID( self.geom, Solid )
3974 self.editor.SetNodeInVolume(NodeID, SolidID)
3975 except SALOME.SALOME_Exception, inst:
3976 raise ValueError, inst.details.text
3979 def SetMeshElementOnShape(self, ElementID, Shape):
3981 Bind an element to a shape
3984 ElementID: an element ID
3985 Shape: a shape (GEOM.GEOM_Object) or shape ID
3988 True if succeed else raises an exception
3991 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
3992 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
3996 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
3997 except SALOME.SALOME_Exception, inst:
3998 raise ValueError, inst.details.text
4002 def MoveNode(self, NodeID, x, y, z):
4004 Move the node with the given id
4007 NodeID: the id of the node
4008 x: a new X coordinate
4009 y: a new Y coordinate
4010 z: a new Z coordinate
4013 True if succeed else False
4016 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
4017 if hasVars: self.mesh.SetParameters(Parameters)
4018 return self.editor.MoveNode(NodeID, x, y, z)
4020 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
4022 Find the node closest to a point and moves it to a point location
4025 x: the X coordinate of a point
4026 y: the Y coordinate of a point
4027 z: the Z coordinate of a point
4028 NodeID: if specified (>0), the node with this ID is moved,
4029 otherwise, the node closest to point (*x*, *y*, *z*) is moved
4032 the ID of a moved node
4035 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
4036 if hasVars: self.mesh.SetParameters(Parameters)
4037 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
4039 def FindNodeClosestTo(self, x, y, z):
4041 Find the node closest to a point
4044 x: the X coordinate of a point
4045 y: the Y coordinate of a point
4046 z: the Z coordinate of a point
4052 #preview = self.mesh.GetMeshEditPreviewer()
4053 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
4054 return self.editor.FindNodeClosestTo(x, y, z)
4056 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
4058 Find the elements where a point lays IN or ON
4061 x,y,z (float): coordinates of the point
4062 elementType (SMESH.ElementType): type of elements to find; SMESH.ALL type
4063 means elements of any type excluding nodes, discrete and 0D elements.
4064 meshPart: a part of mesh (:class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`) to search within
4067 list of IDs of found elements
4071 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
4073 return self.editor.FindElementsByPoint(x, y, z, elementType)
4075 def GetPointState(self, x, y, z):
4077 Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
4078 0-IN, 1-OUT, 2-ON, 3-UNKNOWN.
4079 UNKNOWN state means that either mesh is wrong or the analysis fails.
4082 return self.editor.GetPointState(x, y, z)
4084 def IsManifold(self):
4086 Check if a 2D mesh is manifold
4089 return self.editor.IsManifold()
4091 def IsCoherentOrientation2D(self):
4093 Check if orientation of 2D elements is coherent
4096 return self.editor.IsCoherentOrientation2D()
4098 def MeshToPassThroughAPoint(self, x, y, z):
4100 Find the node closest to a point and moves it to a point location
4103 x: the X coordinate of a point
4104 y: the Y coordinate of a point
4105 z: the Z coordinate of a point
4108 the ID of a moved node
4111 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
4113 def InverseDiag(self, NodeID1, NodeID2):
4115 Replace two neighbour triangles sharing Node1-Node2 link
4116 with the triangles built on the same 4 nodes but having other common link.
4119 NodeID1: the ID of the first node
4120 NodeID2: the ID of the second node
4123 False if proper faces were not found
4125 return self.editor.InverseDiag(NodeID1, NodeID2)
4127 def DeleteDiag(self, NodeID1, NodeID2):
4129 Replace two neighbour triangles sharing *Node1-Node2* link
4130 with a quadrangle built on the same 4 nodes.
4133 NodeID1: ID of the first node
4134 NodeID2: ID of the second node
4137 False if proper faces were not found
4140 return self.editor.DeleteDiag(NodeID1, NodeID2)
4142 def Reorient(self, IDsOfElements=None):
4144 Reorient elements by ids
4147 IDsOfElements: if undefined reorients all mesh elements
4150 True if succeed else False
4153 if IDsOfElements == None:
4154 IDsOfElements = self.GetElementsId()
4155 return self.editor.Reorient(IDsOfElements)
4157 def ReorientObject(self, theObject):
4159 Reorient all elements of the object
4162 theObject: :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
4165 True if succeed else False
4168 if ( isinstance( theObject, Mesh )):
4169 theObject = theObject.GetMesh()
4170 return self.editor.ReorientObject(theObject)
4172 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
4174 Reorient faces contained in *the2DObject*.
4177 the2DObject: is a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>` or list of IDs of 2D elements
4178 theDirection: is a desired direction of normal of *theFace*.
4179 It can be either a GEOM vector or a list of coordinates [x,y,z].
4180 theFaceOrPoint: defines a face of *the2DObject* whose normal will be
4181 compared with theDirection. It can be either ID of face or a point
4182 by which the face will be found. The point can be given as either
4183 a GEOM vertex or a list of point coordinates.
4186 number of reoriented faces
4189 unRegister = genObjUnRegister()
4191 if isinstance( the2DObject, Mesh ):
4192 the2DObject = the2DObject.GetMesh()
4193 if isinstance( the2DObject, list ):
4194 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
4195 unRegister.set( the2DObject )
4196 # check theDirection
4197 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
4198 theDirection = self.smeshpyD.GetDirStruct( theDirection )
4199 if isinstance( theDirection, list ):
4200 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
4201 # prepare theFace and thePoint
4202 theFace = theFaceOrPoint
4203 thePoint = PointStruct(0,0,0)
4204 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
4205 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
4207 if isinstance( theFaceOrPoint, list ):
4208 thePoint = PointStruct( *theFaceOrPoint )
4210 if isinstance( theFaceOrPoint, PointStruct ):
4211 thePoint = theFaceOrPoint
4213 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
4215 def Reorient2DBy3D(self, the2DObject, the3DObject, theOutsideNormal=True ):
4217 Reorient faces according to adjacent volumes.
4220 the2DObject: is a :class:`mesh, sub-mesh, group, filter <SMESH.SMESH_IDSource>` or list of
4221 either IDs of faces or face groups.
4222 the3DObject: is a :class:`mesh, sub-mesh, group, filter <SMESH.SMESH_IDSource>` or list of IDs of volumes.
4223 theOutsideNormal: to orient faces to have their normals
4224 pointing either *outside* or *inside* the adjacent volumes.
4227 number of reoriented faces.
4230 unRegister = genObjUnRegister()
4232 if not isinstance( the2DObject, list ):
4233 the2DObject = [ the2DObject ]
4234 elif the2DObject and isinstance( the2DObject[0], int ):
4235 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
4236 unRegister.set( the2DObject )
4237 the2DObject = [ the2DObject ]
4238 for i,obj2D in enumerate( the2DObject ):
4239 if isinstance( obj2D, Mesh ):
4240 the2DObject[i] = obj2D.GetMesh()
4241 if isinstance( obj2D, list ):
4242 the2DObject[i] = self.GetIDSource( obj2D, SMESH.FACE )
4243 unRegister.set( the2DObject[i] )
4245 if isinstance( the3DObject, Mesh ):
4246 the3DObject = the3DObject.GetMesh()
4247 if isinstance( the3DObject, list ):
4248 the3DObject = self.GetIDSource( the3DObject, SMESH.VOLUME )
4249 unRegister.set( the3DObject )
4250 return self.editor.Reorient2DBy3D( the2DObject, the3DObject, theOutsideNormal )
4252 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
4254 Fuse the neighbouring triangles into quadrangles.
4257 IDsOfElements: The triangles to be fused.
4258 theCriterion: a numerical functor, in terms of enum :class:`SMESH.FunctorType`, used to
4259 applied to possible quadrangles to choose a neighbour to fuse with.
4260 Note that not all items of :class:`SMESH.FunctorType` corresponds
4261 to numerical functors.
4262 MaxAngle: is the maximum angle between element normals at which the fusion
4263 is still performed; theMaxAngle is measured in radians.
4264 Also it could be a name of variable which defines angle in degrees.
4267 True in case of success, False otherwise.
4270 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
4271 self.mesh.SetParameters(Parameters)
4272 if not IDsOfElements:
4273 IDsOfElements = self.GetElementsId()
4274 Functor = self.smeshpyD.GetFunctor(theCriterion)
4275 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
4277 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
4279 Fuse the neighbouring triangles of the object into quadrangles
4282 theObject: is :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
4283 theCriterion: is a numerical functor, in terms of enum :class:`SMESH.FunctorType`,
4284 applied to possible quadrangles to choose a neighbour to fuse with.
4285 Note that not all items of :class:`SMESH.FunctorType` corresponds
4286 to numerical functors.
4287 MaxAngle: a max angle between element normals at which the fusion
4288 is still performed; theMaxAngle is measured in radians.
4291 True in case of success, False otherwise.
4294 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
4295 self.mesh.SetParameters(Parameters)
4296 if isinstance( theObject, Mesh ):
4297 theObject = theObject.GetMesh()
4298 Functor = self.smeshpyD.GetFunctor(theCriterion)
4299 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
4301 def QuadToTri (self, IDsOfElements, theCriterion = None):
4303 Split quadrangles into triangles.
4306 IDsOfElements: the faces to be splitted.
4307 theCriterion: is a numerical functor, in terms of enum :class:`SMESH.FunctorType`, used to
4308 choose a diagonal for splitting. If *theCriterion* is None, which is a default
4309 value, then quadrangles will be split by the smallest diagonal.
4310 Note that not all items of :class:`SMESH.FunctorType` corresponds
4311 to numerical functors.
4314 True in case of success, False otherwise.
4316 if IDsOfElements == []:
4317 IDsOfElements = self.GetElementsId()
4318 if theCriterion is None:
4319 theCriterion = FT_MaxElementLength2D
4320 Functor = self.smeshpyD.GetFunctor(theCriterion)
4321 return self.editor.QuadToTri(IDsOfElements, Functor)
4323 def QuadToTriObject (self, theObject, theCriterion = None):
4325 Split quadrangles into triangles.
4328 theObject: the object from which the list of elements is taken,
4329 this is :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
4330 theCriterion: is a numerical functor, in terms of enum :class:`SMESH.FunctorType`, used to
4331 choose a diagonal for splitting. If *theCriterion* is None, which is a default
4332 value, then quadrangles will be split by the smallest diagonal.
4333 Note that not all items of :class:`SMESH.FunctorType` corresponds
4334 to numerical functors.
4337 True in case of success, False otherwise.
4339 if ( isinstance( theObject, Mesh )):
4340 theObject = theObject.GetMesh()
4341 if theCriterion is None:
4342 theCriterion = FT_MaxElementLength2D
4343 Functor = self.smeshpyD.GetFunctor(theCriterion)
4344 return self.editor.QuadToTriObject(theObject, Functor)
4346 def QuadTo4Tri (self, theElements=[]):
4348 Split each of given quadrangles into 4 triangles. A node is added at the center of
4352 theElements: the faces to be splitted. This can be either
4353 :class:`mesh, sub-mesh, group, filter <SMESH.SMESH_IDSource>`
4354 or a list of face IDs. By default all quadrangles are split
4356 unRegister = genObjUnRegister()
4357 if isinstance( theElements, Mesh ):
4358 theElements = theElements.mesh
4359 elif not theElements:
4360 theElements = self.mesh
4361 elif isinstance( theElements, list ):
4362 theElements = self.GetIDSource( theElements, SMESH.FACE )
4363 unRegister.set( theElements )
4364 return self.editor.QuadTo4Tri( theElements )
4366 def SplitQuad (self, IDsOfElements, Diag13):
4368 Split quadrangles into triangles.
4371 IDsOfElements: the faces to be splitted
4372 Diag13: is used to choose a diagonal for splitting.
4375 True in case of success, False otherwise.
4377 if IDsOfElements == []:
4378 IDsOfElements = self.GetElementsId()
4379 return self.editor.SplitQuad(IDsOfElements, Diag13)
4381 def SplitQuadObject (self, theObject, Diag13):
4383 Split quadrangles into triangles.
4386 theObject: the object from which the list of elements is taken,
4387 this is :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
4388 Diag13: is used to choose a diagonal for splitting.
4391 True in case of success, False otherwise.
4393 if ( isinstance( theObject, Mesh )):
4394 theObject = theObject.GetMesh()
4395 return self.editor.SplitQuadObject(theObject, Diag13)
4397 def BestSplit (self, IDOfQuad, theCriterion):
4399 Find a better splitting of the given quadrangle.
4402 IDOfQuad: the ID of the quadrangle to be splitted.
4403 theCriterion: is a numerical functor, in terms of enum :class:`SMESH.FunctorType`, used to
4404 choose a diagonal for splitting.
4405 Note that not all items of :class:`SMESH.FunctorType` corresponds
4406 to numerical functors.
4409 * 1 if 1-3 diagonal is better,
4410 * 2 if 2-4 diagonal is better,
4411 * 0 if error occurs.
4413 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
4415 def SplitVolumesIntoTetra(self, elems, method=smeshBuilder.Hex_5Tet ):
4417 Split volumic elements into tetrahedrons
4420 elems: either a list of elements or a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
4421 method: flags passing splitting method:
4422 smesh.Hex_5Tet, smesh.Hex_6Tet, smesh.Hex_24Tet.
4423 smesh.Hex_5Tet - to split the hexahedron into 5 tetrahedrons, etc.
4425 unRegister = genObjUnRegister()
4426 if isinstance( elems, Mesh ):
4427 elems = elems.GetMesh()
4428 if ( isinstance( elems, list )):
4429 elems = self.editor.MakeIDSource(elems, SMESH.VOLUME)
4430 unRegister.set( elems )
4431 self.editor.SplitVolumesIntoTetra(elems, method)
4434 def SplitBiQuadraticIntoLinear(self, elems=None):
4436 Split bi-quadratic elements into linear ones without creation of additional nodes:
4438 - bi-quadratic triangle will be split into 3 linear quadrangles;
4439 - bi-quadratic quadrangle will be split into 4 linear quadrangles;
4440 - tri-quadratic hexahedron will be split into 8 linear hexahedra.
4442 Quadratic elements of lower dimension adjacent to the split bi-quadratic element
4443 will be split in order to keep the mesh conformal.
4446 elems: elements to split\: :class:`mesh, sub-mesh, group, filter <SMESH.SMESH_IDSource>` or element IDs;
4447 if None (default), all bi-quadratic elements will be split
4449 unRegister = genObjUnRegister()
4450 if elems and isinstance( elems, list ) and isinstance( elems[0], int ):
4451 elems = self.editor.MakeIDSource(elems, SMESH.ALL)
4452 unRegister.set( elems )
4454 elems = [ self.GetMesh() ]
4455 if isinstance( elems, Mesh ):
4456 elems = [ elems.GetMesh() ]
4457 if not isinstance( elems, list ):
4459 self.editor.SplitBiQuadraticIntoLinear( elems )
4461 def SplitHexahedraIntoPrisms(self, elems, startHexPoint, facetNormal,
4462 method=smeshBuilder.Hex_2Prisms, allDomains=False ):
4464 Split hexahedra into prisms
4467 elems: either a list of elements or a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
4468 startHexPoint: a point used to find a hexahedron for which *facetNormal*
4469 gives a normal vector defining facets to split into triangles.
4470 *startHexPoint* can be either a triple of coordinates or a vertex.
4471 facetNormal: a normal to a facet to split into triangles of a
4472 hexahedron found by *startHexPoint*.
4473 *facetNormal* can be either a triple of coordinates or an edge.
4474 method: flags passing splitting method: smesh.Hex_2Prisms, smesh.Hex_4Prisms.
4475 smesh.Hex_2Prisms - to split the hexahedron into 2 prisms, etc.
4476 allDomains: if :code:`False`, only hexahedra adjacent to one closest
4477 to *startHexPoint* are split, else *startHexPoint*
4478 is used to find the facet to split in all domains present in *elems*.
4481 unRegister = genObjUnRegister()
4482 if isinstance( elems, Mesh ):
4483 elems = elems.GetMesh()
4484 if ( isinstance( elems, list )):
4485 elems = self.editor.MakeIDSource(elems, SMESH.VOLUME)
4486 unRegister.set( elems )
4489 if isinstance( startHexPoint, geomBuilder.GEOM._objref_GEOM_Object):
4490 startHexPoint = self.smeshpyD.GetPointStruct( startHexPoint )
4491 elif isinstance( startHexPoint, list ):
4492 startHexPoint = SMESH.PointStruct( startHexPoint[0],
4495 if isinstance( facetNormal, geomBuilder.GEOM._objref_GEOM_Object):
4496 facetNormal = self.smeshpyD.GetDirStruct( facetNormal )
4497 elif isinstance( facetNormal, list ):
4498 facetNormal = self.smeshpyD.MakeDirStruct( facetNormal[0],
4501 self.mesh.SetParameters( startHexPoint.parameters + facetNormal.PS.parameters )
4503 self.editor.SplitHexahedraIntoPrisms(elems, startHexPoint, facetNormal, method, allDomains)
4505 def SplitQuadsNearTriangularFacets(self):
4507 Split quadrangle faces near triangular facets of volumes
4509 faces_array = self.GetElementsByType(SMESH.FACE)
4510 for face_id in faces_array:
4511 if self.GetElemNbNodes(face_id) == 4: # quadrangle
4512 quad_nodes = self.mesh.GetElemNodes(face_id)
4513 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
4514 isVolumeFound = False
4515 for node1_elem in node1_elems:
4516 if not isVolumeFound:
4517 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
4518 nb_nodes = self.GetElemNbNodes(node1_elem)
4519 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
4520 volume_elem = node1_elem
4521 volume_nodes = self.mesh.GetElemNodes(volume_elem)
4522 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
4523 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
4524 isVolumeFound = True
4525 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
4526 self.SplitQuad([face_id], False) # diagonal 2-4
4527 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
4528 isVolumeFound = True
4529 self.SplitQuad([face_id], True) # diagonal 1-3
4530 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
4531 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
4532 isVolumeFound = True
4533 self.SplitQuad([face_id], True) # diagonal 1-3
4535 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
4537 Split hexahedrons into tetrahedrons.
4539 This operation uses :doc:`pattern_mapping` functionality for splitting.
4542 theObject: the object from which the list of hexahedrons is taken;
4543 this is :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
4544 theNode000,theNode001: within the range [0,7]; gives the orientation of the
4545 pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
4546 will be mapped into *theNode000*-th node of each volume, the (0,0,1)
4547 key-point will be mapped into *theNode001*-th node of each volume.
4548 The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
4551 True in case of success, False otherwise.
4559 # (0,0,1) 4.---------.7 * |
4566 # (0,0,0) 0.---------.3
4567 pattern_tetra = "!!! Nb of points: \n 8 \n\
4577 !!! Indices of points of 6 tetras: \n\
4585 pattern = self.smeshpyD.GetPattern()
4586 isDone = pattern.LoadFromFile(pattern_tetra)
4588 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
4591 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
4592 isDone = pattern.MakeMesh(self.mesh, False, False)
4593 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
4595 # split quafrangle faces near triangular facets of volumes
4596 self.SplitQuadsNearTriangularFacets()
4600 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
4602 Split hexahedrons into prisms.
4604 Uses the :doc:`pattern_mapping` functionality for splitting.
4607 theObject: the object (:class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`) from where the list of hexahedrons is taken;
4608 theNode000,theNode001: (within the range [0,7]) gives the orientation of the
4609 pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
4610 will be mapped into the *theNode000* -th node of each volume, keypoint (0,0,1)
4611 will be mapped into the *theNode001* -th node of each volume.
4612 Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
4615 True in case of success, False otherwise.
4617 # Pattern: 5.---------.6
4622 # (0,0,1) 4.---------.7 |
4629 # (0,0,0) 0.---------.3
4630 pattern_prism = "!!! Nb of points: \n 8 \n\
4640 !!! Indices of points of 2 prisms: \n\
4644 pattern = self.smeshpyD.GetPattern()
4645 isDone = pattern.LoadFromFile(pattern_prism)
4647 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
4650 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
4651 isDone = pattern.MakeMesh(self.mesh, False, False)
4652 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
4654 # Split quafrangle faces near triangular facets of volumes
4655 self.SplitQuadsNearTriangularFacets()
4659 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
4660 MaxNbOfIterations, MaxAspectRatio, Method):
4665 IDsOfElements: the list if ids of elements to smooth
4666 IDsOfFixedNodes: the list of ids of fixed nodes.
4667 Note that nodes built on edges and boundary nodes are always fixed.
4668 MaxNbOfIterations: the maximum number of iterations
4669 MaxAspectRatio: varies in range [1.0, inf]
4670 Method: is either Laplacian (smesh.LAPLACIAN_SMOOTH)
4671 or Centroidal (smesh.CENTROIDAL_SMOOTH)
4674 True in case of success, False otherwise.
4677 if IDsOfElements == []:
4678 IDsOfElements = self.GetElementsId()
4679 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
4680 self.mesh.SetParameters(Parameters)
4681 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
4682 MaxNbOfIterations, MaxAspectRatio, Method)
4684 def SmoothObject(self, theObject, IDsOfFixedNodes,
4685 MaxNbOfIterations, MaxAspectRatio, Method):
4687 Smooth elements which belong to the given object
4690 theObject: the object to smooth
4691 IDsOfFixedNodes: the list of ids of fixed nodes.
4692 Note that nodes built on edges and boundary nodes are always fixed.
4693 MaxNbOfIterations: the maximum number of iterations
4694 MaxAspectRatio: varies in range [1.0, inf]
4695 Method: is either Laplacian (smesh.LAPLACIAN_SMOOTH)
4696 or Centroidal (smesh.CENTROIDAL_SMOOTH)
4699 True in case of success, False otherwise.
4702 if ( isinstance( theObject, Mesh )):
4703 theObject = theObject.GetMesh()
4704 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
4705 MaxNbOfIterations, MaxAspectRatio, Method)
4707 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
4708 MaxNbOfIterations, MaxAspectRatio, Method):
4710 Parametrically smooth the given elements
4713 IDsOfElements: the list if ids of elements to smooth
4714 IDsOfFixedNodes: the list of ids of fixed nodes.
4715 Note that nodes built on edges and boundary nodes are always fixed.
4716 MaxNbOfIterations: the maximum number of iterations
4717 MaxAspectRatio: varies in range [1.0, inf]
4718 Method: is either Laplacian (smesh.LAPLACIAN_SMOOTH)
4719 or Centroidal (smesh.CENTROIDAL_SMOOTH)
4722 True in case of success, False otherwise.
4725 if IDsOfElements == []:
4726 IDsOfElements = self.GetElementsId()
4727 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
4728 self.mesh.SetParameters(Parameters)
4729 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
4730 MaxNbOfIterations, MaxAspectRatio, Method)
4732 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
4733 MaxNbOfIterations, MaxAspectRatio, Method):
4735 Parametrically smooth the elements which belong to the given object
4738 theObject: the object to smooth
4739 IDsOfFixedNodes: the list of ids of fixed nodes.
4740 Note that nodes built on edges and boundary nodes are always fixed.
4741 MaxNbOfIterations: the maximum number of iterations
4742 MaxAspectRatio: varies in range [1.0, inf]
4743 Method: is either Laplacian (smesh.LAPLACIAN_SMOOTH)
4744 or Centroidal (smesh.CENTROIDAL_SMOOTH)
4747 True in case of success, False otherwise.
4750 if ( isinstance( theObject, Mesh )):
4751 theObject = theObject.GetMesh()
4752 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
4753 MaxNbOfIterations, MaxAspectRatio, Method)
4755 def ConvertToQuadratic(self, theForce3d=False, theSubMesh=None, theToBiQuad=False):
4757 Convert the mesh to quadratic or bi-quadratic, deletes old elements, replacing
4758 them with quadratic with the same id.
4761 theForce3d: method of new node creation:
4763 * False - the medium node lies at the geometrical entity from which the mesh element is built
4764 * True - the medium node lies at the middle of the line segments connecting two nodes of a mesh element
4765 theSubMesh: a :class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>` to convert
4766 theToBiQuad: If True, converts the mesh to bi-quadratic
4769 :class:`SMESH.ComputeError` which can hold a warning
4772 If *theSubMesh* is provided, the mesh can become non-conformal
4775 if isinstance( theSubMesh, Mesh ):
4776 theSubMesh = theSubMesh.mesh
4778 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
4781 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
4783 self.editor.ConvertToQuadratic(theForce3d)
4784 error = self.editor.GetLastError()
4785 if error and error.comment:
4789 def ConvertFromQuadratic(self, theSubMesh=None):
4791 Convert the mesh from quadratic to ordinary,
4792 deletes old quadratic elements,
4793 replacing them with ordinary mesh elements with the same id.
4796 theSubMesh: a :class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>` to convert
4799 If *theSubMesh* is provided, the mesh can become non-conformal
4803 self.editor.ConvertFromQuadraticObject(theSubMesh)
4805 return self.editor.ConvertFromQuadratic()
4807 def Make2DMeshFrom3D(self):
4809 Create 2D mesh as skin on boundary faces of a 3D mesh
4812 True if operation has been completed successfully, False otherwise
4815 return self.editor.Make2DMeshFrom3D()
4817 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
4818 toCopyElements=False, toCopyExistingBondary=False):
4820 Create missing boundary elements
4823 elements: elements whose boundary is to be checked:
4824 :class:`mesh, sub-mesh, group, filter <SMESH.SMESH_IDSource>` or list of elements.
4825 If *elements* is mesh, it must be the mesh whose MakeBoundaryMesh() is called
4826 dimension: defines type of boundary elements to create, either of
4827 { SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D }.
4828 SMESH.BND_1DFROM3D create mesh edges on all borders of free facets of 3D cells
4829 groupName: a name of group to store created boundary elements in,
4830 "" means not to create the group
4831 meshName: a name of new mesh to store created boundary elements in,
4832 "" means not to create the new mesh
4833 toCopyElements: if True, the checked elements will be copied into
4834 the new mesh else only boundary elements will be copied into the new mesh
4835 toCopyExistingBondary: if True, not only new but also pre-existing
4836 boundary elements will be copied into the new mesh
4839 tuple (:class:`Mesh`, :class:`group <SMESH.SMESH_Group>`) where boundary elements were added to
4842 unRegister = genObjUnRegister()
4843 if isinstance( elements, Mesh ):
4844 elements = elements.GetMesh()
4845 if ( isinstance( elements, list )):
4846 elemType = SMESH.ALL
4847 if elements: elemType = self.GetElementType( elements[0], iselem=True)
4848 elements = self.editor.MakeIDSource(elements, elemType)
4849 unRegister.set( elements )
4850 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
4851 toCopyElements,toCopyExistingBondary)
4852 if mesh: mesh = self.smeshpyD.Mesh(mesh)
4855 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
4856 toCopyAll=False, groups=[]):
4858 Create missing boundary elements around either the whole mesh or
4862 dimension: defines type of boundary elements to create, either of
4863 { SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D }
4864 groupName: a name of group to store all boundary elements in,
4865 "" means not to create the group
4866 meshName: a name of a new mesh, which is a copy of the initial
4867 mesh + created boundary elements; "" means not to create the new mesh
4868 toCopyAll: if True, the whole initial mesh will be copied into
4869 the new mesh else only boundary elements will be copied into the new mesh
4870 groups: list of :class:`sub-meshes, groups or filters <SMESH.SMESH_IDSource>` of elements to make boundary around
4873 tuple( long, mesh, groups )
4874 - long - number of added boundary elements
4875 - mesh - the :class:`Mesh` where elements were added to
4876 - group - the :class:`group <SMESH.SMESH_Group>` of boundary elements or None
4879 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
4881 if mesh: mesh = self.smeshpyD.Mesh(mesh)
4882 return nb, mesh, group
4884 def RenumberNodes(self):
4886 Renumber mesh nodes to remove unused node IDs
4888 self.editor.RenumberNodes()
4890 def RenumberElements(self):
4892 Renumber mesh elements to remove unused element IDs
4894 self.editor.RenumberElements()
4896 def _getIdSourceList(self, arg, idType, unRegister):
4898 Private method converting *arg* into a list of :class:`SMESH.SMESH_IDSource`
4900 if arg and isinstance( arg, list ):
4901 if isinstance( arg[0], int ):
4902 arg = self.GetIDSource( arg, idType )
4903 unRegister.set( arg )
4904 elif isinstance( arg[0], Mesh ):
4905 arg[0] = arg[0].GetMesh()
4906 elif isinstance( arg, Mesh ):
4908 if arg and isinstance( arg, SMESH._objref_SMESH_IDSource ):
4912 def RotationSweepObjects(self, nodes, edges, faces, Axis, AngleInRadians, NbOfSteps, Tolerance,
4913 MakeGroups=False, TotalAngle=False):
4915 Generate new elements by rotation of the given elements and nodes around the axis
4918 nodes: nodes to revolve: a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`
4919 edges: edges to revolve: a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`
4920 faces: faces to revolve: a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`
4921 Axis: the axis of rotation: :class:`SMESH.AxisStruct`, line (geom object) or [x,y,z,dx,dy,dz]
4922 AngleInRadians: the angle of Rotation (in radians) or a name of variable
4923 which defines angle in degrees
4924 NbOfSteps: the number of steps
4925 Tolerance: tolerance
4926 MakeGroups: forces the generation of new groups from existing ones
4927 TotalAngle: gives meaning of AngleInRadians: if True then it is an angular size
4928 of all steps, else - size of each step
4931 the list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
4934 unRegister = genObjUnRegister()
4935 nodes = self._getIdSourceList( nodes, SMESH.NODE, unRegister )
4936 edges = self._getIdSourceList( edges, SMESH.EDGE, unRegister )
4937 faces = self._getIdSourceList( faces, SMESH.FACE, unRegister )
4939 if isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object):
4940 Axis = self.smeshpyD.GetAxisStruct( Axis )
4941 if isinstance( Axis, list ):
4942 Axis = SMESH.AxisStruct( *Axis )
4944 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
4945 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
4946 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
4947 self.mesh.SetParameters(Parameters)
4948 if TotalAngle and NbOfSteps:
4949 AngleInRadians /= NbOfSteps
4950 return self.editor.RotationSweepObjects( nodes, edges, faces,
4951 Axis, AngleInRadians,
4952 NbOfSteps, Tolerance, MakeGroups)
4954 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
4955 MakeGroups=False, TotalAngle=False):
4957 Generate new elements by rotation of the elements around the axis
4960 IDsOfElements: the list of ids of elements to sweep
4961 Axis: the axis of rotation, :class:`SMESH.AxisStruct` or line(geom object)
4962 AngleInRadians: the angle of Rotation (in radians) or a name of variable which defines angle in degrees
4963 NbOfSteps: the number of steps
4964 Tolerance: tolerance
4965 MakeGroups: forces the generation of new groups from existing ones
4966 TotalAngle: gives meaning of AngleInRadians: if True then it is an angular size
4967 of all steps, else - size of each step
4970 the list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
4973 return self.RotationSweepObjects([], IDsOfElements, IDsOfElements, Axis,
4974 AngleInRadians, NbOfSteps, Tolerance,
4975 MakeGroups, TotalAngle)
4977 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
4978 MakeGroups=False, TotalAngle=False):
4980 Generate new elements by rotation of the elements of object around the axis
4981 theObject object which elements should be sweeped.
4982 It can be a mesh, a sub mesh or a group.
4985 Axis: the axis of rotation, :class:`SMESH.AxisStruct` or line(geom object)
4986 AngleInRadians: the angle of Rotation
4987 NbOfSteps: number of steps
4988 Tolerance: tolerance
4989 MakeGroups: forces the generation of new groups from existing ones
4990 TotalAngle: gives meaning of AngleInRadians: if True then it is an angular size
4991 of all steps, else - size of each step
4994 the list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
4997 return self.RotationSweepObjects( [], theObject, theObject, Axis,
4998 AngleInRadians, NbOfSteps, Tolerance,
4999 MakeGroups, TotalAngle )
5001 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
5002 MakeGroups=False, TotalAngle=False):
5004 Generate new elements by rotation of the elements of object around the axis
5005 theObject object which elements should be sweeped.
5006 It can be a mesh, a sub mesh or a group.
5009 Axis: the axis of rotation, :class:`SMESH.AxisStruct` or line(geom object)
5010 AngleInRadians: the angle of Rotation
5011 NbOfSteps: number of steps
5012 Tolerance: tolerance
5013 MakeGroups: forces the generation of new groups from existing ones
5014 TotalAngle: gives meaning of AngleInRadians: if True then it is an angular size
5015 of all steps, else - size of each step
5018 the list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True,
5019 empty list otherwise
5022 return self.RotationSweepObjects([],theObject,[], Axis,
5023 AngleInRadians, NbOfSteps, Tolerance,
5024 MakeGroups, TotalAngle)
5026 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
5027 MakeGroups=False, TotalAngle=False):
5029 Generate new elements by rotation of the elements of object around the axis
5030 theObject object which elements should be sweeped.
5031 It can be a mesh, a sub mesh or a group.
5034 Axis: the axis of rotation, :class:`SMESH.AxisStruct` or line(geom object)
5035 AngleInRadians: the angle of Rotation
5036 NbOfSteps: number of steps
5037 Tolerance: tolerance
5038 MakeGroups: forces the generation of new groups from existing ones
5039 TotalAngle: gives meaning of AngleInRadians: if True then it is an angular size
5040 of all steps, else - size of each step
5043 the list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5046 return self.RotationSweepObjects([],[],theObject, Axis, AngleInRadians,
5047 NbOfSteps, Tolerance, MakeGroups, TotalAngle)
5049 def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False,
5050 scaleFactors=[], linearVariation=False, basePoint=[] ):
5052 Generate new elements by extrusion of the given elements and nodes
5055 nodes: nodes to extrude: a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`
5056 edges: edges to extrude: a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`
5057 faces: faces to extrude: a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`
5058 StepVector: vector or :class:`SMESH.DirStruct` or 3 vector components, defining
5059 the direction and value of extrusion for one step (the total extrusion
5060 length will be NbOfSteps * ||StepVector||)
5061 NbOfSteps: the number of steps
5062 MakeGroups: forces the generation of new groups from existing ones
5063 scaleFactors: optional scale factors to apply during extrusion
5064 linearVariation: if *True*, scaleFactors are spread over all *scaleFactors*,
5065 else scaleFactors[i] is applied to nodes at the i-th extrusion step
5066 basePoint: optional scaling center; if not provided, a gravity center of
5067 nodes and elements being extruded is used as the scaling center.
5070 - a list of tree components of the point or
5074 the list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5076 Example: :ref:`tui_extrusion`
5078 unRegister = genObjUnRegister()
5079 nodes = self._getIdSourceList( nodes, SMESH.NODE, unRegister )
5080 edges = self._getIdSourceList( edges, SMESH.EDGE, unRegister )
5081 faces = self._getIdSourceList( faces, SMESH.FACE, unRegister )
5083 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
5084 StepVector = self.smeshpyD.GetDirStruct(StepVector)
5085 if isinstance( StepVector, list ):
5086 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
5088 if isinstance( basePoint, int):
5089 xyz = self.GetNodeXYZ( basePoint )
5091 raise RuntimeError, "Invalid node ID: %s" % basePoint
5093 if isinstance( basePoint, geomBuilder.GEOM._objref_GEOM_Object ):
5094 basePoint = self.geompyD.PointCoordinates( basePoint )
5096 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
5097 Parameters = StepVector.PS.parameters + var_separator + Parameters
5098 self.mesh.SetParameters(Parameters)
5100 return self.editor.ExtrusionSweepObjects( nodes, edges, faces,
5101 StepVector, NbOfSteps,
5102 scaleFactors, linearVariation, basePoint,
5106 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
5108 Generate new elements by extrusion of the elements with given ids
5111 IDsOfElements: the list of ids of elements or nodes for extrusion
5112 StepVector: vector or :class:`SMESH.DirStruct` or 3 vector components, defining
5113 the direction and value of extrusion for one step (the total extrusion
5114 length will be NbOfSteps * ||StepVector||)
5115 NbOfSteps: the number of steps
5116 MakeGroups: forces the generation of new groups from existing ones
5117 IsNodes: is True if elements with given ids are nodes
5120 the list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5122 Example: :ref:`tui_extrusion`
5125 if IsNodes: n = IDsOfElements
5126 else : e,f, = IDsOfElements,IDsOfElements
5127 return self.ExtrusionSweepObjects(n,e,f, StepVector, NbOfSteps, MakeGroups)
5129 def ExtrusionByNormal(self, Elements, StepSize, NbOfSteps,
5130 ByAverageNormal=False, UseInputElemsOnly=True, MakeGroups=False, Dim = 2):
5132 Generate new elements by extrusion along the normal to a discretized surface or wire
5135 Elements: elements to extrude - a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`.
5136 Only faces can be extruded so far. A sub-mesh should be a sub-mesh on geom faces.
5137 StepSize: length of one extrusion step (the total extrusion
5138 length will be *NbOfSteps* *StepSize*).
5139 NbOfSteps: number of extrusion steps.
5140 ByAverageNormal: if True each node is translated by *StepSize*
5141 along the average of the normal vectors to the faces sharing the node;
5142 else each node is translated along the same average normal till
5143 intersection with the plane got by translation of the face sharing
5144 the node along its own normal by *StepSize*.
5145 UseInputElemsOnly: to use only *Elements* when computing extrusion direction
5146 for every node of *Elements*.
5147 MakeGroups: forces generation of new groups from existing ones.
5148 Dim: dimension of elements to extrude: 2 - faces or 1 - edges. Extrusion of edges
5149 is not yet implemented. This parameter is used if *Elements* contains
5150 both faces and edges, i.e. *Elements* is a Mesh.
5153 the list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True,
5154 empty list otherwise.
5155 Example: :ref:`tui_extrusion`
5158 unRegister = genObjUnRegister()
5159 if isinstance( Elements, Mesh ):
5160 Elements = [ Elements.GetMesh() ]
5161 if isinstance( Elements, list ):
5163 raise RuntimeError, "Elements empty!"
5164 if isinstance( Elements[0], int ):
5165 Elements = self.GetIDSource( Elements, SMESH.ALL )
5166 unRegister.set( Elements )
5167 if not isinstance( Elements, list ):
5168 Elements = [ Elements ]
5169 StepSize,NbOfSteps,Parameters,hasVars = ParseParameters(StepSize,NbOfSteps)
5170 self.mesh.SetParameters(Parameters)
5171 return self.editor.ExtrusionByNormal(Elements, StepSize, NbOfSteps,
5172 ByAverageNormal, UseInputElemsOnly, MakeGroups, Dim)
5174 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
5176 Generate new elements by extrusion of the elements or nodes which belong to the object
5179 theObject: the object whose elements or nodes should be processed.
5180 It can be a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`.
5181 StepVector: vector or :class:`SMESH.DirStruct` or 3 vector components, defining
5182 the direction and value of extrusion for one step (the total extrusion
5183 length will be NbOfSteps * ||StepVector||)
5184 NbOfSteps: the number of steps
5185 MakeGroups: forces the generation of new groups from existing ones
5186 IsNodes: is True if elements to extrude are nodes
5189 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5190 Example: :ref:`tui_extrusion`
5194 if IsNodes: n = theObject
5195 else : e,f, = theObject,theObject
5196 return self.ExtrusionSweepObjects(n,e,f, StepVector, NbOfSteps, MakeGroups)
5198 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
5200 Generate new elements by extrusion of edges which belong to the object
5203 theObject: object whose 1D elements should be processed.
5204 It can be a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`.
5205 StepVector: vector or :class:`SMESH.DirStruct` or 3 vector components, defining
5206 the direction and value of extrusion for one step (the total extrusion
5207 length will be NbOfSteps * ||StepVector||)
5208 NbOfSteps: the number of steps
5209 MakeGroups: to generate new groups from existing ones
5212 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5213 Example: :ref:`tui_extrusion`
5216 return self.ExtrusionSweepObjects([],theObject,[], StepVector, NbOfSteps, MakeGroups)
5218 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
5220 Generate new elements by extrusion of faces which belong to the object
5223 theObject: object whose 2D elements should be processed.
5224 It can be a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`.
5225 StepVector: vector or :class:`SMESH.DirStruct` or 3 vector components, defining
5226 the direction and value of extrusion for one step (the total extrusion
5227 length will be NbOfSteps * ||StepVector||)
5228 NbOfSteps: the number of steps
5229 MakeGroups: forces the generation of new groups from existing ones
5232 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5233 Example: :ref:`tui_extrusion`
5236 return self.ExtrusionSweepObjects([],[],theObject, StepVector, NbOfSteps, MakeGroups)
5238 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
5239 ExtrFlags, SewTolerance, MakeGroups=False):
5241 Generate new elements by extrusion of the elements with given ids
5244 IDsOfElements: is ids of elements
5245 StepVector: vector or :class:`SMESH.DirStruct` or 3 vector components, defining
5246 the direction and value of extrusion for one step (the total extrusion
5247 length will be NbOfSteps * ||StepVector||)
5248 NbOfSteps: the number of steps
5249 ExtrFlags: sets flags for extrusion
5250 SewTolerance: uses for comparing locations of nodes if flag
5251 EXTRUSION_FLAG_SEW is set
5252 MakeGroups: forces the generation of new groups from existing ones
5255 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5258 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
5259 StepVector = self.smeshpyD.GetDirStruct(StepVector)
5260 if isinstance( StepVector, list ):
5261 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
5262 return self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
5263 ExtrFlags, SewTolerance, MakeGroups)
5265 def ExtrusionAlongPathObjects(self, Nodes, Edges, Faces, PathMesh, PathShape=None,
5266 NodeStart=1, HasAngles=False, Angles=[], LinearVariation=False,
5267 HasRefPoint=False, RefPoint=[0,0,0], MakeGroups=False):
5269 Generate new elements by extrusion of the given elements and nodes along the path.
5270 The path of extrusion must be a meshed edge.
5273 Nodes: nodes to extrude: a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`
5274 Edges: edges to extrude: a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`
5275 Faces: faces to extrude: a list including ids, :class:`a mesh, sub-meshes, groups or filters <SMESH.SMESH_IDSource>`
5276 PathMesh: 1D mesh or 1D sub-mesh, along which proceeds the extrusion
5277 PathShape: shape (edge) defines the sub-mesh of PathMesh if PathMesh
5278 contains not only path segments, else it can be None
5279 NodeStart: the first or the last node on the path. Defines the direction of extrusion
5280 HasAngles: allows the shape to be rotated around the path
5281 to get the resulting mesh in a helical fashion
5282 Angles: list of angles
5283 LinearVariation: forces the computation of rotation angles as linear
5284 variation of the given Angles along path steps
5285 HasRefPoint: allows using the reference point
5286 RefPoint: the reference point around which the shape is rotated (the mass center of the
5287 shape by default). The User can specify any point as the Reference Point.
5288 *RefPoint* can be either GEOM Vertex, [x,y,z] or :class:`SMESH.PointStruct`
5289 MakeGroups: forces the generation of new groups from existing ones
5292 list of created :class:`groups <SMESH.SMESH_GroupBase>` and
5293 :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>`
5294 Example: :ref:`tui_extrusion_along_path`
5297 unRegister = genObjUnRegister()
5298 Nodes = self._getIdSourceList( Nodes, SMESH.NODE, unRegister )
5299 Edges = self._getIdSourceList( Edges, SMESH.EDGE, unRegister )
5300 Faces = self._getIdSourceList( Faces, SMESH.FACE, unRegister )
5302 if isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object):
5303 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
5304 if isinstance( RefPoint, list ):
5305 if not RefPoint: RefPoint = [0,0,0]
5306 RefPoint = SMESH.PointStruct( *RefPoint )
5307 if isinstance( PathMesh, Mesh ):
5308 PathMesh = PathMesh.GetMesh()
5309 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
5310 Parameters = AnglesParameters + var_separator + RefPoint.parameters
5311 self.mesh.SetParameters(Parameters)
5312 return self.editor.ExtrusionAlongPathObjects(Nodes, Edges, Faces,
5313 PathMesh, PathShape, NodeStart,
5314 HasAngles, Angles, LinearVariation,
5315 HasRefPoint, RefPoint, MakeGroups)
5317 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
5318 HasAngles=False, Angles=[], LinearVariation=False,
5319 HasRefPoint=False, RefPoint=[0,0,0], MakeGroups=False,
5320 ElemType=SMESH.FACE):
5322 Generate new elements by extrusion of the given elements.
5323 The path of extrusion must be a meshed edge.
5326 Base: :class:`mesh, sub-mesh, group, filter <SMESH.SMESH_IDSource>`, or list of ids of elements for extrusion
5327 Path: 1D mesh or 1D sub-mesh, along which proceeds the extrusion
5328 NodeStart: the start node from Path. Defines the direction of extrusion
5329 HasAngles: allows the shape to be rotated around the path
5330 to get the resulting mesh in a helical fashion
5331 Angles: list of angles in radians
5332 LinearVariation: forces the computation of rotation angles as linear
5333 variation of the given Angles along path steps
5334 HasRefPoint: allows using the reference point
5335 RefPoint: the reference point around which the elements are rotated (the mass
5336 center of the elements by default).
5337 The User can specify any point as the Reference Point.
5338 *RefPoint* can be either GEOM Vertex, [x,y,z] or :class:`SMESH.PointStruct`
5339 MakeGroups: forces the generation of new groups from existing ones
5340 ElemType: type of elements for extrusion (if param Base is a mesh)
5343 list of created :class:`groups <SMESH.SMESH_GroupBase>` and
5344 :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>`
5345 if *MakeGroups* == True, only :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>`
5347 Example: :ref:`tui_extrusion_along_path`
5351 if ElemType == SMESH.NODE: n = Base
5352 if ElemType == SMESH.EDGE: e = Base
5353 if ElemType == SMESH.FACE: f = Base
5354 gr,er = self.ExtrusionAlongPathObjects(n,e,f, Path, None, NodeStart,
5355 HasAngles, Angles, LinearVariation,
5356 HasRefPoint, RefPoint, MakeGroups)
5357 if MakeGroups: return gr,er
5360 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
5361 HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
5362 MakeGroups=False, LinearVariation=False):
5364 Generate new elements by extrusion of the given elements.
5365 The path of extrusion must be a meshed edge.
5368 IDsOfElements: ids of elements
5369 PathMesh: mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
5370 PathShape: shape (edge) defines the sub-mesh for the path
5371 NodeStart: the first or the last node on the edge. Defines the direction of extrusion
5372 HasAngles: allows the shape to be rotated around the path
5373 to get the resulting mesh in a helical fashion
5374 Angles: list of angles in radians
5375 HasRefPoint: allows using the reference point
5376 RefPoint: the reference point around which the shape is rotated (the mass center of the shape by default).
5377 The User can specify any point as the Reference Point.
5378 *RefPoint* can be either GEOM Vertex, [x,y,z] or :class:`SMESH.PointStruct`
5379 MakeGroups: forces the generation of new groups from existing ones
5380 LinearVariation: forces the computation of rotation angles as linear
5381 variation of the given Angles along path steps
5384 list of created :class:`groups <SMESH.SMESH_GroupBase>` and
5385 :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>`
5386 if *MakeGroups* == True, only :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>` otherwise
5387 Example: :ref:`tui_extrusion_along_path`
5390 n,e,f = [],IDsOfElements,IDsOfElements
5391 gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape,
5392 NodeStart, HasAngles, Angles,
5394 HasRefPoint, RefPoint, MakeGroups)
5395 if MakeGroups: return gr,er
5398 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
5399 HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
5400 MakeGroups=False, LinearVariation=False):
5402 Generate new elements by extrusion of the elements which belong to the object.
5403 The path of extrusion must be a meshed edge.
5406 theObject: the object whose elements should be processed.
5407 It can be a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`.
5408 PathMesh: mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
5409 PathShape: shape (edge) defines the sub-mesh for the path
5410 NodeStart: the first or the last node on the edge. Defines the direction of extrusion
5411 HasAngles: allows the shape to be rotated around the path
5412 to get the resulting mesh in a helical fashion
5413 Angles: list of angles
5414 HasRefPoint: allows using the reference point
5415 RefPoint: the reference point around which the shape is rotated (the mass center of the shape by default).
5416 The User can specify any point as the Reference Point.
5417 *RefPoint* can be either GEOM Vertex, [x,y,z] or :class:`SMESH.PointStruct`
5418 MakeGroups: forces the generation of new groups from existing ones
5419 LinearVariation: forces the computation of rotation angles as linear
5420 variation of the given Angles along path steps
5423 list of created :class:`groups <SMESH.SMESH_GroupBase>` and
5424 :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>` if *MakeGroups* == True,
5425 only :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>` otherwise
5426 Example: :ref:`tui_extrusion_along_path`
5429 n,e,f = [],theObject,theObject
5430 gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart,
5431 HasAngles, Angles, LinearVariation,
5432 HasRefPoint, RefPoint, MakeGroups)
5433 if MakeGroups: return gr,er
5436 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
5437 HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
5438 MakeGroups=False, LinearVariation=False):
5440 Generate new elements by extrusion of mesh segments which belong to the object.
5441 The path of extrusion must be a meshed edge.
5444 theObject: the object whose 1D elements should be processed.
5445 It can be a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`.
5446 PathMesh: mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
5447 PathShape: shape (edge) defines the sub-mesh for the path
5448 NodeStart: the first or the last node on the edge. Defines the direction of extrusion
5449 HasAngles: allows the shape to be rotated around the path
5450 to get the resulting mesh in a helical fashion
5451 Angles: list of angles
5452 HasRefPoint: allows using the reference point
5453 RefPoint: the reference point around which the shape is rotated (the mass center of the shape by default).
5454 The User can specify any point as the Reference Point.
5455 *RefPoint* can be either GEOM Vertex, [x,y,z] or :class:`SMESH.PointStruct`
5456 MakeGroups: forces the generation of new groups from existing ones
5457 LinearVariation: forces the computation of rotation angles as linear
5458 variation of the given Angles along path steps
5461 list of created :class:`groups <SMESH.SMESH_GroupBase>` and
5462 :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>` if *MakeGroups* == True,
5463 only :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>` otherwise
5464 Example: :ref:`tui_extrusion_along_path`
5467 n,e,f = [],theObject,[]
5468 gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart,
5469 HasAngles, Angles, LinearVariation,
5470 HasRefPoint, RefPoint, MakeGroups)
5471 if MakeGroups: return gr,er
5474 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
5475 HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
5476 MakeGroups=False, LinearVariation=False):
5478 Generate new elements by extrusion of faces which belong to the object.
5479 The path of extrusion must be a meshed edge.
5482 theObject: the object whose 2D elements should be processed.
5483 It can be a :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`.
5484 PathMesh: mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
5485 PathShape: shape (edge) defines the sub-mesh for the path
5486 NodeStart: the first or the last node on the edge. Defines the direction of extrusion
5487 HasAngles: allows the shape to be rotated around the path
5488 to get the resulting mesh in a helical fashion
5489 Angles: list of angles
5490 HasRefPoint: allows using the reference point
5491 RefPoint: the reference point around which the shape is rotated (the mass center of the shape by default).
5492 The User can specify any point as the Reference Point.
5493 *RefPoint* can be either GEOM Vertex, [x,y,z] or :class:`SMESH.PointStruct`
5494 MakeGroups: forces the generation of new groups from existing ones
5495 LinearVariation: forces the computation of rotation angles as linear
5496 variation of the given Angles along path steps
5499 list of created :class:`groups <SMESH.SMESH_GroupBase>` and
5500 :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>` if *MakeGroups* == True,
5501 only :class:`error code <SMESH.SMESH_MeshEditor.Extrusion_Error>` otherwise
5502 Example: :ref:`tui_extrusion_along_path`
5505 n,e,f = [],[],theObject
5506 gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart,
5507 HasAngles, Angles, LinearVariation,
5508 HasRefPoint, RefPoint, MakeGroups)
5509 if MakeGroups: return gr,er
5512 def Mirror(self, IDsOfElements, Mirror, theMirrorType=None, Copy=0, MakeGroups=False):
5514 Create a symmetrical copy of mesh elements
5517 IDsOfElements: list of elements ids
5518 Mirror: is :class:`SMESH.AxisStruct` or geom object (point, line, plane)
5519 theMirrorType: smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE.
5520 If the *Mirror* is a geom object this parameter is unnecessary
5521 Copy: allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
5522 MakeGroups: forces the generation of new groups from existing ones (if Copy)
5525 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5528 if IDsOfElements == []:
5529 IDsOfElements = self.GetElementsId()
5530 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
5531 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
5532 theMirrorType = Mirror._mirrorType
5534 self.mesh.SetParameters(Mirror.parameters)
5535 if Copy and MakeGroups:
5536 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
5537 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
5540 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType=0, MakeGroups=0, NewMeshName=""):
5542 Create a new mesh by a symmetrical copy of mesh elements
5545 IDsOfElements: the list of elements ids
5546 Mirror: is :class:`SMESH.AxisStruct` or geom object (point, line, plane)
5547 theMirrorType: smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE.
5548 If the *Mirror* is a geom object this parameter is unnecessary
5549 MakeGroups: to generate new groups from existing ones
5550 NewMeshName: a name of the new mesh to create
5553 instance of class :class:`Mesh`
5556 if IDsOfElements == []:
5557 IDsOfElements = self.GetElementsId()
5558 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
5559 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
5560 theMirrorType = Mirror._mirrorType
5562 self.mesh.SetParameters(Mirror.parameters)
5563 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
5564 MakeGroups, NewMeshName)
5565 return Mesh(self.smeshpyD,self.geompyD,mesh)
5567 def MirrorObject (self, theObject, Mirror, theMirrorType=None, Copy=0, MakeGroups=False):
5569 Create a symmetrical copy of the object
5572 theObject: :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
5573 Mirror: :class:`SMESH.AxisStruct` or geom object (point, line, plane)
5574 theMirrorType: smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE.
5575 If the *Mirror* is a geom object this parameter is unnecessary
5576 Copy: allows copying the element (Copy==True) or replacing it with its mirror (Copy==False)
5577 MakeGroups: forces the generation of new groups from existing ones (if Copy)
5580 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5583 if ( isinstance( theObject, Mesh )):
5584 theObject = theObject.GetMesh()
5585 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
5586 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
5587 theMirrorType = Mirror._mirrorType
5589 self.mesh.SetParameters(Mirror.parameters)
5590 if Copy and MakeGroups:
5591 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
5592 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
5595 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType=0,MakeGroups=0,NewMeshName=""):
5597 Create a new mesh by a symmetrical copy of the object
5600 theObject: :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
5601 Mirror: :class:`SMESH.AxisStruct` or geom object (point, line, plane)
5602 theMirrorType: smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE.
5603 If the *Mirror* is a geom object this parameter is unnecessary
5604 MakeGroups: forces the generation of new groups from existing ones
5605 NewMeshName: the name of the new mesh to create
5608 instance of class :class:`Mesh`
5611 if ( isinstance( theObject, Mesh )):
5612 theObject = theObject.GetMesh()
5613 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
5614 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
5615 theMirrorType = Mirror._mirrorType
5617 self.mesh.SetParameters(Mirror.parameters)
5618 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
5619 MakeGroups, NewMeshName)
5620 return Mesh( self.smeshpyD,self.geompyD,mesh )
5622 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
5624 Translate the elements
5627 IDsOfElements: list of elements ids
5628 Vector: the direction of translation (:class:`SMESH.DirStruct` or vector or 3 vector components)
5629 Copy: allows copying the translated elements
5630 MakeGroups: forces the generation of new groups from existing ones (if Copy)
5633 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5636 if IDsOfElements == []:
5637 IDsOfElements = self.GetElementsId()
5638 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
5639 Vector = self.smeshpyD.GetDirStruct(Vector)
5640 if isinstance( Vector, list ):
5641 Vector = self.smeshpyD.MakeDirStruct(*Vector)
5642 self.mesh.SetParameters(Vector.PS.parameters)
5643 if Copy and MakeGroups:
5644 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
5645 self.editor.Translate(IDsOfElements, Vector, Copy)
5648 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
5650 Create a new mesh of translated elements
5653 IDsOfElements: list of elements ids
5654 Vector: the direction of translation (:class:`SMESH.DirStruct` or vector or 3 vector components)
5655 MakeGroups: forces the generation of new groups from existing ones
5656 NewMeshName: the name of the newly created mesh
5659 instance of class :class:`Mesh`
5662 if IDsOfElements == []:
5663 IDsOfElements = self.GetElementsId()
5664 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
5665 Vector = self.smeshpyD.GetDirStruct(Vector)
5666 if isinstance( Vector, list ):
5667 Vector = self.smeshpyD.MakeDirStruct(*Vector)
5668 self.mesh.SetParameters(Vector.PS.parameters)
5669 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
5670 return Mesh ( self.smeshpyD, self.geompyD, mesh )
5672 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
5674 Translate the object
5677 theObject: the object to translate (:class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`)
5678 Vector: direction of translation (:class:`SMESH.DirStruct` or geom vector or 3 vector components)
5679 Copy: allows copying the translated elements
5680 MakeGroups: forces the generation of new groups from existing ones (if Copy)
5683 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5686 if ( isinstance( theObject, Mesh )):
5687 theObject = theObject.GetMesh()
5688 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
5689 Vector = self.smeshpyD.GetDirStruct(Vector)
5690 if isinstance( Vector, list ):
5691 Vector = self.smeshpyD.MakeDirStruct(*Vector)
5692 self.mesh.SetParameters(Vector.PS.parameters)
5693 if Copy and MakeGroups:
5694 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
5695 self.editor.TranslateObject(theObject, Vector, Copy)
5698 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
5700 Create a new mesh from the translated object
5703 theObject: the object to translate (:class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`)
5704 Vector: the direction of translation (:class:`SMESH.DirStruct` or geom vector or 3 vector components)
5705 MakeGroups: forces the generation of new groups from existing ones
5706 NewMeshName: the name of the newly created mesh
5709 instance of class :class:`Mesh`
5712 if isinstance( theObject, Mesh ):
5713 theObject = theObject.GetMesh()
5714 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
5715 Vector = self.smeshpyD.GetDirStruct(Vector)
5716 if isinstance( Vector, list ):
5717 Vector = self.smeshpyD.MakeDirStruct(*Vector)
5718 self.mesh.SetParameters(Vector.PS.parameters)
5719 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
5720 return Mesh( self.smeshpyD, self.geompyD, mesh )
5724 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
5729 theObject: the object to translate (:class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`)
5730 thePoint: base point for scale (:class:`SMESH.PointStruct` or list of 3 coordinates)
5731 theScaleFact: list of 1-3 scale factors for axises
5732 Copy: allows copying the translated elements
5733 MakeGroups: forces the generation of new groups from existing
5737 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True,
5738 empty list otherwise
5740 unRegister = genObjUnRegister()
5741 if ( isinstance( theObject, Mesh )):
5742 theObject = theObject.GetMesh()
5743 if ( isinstance( theObject, list )):
5744 theObject = self.GetIDSource(theObject, SMESH.ALL)
5745 unRegister.set( theObject )
5746 if ( isinstance( thePoint, list )):
5747 thePoint = PointStruct( thePoint[0], thePoint[1], thePoint[2] )
5748 if ( isinstance( theScaleFact, float )):
5749 theScaleFact = [theScaleFact]
5750 if ( isinstance( theScaleFact, int )):
5751 theScaleFact = [ float(theScaleFact)]
5753 self.mesh.SetParameters(thePoint.parameters)
5755 if Copy and MakeGroups:
5756 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
5757 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
5760 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
5762 Create a new mesh from the translated object
5765 theObject: the object to translate (:class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`)
5766 thePoint: base point for scale (:class:`SMESH.PointStruct` or list of 3 coordinates)
5767 theScaleFact: list of 1-3 scale factors for axises
5768 MakeGroups: forces the generation of new groups from existing ones
5769 NewMeshName: the name of the newly created mesh
5772 instance of class :class:`Mesh`
5774 unRegister = genObjUnRegister()
5775 if (isinstance(theObject, Mesh)):
5776 theObject = theObject.GetMesh()
5777 if ( isinstance( theObject, list )):
5778 theObject = self.GetIDSource(theObject,SMESH.ALL)
5779 unRegister.set( theObject )
5780 if ( isinstance( thePoint, list )):
5781 thePoint = PointStruct( thePoint[0], thePoint[1], thePoint[2] )
5782 if ( isinstance( theScaleFact, float )):
5783 theScaleFact = [theScaleFact]
5784 if ( isinstance( theScaleFact, int )):
5785 theScaleFact = [ float(theScaleFact)]
5787 self.mesh.SetParameters(thePoint.parameters)
5788 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
5789 MakeGroups, NewMeshName)
5790 return Mesh( self.smeshpyD, self.geompyD, mesh )
5794 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
5799 IDsOfElements: list of elements ids
5800 Axis: the axis of rotation (:class:`SMESH.AxisStruct` or geom line)
5801 AngleInRadians: the angle of rotation (in radians) or a name of variable which defines angle in degrees
5802 Copy: allows copying the rotated elements
5803 MakeGroups: forces the generation of new groups from existing ones (if Copy)
5806 list of created :class:`groups <SMESH.SMESH_GroupBase>` if *MakeGroups* == True, empty list otherwise
5810 if IDsOfElements == []:
5811 IDsOfElements = self.GetElementsId()
5812 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
5813 Axis = self.smeshpyD.GetAxisStruct(Axis)
5814 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
5815 Parameters = Axis.parameters + var_separator + Parameters
5816 self.mesh.SetParameters(Parameters)
5817 if Copy and MakeGroups:
5818 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
5819 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
5822 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
5824 Create a new mesh of rotated elements
5827 IDsOfElements: list of element ids
5828 Axis: the axis of rotation (:class:`SMESH.AxisStruct` or geom line)
5829 AngleInRadians: the angle of rotation (in radians) or a name of variable which defines angle in degrees
5830 MakeGroups: forces the generation of new groups from existing ones
5831 NewMeshName: the name of the newly created mesh
5834 instance of class :class:`Mesh`
5837 if IDsOfElements == []:
5838 IDsOfElements = self.GetElementsId()
5839 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
5840 Axis = self.smeshpyD.GetAxisStruct(Axis)
5841 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
5842 Parameters = Axis.parameters + var_separator + Parameters
5843 self.mesh.SetParameters(Parameters)
5844 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
5845 MakeGroups, NewMeshName)
5846 return Mesh( self.smeshpyD, self.geompyD, mesh )
5848 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
5853 theObject: the object to rotate (:class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`)
5854 Axis: the axis of rotation (:class:`SMESH.AxisStruct` or geom line)
5855 AngleInRadians: the angle of rotation (in radians) or a name of variable which defines angle in degrees
5856 Copy: allows copying the rotated elements
5857 MakeGroups: forces the generation of new groups from existing ones (if Copy)
5860 list of created :class:`groups <SMESH.SMESH_GroupBase>` if MakeGroups==True, empty list otherwise
5863 if (isinstance(theObject, Mesh)):
5864 theObject = theObject.GetMesh()
5865 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
5866 Axis = self.smeshpyD.GetAxisStruct(Axis)
5867 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
5868 Parameters = Axis.parameters + ":" + Parameters
5869 self.mesh.SetParameters(Parameters)
5870 if Copy and MakeGroups:
5871 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
5872 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
5875 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
5877 Create a new mesh from the rotated object
5880 theObject: the object to rotate (:class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`)
5881 Axis: the axis of rotation (:class:`SMESH.AxisStruct` or geom line)
5882 AngleInRadians: the angle of rotation (in radians) or a name of variable which defines angle in degrees
5883 MakeGroups: forces the generation of new groups from existing ones
5884 NewMeshName: the name of the newly created mesh
5887 instance of class :class:`Mesh`
5890 if (isinstance( theObject, Mesh )):
5891 theObject = theObject.GetMesh()
5892 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
5893 Axis = self.smeshpyD.GetAxisStruct(Axis)
5894 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
5895 Parameters = Axis.parameters + ":" + Parameters
5896 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
5897 MakeGroups, NewMeshName)
5898 self.mesh.SetParameters(Parameters)
5899 return Mesh( self.smeshpyD, self.geompyD, mesh )
5901 def Offset(self, theObject, Value, MakeGroups=False, CopyElements=False, NewMeshName=''):
5903 Create an offset mesh from the given 2D object
5906 theObject (SMESH.SMESH_IDSource): the source object (mesh, sub-mesh, group or filter)
5907 theValue (float): signed offset size
5908 MakeGroups (boolean): forces the generation of new groups from existing ones
5909 CopyElements (boolean): if *NewMeshName* is empty, True means to keep original elements,
5910 False means to remove original elements.
5911 NewMeshName (string): the name of a mesh to create. If empty, offset elements are added to this mesh
5914 A tuple (:class:`Mesh`, list of :class:`groups <SMESH.SMESH_Group>`)
5917 if isinstance( theObject, Mesh ):
5918 theObject = theObject.GetMesh()
5919 theValue,Parameters,hasVars = ParseParameters(Value)
5920 mesh_groups = self.editor.Offset(theObject, Value, MakeGroups, CopyElements, NewMeshName)
5921 self.mesh.SetParameters(Parameters)
5922 # if mesh_groups[0]:
5923 # return Mesh( self.smeshpyD, self.geompyD, mesh_groups[0] ), mesh_groups[1]
5926 def FindCoincidentNodes (self, Tolerance, SeparateCornerAndMediumNodes=False):
5928 Find groups of adjacent nodes within Tolerance.
5931 Tolerance (float): the value of tolerance
5932 SeparateCornerAndMediumNodes (boolean): if *True*, in quadratic mesh puts
5933 corner and medium nodes in separate groups thus preventing
5934 their further merge.
5937 the list of groups of nodes IDs (e.g. [[1,12,13],[4,25]])
5940 return self.editor.FindCoincidentNodes( Tolerance, SeparateCornerAndMediumNodes )
5942 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance,
5943 exceptNodes=[], SeparateCornerAndMediumNodes=False):
5945 Find groups of ajacent nodes within Tolerance.
5948 Tolerance: the value of tolerance
5949 SubMeshOrGroup: :class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`
5950 exceptNodes: list of either SubMeshes, Groups or node IDs to exclude from search
5951 SeparateCornerAndMediumNodes: if *True*, in quadratic mesh puts
5952 corner and medium nodes in separate groups thus preventing
5953 their further merge.
5956 the list of groups of nodes IDs (e.g. [[1,12,13],[4,25]])
5959 unRegister = genObjUnRegister()
5960 if (isinstance( SubMeshOrGroup, Mesh )):
5961 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
5962 if not isinstance( exceptNodes, list ):
5963 exceptNodes = [ exceptNodes ]
5964 if exceptNodes and isinstance( exceptNodes[0], int ):
5965 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE )]
5966 unRegister.set( exceptNodes )
5967 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,
5968 exceptNodes, SeparateCornerAndMediumNodes)
5970 def MergeNodes (self, GroupsOfNodes, NodesToKeep=[], AvoidMakingHoles=False):
5975 GroupsOfNodes: a list of groups of nodes IDs for merging.
5976 E.g. [[1,12,13],[25,4]] means that nodes 12, 13 and 4 will be removed and replaced
5977 in all elements and groups by nodes 1 and 25 correspondingly
5978 NodesToKeep: nodes to keep in the mesh: a list of groups, sub-meshes or node IDs.
5979 If *NodesToKeep* does not include a node to keep for some group to merge,
5980 then the first node in the group is kept.
5981 AvoidMakingHoles: prevent merging nodes which cause removal of elements becoming
5984 # NodesToKeep are converted to SMESH.SMESH_IDSource in meshEditor.MergeNodes()
5985 self.editor.MergeNodes( GroupsOfNodes, NodesToKeep, AvoidMakingHoles )
5987 def FindEqualElements (self, MeshOrSubMeshOrGroup=None):
5989 Find the elements built on the same nodes.
5992 MeshOrSubMeshOrGroup: :class:`mesh, sub-mesh, group or filter <SMESH.SMESH_IDSource>`
5995 the list of groups of equal elements IDs (e.g. [[1,12,13],[4,25]])
5998 if not MeshOrSubMeshOrGroup:
5999 MeshOrSubMeshOrGroup=self.mesh
6000 elif isinstance( MeshOrSubMeshOrGroup, Mesh ):
6001 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
6002 return self.editor.FindEqualElements( MeshOrSubMeshOrGroup )
6004 def MergeElements(self, GroupsOfElementsID):
6006 Merge elements in each given group.
6009 GroupsOfElementsID: a list of groups (lists) of elements IDs for merging
6010 (e.g. [[1,12,13],[25,4]] means that elements 12, 13 and 4 will be removed and
6011 replaced in all groups by elements 1 and 25)
6014 self.editor.MergeElements(GroupsOfElementsID)
6016 def MergeEqualElements(self):
6018 Leave one element and remove all other elements built on the same nodes.
6021 self.editor.MergeEqualElements()
6023 def FindFreeBorders(self, ClosedOnly=True):
6025 Returns all or only closed free borders
6028 list of SMESH.FreeBorder's
6031 return self.editor.FindFreeBorders( ClosedOnly )
6033 def FillHole(self, holeNodes):
6035 Fill with 2D elements a hole defined by a SMESH.FreeBorder.
6038 FreeBorder: either a SMESH.FreeBorder or a list on node IDs. These nodes
6039 must describe all sequential nodes of the hole border. The first and the last
6040 nodes must be the same. Use :meth:`FindFreeBorders` to get nodes of holes.
6044 if holeNodes and isinstance( holeNodes, list ) and isinstance( holeNodes[0], int ):
6045 holeNodes = SMESH.FreeBorder(nodeIDs=holeNodes)
6046 if not isinstance( holeNodes, SMESH.FreeBorder ):
6047 raise TypeError, "holeNodes must be either SMESH.FreeBorder or list of integer and not %s" % holeNodes
6048 self.editor.FillHole( holeNodes )
6050 def FindCoincidentFreeBorders (self, tolerance=0.):
6052 Return groups of FreeBorder's coincident within the given tolerance.
6055 tolerance: the tolerance. If the tolerance <= 0.0 then one tenth of an average
6056 size of elements adjacent to free borders being compared is used.
6059 SMESH.CoincidentFreeBorders structure
6062 return self.editor.FindCoincidentFreeBorders( tolerance )
6064 def SewCoincidentFreeBorders (self, freeBorders, createPolygons=False, createPolyhedra=False):
6066 Sew FreeBorder's of each group
6069 freeBorders: either a SMESH.CoincidentFreeBorders structure or a list of lists
6070 where each enclosed list contains node IDs of a group of coincident free
6071 borders such that each consequent triple of IDs within a group describes
6072 a free border in a usual way: n1, n2, nLast - i.e. 1st node, 2nd node and
6073 last node of a border.
6074 For example [[1, 2, 10, 20, 21, 40], [11, 12, 15, 55, 54, 41]] describes two
6075 groups of coincident free borders, each group including two borders.
6076 createPolygons: if :code:`True` faces adjacent to free borders are converted to
6077 polygons if a node of opposite border falls on a face edge, else such
6078 faces are split into several ones.
6079 createPolyhedra: if :code:`True` volumes adjacent to free borders are converted to
6080 polyhedra if a node of opposite border falls on a volume edge, else such
6081 volumes, if any, remain intact and the mesh becomes non-conformal.
6084 a number of successfully sewed groups
6087 if freeBorders and isinstance( freeBorders, list ):
6088 # construct SMESH.CoincidentFreeBorders
6089 if isinstance( freeBorders[0], int ):
6090 freeBorders = [freeBorders]
6092 coincidentGroups = []
6093 for nodeList in freeBorders:
6094 if not nodeList or len( nodeList ) % 3:
6095 raise ValueError, "Wrong number of nodes in this group: %s" % nodeList
6098 group.append ( SMESH.FreeBorderPart( len(borders), 0, 1, 2 ))
6099 borders.append( SMESH.FreeBorder( nodeList[:3] ))
6100 nodeList = nodeList[3:]
6102 coincidentGroups.append( group )
6104 freeBorders = SMESH.CoincidentFreeBorders( borders, coincidentGroups )
6106 return self.editor.SewCoincidentFreeBorders( freeBorders, createPolygons, createPolyhedra )
6108 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
6109 FirstNodeID2, SecondNodeID2, LastNodeID2,
6110 CreatePolygons, CreatePolyedrs):
6115 :class:`error code <SMESH.SMESH_MeshEditor.Sew_Error>`
6118 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
6119 FirstNodeID2, SecondNodeID2, LastNodeID2,
6120 CreatePolygons, CreatePolyedrs)
6122 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
6123 FirstNodeID2, SecondNodeID2):
6125 Sew conform free borders
6128 :class:`error code <SMESH.SMESH_MeshEditor.Sew_Error>`
6131 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
6132 FirstNodeID2, SecondNodeID2)
6134 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
6135 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
6140 :class:`error code <SMESH.SMESH_MeshEditor.Sew_Error>`
6143 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
6144 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
6146 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
6147 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
6148 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
6150 Sew two sides of a mesh. The nodes belonging to Side1 are
6151 merged with the nodes of elements of Side2.
6152 The number of elements in theSide1 and in theSide2 must be
6153 equal and they should have similar nodal connectivity.
6154 The nodes to merge should belong to side borders and
6155 the first node should be linked to the second.
6158 :class:`error code <SMESH.SMESH_MeshEditor.Sew_Error>`
6161 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
6162 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
6163 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
6165 def ChangeElemNodes(self, ide, newIDs):
6167 Set new nodes for the given element.
6174 False if the number of nodes does not correspond to the type of element
6177 return self.editor.ChangeElemNodes(ide, newIDs)
6179 def GetLastCreatedNodes(self):
6181 If during the last operation of :class:`SMESH.SMESH_MeshEditor` some nodes were
6182 created, this method return the list of their IDs.
6183 If new nodes were not created - return empty list
6186 the list of integer values (can be empty)
6189 return self.editor.GetLastCreatedNodes()
6191 def GetLastCreatedElems(self):
6193 If during the last operation of :class:`SMESH.SMESH_MeshEditor` some elements were
6194 created this method return the list of their IDs.
6195 If new elements were not created - return empty list
6198 the list of integer values (can be empty)
6201 return self.editor.GetLastCreatedElems()
6203 def ClearLastCreated(self):
6205 Forget what nodes and elements were created by the last mesh edition operation
6208 self.editor.ClearLastCreated()
6210 def DoubleElements(self, theElements, theGroupName=""):
6212 Create duplicates of given elements, i.e. create new elements based on the
6213 same nodes as the given ones.
6216 theElements: container of elements to duplicate. It can be a
6217 :class:`mesh, sub-mesh, group, filter <SMESH.SMESH_IDSource>`
6218 or a list of element IDs. If *theElements* is
6219 a :class:`Mesh`, elements of highest dimension are duplicated
6220 theGroupName: a name of group to contain the generated elements.
6221 If a group with such a name already exists, the new elements
6222 are added to the existng group, else a new group is created.
6223 If *theGroupName* is empty, new elements are not added
6227 a :class:`group <SMESH.SMESH_Group>` where the new elements are added.
6228 None if *theGroupName* == "".
6231 unRegister = genObjUnRegister()
6232 if isinstance( theElements, Mesh ):
6233 theElements = theElements.mesh
6234 elif isinstance( theElements, list ):
6235 theElements = self.GetIDSource( theElements, SMESH.ALL )
6236 unRegister.set( theElements )
6237 return self.editor.DoubleElements(theElements, theGroupName)
6239 def DoubleNodes(self, theNodes, theModifiedElems):
6241 Create a hole in a mesh by doubling the nodes of some particular elements
6244 theNodes: IDs of nodes to be doubled
6245 theModifiedElems: IDs of elements to be updated by the new (doubled)
6246 nodes. If list of element identifiers is empty then nodes are doubled but
6247 they not assigned to elements
6250 True if operation has been completed successfully, False otherwise
6253 return self.editor.DoubleNodes(theNodes, theModifiedElems)
6255 def DoubleNode(self, theNodeId, theModifiedElems):
6257 Create a hole in a mesh by doubling the nodes of some particular elements.
6258 This method provided for convenience works as :meth:`DoubleNodes`.
6261 theNodeId: IDs of node to double
6262 theModifiedElems: IDs of elements to update
6265 True if operation has been completed successfully, False otherwise
6268 return self.editor.DoubleNode(theNodeId, theModifiedElems)
6270 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
6272 Create a hole in a mesh by doubling the nodes of some particular elements.
6273 This method provided for convenience works as :meth:`DoubleNodes`.
6276 theNodes: group of nodes to double.
6277 theModifiedElems: group of elements to update.
6278 theMakeGroup: forces the generation of a group containing new nodes.
6281 True or a created group if operation has been completed successfully,
6282 False or None otherwise
6286 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
6287 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
6289 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
6291 Create a hole in a mesh by doubling the nodes of some particular elements.
6292 This method provided for convenience works as :meth:`DoubleNodes`.
6295 theNodes: list of groups of nodes to double.
6296 theModifiedElems: list of groups of elements to update.
6297 theMakeGroup: forces the generation of a group containing new nodes.
6300 True if operation has been completed successfully, False otherwise
6304 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
6305 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
6307 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
6309 Create a hole in a mesh by doubling the nodes of some particular elements
6312 theElems: the list of elements (edges or faces) to replicate.
6313 The nodes for duplication could be found from these elements
6314 theNodesNot: list of nodes NOT to replicate
6315 theAffectedElems: the list of elements (cells and edges) to which the
6316 replicated nodes should be associated to
6319 True if operation has been completed successfully, False otherwise
6322 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
6324 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
6326 Create a hole in a mesh by doubling the nodes of some particular elements
6329 theElems: the list of elements (edges or faces) to replicate.
6330 The nodes for duplication could be found from these elements
6331 theNodesNot: list of nodes NOT to replicate
6332 theShape: shape to detect affected elements (element which geometric center
6333 located on or inside shape).
6334 The replicated nodes should be associated to affected elements.
6337 True if operation has been completed successfully, False otherwise
6340 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
6342 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
6343 theMakeGroup=False, theMakeNodeGroup=False):
6345 Create a hole in a mesh by doubling the nodes of some particular elements.
6346 This method provided for convenience works as :meth:`DoubleNodes`.
6349 theElems: group of of elements (edges or faces) to replicate.
6350 theNodesNot: group of nodes NOT to replicate.
6351 theAffectedElems: group of elements to which the replicated nodes
6352 should be associated to.
6353 theMakeGroup: forces the generation of a group containing new elements.
6354 theMakeNodeGroup: forces the generation of a group containing new nodes.
6357 True or created groups (one or two) if operation has been completed successfully,
6358 False or None otherwise
6361 if theMakeGroup or theMakeNodeGroup:
6362 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
6364 theMakeGroup, theMakeNodeGroup)
6365 if theMakeGroup and theMakeNodeGroup:
6368 return twoGroups[ int(theMakeNodeGroup) ]
6369 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
6371 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
6373 Create a hole in a mesh by doubling the nodes of some particular elements.
6374 This method provided for convenience works as :meth:`DoubleNodes`.
6377 theElems: group of of elements (edges or faces) to replicate
6378 theNodesNot: group of nodes not to replicate
6379 theShape: shape to detect affected elements (element which geometric center
6380 located on or inside shape).
6381 The replicated nodes should be associated to affected elements
6384 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
6386 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
6387 theMakeGroup=False, theMakeNodeGroup=False):
6389 Create a hole in a mesh by doubling the nodes of some particular elements.
6390 This method provided for convenience works as :meth:`DoubleNodes`.
6393 theElems: list of groups of elements (edges or faces) to replicate
6394 theNodesNot: list of groups of nodes NOT to replicate
6395 theAffectedElems: group of elements to which the replicated nodes
6396 should be associated to
6397 theMakeGroup: forces generation of a group containing new elements.
6398 theMakeNodeGroup: forces generation of a group containing new nodes
6401 True or created groups (one or two) if operation has been completed successfully,
6402 False or None otherwise
6405 if theMakeGroup or theMakeNodeGroup:
6406 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
6408 theMakeGroup, theMakeNodeGroup)
6409 if theMakeGroup and theMakeNodeGroup:
6412 return twoGroups[ int(theMakeNodeGroup) ]
6413 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
6415 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
6417 Create a hole in a mesh by doubling the nodes of some particular elements.
6418 This method provided for convenience works as :meth:`DoubleNodes`.
6421 theElems: list of groups of elements (edges or faces) to replicate
6422 theNodesNot: list of groups of nodes NOT to replicate
6423 theShape: shape to detect affected elements (element which geometric center
6424 located on or inside shape).
6425 The replicated nodes should be associated to affected elements
6428 True if operation has been completed successfully, False otherwise
6431 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
6433 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
6435 Identify the elements that will be affected by node duplication (actual duplication is not performed).
6436 This method is the first step of :meth:`DoubleNodeElemGroupsInRegion`.
6439 theElems: list of groups of nodes or elements (edges or faces) to replicate
6440 theNodesNot: list of groups of nodes NOT to replicate
6441 theShape: shape to detect affected elements (element which geometric center
6442 located on or inside shape).
6443 The replicated nodes should be associated to affected elements
6446 groups of affected elements in order: volumes, faces, edges
6449 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
6451 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems, onAllBoundaries=False ):
6453 Double nodes on shared faces between groups of volumes and create flat elements on demand.
6454 The list of groups must describe a partition of the mesh volumes.
6455 The nodes of the internal faces at the boundaries of the groups are doubled.
6456 In option, the internal faces are replaced by flat elements.
6457 Triangles are transformed to prisms, and quadrangles to hexahedrons.
6460 theDomains: list of groups of volumes
6461 createJointElems: if True, create the elements
6462 onAllBoundaries: if True, the nodes and elements are also created on
6463 the boundary between *theDomains* and the rest mesh
6466 True if operation has been completed successfully, False otherwise
6469 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems, onAllBoundaries )
6471 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
6473 Double nodes on some external faces and create flat elements.
6474 Flat elements are mainly used by some types of mechanic calculations.
6476 Each group of the list must be constituted of faces.
6477 Triangles are transformed in prisms, and quadrangles in hexahedrons.
6480 theGroupsOfFaces: list of groups of faces
6483 True if operation has been completed successfully, False otherwise
6486 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
6488 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
6490 Identify all the elements around a geom shape, get the faces delimiting the hole
6492 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
6494 def MakePolyLine(self, segments, groupName='', isPreview=False ):
6496 Create a polyline consisting of 1D mesh elements each lying on a 2D element of
6497 the initial mesh. Positions of new nodes are found by cutting the mesh by the
6498 plane passing through pairs of points specified by each :class:`SMESH.PolySegment` structure.
6499 If there are several paths connecting a pair of points, the shortest path is
6500 selected by the module. Position of the cutting plane is defined by the two
6501 points and an optional vector lying on the plane specified by a PolySegment.
6502 By default the vector is defined by Mesh module as following. A middle point
6503 of the two given points is computed. The middle point is projected to the mesh.
6504 The vector goes from the middle point to the projection point. In case of planar
6505 mesh, the vector is normal to the mesh.
6507 *segments* [i].vector returns the used vector which goes from the middle point to its projection.
6510 segments: list of :class:`SMESH.PolySegment` defining positions of cutting planes.
6511 groupName: optional name of a group where created mesh segments will be added.
6514 editor = self.editor
6516 editor = self.mesh.GetMeshEditPreviewer()
6517 segmentsRes = editor.MakePolyLine( segments, groupName )
6518 for i, seg in enumerate( segmentsRes ):
6519 segments[i].vector = seg.vector
6521 return editor.GetPreviewData()
6524 def GetFunctor(self, funcType ):
6526 Return a cached numerical functor by its type.
6529 funcType: functor type: an item of :class:`SMESH.FunctorType` enumeration.
6530 Note that not all items correspond to numerical functors.
6533 :class:`SMESH.NumericalFunctor`. The functor is already initialized with a mesh
6536 fn = self.functors[ funcType._v ]
6538 fn = self.smeshpyD.GetFunctor(funcType)
6539 fn.SetMesh(self.mesh)
6540 self.functors[ funcType._v ] = fn
6543 def FunctorValue(self, funcType, elemId, isElem=True):
6545 Return value of a functor for a given element
6548 funcType: an item of :class:`SMESH.FunctorType` enum.
6549 elemId: element or node ID
6550 isElem: *elemId* is ID of element or node
6553 the functor value or zero in case of invalid arguments
6556 fn = self.GetFunctor( funcType )
6557 if fn.GetElementType() == self.GetElementType(elemId, isElem):
6558 val = fn.GetValue(elemId)
6563 def GetLength(self, elemId=None):
6565 Get length of 1D element or sum of lengths of all 1D mesh elements
6568 elemId: mesh element ID (if not defined - sum of length of all 1D elements will be calculated)
6571 element's length value if *elemId* is specified or sum of all 1D mesh elements' lengths otherwise
6576 length = self.smeshpyD.GetLength(self)
6578 length = self.FunctorValue(SMESH.FT_Length, elemId)
6581 def GetArea(self, elemId=None):
6583 Get area of 2D element or sum of areas of all 2D mesh elements
6584 elemId mesh element ID (if not defined - sum of areas of all 2D elements will be calculated)
6587 element's area value if *elemId* is specified or sum of all 2D mesh elements' areas otherwise
6592 area = self.smeshpyD.GetArea(self)
6594 area = self.FunctorValue(SMESH.FT_Area, elemId)
6597 def GetVolume(self, elemId=None):
6599 Get volume of 3D element or sum of volumes of all 3D mesh elements
6602 elemId: mesh element ID (if not defined - sum of volumes of all 3D elements will be calculated)
6605 element's volume value if *elemId* is specified or sum of all 3D mesh elements' volumes otherwise
6610 volume = self.smeshpyD.GetVolume(self)
6612 volume = self.FunctorValue(SMESH.FT_Volume3D, elemId)
6615 def GetMaxElementLength(self, elemId):
6617 Get maximum element length.
6620 elemId: mesh element ID
6623 element's maximum length value
6626 if self.GetElementType(elemId, True) == SMESH.VOLUME:
6627 ftype = SMESH.FT_MaxElementLength3D
6629 ftype = SMESH.FT_MaxElementLength2D
6630 return self.FunctorValue(ftype, elemId)
6632 def GetAspectRatio(self, elemId):
6634 Get aspect ratio of 2D or 3D element.
6637 elemId: mesh element ID
6640 element's aspect ratio value
6643 if self.GetElementType(elemId, True) == SMESH.VOLUME:
6644 ftype = SMESH.FT_AspectRatio3D
6646 ftype = SMESH.FT_AspectRatio
6647 return self.FunctorValue(ftype, elemId)
6649 def GetWarping(self, elemId):
6651 Get warping angle of 2D element.
6654 elemId: mesh element ID
6657 element's warping angle value
6660 return self.FunctorValue(SMESH.FT_Warping, elemId)
6662 def GetMinimumAngle(self, elemId):
6664 Get minimum angle of 2D element.
6667 elemId: mesh element ID
6670 element's minimum angle value
6673 return self.FunctorValue(SMESH.FT_MinimumAngle, elemId)
6675 def GetTaper(self, elemId):
6677 Get taper of 2D element.
6680 elemId: mesh element ID
6683 element's taper value
6686 return self.FunctorValue(SMESH.FT_Taper, elemId)
6688 def GetSkew(self, elemId):
6690 Get skew of 2D element.
6693 elemId: mesh element ID
6696 element's skew value
6699 return self.FunctorValue(SMESH.FT_Skew, elemId)
6701 def GetMinMax(self, funType, meshPart=None):
6703 Return minimal and maximal value of a given functor.
6706 funType (SMESH.FunctorType): a functor type.
6707 Note that not all items of :class:`SMESH.FunctorType` corresponds
6708 to numerical functors.
6709 meshPart: a part of mesh (:class:`sub-mesh, group or filter <SMESH.SMESH_IDSource>`) to treat
6715 unRegister = genObjUnRegister()
6716 if isinstance( meshPart, list ):
6717 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
6718 unRegister.set( meshPart )
6719 if isinstance( meshPart, Mesh ):
6720 meshPart = meshPart.mesh
6721 fun = self.GetFunctor( funType )
6724 if hasattr( meshPart, "SetMesh" ):
6725 meshPart.SetMesh( self.mesh ) # set mesh to filter
6726 hist = fun.GetLocalHistogram( 1, False, meshPart )
6728 hist = fun.GetHistogram( 1, False )
6730 return hist[0].min, hist[0].max
6733 pass # end of Mesh class
6736 class meshProxy(SMESH._objref_SMESH_Mesh):
6738 Private class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility
6739 with old dump scripts which call SMESH_Mesh directly and not via smeshBuilder.Mesh
6742 SMESH._objref_SMESH_Mesh.__init__(self)
6743 def __deepcopy__(self, memo=None):
6744 new = self.__class__()
6746 def CreateDimGroup(self,*args): # 2 args added: nbCommonNodes, underlyingOnly
6747 if len( args ) == 3:
6748 args += SMESH.ALL_NODES, True
6749 return SMESH._objref_SMESH_Mesh.CreateDimGroup( self, *args )
6751 omniORB.registerObjref(SMESH._objref_SMESH_Mesh._NP_RepositoryId, meshProxy)
6754 class submeshProxy(SMESH._objref_SMESH_subMesh):
6756 Private class wrapping SMESH.SMESH_SubMesh in order to add Compute()
6759 SMESH._objref_SMESH_subMesh.__init__(self)
6761 def __deepcopy__(self, memo=None):
6762 new = self.__class__()
6765 def Compute(self,refresh=False):
6767 Compute the sub-mesh and return the status of the computation
6770 refresh: if *True*, Object Browser is automatically updated (when running in GUI)
6775 This is a method of SMESH.SMESH_submesh that can be obtained via Mesh.GetSubMesh() or
6776 :meth:`smeshBuilder.Mesh.GetSubMesh`.
6780 self.mesh = Mesh( smeshBuilder(), None, self.GetMesh())
6782 ok = self.mesh.Compute( self.GetSubShape(),refresh=[] )
6784 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
6785 smeshgui = salome.ImportComponentGUI("SMESH")
6786 smeshgui.Init(self.mesh.GetStudyId())
6787 smeshgui.SetMeshIcon( salome.ObjectToID( self ), ok, (self.GetNumberOfElements()==0) )
6788 if refresh: salome.sg.updateObjBrowser(True)
6793 omniORB.registerObjref(SMESH._objref_SMESH_subMesh._NP_RepositoryId, submeshProxy)
6796 class meshEditor(SMESH._objref_SMESH_MeshEditor):
6798 Private class used to compensate change of CORBA API of SMESH_MeshEditor for backward
6799 compatibility with old dump scripts which call SMESH_MeshEditor directly and not via
6803 SMESH._objref_SMESH_MeshEditor.__init__(self)
6805 def __getattr__(self, name ): # method called if an attribute not found
6806 if not self.mesh: # look for name() method in Mesh class
6807 self.mesh = Mesh( None, None, SMESH._objref_SMESH_MeshEditor.GetMesh(self))
6808 if hasattr( self.mesh, name ):
6809 return getattr( self.mesh, name )
6810 if name == "ExtrusionAlongPathObjX":
6811 return getattr( self.mesh, "ExtrusionAlongPathX" ) # other method name
6812 print "meshEditor: attribute '%s' NOT FOUND" % name
6814 def __deepcopy__(self, memo=None):
6815 new = self.__class__()
6817 def FindCoincidentNodes(self,*args): # a 2nd arg added (SeparateCornerAndMediumNodes)
6818 if len( args ) == 1: args += False,
6819 return SMESH._objref_SMESH_MeshEditor.FindCoincidentNodes( self, *args )
6820 def FindCoincidentNodesOnPart(self,*args): # a 3d arg added (SeparateCornerAndMediumNodes)
6821 if len( args ) == 2: args += False,
6822 return SMESH._objref_SMESH_MeshEditor.FindCoincidentNodesOnPart( self, *args )
6823 def MergeNodes(self,*args): # 2 args added (NodesToKeep,AvoidMakingHoles)
6824 if len( args ) == 1:
6825 return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], [], False )
6826 NodesToKeep = args[1]
6827 AvoidMakingHoles = args[2] if len( args ) == 3 else False
6828 unRegister = genObjUnRegister()
6830 if isinstance( NodesToKeep, list ) and isinstance( NodesToKeep[0], int ):
6831 NodesToKeep = self.MakeIDSource( NodesToKeep, SMESH.NODE )
6832 if not isinstance( NodesToKeep, list ):
6833 NodesToKeep = [ NodesToKeep ]
6834 return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], NodesToKeep, AvoidMakingHoles )
6836 omniORB.registerObjref(SMESH._objref_SMESH_MeshEditor._NP_RepositoryId, meshEditor)
6838 class Pattern(SMESH._objref_SMESH_Pattern):
6840 Private class wrapping SMESH.SMESH_Pattern CORBA class in order to treat Notebook
6841 variables in some methods
6844 def LoadFromFile(self, patternTextOrFile ):
6845 text = patternTextOrFile
6846 if os.path.exists( text ):
6847 text = open( patternTextOrFile ).read()
6849 return SMESH._objref_SMESH_Pattern.LoadFromFile( self, text )
6851 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
6852 decrFun = lambda i: i-1
6853 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
6854 theMesh.SetParameters(Parameters)
6855 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
6857 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
6858 decrFun = lambda i: i-1
6859 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
6860 theMesh.SetParameters(Parameters)
6861 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
6863 def MakeMesh(self, mesh, CreatePolygons=False, CreatePolyhedra=False):
6864 if isinstance( mesh, Mesh ):
6865 mesh = mesh.GetMesh()
6866 return SMESH._objref_SMESH_Pattern.MakeMesh( self, mesh, CreatePolygons, CreatePolyhedra )
6868 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
6870 Registering the new proxy for Pattern
6875 Private class used to bind methods creating algorithms to the class Mesh
6878 def __init__(self, method):
6880 self.defaultAlgoType = ""
6881 self.algoTypeToClass = {}
6882 self.method = method
6884 def add(self, algoClass):
6886 Store a python class of algorithm
6888 if type( algoClass ).__name__ == 'classobj' and \
6889 hasattr( algoClass, "algoType"):
6890 self.algoTypeToClass[ algoClass.algoType ] = algoClass
6891 if not self.defaultAlgoType and \
6892 hasattr( algoClass, "isDefault") and algoClass.isDefault:
6893 self.defaultAlgoType = algoClass.algoType
6894 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
6896 def copy(self, mesh):
6898 Create a copy of self and assign mesh to the copy
6901 other = algoCreator( self.method )
6902 other.defaultAlgoType = self.defaultAlgoType
6903 other.algoTypeToClass = self.algoTypeToClass
6907 def __call__(self,algo="",geom=0,*args):
6909 Create an instance of algorithm
6913 if isinstance( algo, str ):
6915 elif ( isinstance( algo, geomBuilder.GEOM._objref_GEOM_Object ) and \
6916 not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object )):
6921 if isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
6923 elif not algoType and isinstance( geom, str ):
6928 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ) and not shape:
6930 elif isinstance( arg, str ) and not algoType:
6933 import traceback, sys
6934 msg = "Warning. Unexpected argument in mesh.%s() ---> %s" % ( self.method, arg )
6935 sys.stderr.write( msg + '\n' )
6936 tb = traceback.extract_stack(None,2)
6937 traceback.print_list( [tb[0]] )
6939 algoType = self.defaultAlgoType
6940 if not algoType and self.algoTypeToClass:
6941 algoType = sorted( self.algoTypeToClass.keys() )[0]
6942 if self.algoTypeToClass.has_key( algoType ):
6943 #print "Create algo",algoType
6944 return self.algoTypeToClass[ algoType ]( self.mesh, shape )
6945 raise RuntimeError, "No class found for algo type %s" % algoType
6948 class hypMethodWrapper:
6950 Private class used to substitute and store variable parameters of hypotheses.
6953 def __init__(self, hyp, method):
6955 self.method = method
6956 #print "REBIND:", method.__name__
6959 def __call__(self,*args):
6961 call a method of hypothesis with calling SetVarParameter() before
6965 return self.method( self.hyp, *args ) # hypothesis method with no args
6967 #print "MethWrapper.__call__",self.method.__name__, args
6969 parsed = ParseParameters(*args) # replace variables with their values
6970 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
6971 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
6972 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
6973 # maybe there is a replaced string arg which is not variable
6974 result = self.method( self.hyp, *args )
6975 except ValueError, detail: # raised by ParseParameters()
6977 result = self.method( self.hyp, *args )
6978 except omniORB.CORBA.BAD_PARAM:
6979 raise ValueError, detail # wrong variable name
6984 class genObjUnRegister:
6986 A helper class that calls UnRegister() of SALOME.GenericObj'es stored in it
6989 def __init__(self, genObj=None):
6990 self.genObjList = []
6994 def set(self, genObj):
6995 "Store one or a list of of SALOME.GenericObj'es"
6996 if isinstance( genObj, list ):
6997 self.genObjList.extend( genObj )
6999 self.genObjList.append( genObj )
7003 for genObj in self.genObjList:
7004 if genObj and hasattr( genObj, "UnRegister" ):
7007 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
7009 Bind methods creating mesher plug-ins to the Mesh class
7012 # print "pluginName: ", pluginName
7013 pluginBuilderName = pluginName + "Builder"
7015 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
7016 except Exception, e:
7017 from salome_utils import verbose
7018 if verbose(): print "Exception while loading %s: %s" % ( pluginBuilderName, e )
7020 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
7021 plugin = eval( pluginBuilderName )
7022 # print " plugin:" , str(plugin)
7024 # add methods creating algorithms to Mesh
7025 for k in dir( plugin ):
7026 if k[0] == '_': continue
7027 algo = getattr( plugin, k )
7028 # print " algo:", str(algo)
7029 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
7030 # print " meshMethod:" , str(algo.meshMethod)
7031 if not hasattr( Mesh, algo.meshMethod ):
7032 setattr( Mesh, algo.meshMethod, algoCreator( algo.meshMethod ))
7034 _mmethod = getattr( Mesh, algo.meshMethod )
7035 if hasattr( _mmethod, "add" ):