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
23 ## @package smeshBuilder
24 # Python API for SALOME %Mesh module
26 ## @defgroup l1_auxiliary Auxiliary methods and structures
27 ## @defgroup l1_creating Creating meshes
29 ## @defgroup l2_impexp Importing and exporting meshes
32 ## These are methods of class \ref smeshBuilder.smeshBuilder "smeshBuilder"
34 ## @defgroup l2_construct Constructing meshes
35 ## @defgroup l2_algorithms Defining Algorithms
37 ## @defgroup l3_algos_basic Basic meshing algorithms
38 ## @defgroup l3_algos_proj Projection Algorithms
39 ## @defgroup l3_algos_segmarv Segments around Vertex
40 ## @defgroup l3_algos_3dextr 3D extrusion meshing algorithm
43 ## @defgroup l2_hypotheses Defining hypotheses
45 ## @defgroup l3_hypos_1dhyps 1D Meshing Hypotheses
46 ## @defgroup l3_hypos_2dhyps 2D Meshing Hypotheses
47 ## @defgroup l3_hypos_maxvol Max Element Volume hypothesis
48 ## @defgroup l3_hypos_quad Quadrangle Parameters hypothesis
49 ## @defgroup l3_hypos_additi Additional Hypotheses
52 ## @defgroup l2_submeshes Constructing sub-meshes
53 ## @defgroup l2_editing Editing Meshes
56 ## @defgroup l1_meshinfo Mesh Information
57 ## @defgroup l1_controls Quality controls and Filtering
58 ## @defgroup l1_grouping Grouping elements
60 ## @defgroup l2_grps_create Creating groups
61 ## @defgroup l2_grps_operon Using operations on groups
62 ## @defgroup l2_grps_delete Deleting Groups
65 ## @defgroup l1_modifying Modifying meshes
67 ## @defgroup l2_modif_add Adding nodes and elements
68 ## @defgroup l2_modif_del Removing nodes and elements
69 ## @defgroup l2_modif_edit Modifying nodes and elements
70 ## @defgroup l2_modif_renumber Renumbering nodes and elements
71 ## @defgroup l2_modif_trsf Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging)
72 ## @defgroup l2_modif_unitetri Uniting triangles
73 ## @defgroup l2_modif_cutquadr Cutting elements
74 ## @defgroup l2_modif_changori Changing orientation of elements
75 ## @defgroup l2_modif_smooth Smoothing
76 ## @defgroup l2_modif_extrurev Extrusion and Revolution
77 ## @defgroup l2_modif_tofromqu Convert to/from Quadratic Mesh
78 ## @defgroup l2_modif_duplicat Duplication of nodes and elements (to emulate cracks)
81 ## @defgroup l1_measurements Measurements
84 from salome.geom import geomBuilder
86 import SMESH # This is necessary for back compatibility
88 from salome.smesh.smesh_algorithm import Mesh_Algorithm
95 # In case the omniORBpy EnumItem class does not fully support Python 3
96 # (for instance in version 4.2.1-2), the comparison ordering methods must be
100 SMESH.Entity_Triangle < SMESH.Entity_Quadrangle
102 def enumitem_eq(self, other):
104 if isinstance(other, omniORB.EnumItem):
105 if other._parent_id == self._parent_id:
106 return self._v == other._v
108 return self._parent_id == other._parent_id
110 return id(self) == id(other)
112 return id(self) == id(other)
114 def enumitem_lt(self, other):
116 if isinstance(other, omniORB.EnumItem):
117 if other._parent_id == self._parent_id:
118 return self._v < other._v
120 return self._parent_id < other._parent_id
122 return id(self) < id(other)
124 return id(self) < id(other)
126 def enumitem_le(self, other):
128 if isinstance(other, omniORB.EnumItem):
129 if other._parent_id == self._parent_id:
130 return self._v <= other._v
132 return self._parent_id <= other._parent_id
134 return id(self) <= id(other)
136 return id(self) <= id(other)
138 def enumitem_gt(self, other):
140 if isinstance(other, omniORB.EnumItem):
141 if other._parent_id == self._parent_id:
142 return self._v > other._v
144 return self._parent_id > other._parent_id
146 return id(self) > id(other)
148 return id(self) > id(other)
150 def enumitem_ge(self, other):
152 if isinstance(other, omniORB.EnumItem):
153 if other._parent_id == self._parent_id:
154 return self._v >= other._v
156 return self._parent_id >= other._parent_id
158 return id(self) >= id(other)
160 return id(self) >= id(other)
162 omniORB.EnumItem.__eq__ = enumitem_eq
163 omniORB.EnumItem.__lt__ = enumitem_lt
164 omniORB.EnumItem.__le__ = enumitem_le
165 omniORB.EnumItem.__gt__ = enumitem_gt
166 omniORB.EnumItem.__ge__ = enumitem_ge
169 ## Private class used to workaround a problem that sometimes isinstance(m, Mesh) returns False
171 class MeshMeta(type):
172 def __instancecheck__(cls, inst):
173 """Implement isinstance(inst, cls)."""
174 return any(cls.__subclasscheck__(c)
175 for c in {type(inst), inst.__class__})
177 def __subclasscheck__(cls, sub):
178 """Implement issubclass(sub, cls)."""
179 return type.__subclasscheck__(cls, sub) or (cls.__name__ == sub.__name__ and cls.__module__ == sub.__module__)
181 ## @addtogroup l1_auxiliary
184 ## Convert an angle from degrees to radians
185 def DegreesToRadians(AngleInDegrees):
187 return AngleInDegrees * pi / 180.0
189 import salome_notebook
190 notebook = salome_notebook.notebook
191 # Salome notebook variable separator
194 ## Return list of variable values from salome notebook.
195 # The last argument, if is callable, is used to modify values got from notebook
196 def ParseParameters(*args):
201 if args and callable(args[-1]):
202 args, varModifFun = args[:-1], args[-1]
203 for parameter in args:
205 Parameters += str(parameter) + var_separator
207 if isinstance(parameter,str):
208 # check if there is an inexistent variable name
209 if not notebook.isVariable(parameter):
210 raise ValueError("Variable with name '" + parameter + "' doesn't exist!!!")
211 parameter = notebook.get(parameter)
214 parameter = varModifFun(parameter)
217 Result.append(parameter)
220 Parameters = Parameters[:-1]
221 Result.append( Parameters )
222 Result.append( hasVariables )
225 ## Parse parameters while converting variables to radians
226 def ParseAngles(*args):
227 return ParseParameters( *( args + (DegreesToRadians, )))
229 ## Substitute PointStruct.__init__() to create SMESH.PointStruct using notebook variables.
230 # Parameters are stored in PointStruct.parameters attribute
231 def __initPointStruct(point,*args):
232 point.x, point.y, point.z, point.parameters,hasVars = ParseParameters(*args)
234 SMESH.PointStruct.__init__ = __initPointStruct
236 ## Substitute AxisStruct.__init__() to create SMESH.AxisStruct using notebook variables.
237 # Parameters are stored in AxisStruct.parameters attribute
238 def __initAxisStruct(ax,*args):
240 raise RuntimeError("Bad nb args (%s) passed in SMESH.AxisStruct(x,y,z,dx,dy,dz)"%(len( args )))
241 ax.x, ax.y, ax.z, ax.vx, ax.vy, ax.vz, ax.parameters,hasVars = ParseParameters(*args)
243 SMESH.AxisStruct.__init__ = __initAxisStruct
245 smeshPrecisionConfusion = 1.e-07
246 ## Compare real values using smeshPrecisionConfusion as tolerance
247 def IsEqual(val1, val2, tol=smeshPrecisionConfusion):
248 if abs(val1 - val2) < tol:
254 ## Return object name
258 if isinstance(obj, SALOMEDS._objref_SObject):
262 ior = salome.orb.object_to_string(obj)
266 sobj = salome.myStudy.FindObjectIOR(ior)
268 return sobj.GetName()
269 if hasattr(obj, "GetName"):
270 # unknown CORBA object, having GetName() method
273 # unknown CORBA object, no GetName() method
276 if hasattr(obj, "GetName"):
277 # unknown non-CORBA object, having GetName() method
280 raise RuntimeError("Null or invalid object")
282 ## Print error message if a hypothesis was not assigned.
283 def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh):
285 hypType = "algorithm"
287 hypType = "hypothesis"
290 if hasattr( status, "__getitem__" ):
291 status, reason = status[0], status[1]
292 if status == HYP_UNKNOWN_FATAL:
293 reason = "for unknown reason"
294 elif status == HYP_INCOMPATIBLE:
295 reason = "this hypothesis mismatches the algorithm"
296 elif status == HYP_NOTCONFORM:
297 reason = "a non-conform mesh would be built"
298 elif status == HYP_ALREADY_EXIST:
299 if isAlgo: return # it does not influence anything
300 reason = hypType + " of the same dimension is already assigned to this shape"
301 elif status == HYP_BAD_DIM:
302 reason = hypType + " mismatches the shape"
303 elif status == HYP_CONCURENT:
304 reason = "there are concurrent hypotheses on sub-shapes"
305 elif status == HYP_BAD_SUBSHAPE:
306 reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
307 elif status == HYP_BAD_GEOMETRY:
308 reason = "the algorithm is not applicable to this geometry"
309 elif status == HYP_HIDDEN_ALGO:
310 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
311 elif status == HYP_HIDING_ALGO:
312 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
313 elif status == HYP_NEED_SHAPE:
314 reason = "algorithm can't work without shape"
315 elif status == HYP_INCOMPAT_HYPS:
321 where = '"%s"' % geomName
323 meshName = GetName( mesh )
324 if meshName and meshName != NO_NAME:
325 where = '"%s" shape in "%s" mesh ' % ( geomName, meshName )
326 if status < HYP_UNKNOWN_FATAL and where:
327 print('"%s" was assigned to %s but %s' %( hypName, where, reason ))
329 print('"%s" was not assigned to %s : %s' %( hypName, where, reason ))
331 print('"%s" was not assigned : %s' %( hypName, reason ))
334 ## Private method. Add geom (sub-shape of the main shape) into the study if not yet there
335 def AssureGeomPublished(mesh, geom, name=''):
336 if not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
338 if not geom.GetStudyEntry():
340 if not name and geom.GetShapeType() != geomBuilder.GEOM.COMPOUND:
341 # for all groups SubShapeName() return "Compound_-1"
342 name = mesh.geompyD.SubShapeName(geom, mesh.geom)
344 name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
346 mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
349 ## Return the first vertex of a geometrical edge by ignoring orientation
350 def FirstVertexOnCurve(mesh, edge):
351 vv = mesh.geompyD.SubShapeAll( edge, geomBuilder.geomBuilder.ShapeType["VERTEX"])
353 raise TypeError("Given object has no vertices")
354 if len( vv ) == 1: return vv[0]
355 v0 = mesh.geompyD.MakeVertexOnCurve(edge,0.)
356 xyz = mesh.geompyD.PointCoordinates( v0 ) # coords of the first vertex
357 xyz1 = mesh.geompyD.PointCoordinates( vv[0] )
358 xyz2 = mesh.geompyD.PointCoordinates( vv[1] )
361 dist1 += abs( xyz[i] - xyz1[i] )
362 dist2 += abs( xyz[i] - xyz2[i] )
368 ## Return a long value from enumeration
369 def EnumToLong(theItem):
372 # end of l1_auxiliary
376 # Warning: smeshInst is a singleton
382 ## This class allows to create, load or manipulate meshes.
383 # It has a set of methods to create, load or copy meshes, to combine several meshes, etc.
384 # It also has methods to get infos and measure meshes.
385 class smeshBuilder(SMESH._objref_SMESH_Gen):
387 # MirrorType enumeration
388 POINT = SMESH_MeshEditor.POINT
389 AXIS = SMESH_MeshEditor.AXIS
390 PLANE = SMESH_MeshEditor.PLANE
392 # Smooth_Method enumeration
393 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
394 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
396 PrecisionConfusion = smeshPrecisionConfusion
398 # TopAbs_State enumeration
399 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = list(range(4))
401 # Methods of splitting a hexahedron into tetrahedra
402 Hex_5Tet, Hex_6Tet, Hex_24Tet, Hex_2Prisms, Hex_4Prisms = 1, 2, 3, 1, 2
404 def __new__(cls, *args):
408 #print "==== __new__", engine, smeshInst, doLcc
410 if smeshInst is None:
411 # smesh engine is either retrieved from engine, or created
413 # Following test avoids a recursive loop
415 if smeshInst is not None:
416 # smesh engine not created: existing engine found
420 # FindOrLoadComponent called:
421 # 1. CORBA resolution of server
422 # 2. the __new__ method is called again
423 #print "==== smeshInst = lcc.FindOrLoadComponent ", engine, smeshInst, doLcc
424 smeshInst = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
426 # FindOrLoadComponent not called
427 if smeshInst is None:
428 # smeshBuilder instance is created from lcc.FindOrLoadComponent
429 #print "==== smeshInst = super(smeshBuilder,cls).__new__(cls) ", engine, smeshInst, doLcc
430 smeshInst = super(smeshBuilder,cls).__new__(cls)
432 # smesh engine not created: existing engine found
433 #print "==== existing ", engine, smeshInst, doLcc
435 #print "====1 ", smeshInst
438 #print "====2 ", smeshInst
441 def __init__(self, *args):
443 #print "--------------- smeshbuilder __init__ ---", created
446 SMESH._objref_SMESH_Gen.__init__(self, *args)
448 ## Dump component to the Python script
449 # This method overrides IDL function to allow default values for the parameters.
450 # @ingroup l1_auxiliary
451 def DumpPython(self, theIsPublished=True, theIsMultiFile=True):
452 return SMESH._objref_SMESH_Gen.DumpPython(self, theIsPublished, theIsMultiFile)
454 ## Set mode of DumpPython(), \a historical or \a snapshot.
455 # In the \a historical mode, the Python Dump script includes all commands
456 # performed by SMESH engine. In the \a snapshot mode, commands
457 # relating to objects removed from the Study are excluded from the script
458 # as well as commands not influencing the current state of meshes
459 # @ingroup l1_auxiliary
460 def SetDumpPythonHistorical(self, isHistorical):
461 if isHistorical: val = "true"
463 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
465 ## Set Geometry component
466 # @ingroup l1_auxiliary
467 def init_smesh(self,isPublished = True,geompyD = None):
469 self.UpdateStudy(geompyD)
472 notebook.myStudy = salome.myStudy
474 ## Create a mesh. This can be either an empty mesh, possibly having an underlying geometry,
475 # or a mesh wrapping a CORBA mesh given as a parameter.
476 # @param obj either (1) a CORBA mesh (SMESH._objref_SMESH_Mesh) got e.g. by calling
477 # salome.myStudy.FindObjectID("0:1:2:3").GetObject() or
478 # (2) a Geometrical object for meshing or
480 # @param name the name for the new mesh.
481 # @return an instance of Mesh class.
482 # @ingroup l2_construct
483 def Mesh(self, obj=0, name=0):
484 if isinstance(obj,str):
486 return Mesh(self,self.geompyD,obj,name)
488 ## Return a string representation of the color.
489 # To be used with filters.
490 # @param c color value (SALOMEDS.Color)
491 # @ingroup l1_auxiliary
492 def ColorToString(self,c):
494 if isinstance(c, SALOMEDS.Color):
495 val = "%s;%s;%s" % (c.R, c.G, c.B)
496 elif isinstance(c, str):
499 raise ValueError("Color value should be of string or SALOMEDS.Color type")
502 ## Get PointStruct from vertex
503 # @param theVertex a GEOM object(vertex)
504 # @return SMESH.PointStruct
505 # @ingroup l1_auxiliary
506 def GetPointStruct(self,theVertex):
507 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
508 return PointStruct(x,y,z)
510 ## Get DirStruct from vector
511 # @param theVector a GEOM object(vector)
512 # @return SMESH.DirStruct
513 # @ingroup l1_auxiliary
514 def GetDirStruct(self,theVector):
515 vertices = self.geompyD.SubShapeAll( theVector, geomBuilder.geomBuilder.ShapeType["VERTEX"] )
516 if(len(vertices) != 2):
517 print("Error: vector object is incorrect.")
519 p1 = self.geompyD.PointCoordinates(vertices[0])
520 p2 = self.geompyD.PointCoordinates(vertices[1])
521 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
522 dirst = DirStruct(pnt)
525 ## Make DirStruct from a triplet
526 # @param x,y,z vector components
527 # @return SMESH.DirStruct
528 # @ingroup l1_auxiliary
529 def MakeDirStruct(self,x,y,z):
530 pnt = PointStruct(x,y,z)
531 return DirStruct(pnt)
533 ## Get AxisStruct from object
534 # @param theObj a GEOM object (line or plane)
535 # @return SMESH.AxisStruct
536 # @ingroup l1_auxiliary
537 def GetAxisStruct(self,theObj):
539 edges = self.geompyD.SubShapeAll( theObj, geomBuilder.geomBuilder.ShapeType["EDGE"] )
542 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
543 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
544 vertex1 = self.geompyD.PointCoordinates(vertex1)
545 vertex2 = self.geompyD.PointCoordinates(vertex2)
546 vertex3 = self.geompyD.PointCoordinates(vertex3)
547 vertex4 = self.geompyD.PointCoordinates(vertex4)
548 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
549 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
550 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] ]
551 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
552 axis._mirrorType = SMESH.SMESH_MeshEditor.PLANE
553 elif len(edges) == 1:
554 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
555 p1 = self.geompyD.PointCoordinates( vertex1 )
556 p2 = self.geompyD.PointCoordinates( vertex2 )
557 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
558 axis._mirrorType = SMESH.SMESH_MeshEditor.AXIS
559 elif theObj.GetShapeType() == GEOM.VERTEX:
560 x,y,z = self.geompyD.PointCoordinates( theObj )
561 axis = AxisStruct( x,y,z, 1,0,0,)
562 axis._mirrorType = SMESH.SMESH_MeshEditor.POINT
565 # From SMESH_Gen interface:
566 # ------------------------
568 ## Set the given name to the object
569 # @param obj the object to rename
570 # @param name a new object name
571 # @ingroup l1_auxiliary
572 def SetName(self, obj, name):
573 if isinstance( obj, Mesh ):
575 elif isinstance( obj, Mesh_Algorithm ):
576 obj = obj.GetAlgorithm()
577 ior = salome.orb.object_to_string(obj)
578 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
580 ## Set the current mode
581 # @ingroup l1_auxiliary
582 def SetEmbeddedMode( self,theMode ):
583 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
585 ## Get the current mode
586 # @ingroup l1_auxiliary
587 def IsEmbeddedMode(self):
588 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
590 ## Update the current study. Calling UpdateStudy() allows to
591 # update meshes at switching GEOM->SMESH
592 # @ingroup l1_auxiliary
593 def UpdateStudy( self, geompyD = None ):
596 from salome.geom import geomBuilder
597 geompyD = geomBuilder.geom
600 self.SetGeomEngine(geompyD)
601 SMESH._objref_SMESH_Gen.UpdateStudy(self)
602 sb = salome.myStudy.NewBuilder()
603 sc = salome.myStudy.FindComponent("SMESH")
604 if sc: sb.LoadWith(sc, self)
607 ## Sets enable publishing in the study. Calling SetEnablePublish( false ) allows to
608 # switch OFF publishing in the Study of mesh objects.
609 # @ingroup l1_auxiliary
610 def SetEnablePublish( self, theIsEnablePublish ):
611 #self.SetEnablePublish(theIsEnablePublish)
612 SMESH._objref_SMESH_Gen.SetEnablePublish(self,theIsEnablePublish)
614 notebook = salome_notebook.NoteBook( theIsEnablePublish )
616 ## Create a Mesh object importing data from the given UNV file
617 # @return an instance of Mesh class
619 def CreateMeshesFromUNV( self,theFileName ):
620 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
621 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
624 ## Create a Mesh object(s) importing data from the given MED file
625 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
627 def CreateMeshesFromMED( self,theFileName ):
628 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
629 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
630 return aMeshes, aStatus
632 ## Create a Mesh object(s) importing data from the given SAUV file
633 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
635 def CreateMeshesFromSAUV( self,theFileName ):
636 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
637 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
638 return aMeshes, aStatus
640 ## Create a Mesh object importing data from the given STL file
641 # @return an instance of Mesh class
643 def CreateMeshesFromSTL( self, theFileName ):
644 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
645 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
648 ## Create Mesh objects importing data from the given CGNS file
649 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
651 def CreateMeshesFromCGNS( self, theFileName ):
652 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
653 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
654 return aMeshes, aStatus
656 ## Create a Mesh object importing data from the given GMF file.
657 # GMF files must have .mesh extension for the ASCII format and .meshb for
659 # @return [ an instance of Mesh class, SMESH.ComputeError ]
661 def CreateMeshesFromGMF( self, theFileName ):
662 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
665 if error.comment: print("*** CreateMeshesFromGMF() errors:\n", error.comment)
666 return Mesh(self, self.geompyD, aSmeshMesh), error
668 ## Concatenate the given meshes into one mesh. All groups of input meshes will be
669 # present in the new mesh.
670 # @param meshes the meshes, sub-meshes and groups to combine into one mesh
671 # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
672 # @param mergeNodesAndElements if true, equal nodes and elements are merged
673 # @param mergeTolerance tolerance for merging nodes
674 # @param allGroups forces creation of groups corresponding to every input mesh
675 # @param name name of a new mesh
676 # @return an instance of Mesh class
677 # @ingroup l1_creating
678 def Concatenate( self, meshes, uniteIdenticalGroups,
679 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
681 if not meshes: return None
682 for i,m in enumerate(meshes):
683 if isinstance(m, Mesh):
684 meshes[i] = m.GetMesh()
685 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
686 meshes[0].SetParameters(Parameters)
688 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
689 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
691 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
692 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
693 aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
696 ## Create a mesh by copying a part of another mesh.
697 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
698 # to copy nodes or elements not contained in any mesh object,
699 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
700 # @param meshName a name of the new mesh
701 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
702 # @param toKeepIDs to preserve order of the copied elements or not
703 # @return an instance of Mesh class
704 # @ingroup l1_creating
705 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
706 if (isinstance( meshPart, Mesh )):
707 meshPart = meshPart.GetMesh()
708 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
709 return Mesh(self, self.geompyD, mesh)
711 ## Return IDs of sub-shapes
712 # @return the list of integer values
713 # @ingroup l1_auxiliary
714 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
715 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
717 ## Create a pattern mapper.
718 # @return an instance of SMESH_Pattern
720 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
721 # @ingroup l1_modifying
722 def GetPattern(self):
723 return SMESH._objref_SMESH_Gen.GetPattern(self)
725 ## Set number of segments per diagonal of boundary box of geometry, by which
726 # default segment length of appropriate 1D hypotheses is defined in GUI.
727 # Default value is 10.
728 # @ingroup l1_auxiliary
729 def SetBoundaryBoxSegmentation(self, nbSegments):
730 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
732 # Filtering. Auxiliary functions:
733 # ------------------------------
735 ## Create an empty criterion
736 # @return SMESH.Filter.Criterion
737 # @ingroup l1_controls
738 def GetEmptyCriterion(self):
739 Type = EnumToLong(FT_Undefined)
740 Compare = EnumToLong(FT_Undefined)
744 UnaryOp = EnumToLong(FT_Undefined)
745 BinaryOp = EnumToLong(FT_Undefined)
748 Precision = -1 ##@1e-07
749 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
750 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
752 ## Create a criterion by the given parameters
753 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
754 # @param elementType the type of elements(SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
755 # @param CritType the type of criterion (SMESH.FT_Taper, SMESH.FT_Area, etc.)
756 # Type SMESH.FunctorType._items in the Python Console to see all values.
757 # Note that the items starting from FT_LessThan are not suitable for CritType.
758 # @param Compare belongs to {SMESH.FT_LessThan, SMESH.FT_MoreThan, SMESH.FT_EqualTo}
759 # @param Threshold the threshold value (range of ids as string, shape, numeric)
760 # @param UnaryOp SMESH.FT_LogicalNOT or SMESH.FT_Undefined
761 # @param BinaryOp a binary logical operation SMESH.FT_LogicalAND, SMESH.FT_LogicalOR or
763 # @param Tolerance the tolerance used by SMESH.FT_BelongToGeom, SMESH.FT_BelongToSurface,
764 # SMESH.FT_LyingOnGeom, SMESH.FT_CoplanarFaces criteria
765 # @return SMESH.Filter.Criterion
767 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
768 # @ingroup l1_controls
769 def GetCriterion(self,elementType,
771 Compare = FT_EqualTo,
773 UnaryOp=FT_Undefined,
774 BinaryOp=FT_Undefined,
776 if not CritType in SMESH.FunctorType._items:
777 raise TypeError("CritType should be of SMESH.FunctorType")
778 aCriterion = self.GetEmptyCriterion()
779 aCriterion.TypeOfElement = elementType
780 aCriterion.Type = EnumToLong(CritType)
781 aCriterion.Tolerance = Tolerance
783 aThreshold = Threshold
785 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
786 aCriterion.Compare = EnumToLong(Compare)
787 elif Compare == "=" or Compare == "==":
788 aCriterion.Compare = EnumToLong(FT_EqualTo)
790 aCriterion.Compare = EnumToLong(FT_LessThan)
792 aCriterion.Compare = EnumToLong(FT_MoreThan)
793 elif Compare != FT_Undefined:
794 aCriterion.Compare = EnumToLong(FT_EqualTo)
797 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
798 FT_BelongToCylinder, FT_LyingOnGeom]:
799 # Check that Threshold is GEOM object
800 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object):
801 aCriterion.ThresholdStr = GetName(aThreshold)
802 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
803 if not aCriterion.ThresholdID:
804 name = aCriterion.ThresholdStr
806 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
807 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
808 # or a name of GEOM object
809 elif isinstance( aThreshold, str ):
810 aCriterion.ThresholdStr = aThreshold
812 raise TypeError("The Threshold should be a shape.")
813 if isinstance(UnaryOp,float):
814 aCriterion.Tolerance = UnaryOp
815 UnaryOp = FT_Undefined
817 elif CritType == FT_BelongToMeshGroup:
818 # Check that Threshold is a group
819 if isinstance(aThreshold, SMESH._objref_SMESH_GroupBase):
820 if aThreshold.GetType() != elementType:
821 raise ValueError("Group type mismatches Element type")
822 aCriterion.ThresholdStr = aThreshold.GetName()
823 aCriterion.ThresholdID = salome.orb.object_to_string( aThreshold )
824 study = salome.myStudy
826 so = study.FindObjectIOR( aCriterion.ThresholdID )
830 aCriterion.ThresholdID = entry
832 raise TypeError("The Threshold should be a Mesh Group")
833 elif CritType == FT_RangeOfIds:
834 # Check that Threshold is string
835 if isinstance(aThreshold, str):
836 aCriterion.ThresholdStr = aThreshold
838 raise TypeError("The Threshold should be a string.")
839 elif CritType == FT_CoplanarFaces:
840 # Check the Threshold
841 if isinstance(aThreshold, int):
842 aCriterion.ThresholdID = str(aThreshold)
843 elif isinstance(aThreshold, str):
846 raise ValueError("Invalid ID of mesh face: '%s'"%aThreshold)
847 aCriterion.ThresholdID = aThreshold
849 raise TypeError("The Threshold should be an ID of mesh face and not '%s'"%aThreshold)
850 elif CritType == FT_ConnectedElements:
851 # Check the Threshold
852 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object): # shape
853 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
854 if not aCriterion.ThresholdID:
855 name = aThreshold.GetName()
857 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
858 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
859 elif isinstance(aThreshold, int): # node id
860 aCriterion.Threshold = aThreshold
861 elif isinstance(aThreshold, list): # 3 point coordinates
862 if len( aThreshold ) < 3:
863 raise ValueError("too few point coordinates, must be 3")
864 aCriterion.ThresholdStr = " ".join( [str(c) for c in aThreshold[:3]] )
865 elif isinstance(aThreshold, str):
866 if aThreshold.isdigit():
867 aCriterion.Threshold = aThreshold # node id
869 aCriterion.ThresholdStr = aThreshold # hope that it's point coordinates
871 raise TypeError("The Threshold should either a VERTEX, or a node ID, "\
872 "or a list of point coordinates and not '%s'"%aThreshold)
873 elif CritType == FT_ElemGeomType:
874 # Check the Threshold
876 aCriterion.Threshold = EnumToLong(aThreshold)
877 assert( aThreshold in SMESH.GeometryType._items )
879 if isinstance(aThreshold, int):
880 aCriterion.Threshold = aThreshold
882 raise TypeError("The Threshold should be an integer or SMESH.GeometryType.")
885 elif CritType == FT_EntityType:
886 # Check the Threshold
888 aCriterion.Threshold = EnumToLong(aThreshold)
889 assert( aThreshold in SMESH.EntityType._items )
891 if isinstance(aThreshold, int):
892 aCriterion.Threshold = aThreshold
894 raise TypeError("The Threshold should be an integer or SMESH.EntityType.")
898 elif CritType == FT_GroupColor:
899 # Check the Threshold
901 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
903 raise TypeError("The threshold value should be of SALOMEDS.Color type")
905 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
906 FT_LinearOrQuadratic, FT_BadOrientedVolume,
907 FT_BareBorderFace, FT_BareBorderVolume,
908 FT_OverConstrainedFace, FT_OverConstrainedVolume,
909 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
910 # At this point the Threshold is unnecessary
911 if aThreshold == FT_LogicalNOT:
912 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
913 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
914 aCriterion.BinaryOp = aThreshold
918 aThreshold = float(aThreshold)
919 aCriterion.Threshold = aThreshold
921 raise TypeError("The Threshold should be a number.")
924 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
925 aCriterion.UnaryOp = EnumToLong(FT_LogicalNOT)
927 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
928 aCriterion.BinaryOp = EnumToLong(Threshold)
930 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
931 aCriterion.BinaryOp = EnumToLong(UnaryOp)
933 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
934 aCriterion.BinaryOp = EnumToLong(BinaryOp)
938 ## Create a filter with the given parameters
939 # @param elementType the type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
940 # @param CritType the type of criterion (SMESH.FT_Taper, SMESH.FT_Area, etc.)
941 # Type SMESH.FunctorType._items in the Python Console to see all values.
942 # Note that the items starting from FT_LessThan are not suitable for CritType.
943 # @param Compare belongs to {SMESH.FT_LessThan, SMESH.FT_MoreThan, SMESH.FT_EqualTo}
944 # @param Threshold the threshold value (range of ids as string, shape, numeric)
945 # @param UnaryOp SMESH.FT_LogicalNOT or SMESH.FT_Undefined
946 # @param Tolerance the tolerance used by SMESH.FT_BelongToGeom, SMESH.FT_BelongToSurface,
947 # SMESH.FT_LyingOnGeom, SMESH.FT_CoplanarFaces and SMESH.FT_EqualNodes criteria
948 # @param mesh the mesh to initialize the filter with
949 # @return SMESH_Filter
951 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
952 # @ingroup l1_controls
953 def GetFilter(self,elementType,
954 CritType=FT_Undefined,
957 UnaryOp=FT_Undefined,
960 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
961 aFilterMgr = self.CreateFilterManager()
962 aFilter = aFilterMgr.CreateFilter()
964 aCriteria.append(aCriterion)
965 aFilter.SetCriteria(aCriteria)
967 if isinstance( mesh, Mesh ): aFilter.SetMesh( mesh.GetMesh() )
968 else : aFilter.SetMesh( mesh )
969 aFilterMgr.UnRegister()
972 ## Create a filter from criteria
973 # @param criteria a list of criteria
974 # @param binOp binary operator used when binary operator of criteria is undefined
975 # @return SMESH_Filter
977 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
978 # @ingroup l1_controls
979 def GetFilterFromCriteria(self,criteria, binOp=SMESH.FT_LogicalAND):
980 for i in range( len( criteria ) - 1 ):
981 if criteria[i].BinaryOp == EnumToLong( SMESH.FT_Undefined ):
982 criteria[i].BinaryOp = EnumToLong( binOp )
983 aFilterMgr = self.CreateFilterManager()
984 aFilter = aFilterMgr.CreateFilter()
985 aFilter.SetCriteria(criteria)
986 aFilterMgr.UnRegister()
989 ## Create a numerical functor by its type
990 # @param theCriterion functor type - an item of SMESH.FunctorType enumeration.
991 # Type SMESH.FunctorType._items in the Python Console to see all items.
992 # Note that not all items correspond to numerical functors.
993 # @return SMESH_NumericalFunctor
994 # @ingroup l1_controls
995 def GetFunctor(self,theCriterion):
996 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
998 aFilterMgr = self.CreateFilterManager()
1000 if theCriterion == FT_AspectRatio:
1001 functor = aFilterMgr.CreateAspectRatio()
1002 elif theCriterion == FT_AspectRatio3D:
1003 functor = aFilterMgr.CreateAspectRatio3D()
1004 elif theCriterion == FT_Warping:
1005 functor = aFilterMgr.CreateWarping()
1006 elif theCriterion == FT_MinimumAngle:
1007 functor = aFilterMgr.CreateMinimumAngle()
1008 elif theCriterion == FT_Taper:
1009 functor = aFilterMgr.CreateTaper()
1010 elif theCriterion == FT_Skew:
1011 functor = aFilterMgr.CreateSkew()
1012 elif theCriterion == FT_Area:
1013 functor = aFilterMgr.CreateArea()
1014 elif theCriterion == FT_Volume3D:
1015 functor = aFilterMgr.CreateVolume3D()
1016 elif theCriterion == FT_MaxElementLength2D:
1017 functor = aFilterMgr.CreateMaxElementLength2D()
1018 elif theCriterion == FT_MaxElementLength3D:
1019 functor = aFilterMgr.CreateMaxElementLength3D()
1020 elif theCriterion == FT_MultiConnection:
1021 functor = aFilterMgr.CreateMultiConnection()
1022 elif theCriterion == FT_MultiConnection2D:
1023 functor = aFilterMgr.CreateMultiConnection2D()
1024 elif theCriterion == FT_Length:
1025 functor = aFilterMgr.CreateLength()
1026 elif theCriterion == FT_Length2D:
1027 functor = aFilterMgr.CreateLength2D()
1028 elif theCriterion == FT_NodeConnectivityNumber:
1029 functor = aFilterMgr.CreateNodeConnectivityNumber()
1030 elif theCriterion == FT_BallDiameter:
1031 functor = aFilterMgr.CreateBallDiameter()
1033 print("Error: given parameter is not numerical functor type.")
1034 aFilterMgr.UnRegister()
1037 ## Create hypothesis
1038 # @param theHType mesh hypothesis type (string)
1039 # @param theLibName mesh plug-in library name
1040 # @return created hypothesis instance
1041 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
1042 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
1044 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
1047 # wrap hypothesis methods
1048 #print "HYPOTHESIS", theHType
1049 for meth_name in dir( hyp.__class__ ):
1050 if not meth_name.startswith("Get") and \
1051 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
1052 method = getattr ( hyp.__class__, meth_name )
1053 if callable(method):
1054 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
1058 ## Get the mesh statistic
1059 # @return dictionary "element type" - "count of elements"
1060 # @ingroup l1_meshinfo
1061 def GetMeshInfo(self, obj):
1062 if isinstance( obj, Mesh ):
1065 if hasattr(obj, "GetMeshInfo"):
1066 values = obj.GetMeshInfo()
1067 for i in range(EnumToLong(SMESH.Entity_Last)):
1068 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
1072 ## Get minimum distance between two objects
1074 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
1075 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
1077 # @param src1 first source object
1078 # @param src2 second source object
1079 # @param id1 node/element id from the first source
1080 # @param id2 node/element id from the second (or first) source
1081 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
1082 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
1083 # @return minimum distance value
1084 # @sa GetMinDistance()
1085 # @ingroup l1_measurements
1086 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
1087 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
1091 result = result.value
1094 ## Get measure structure specifying minimum distance data between two objects
1096 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
1097 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
1099 # @param src1 first source object
1100 # @param src2 second source object
1101 # @param id1 node/element id from the first source
1102 # @param id2 node/element id from the second (or first) source
1103 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
1104 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
1105 # @return Measure structure or None if input data is invalid
1107 # @ingroup l1_measurements
1108 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
1109 if isinstance(src1, Mesh): src1 = src1.mesh
1110 if isinstance(src2, Mesh): src2 = src2.mesh
1111 if src2 is None and id2 != 0: src2 = src1
1112 if not hasattr(src1, "_narrow"): return None
1113 src1 = src1._narrow(SMESH.SMESH_IDSource)
1114 if not src1: return None
1115 unRegister = genObjUnRegister()
1118 e = m.GetMeshEditor()
1120 src1 = e.MakeIDSource([id1], SMESH.FACE)
1122 src1 = e.MakeIDSource([id1], SMESH.NODE)
1123 unRegister.set( src1 )
1125 if hasattr(src2, "_narrow"):
1126 src2 = src2._narrow(SMESH.SMESH_IDSource)
1127 if src2 and id2 != 0:
1129 e = m.GetMeshEditor()
1131 src2 = e.MakeIDSource([id2], SMESH.FACE)
1133 src2 = e.MakeIDSource([id2], SMESH.NODE)
1134 unRegister.set( src2 )
1137 aMeasurements = self.CreateMeasurements()
1138 unRegister.set( aMeasurements )
1139 result = aMeasurements.MinDistance(src1, src2)
1142 ## Get bounding box of the specified object(s)
1143 # @param objects single source object or list of source objects
1144 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
1145 # @sa GetBoundingBox()
1146 # @ingroup l1_measurements
1147 def BoundingBox(self, objects):
1148 result = self.GetBoundingBox(objects)
1152 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
1155 ## Get measure structure specifying bounding box data of the specified object(s)
1156 # @param objects single source object or list of source objects
1157 # @return Measure structure
1159 # @ingroup l1_measurements
1160 def GetBoundingBox(self, objects):
1161 if isinstance(objects, tuple):
1162 objects = list(objects)
1163 if not isinstance(objects, list):
1167 if isinstance(o, Mesh):
1168 srclist.append(o.mesh)
1169 elif hasattr(o, "_narrow"):
1170 src = o._narrow(SMESH.SMESH_IDSource)
1171 if src: srclist.append(src)
1174 aMeasurements = self.CreateMeasurements()
1175 result = aMeasurements.BoundingBox(srclist)
1176 aMeasurements.UnRegister()
1179 ## Get sum of lengths of all 1D elements in the mesh object.
1180 # @param obj mesh, submesh or group
1181 # @return sum of lengths of all 1D elements
1182 # @ingroup l1_measurements
1183 def GetLength(self, obj):
1184 if isinstance(obj, Mesh): obj = obj.mesh
1185 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1186 aMeasurements = self.CreateMeasurements()
1187 value = aMeasurements.Length(obj)
1188 aMeasurements.UnRegister()
1191 ## Get sum of areas of all 2D elements in the mesh object.
1192 # @param obj mesh, submesh or group
1193 # @return sum of areas of all 2D elements
1194 # @ingroup l1_measurements
1195 def GetArea(self, obj):
1196 if isinstance(obj, Mesh): obj = obj.mesh
1197 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1198 aMeasurements = self.CreateMeasurements()
1199 value = aMeasurements.Area(obj)
1200 aMeasurements.UnRegister()
1203 ## Get sum of volumes of all 3D elements in the mesh object.
1204 # @param obj mesh, submesh or group
1205 # @return sum of volumes of all 3D elements
1206 # @ingroup l1_measurements
1207 def GetVolume(self, obj):
1208 if isinstance(obj, Mesh): obj = obj.mesh
1209 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1210 aMeasurements = self.CreateMeasurements()
1211 value = aMeasurements.Volume(obj)
1212 aMeasurements.UnRegister()
1215 pass # end of class smeshBuilder
1218 #Registering the new proxy for SMESH_Gen
1219 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
1221 ## Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1222 # interface to create or load meshes.
1227 # salome.salome_init()
1228 # from salome.smesh import smeshBuilder
1229 # smesh = smeshBuilder.New()
1231 # @param isPublished If False, the notebool will not be used.
1232 # @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1233 # @return smeshBuilder instance
1235 def New( isPublished = True, instance=None):
1237 Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1238 interface to create or load meshes.
1242 salome.salome_init()
1243 from salome.smesh import smeshBuilder
1244 smesh = smeshBuilder.New()
1247 isPublished If False, the notebool will not be used.
1248 instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1250 smeshBuilder instance
1258 smeshInst = smeshBuilder()
1259 assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__
1260 smeshInst.init_smesh(isPublished)
1264 # Public class: Mesh
1265 # ==================
1267 ## This class allows defining and managing a mesh.
1268 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1269 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1270 # new nodes and elements and by changing the existing entities), to get information
1271 # about a mesh and to export a mesh in different formats.
1272 class Mesh(metaclass=MeshMeta):
1279 # Create a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1280 # sets the GUI name of this mesh to \a name.
1281 # @param smeshpyD an instance of smeshBuilder class
1282 # @param geompyD an instance of geomBuilder class
1283 # @param obj Shape to be meshed or SMESH_Mesh object
1284 # @param name Study name of the mesh
1285 # @ingroup l2_construct
1286 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1287 self.smeshpyD = smeshpyD
1288 self.geompyD = geompyD
1293 if isinstance(obj, geomBuilder.GEOM._objref_GEOM_Object):
1296 # publish geom of mesh (issue 0021122)
1297 if not self.geom.GetStudyEntry():
1301 geo_name = name + " shape"
1303 geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1304 geompyD.addToStudy( self.geom, geo_name )
1305 self.SetMesh( self.smeshpyD.CreateMesh(self.geom) )
1307 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1310 self.SetMesh( self.smeshpyD.CreateEmptyMesh() )
1312 self.smeshpyD.SetName(self.mesh, name)
1314 self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1317 self.geom = self.mesh.GetShapeToMesh()
1319 self.editor = self.mesh.GetMeshEditor()
1320 self.functors = [None] * EnumToLong(SMESH.FT_Undefined)
1322 # set self to algoCreator's
1323 for attrName in dir(self):
1324 attr = getattr( self, attrName )
1325 if isinstance( attr, algoCreator ):
1326 setattr( self, attrName, attr.copy( self ))
1331 ## Destructor. Clean-up resources
1334 #self.mesh.UnRegister()
1338 ## Initialize the Mesh object from an instance of SMESH_Mesh interface
1339 # @param theMesh a SMESH_Mesh object
1340 # @ingroup l2_construct
1341 def SetMesh(self, theMesh):
1342 # do not call Register() as this prevents mesh servant deletion at closing study
1343 #if self.mesh: self.mesh.UnRegister()
1346 #self.mesh.Register()
1347 self.geom = self.mesh.GetShapeToMesh()
1350 ## Return the mesh, that is an instance of SMESH_Mesh interface
1351 # @return a SMESH_Mesh object
1352 # @ingroup l2_construct
1356 ## Get the name of the mesh
1357 # @return the name of the mesh as a string
1358 # @ingroup l2_construct
1360 name = GetName(self.GetMesh())
1363 ## Set a name to the mesh
1364 # @param name a new name of the mesh
1365 # @ingroup l2_construct
1366 def SetName(self, name):
1367 self.smeshpyD.SetName(self.GetMesh(), name)
1369 ## Get a sub-mesh object associated to a \a geom geometrical object.
1370 # @param geom a geometrical object (shape)
1371 # @param name a name for the sub-mesh in the Object Browser
1372 # @return an object of type SMESH.SMESH_subMesh, representing a part of mesh,
1373 # which lies on the given shape
1375 # The sub-mesh object gives access to the IDs of nodes and elements.
1376 # The sub-mesh object has the following methods:
1377 # - SMESH.SMESH_subMesh.GetNumberOfElements()
1378 # - SMESH.SMESH_subMesh.GetNumberOfNodes( all )
1379 # - SMESH.SMESH_subMesh.GetElementsId()
1380 # - SMESH.SMESH_subMesh.GetElementsByType( ElementType )
1381 # - SMESH.SMESH_subMesh.GetNodesId()
1382 # - SMESH.SMESH_subMesh.GetSubShape()
1383 # - SMESH.SMESH_subMesh.GetFather()
1384 # - SMESH.SMESH_subMesh.GetId()
1385 # @note A sub-mesh is implicitly created when a sub-shape is specified at
1386 # creating an algorithm, for example: <code>algo1D = mesh.Segment(geom=Edge_1) </code>
1387 # creates a sub-mesh on @c Edge_1 and assign Wire Discretization algorithm to it.
1388 # The created sub-mesh can be retrieved from the algorithm:
1389 # <code>submesh = algo1D.GetSubMesh()</code>
1390 # @ingroup l2_submeshes
1391 def GetSubMesh(self, geom, name):
1392 AssureGeomPublished( self, geom, name )
1393 submesh = self.mesh.GetSubMesh( geom, name )
1396 ## Return the shape associated to the mesh
1397 # @return a GEOM_Object
1398 # @ingroup l2_construct
1402 ## Associate the given shape to the mesh (entails the recreation of the mesh)
1403 # @param geom the shape to be meshed (GEOM_Object)
1404 # @ingroup l2_construct
1405 def SetShape(self, geom):
1406 self.mesh = self.smeshpyD.CreateMesh(geom)
1408 ## Load mesh from the study after opening the study
1412 ## Return true if the hypotheses are defined well
1413 # @param theSubObject a sub-shape of a mesh shape
1414 # @return True or False
1415 # @ingroup l2_construct
1416 def IsReadyToCompute(self, theSubObject):
1417 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1419 ## Return errors of hypotheses definition.
1420 # The list of errors is empty if everything is OK.
1421 # @param theSubObject a sub-shape of a mesh shape
1422 # @return a list of errors
1423 # @ingroup l2_construct
1424 def GetAlgoState(self, theSubObject):
1425 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1427 ## Return a geometrical object on which the given element was built.
1428 # The returned geometrical object, if not nil, is either found in the
1429 # study or published by this method with the given name
1430 # @param theElementID the id of the mesh element
1431 # @param theGeomName the user-defined name of the geometrical object
1432 # @return GEOM::GEOM_Object instance
1433 # @ingroup l1_meshinfo
1434 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1435 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1437 ## Return the mesh dimension depending on the dimension of the underlying shape
1438 # or, if the mesh is not based on any shape, basing on deimension of elements
1439 # @return mesh dimension as an integer value [0,3]
1440 # @ingroup l1_meshinfo
1441 def MeshDimension(self):
1442 if self.mesh.HasShapeToMesh():
1443 shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
1444 if len( shells ) > 0 :
1446 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1448 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1453 if self.NbVolumes() > 0: return 3
1454 if self.NbFaces() > 0: return 2
1455 if self.NbEdges() > 0: return 1
1458 ## Evaluate size of prospective mesh on a shape
1459 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1460 # To know predicted number of e.g. edges, inquire it this way
1461 # Evaluate()[ EnumToLong( Entity_Edge )]
1462 # @ingroup l2_construct
1463 def Evaluate(self, geom=0):
1464 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1466 geom = self.mesh.GetShapeToMesh()
1469 return self.smeshpyD.Evaluate(self.mesh, geom)
1472 ## Compute the mesh and return the status of the computation
1473 # @param geom geomtrical shape on which mesh data should be computed
1474 # @param discardModifs if True and the mesh has been edited since
1475 # a last total re-compute and that may prevent successful partial re-compute,
1476 # then the mesh is cleaned before Compute()
1477 # @param refresh if @c True, Object browser is automatically updated (when running in GUI)
1478 # @return True or False
1479 # @ingroup l2_construct
1480 def Compute(self, geom=0, discardModifs=False, refresh=False):
1481 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1483 geom = self.mesh.GetShapeToMesh()
1488 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1490 ok = self.smeshpyD.Compute(self.mesh, geom)
1491 except SALOME.SALOME_Exception as ex:
1492 print("Mesh computation failed, exception caught:")
1493 print(" ", ex.details.text)
1496 print("Mesh computation failed, exception caught:")
1497 traceback.print_exc()
1501 # Treat compute errors
1502 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1504 for err in computeErrors:
1505 if self.mesh.HasShapeToMesh():
1506 shapeText = " on %s" % self.GetSubShapeName( err.subShapeID )
1508 stdErrors = ["OK", #COMPERR_OK
1509 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1510 "std::exception", #COMPERR_STD_EXCEPTION
1511 "OCC exception", #COMPERR_OCC_EXCEPTION
1512 "..", #COMPERR_SLM_EXCEPTION
1513 "Unknown exception", #COMPERR_EXCEPTION
1514 "Memory allocation problem", #COMPERR_MEMORY_PB
1515 "Algorithm failed", #COMPERR_ALGO_FAILED
1516 "Unexpected geometry", #COMPERR_BAD_SHAPE
1517 "Warning", #COMPERR_WARNING
1518 "Computation cancelled",#COMPERR_CANCELED
1519 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1521 if err.code < len(stdErrors): errText = stdErrors[err.code]
1523 errText = "code %s" % -err.code
1524 if errText: errText += ". "
1525 errText += err.comment
1526 if allReasons: allReasons += "\n"
1528 allReasons += '- "%s"%s - %s' %(err.algoName, shapeText, errText)
1530 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1534 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1536 if err.isGlobalAlgo:
1544 reason = '%s %sD algorithm is missing' % (glob, dim)
1545 elif err.state == HYP_MISSING:
1546 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1547 % (glob, dim, name, dim))
1548 elif err.state == HYP_NOTCONFORM:
1549 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1550 elif err.state == HYP_BAD_PARAMETER:
1551 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1552 % ( glob, dim, name ))
1553 elif err.state == HYP_BAD_GEOMETRY:
1554 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1555 'geometry' % ( glob, dim, name ))
1556 elif err.state == HYP_HIDDEN_ALGO:
1557 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1558 'algorithm of upper dimension generating %sD mesh'
1559 % ( glob, dim, name, glob, dim ))
1561 reason = ("For unknown reason. "
1562 "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1564 if allReasons: allReasons += "\n"
1565 allReasons += "- " + reason
1567 if not ok or allReasons != "":
1568 msg = '"' + GetName(self.mesh) + '"'
1569 if ok: msg += " has been computed with warnings"
1570 else: msg += " has not been computed"
1571 if allReasons != "": msg += ":"
1576 if salome.sg.hasDesktop():
1577 if not isinstance( refresh, list): # not a call from subMesh.Compute()
1578 smeshgui = salome.ImportComponentGUI("SMESH")
1580 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1581 if refresh: salome.sg.updateObjBrowser()
1585 ## Return a list of error messages (SMESH.ComputeError) of the last Compute()
1586 # @ingroup l2_construct
1587 def GetComputeErrors(self, shape=0 ):
1589 shape = self.mesh.GetShapeToMesh()
1590 return self.smeshpyD.GetComputeErrors( self.mesh, shape )
1592 ## Return a name of a sub-shape by its ID
1593 # @param subShapeID a unique ID of a sub-shape
1594 # @return a string describing the sub-shape; possible variants:
1595 # - "Face_12" (published sub-shape)
1596 # - FACE #3 (not published sub-shape)
1597 # - sub-shape #3 (invalid sub-shape ID)
1598 # - #3 (error in this function)
1599 # @ingroup l1_auxiliary
1600 def GetSubShapeName(self, subShapeID ):
1601 if not self.mesh.HasShapeToMesh():
1605 mainIOR = salome.orb.object_to_string( self.GetShape() )
1607 mainSO = s.FindObjectIOR(mainIOR)
1610 shapeText = '"%s"' % mainSO.GetName()
1611 subIt = s.NewChildIterator(mainSO)
1613 subSO = subIt.Value()
1615 obj = subSO.GetObject()
1616 if not obj: continue
1617 go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
1620 ids = self.geompyD.GetSubShapeID( self.GetShape(), go )
1623 if ids == subShapeID:
1624 shapeText = '"%s"' % subSO.GetName()
1626 shape = self.geompyD.GetSubShape( self.GetShape(), [subShapeID])
1628 shapeText = '%s #%s' % (shape.GetShapeType(), subShapeID)
1630 shapeText = 'sub-shape #%s' % (subShapeID)
1632 shapeText = "#%s" % (subShapeID)
1635 ## Return a list of sub-shapes meshing of which failed, grouped into GEOM groups by
1636 # error of an algorithm
1637 # @param publish if @c True, the returned groups will be published in the study
1638 # @return a list of GEOM groups each named after a failed algorithm
1639 # @ingroup l2_construct
1640 def GetFailedShapes(self, publish=False):
1643 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, self.GetShape() )
1644 for err in computeErrors:
1645 shape = self.geompyD.GetSubShape( self.GetShape(), [err.subShapeID])
1646 if not shape: continue
1647 if err.algoName in algo2shapes:
1648 algo2shapes[ err.algoName ].append( shape )
1650 algo2shapes[ err.algoName ] = [ shape ]
1654 for algoName, shapes in list(algo2shapes.items()):
1656 groupType = EnumToLong( shapes[0].GetShapeType() )
1657 otherTypeShapes = []
1659 group = self.geompyD.CreateGroup( self.geom, groupType )
1660 for shape in shapes:
1661 if shape.GetShapeType() == shapes[0].GetShapeType():
1662 sameTypeShapes.append( shape )
1664 otherTypeShapes.append( shape )
1665 self.geompyD.UnionList( group, sameTypeShapes )
1667 group.SetName( "%s %s" % ( algoName, shapes[0].GetShapeType() ))
1669 group.SetName( algoName )
1670 groups.append( group )
1671 shapes = otherTypeShapes
1674 for group in groups:
1675 self.geompyD.addToStudyInFather( self.geom, group, group.GetName() )
1678 ## Return sub-mesh objects list in meshing order
1679 # @return list of lists of sub-meshes
1680 # @ingroup l2_construct
1681 def GetMeshOrder(self):
1682 return self.mesh.GetMeshOrder()
1684 ## Set order in which concurrent sub-meshes should be meshed
1685 # @param submeshes list of lists of sub-meshes
1686 # @ingroup l2_construct
1687 def SetMeshOrder(self, submeshes):
1688 return self.mesh.SetMeshOrder(submeshes)
1690 ## Remove all nodes and elements generated on geometry. Imported elements remain.
1691 # @param refresh if @c True, Object browser is automatically updated (when running in GUI)
1692 # @ingroup l2_construct
1693 def Clear(self, refresh=False):
1695 if ( salome.sg.hasDesktop() ):
1696 smeshgui = salome.ImportComponentGUI("SMESH")
1698 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1699 if refresh: salome.sg.updateObjBrowser()
1701 ## Remove all nodes and elements of indicated shape
1702 # @param refresh if @c True, Object browser is automatically updated (when running in GUI)
1703 # @param geomId the ID of a sub-shape to remove elements on
1704 # @ingroup l2_submeshes
1705 def ClearSubMesh(self, geomId, refresh=False):
1706 self.mesh.ClearSubMesh(geomId)
1707 if salome.sg.hasDesktop():
1708 smeshgui = salome.ImportComponentGUI("SMESH")
1710 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1711 if refresh: salome.sg.updateObjBrowser()
1713 ## Compute a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron
1714 # @param fineness [0.0,1.0] defines mesh fineness
1715 # @return True or False
1716 # @ingroup l3_algos_basic
1717 def AutomaticTetrahedralization(self, fineness=0):
1718 dim = self.MeshDimension()
1720 self.RemoveGlobalHypotheses()
1721 self.Segment().AutomaticLength(fineness)
1723 self.Triangle().LengthFromEdges()
1728 return self.Compute()
1730 ## Compute an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1731 # @param fineness [0.0, 1.0] defines mesh fineness
1732 # @return True or False
1733 # @ingroup l3_algos_basic
1734 def AutomaticHexahedralization(self, fineness=0):
1735 dim = self.MeshDimension()
1736 # assign the hypotheses
1737 self.RemoveGlobalHypotheses()
1738 self.Segment().AutomaticLength(fineness)
1745 return self.Compute()
1747 ## Assign a hypothesis
1748 # @param hyp a hypothesis to assign
1749 # @param geom a subhape of mesh geometry
1750 # @return SMESH.Hypothesis_Status
1751 # @ingroup l2_editing
1752 def AddHypothesis(self, hyp, geom=0):
1753 if isinstance( hyp, geomBuilder.GEOM._objref_GEOM_Object ):
1754 hyp, geom = geom, hyp
1755 if isinstance( hyp, Mesh_Algorithm ):
1756 hyp = hyp.GetAlgorithm()
1761 geom = self.mesh.GetShapeToMesh()
1764 if self.mesh.HasShapeToMesh():
1765 hyp_type = hyp.GetName()
1766 lib_name = hyp.GetLibName()
1767 # checkAll = ( not geom.IsSame( self.mesh.GetShapeToMesh() ))
1768 # if checkAll and geom:
1769 # checkAll = geom.GetType() == 37
1771 isApplicable = self.smeshpyD.IsApplicable(hyp_type, lib_name, geom, checkAll)
1773 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1774 status = self.mesh.AddHypothesis(geom, hyp)
1776 status = HYP_BAD_GEOMETRY, ""
1777 hyp_name = GetName( hyp )
1780 geom_name = geom.GetName()
1781 isAlgo = hyp._narrow( SMESH_Algo )
1782 TreatHypoStatus( status, hyp_name, geom_name, isAlgo, self )
1785 ## Return True if an algorithm of hypothesis is assigned to a given shape
1786 # @param hyp a hypothesis to check
1787 # @param geom a subhape of mesh geometry
1788 # @return True of False
1789 # @ingroup l2_editing
1790 def IsUsedHypothesis(self, hyp, geom):
1791 if not hyp: # or not geom
1793 if isinstance( hyp, Mesh_Algorithm ):
1794 hyp = hyp.GetAlgorithm()
1796 hyps = self.GetHypothesisList(geom)
1798 if h.GetId() == hyp.GetId():
1802 ## Unassign a hypothesis
1803 # @param hyp a hypothesis to unassign
1804 # @param geom a sub-shape of mesh geometry
1805 # @return SMESH.Hypothesis_Status
1806 # @ingroup l2_editing
1807 def RemoveHypothesis(self, hyp, geom=0):
1810 if isinstance( hyp, Mesh_Algorithm ):
1811 hyp = hyp.GetAlgorithm()
1817 if self.IsUsedHypothesis( hyp, shape ):
1818 return self.mesh.RemoveHypothesis( shape, hyp )
1819 hypName = GetName( hyp )
1820 geoName = GetName( shape )
1821 print("WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName ))
1824 ## Get the list of hypotheses added on a geometry
1825 # @param geom a sub-shape of mesh geometry
1826 # @return the sequence of SMESH_Hypothesis
1827 # @ingroup l2_editing
1828 def GetHypothesisList(self, geom):
1829 return self.mesh.GetHypothesisList( geom )
1831 ## Remove all global hypotheses
1832 # @ingroup l2_editing
1833 def RemoveGlobalHypotheses(self):
1834 current_hyps = self.mesh.GetHypothesisList( self.geom )
1835 for hyp in current_hyps:
1836 self.mesh.RemoveHypothesis( self.geom, hyp )
1840 ## Export the mesh in a file in MED format
1841 ## allowing to overwrite the file if it exists or add the exported data to its contents
1842 # @param f is the file name
1843 # @param auto_groups boolean parameter for creating/not creating
1844 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1845 # the typical use is auto_groups=False.
1846 # @param version MED format version (MED_V2_1 or MED_V2_2,
1847 # the latter meaning any current version). The parameter is
1848 # obsolete since MED_V2_1 is no longer supported.
1849 # @param overwrite boolean parameter for overwriting/not overwriting the file
1850 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1851 # @param autoDimension if @c True (default), a space dimension of a MED mesh can be either
1852 # - 1D if all mesh nodes lie on OX coordinate axis, or
1853 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1854 # - 3D in the rest cases.<br>
1855 # If @a autoDimension is @c False, the space dimension is always 3.
1856 # @param fields list of GEOM fields defined on the shape to mesh.
1857 # @param geomAssocFields each character of this string means a need to export a
1858 # corresponding field; correspondence between fields and characters is following:
1859 # - 'v' stands for "_vertices _" field;
1860 # - 'e' stands for "_edges _" field;
1861 # - 'f' stands for "_faces _" field;
1862 # - 's' stands for "_solids _" field.
1863 # @ingroup l2_impexp
1864 def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
1865 overwrite=1, meshPart=None, autoDimension=True, fields=[], geomAssocFields=''):
1866 if meshPart or fields or geomAssocFields:
1867 unRegister = genObjUnRegister()
1868 if isinstance( meshPart, list ):
1869 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1870 unRegister.set( meshPart )
1871 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension,
1872 fields, geomAssocFields)
1874 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
1876 ## Export the mesh in a file in SAUV format
1877 # @param f is the file name
1878 # @param auto_groups boolean parameter for creating/not creating
1879 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1880 # the typical use is auto_groups=false.
1881 # @ingroup l2_impexp
1882 def ExportSAUV(self, f, auto_groups=0):
1883 self.mesh.ExportSAUV(f, auto_groups)
1885 ## Export the mesh in a file in DAT format
1886 # @param f the file name
1887 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1888 # @ingroup l2_impexp
1889 def ExportDAT(self, f, meshPart=None):
1891 unRegister = genObjUnRegister()
1892 if isinstance( meshPart, list ):
1893 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1894 unRegister.set( meshPart )
1895 self.mesh.ExportPartToDAT( meshPart, f )
1897 self.mesh.ExportDAT(f)
1899 ## Export the mesh in a file in UNV format
1900 # @param f the file name
1901 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1902 # @ingroup l2_impexp
1903 def ExportUNV(self, f, meshPart=None):
1905 unRegister = genObjUnRegister()
1906 if isinstance( meshPart, list ):
1907 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1908 unRegister.set( meshPart )
1909 self.mesh.ExportPartToUNV( meshPart, f )
1911 self.mesh.ExportUNV(f)
1913 ## Export the mesh in a file in STL format
1914 # @param f the file name
1915 # @param ascii defines the file encoding
1916 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1917 # @ingroup l2_impexp
1918 def ExportSTL(self, f, ascii=1, meshPart=None):
1920 unRegister = genObjUnRegister()
1921 if isinstance( meshPart, list ):
1922 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1923 unRegister.set( meshPart )
1924 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1926 self.mesh.ExportSTL(f, ascii)
1928 ## Export the mesh in a file in CGNS format
1929 # @param f is the file name
1930 # @param overwrite boolean parameter for overwriting/not overwriting the file
1931 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1932 # @ingroup l2_impexp
1933 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1934 unRegister = genObjUnRegister()
1935 if isinstance( meshPart, list ):
1936 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1937 unRegister.set( meshPart )
1938 if isinstance( meshPart, Mesh ):
1939 meshPart = meshPart.mesh
1941 meshPart = self.mesh
1942 self.mesh.ExportCGNS(meshPart, f, overwrite)
1944 ## Export the mesh in a file in GMF format.
1945 # GMF files must have .mesh extension for the ASCII format and .meshb for
1946 # the bynary format. Other extensions are not allowed.
1947 # @param f is the file name
1948 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1949 # @ingroup l2_impexp
1950 def ExportGMF(self, f, meshPart=None):
1951 unRegister = genObjUnRegister()
1952 if isinstance( meshPart, list ):
1953 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1954 unRegister.set( meshPart )
1955 if isinstance( meshPart, Mesh ):
1956 meshPart = meshPart.mesh
1958 meshPart = self.mesh
1959 self.mesh.ExportGMF(meshPart, f, True)
1961 ## Deprecated, used only for compatibility! Please, use ExportMED() method instead.
1962 # Export the mesh in a file in MED format
1963 # allowing to overwrite the file if it exists or add the exported data to its contents
1964 # @param f the file name
1965 # @param version MED format version (MED_V2_1 or MED_V2_2,
1966 # the latter meaning any current version). The parameter is
1967 # obsolete since MED_V2_1 is no longer supported.
1968 # @param opt boolean parameter for creating/not creating
1969 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1970 # @param overwrite boolean parameter for overwriting/not overwriting the file
1971 # @param autoDimension if @c True (default), a space dimension of a MED mesh can be either
1972 # - 1D if all mesh nodes lie on OX coordinate axis, or
1973 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1974 # - 3D in the rest cases.<br>
1975 # If @a autoDimension is @c False, the space dimension is always 3.
1976 # @ingroup l2_impexp
1977 def ExportToMED(self, f, version=MED_V2_2, opt=0, overwrite=1, autoDimension=True):
1978 self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension)
1980 # Operations with groups:
1981 # ----------------------
1983 ## Create an empty mesh group
1984 # @param elementType the type of elements in the group; either of
1985 # (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
1986 # @param name the name of the mesh group
1987 # @return SMESH_Group
1988 # @ingroup l2_grps_create
1989 def CreateEmptyGroup(self, elementType, name):
1990 return self.mesh.CreateGroup(elementType, name)
1992 ## Create a mesh group based on the geometric object \a grp
1993 # and gives a \a name, \n if this parameter is not defined
1994 # the name is the same as the geometric group name \n
1995 # Note: Works like GroupOnGeom().
1996 # @param grp a geometric group, a vertex, an edge, a face or a solid
1997 # @param name the name of the mesh group
1998 # @return SMESH_GroupOnGeom
1999 # @ingroup l2_grps_create
2000 def Group(self, grp, name=""):
2001 return self.GroupOnGeom(grp, name)
2003 ## Create a mesh group based on the geometrical object \a grp
2004 # and gives a \a name, \n if this parameter is not defined
2005 # the name is the same as the geometrical group name
2006 # @param grp a geometrical group, a vertex, an edge, a face or a solid
2007 # @param name the name of the mesh group
2008 # @param typ the type of elements in the group; either of
2009 # (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME). If not set, it is
2010 # automatically detected by the type of the geometry
2011 # @return SMESH_GroupOnGeom
2012 # @ingroup l2_grps_create
2013 def GroupOnGeom(self, grp, name="", typ=None):
2014 AssureGeomPublished( self, grp, name )
2016 name = grp.GetName()
2018 typ = self._groupTypeFromShape( grp )
2019 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
2021 ## Pivate method to get a type of group on geometry
2022 def _groupTypeFromShape( self, shape ):
2023 tgeo = str(shape.GetShapeType())
2024 if tgeo == "VERTEX":
2026 elif tgeo == "EDGE":
2028 elif tgeo == "FACE" or tgeo == "SHELL":
2030 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
2032 elif tgeo == "COMPOUND":
2033 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
2035 raise ValueError("_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape))
2036 return self._groupTypeFromShape( sub[0] )
2038 raise ValueError("_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape))
2041 ## Create a mesh group with given \a name based on the \a filter which
2042 ## is a special type of group dynamically updating it's contents during
2043 ## mesh modification
2044 # @param typ the type of elements in the group; either of
2045 # (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
2046 # @param name the name of the mesh group
2047 # @param filter the filter defining group contents
2048 # @return SMESH_GroupOnFilter
2049 # @ingroup l2_grps_create
2050 def GroupOnFilter(self, typ, name, filter):
2051 return self.mesh.CreateGroupFromFilter(typ, name, filter)
2053 ## Create a mesh group by the given ids of elements
2054 # @param groupName the name of the mesh group
2055 # @param elementType the type of elements in the group; either of
2056 # (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
2057 # @param elemIDs either the list of ids, group, sub-mesh, or filter
2058 # @return SMESH_Group
2059 # @ingroup l2_grps_create
2060 def MakeGroupByIds(self, groupName, elementType, elemIDs):
2061 group = self.mesh.CreateGroup(elementType, groupName)
2062 if hasattr( elemIDs, "GetIDs" ):
2063 if hasattr( elemIDs, "SetMesh" ):
2064 elemIDs.SetMesh( self.GetMesh() )
2065 group.AddFrom( elemIDs )
2070 ## Create a mesh group by the given conditions
2071 # @param groupName the name of the mesh group
2072 # @param elementType the type of elements(SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
2073 # @param CritType the type of criterion (SMESH.FT_Taper, SMESH.FT_Area, etc.)
2074 # Type SMESH.FunctorType._items in the Python Console to see all values.
2075 # Note that the items starting from FT_LessThan are not suitable for CritType.
2076 # @param Compare belongs to {SMESH.FT_LessThan, SMESH.FT_MoreThan, SMESH.FT_EqualTo}
2077 # @param Threshold the threshold value (range of ids as string, shape, numeric)
2078 # @param UnaryOp SMESH.FT_LogicalNOT or SMESH.FT_Undefined
2079 # @param Tolerance the tolerance used by SMESH.FT_BelongToGeom, SMESH.FT_BelongToSurface,
2080 # SMESH.FT_LyingOnGeom, SMESH.FT_CoplanarFaces criteria
2081 # @return SMESH_GroupOnFilter
2082 # @ingroup l2_grps_create
2086 CritType=FT_Undefined,
2089 UnaryOp=FT_Undefined,
2091 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
2092 group = self.MakeGroupByCriterion(groupName, aCriterion)
2095 ## Create a mesh group by the given criterion
2096 # @param groupName the name of the mesh group
2097 # @param Criterion the instance of Criterion class
2098 # @return SMESH_GroupOnFilter
2099 # @ingroup l2_grps_create
2100 def MakeGroupByCriterion(self, groupName, Criterion):
2101 return self.MakeGroupByCriteria( groupName, [Criterion] )
2103 ## Create a mesh group by the given criteria (list of criteria)
2104 # @param groupName the name of the mesh group
2105 # @param theCriteria the list of criteria
2106 # @param binOp binary operator used when binary operator of criteria is undefined
2107 # @return SMESH_GroupOnFilter
2108 # @ingroup l2_grps_create
2109 def MakeGroupByCriteria(self, groupName, theCriteria, binOp=SMESH.FT_LogicalAND):
2110 aFilter = self.smeshpyD.GetFilterFromCriteria( theCriteria, binOp )
2111 group = self.MakeGroupByFilter(groupName, aFilter)
2114 ## Create a mesh group by the given filter
2115 # @param groupName the name of the mesh group
2116 # @param theFilter the instance of Filter class
2117 # @return SMESH_GroupOnFilter
2118 # @ingroup l2_grps_create
2119 def MakeGroupByFilter(self, groupName, theFilter):
2120 #group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
2121 #theFilter.SetMesh( self.mesh )
2122 #group.AddFrom( theFilter )
2123 group = self.GroupOnFilter( theFilter.GetElementType(), groupName, theFilter )
2127 # @ingroup l2_grps_delete
2128 def RemoveGroup(self, group):
2129 self.mesh.RemoveGroup(group)
2131 ## Remove a group with its contents
2132 # @ingroup l2_grps_delete
2133 def RemoveGroupWithContents(self, group):
2134 self.mesh.RemoveGroupWithContents(group)
2136 ## Get the list of groups existing in the mesh in the order
2137 # of creation (starting from the oldest one)
2138 # @param elemType type of elements the groups contain; either of
2139 # (SMESH.ALL, SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME);
2140 # by default groups of elements of all types are returned
2141 # @return a sequence of SMESH_GroupBase
2142 # @ingroup l2_grps_create
2143 def GetGroups(self, elemType = SMESH.ALL):
2144 groups = self.mesh.GetGroups()
2145 if elemType == SMESH.ALL:
2149 if g.GetType() == elemType:
2150 typedGroups.append( g )
2155 ## Get the number of groups existing in the mesh
2156 # @return the quantity of groups as an integer value
2157 # @ingroup l2_grps_create
2159 return self.mesh.NbGroups()
2161 ## Get the list of names of groups existing in the mesh
2162 # @return list of strings
2163 # @ingroup l2_grps_create
2164 def GetGroupNames(self):
2165 groups = self.GetGroups()
2167 for group in groups:
2168 names.append(group.GetName())
2171 ## Find groups by name and type
2172 # @param name name of the group of interest
2173 # @param elemType type of elements the groups contain; either of
2174 # (SMESH.ALL, SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME);
2175 # by default one group of any type of elements is returned
2176 # if elemType == SMESH.ALL then all groups of any type are returned
2177 # @return a list of SMESH_GroupBase's
2178 # @ingroup l2_grps_create
2179 def GetGroupByName(self, name, elemType = None):
2181 for group in self.GetGroups():
2182 if group.GetName() == name:
2183 if elemType is None:
2185 if ( elemType == SMESH.ALL or
2186 group.GetType() == elemType ):
2187 groups.append( group )
2190 ## Produce a union of two groups.
2191 # A new group is created. All mesh elements that are
2192 # present in the initial groups are added to the new one
2193 # @return an instance of SMESH_Group
2194 # @ingroup l2_grps_operon
2195 def UnionGroups(self, group1, group2, name):
2196 return self.mesh.UnionGroups(group1, group2, name)
2198 ## Produce a union list of groups.
2199 # New group is created. All mesh elements that are present in
2200 # initial groups are added to the new one
2201 # @return an instance of SMESH_Group
2202 # @ingroup l2_grps_operon
2203 def UnionListOfGroups(self, groups, name):
2204 return self.mesh.UnionListOfGroups(groups, name)
2206 ## Prodice an intersection of two groups.
2207 # A new group is created. All mesh elements that are common
2208 # for the two initial groups are added to the new one.
2209 # @return an instance of SMESH_Group
2210 # @ingroup l2_grps_operon
2211 def IntersectGroups(self, group1, group2, name):
2212 return self.mesh.IntersectGroups(group1, group2, name)
2214 ## Produce an intersection of groups.
2215 # New group is created. All mesh elements that are present in all
2216 # initial groups simultaneously are added to the new one
2217 # @return an instance of SMESH_Group
2218 # @ingroup l2_grps_operon
2219 def IntersectListOfGroups(self, groups, name):
2220 return self.mesh.IntersectListOfGroups(groups, name)
2222 ## Produce a cut of two groups.
2223 # A new group is created. All mesh elements that are present in
2224 # the main group but are not present in the tool group are added to the new one
2225 # @return an instance of SMESH_Group
2226 # @ingroup l2_grps_operon
2227 def CutGroups(self, main_group, tool_group, name):
2228 return self.mesh.CutGroups(main_group, tool_group, name)
2230 ## Produce a cut of groups.
2231 # A new group is created. All mesh elements that are present in main groups
2232 # but do not present in tool groups are added to the new one
2233 # @return an instance of SMESH_Group
2234 # @ingroup l2_grps_operon
2235 def CutListOfGroups(self, main_groups, tool_groups, name):
2236 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
2239 # Create a standalone group of entities basing on nodes of other groups.
2240 # \param groups - list of reference groups, sub-meshes or filters, of any type.
2241 # \param elemType - a type of elements to include to the new group; either of
2242 # (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
2243 # \param name - a name of the new group.
2244 # \param nbCommonNodes - a criterion of inclusion of an element to the new group
2245 # basing on number of element nodes common with reference \a groups.
2246 # Meaning of possible values are:
2247 # - SMESH.ALL_NODES - include if all nodes are common,
2248 # - SMESH.MAIN - include if all corner nodes are common (meaningful for a quadratic mesh),
2249 # - SMESH.AT_LEAST_ONE - include if one or more node is common,
2250 # - SMEHS.MAJORITY - include if half of nodes or more are common.
2251 # \param underlyingOnly - if \c True (default), an element is included to the
2252 # new group provided that it is based on nodes of an element of \a groups;
2253 # in this case the reference \a groups are supposed to be of higher dimension
2254 # than \a elemType, which can be useful for example to get all faces lying on
2255 # volumes of the reference \a groups.
2256 # @return an instance of SMESH_Group
2257 # @ingroup l2_grps_operon
2258 def CreateDimGroup(self, groups, elemType, name,
2259 nbCommonNodes = SMESH.ALL_NODES, underlyingOnly = True):
2260 if isinstance( groups, SMESH._objref_SMESH_IDSource ):
2262 return self.mesh.CreateDimGroup(groups, elemType, name, nbCommonNodes, underlyingOnly)
2265 ## Convert group on geom into standalone group
2266 # @ingroup l2_grps_operon
2267 def ConvertToStandalone(self, group):
2268 return self.mesh.ConvertToStandalone(group)
2270 # Get some info about mesh:
2271 # ------------------------
2273 ## Return the log of nodes and elements added or removed
2274 # since the previous clear of the log.
2275 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
2276 # @return list of log_block structures:
2281 # @ingroup l1_auxiliary
2282 def GetLog(self, clearAfterGet):
2283 return self.mesh.GetLog(clearAfterGet)
2285 ## Clear the log of nodes and elements added or removed since the previous
2286 # clear. Must be used immediately after GetLog if clearAfterGet is false.
2287 # @ingroup l1_auxiliary
2289 self.mesh.ClearLog()
2291 ## Toggle auto color mode on the object.
2292 # @param theAutoColor the flag which toggles auto color mode.
2294 # If switched on, a default color of a new group in Create Group dialog is chosen randomly.
2295 # @ingroup l1_grouping
2296 def SetAutoColor(self, theAutoColor):
2297 self.mesh.SetAutoColor(theAutoColor)
2299 ## Get flag of object auto color mode.
2300 # @return True or False
2301 # @ingroup l1_grouping
2302 def GetAutoColor(self):
2303 return self.mesh.GetAutoColor()
2305 ## Get the internal ID
2306 # @return integer value, which is the internal Id of the mesh
2307 # @ingroup l1_auxiliary
2309 return self.mesh.GetId()
2311 ## Check the group names for duplications.
2312 # Consider the maximum group name length stored in MED file.
2313 # @return True or False
2314 # @ingroup l1_grouping
2315 def HasDuplicatedGroupNamesMED(self):
2316 return self.mesh.HasDuplicatedGroupNamesMED()
2318 ## Obtain the mesh editor tool
2319 # @return an instance of SMESH_MeshEditor
2320 # @ingroup l1_modifying
2321 def GetMeshEditor(self):
2324 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
2325 # can be passed as argument to a method accepting mesh, group or sub-mesh
2326 # @param ids list of IDs
2327 # @param elemType type of elements; this parameter is used to distinguish
2328 # IDs of nodes from IDs of elements; by default ids are treated as
2329 # IDs of elements; use SMESH.NODE if ids are IDs of nodes.
2330 # @return an instance of SMESH_IDSource
2331 # @warning call UnRegister() for the returned object as soon as it is no more useful:
2332 # idSrc = mesh.GetIDSource( [1,3,5], SMESH.NODE )
2333 # mesh.DoSomething( idSrc )
2334 # idSrc.UnRegister()
2335 # @ingroup l1_auxiliary
2336 def GetIDSource(self, ids, elemType = SMESH.ALL):
2337 if isinstance( ids, int ):
2339 return self.editor.MakeIDSource(ids, elemType)
2342 # Get informations about mesh contents:
2343 # ------------------------------------
2345 ## Get the mesh stattistic
2346 # @return dictionary type element - count of elements
2347 # @ingroup l1_meshinfo
2348 def GetMeshInfo(self, obj = None):
2349 if not obj: obj = self.mesh
2350 return self.smeshpyD.GetMeshInfo(obj)
2352 ## Return the number of nodes in the mesh
2353 # @return an integer value
2354 # @ingroup l1_meshinfo
2356 return self.mesh.NbNodes()
2358 ## Return the number of elements in the mesh
2359 # @return an integer value
2360 # @ingroup l1_meshinfo
2361 def NbElements(self):
2362 return self.mesh.NbElements()
2364 ## Return the number of 0d elements in the mesh
2365 # @return an integer value
2366 # @ingroup l1_meshinfo
2367 def Nb0DElements(self):
2368 return self.mesh.Nb0DElements()
2370 ## Return the number of ball discrete elements in the mesh
2371 # @return an integer value
2372 # @ingroup l1_meshinfo
2374 return self.mesh.NbBalls()
2376 ## Return the number of edges in the mesh
2377 # @return an integer value
2378 # @ingroup l1_meshinfo
2380 return self.mesh.NbEdges()
2382 ## Return the number of edges with the given order in the mesh
2383 # @param elementOrder the order of elements:
2384 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2385 # @return an integer value
2386 # @ingroup l1_meshinfo
2387 def NbEdgesOfOrder(self, elementOrder):
2388 return self.mesh.NbEdgesOfOrder(elementOrder)
2390 ## Return the number of faces in the mesh
2391 # @return an integer value
2392 # @ingroup l1_meshinfo
2394 return self.mesh.NbFaces()
2396 ## Return the number of faces with the given order in the mesh
2397 # @param elementOrder the order of elements:
2398 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2399 # @return an integer value
2400 # @ingroup l1_meshinfo
2401 def NbFacesOfOrder(self, elementOrder):
2402 return self.mesh.NbFacesOfOrder(elementOrder)
2404 ## Return the number of triangles in the mesh
2405 # @return an integer value
2406 # @ingroup l1_meshinfo
2407 def NbTriangles(self):
2408 return self.mesh.NbTriangles()
2410 ## Return the number of triangles with the given order in the mesh
2411 # @param elementOrder is the order of elements:
2412 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2413 # @return an integer value
2414 # @ingroup l1_meshinfo
2415 def NbTrianglesOfOrder(self, elementOrder):
2416 return self.mesh.NbTrianglesOfOrder(elementOrder)
2418 ## Return the number of biquadratic triangles in the mesh
2419 # @return an integer value
2420 # @ingroup l1_meshinfo
2421 def NbBiQuadTriangles(self):
2422 return self.mesh.NbBiQuadTriangles()
2424 ## Return the number of quadrangles in the mesh
2425 # @return an integer value
2426 # @ingroup l1_meshinfo
2427 def NbQuadrangles(self):
2428 return self.mesh.NbQuadrangles()
2430 ## Return the number of quadrangles with the given order in the mesh
2431 # @param elementOrder the order of elements:
2432 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2433 # @return an integer value
2434 # @ingroup l1_meshinfo
2435 def NbQuadranglesOfOrder(self, elementOrder):
2436 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2438 ## Return the number of biquadratic quadrangles in the mesh
2439 # @return an integer value
2440 # @ingroup l1_meshinfo
2441 def NbBiQuadQuadrangles(self):
2442 return self.mesh.NbBiQuadQuadrangles()
2444 ## Return the number of polygons of given order in the mesh
2445 # @param elementOrder the order of elements:
2446 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2447 # @return an integer value
2448 # @ingroup l1_meshinfo
2449 def NbPolygons(self, elementOrder = SMESH.ORDER_ANY):
2450 return self.mesh.NbPolygonsOfOrder(elementOrder)
2452 ## Return the number of volumes in the mesh
2453 # @return an integer value
2454 # @ingroup l1_meshinfo
2455 def NbVolumes(self):
2456 return self.mesh.NbVolumes()
2458 ## Return the number of volumes with the given order in the mesh
2459 # @param elementOrder the order of elements:
2460 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2461 # @return an integer value
2462 # @ingroup l1_meshinfo
2463 def NbVolumesOfOrder(self, elementOrder):
2464 return self.mesh.NbVolumesOfOrder(elementOrder)
2466 ## Return the number of tetrahedrons in the mesh
2467 # @return an integer value
2468 # @ingroup l1_meshinfo
2470 return self.mesh.NbTetras()
2472 ## Return the number of tetrahedrons with the given order in the mesh
2473 # @param elementOrder the order of elements:
2474 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2475 # @return an integer value
2476 # @ingroup l1_meshinfo
2477 def NbTetrasOfOrder(self, elementOrder):
2478 return self.mesh.NbTetrasOfOrder(elementOrder)
2480 ## Return the number of hexahedrons in the mesh
2481 # @return an integer value
2482 # @ingroup l1_meshinfo
2484 return self.mesh.NbHexas()
2486 ## Return the number of hexahedrons with the given order in the mesh
2487 # @param elementOrder the order of elements:
2488 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2489 # @return an integer value
2490 # @ingroup l1_meshinfo
2491 def NbHexasOfOrder(self, elementOrder):
2492 return self.mesh.NbHexasOfOrder(elementOrder)
2494 ## Return the number of triquadratic hexahedrons in the mesh
2495 # @return an integer value
2496 # @ingroup l1_meshinfo
2497 def NbTriQuadraticHexas(self):
2498 return self.mesh.NbTriQuadraticHexas()
2500 ## Return the number of pyramids in the mesh
2501 # @return an integer value
2502 # @ingroup l1_meshinfo
2503 def NbPyramids(self):
2504 return self.mesh.NbPyramids()
2506 ## Return the number of pyramids with the given order in the mesh
2507 # @param elementOrder the order of elements:
2508 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2509 # @return an integer value
2510 # @ingroup l1_meshinfo
2511 def NbPyramidsOfOrder(self, elementOrder):
2512 return self.mesh.NbPyramidsOfOrder(elementOrder)
2514 ## Return the number of prisms in the mesh
2515 # @return an integer value
2516 # @ingroup l1_meshinfo
2518 return self.mesh.NbPrisms()
2520 ## Return the number of prisms with the given order in the mesh
2521 # @param elementOrder the order of elements:
2522 # SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2523 # @return an integer value
2524 # @ingroup l1_meshinfo
2525 def NbPrismsOfOrder(self, elementOrder):
2526 return self.mesh.NbPrismsOfOrder(elementOrder)
2528 ## Return the number of hexagonal prisms in the mesh
2529 # @return an integer value
2530 # @ingroup l1_meshinfo
2531 def NbHexagonalPrisms(self):
2532 return self.mesh.NbHexagonalPrisms()
2534 ## Return the number of polyhedrons in the mesh
2535 # @return an integer value
2536 # @ingroup l1_meshinfo
2537 def NbPolyhedrons(self):
2538 return self.mesh.NbPolyhedrons()
2540 ## Return the number of submeshes in the mesh
2541 # @return an integer value
2542 # @ingroup l1_meshinfo
2543 def NbSubMesh(self):
2544 return self.mesh.NbSubMesh()
2546 ## Return the list of mesh elements IDs
2547 # @return the list of integer values
2548 # @ingroup l1_meshinfo
2549 def GetElementsId(self):
2550 return self.mesh.GetElementsId()
2552 ## Return the list of IDs of mesh elements with the given type
2553 # @param elementType the required type of elements, either of
2554 # (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2555 # @return list of integer values
2556 # @ingroup l1_meshinfo
2557 def GetElementsByType(self, elementType):
2558 return self.mesh.GetElementsByType(elementType)
2560 ## Return the list of mesh nodes IDs
2561 # @return the list of integer values
2562 # @ingroup l1_meshinfo
2563 def GetNodesId(self):
2564 return self.mesh.GetNodesId()
2566 # Get the information about mesh elements:
2567 # ------------------------------------
2569 ## Return the type of mesh element
2570 # @return the value from SMESH::ElementType enumeration
2571 # Type SMESH.ElementType._items in the Python Console to see all possible values.
2572 # @ingroup l1_meshinfo
2573 def GetElementType(self, id, iselem=True):
2574 return self.mesh.GetElementType(id, iselem)
2576 ## Return the geometric type of mesh element
2577 # @return the value from SMESH::EntityType enumeration
2578 # Type SMESH.EntityType._items in the Python Console to see all possible values.
2579 # @ingroup l1_meshinfo
2580 def GetElementGeomType(self, id):
2581 return self.mesh.GetElementGeomType(id)
2583 ## Return the shape type of mesh element
2584 # @return the value from SMESH::GeometryType enumeration.
2585 # Type SMESH.GeometryType._items in the Python Console to see all possible values.
2586 # @ingroup l1_meshinfo
2587 def GetElementShape(self, id):
2588 return self.mesh.GetElementShape(id)
2590 ## Return the list of submesh elements IDs
2591 # @param Shape a geom object(sub-shape)
2592 # Shape must be the sub-shape of a ShapeToMesh()
2593 # @return the list of integer values
2594 # @ingroup l1_meshinfo
2595 def GetSubMeshElementsId(self, Shape):
2596 if isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object):
2597 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2600 return self.mesh.GetSubMeshElementsId(ShapeID)
2602 ## Return the list of submesh nodes IDs
2603 # @param Shape a geom object(sub-shape)
2604 # Shape must be the sub-shape of a ShapeToMesh()
2605 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2606 # @return the list of integer values
2607 # @ingroup l1_meshinfo
2608 def GetSubMeshNodesId(self, Shape, all):
2609 if isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object):
2610 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2613 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2615 ## Return type of elements on given shape
2616 # @param Shape a geom object(sub-shape)
2617 # Shape must be a sub-shape of a ShapeToMesh()
2618 # @return element type
2619 # @ingroup l1_meshinfo
2620 def GetSubMeshElementType(self, Shape):
2621 if isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object):
2622 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2625 return self.mesh.GetSubMeshElementType(ShapeID)
2627 ## Get the mesh description
2628 # @return string value
2629 # @ingroup l1_meshinfo
2631 return self.mesh.Dump()
2634 # Get the information about nodes and elements of a mesh by its IDs:
2635 # -----------------------------------------------------------
2637 ## Get XYZ coordinates of a node
2638 # \n If there is no nodes for the given ID - return an empty list
2639 # @return a list of double precision values
2640 # @ingroup l1_meshinfo
2641 def GetNodeXYZ(self, id):
2642 return self.mesh.GetNodeXYZ(id)
2644 ## Return list of IDs of inverse elements for the given node
2645 # \n If there is no node for the given ID - return an empty list
2646 # @return a list of integer values
2647 # @ingroup l1_meshinfo
2648 def GetNodeInverseElements(self, id):
2649 return self.mesh.GetNodeInverseElements(id)
2651 ## Return the position of a node on the shape
2652 # @return SMESH::NodePosition
2653 # @ingroup l1_meshinfo
2654 def GetNodePosition(self,NodeID):
2655 return self.mesh.GetNodePosition(NodeID)
2657 ## Return the position of an element on the shape
2658 # @return SMESH::ElementPosition
2659 # @ingroup l1_meshinfo
2660 def GetElementPosition(self,ElemID):
2661 return self.mesh.GetElementPosition(ElemID)
2663 ## Return the ID of the shape, on which the given node was generated.
2664 # @return an integer value > 0 or -1 if there is no node for the given
2665 # ID or the node is not assigned to any geometry
2666 # @ingroup l1_meshinfo
2667 def GetShapeID(self, id):
2668 return self.mesh.GetShapeID(id)
2670 ## Return the ID of the shape, on which the given element was generated.
2671 # @return an integer value > 0 or -1 if there is no element for the given
2672 # ID or the element is not assigned to any geometry
2673 # @ingroup l1_meshinfo
2674 def GetShapeIDForElem(self,id):
2675 return self.mesh.GetShapeIDForElem(id)
2677 ## Return the number of nodes of the given element
2678 # @return an integer value > 0 or -1 if there is no element for the given ID
2679 # @ingroup l1_meshinfo
2680 def GetElemNbNodes(self, id):
2681 return self.mesh.GetElemNbNodes(id)
2683 ## Return the node ID the given (zero based) index for the given element
2684 # \n If there is no element for the given ID - return -1
2685 # \n If there is no node for the given index - return -2
2686 # @return an integer value
2687 # @ingroup l1_meshinfo
2688 def GetElemNode(self, id, index):
2689 return self.mesh.GetElemNode(id, index)
2691 ## Return the IDs of nodes of the given element
2692 # @return a list of integer values
2693 # @ingroup l1_meshinfo
2694 def GetElemNodes(self, id):
2695 return self.mesh.GetElemNodes(id)
2697 ## Return true if the given node is the medium node in the given quadratic element
2698 # @ingroup l1_meshinfo
2699 def IsMediumNode(self, elementID, nodeID):
2700 return self.mesh.IsMediumNode(elementID, nodeID)
2702 ## Return true if the given node is the medium node in one of quadratic elements
2703 # @param nodeID ID of the node
2704 # @param elementType the type of elements to check a state of the node, either of
2705 # (SMESH.ALL, SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2706 # @ingroup l1_meshinfo
2707 def IsMediumNodeOfAnyElem(self, nodeID, elementType = SMESH.ALL ):
2708 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2710 ## Return the number of edges for the given element
2711 # @ingroup l1_meshinfo
2712 def ElemNbEdges(self, id):
2713 return self.mesh.ElemNbEdges(id)
2715 ## Return the number of faces for the given element
2716 # @ingroup l1_meshinfo
2717 def ElemNbFaces(self, id):
2718 return self.mesh.ElemNbFaces(id)
2720 ## Return nodes of given face (counted from zero) for given volumic element.
2721 # @ingroup l1_meshinfo
2722 def GetElemFaceNodes(self,elemId, faceIndex):
2723 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2725 ## Return three components of normal of given mesh face
2726 # (or an empty array in KO case)
2727 # @ingroup l1_meshinfo
2728 def GetFaceNormal(self, faceId, normalized=False):
2729 return self.mesh.GetFaceNormal(faceId,normalized)
2731 ## Return an element based on all given nodes.
2732 # @ingroup l1_meshinfo
2733 def FindElementByNodes(self, nodes):
2734 return self.mesh.FindElementByNodes(nodes)
2736 ## Return elements including all given nodes.
2737 # @ingroup l1_meshinfo
2738 def GetElementsByNodes(self, nodes, elemType=SMESH.ALL):
2739 return self.mesh.GetElementsByNodes( nodes, elemType )
2741 ## Return true if the given element is a polygon
2742 # @ingroup l1_meshinfo
2743 def IsPoly(self, id):
2744 return self.mesh.IsPoly(id)
2746 ## Return true if the given element is quadratic
2747 # @ingroup l1_meshinfo
2748 def IsQuadratic(self, id):
2749 return self.mesh.IsQuadratic(id)
2751 ## Return diameter of a ball discrete element or zero in case of an invalid \a id
2752 # @ingroup l1_meshinfo
2753 def GetBallDiameter(self, id):
2754 return self.mesh.GetBallDiameter(id)
2756 ## Return XYZ coordinates of the barycenter of the given element
2757 # \n If there is no element for the given ID - return an empty list
2758 # @return a list of three double values
2759 # @ingroup l1_meshinfo
2760 def BaryCenter(self, id):
2761 return self.mesh.BaryCenter(id)
2763 ## Pass mesh elements through the given filter and return IDs of fitting elements
2764 # @param theFilter SMESH_Filter
2765 # @return a list of ids
2766 # @ingroup l1_controls
2767 def GetIdsFromFilter(self, theFilter):
2768 theFilter.SetMesh( self.mesh )
2769 return theFilter.GetIDs()
2771 # Get mesh measurements information:
2772 # ------------------------------------
2774 ## Verify whether a 2D mesh element has free edges (edges connected to one face only)\n
2775 # Return a list of special structures (borders).
2776 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2777 # @ingroup l1_measurements
2778 def GetFreeBorders(self):
2779 aFilterMgr = self.smeshpyD.CreateFilterManager()
2780 aPredicate = aFilterMgr.CreateFreeEdges()
2781 aPredicate.SetMesh(self.mesh)
2782 aBorders = aPredicate.GetBorders()
2783 aFilterMgr.UnRegister()
2786 ## Get minimum distance between two nodes, elements or distance to the origin
2787 # @param id1 first node/element id
2788 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2789 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2790 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2791 # @return minimum distance value
2792 # @sa GetMinDistance()
2793 # @ingroup l1_measurements
2794 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2795 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2796 return aMeasure.value
2798 ## Get measure structure specifying minimum distance data between two objects
2799 # @param id1 first node/element id
2800 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2801 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2802 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2803 # @return Measure structure
2805 # @ingroup l1_measurements
2806 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2808 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2810 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2813 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2815 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2820 aMeasurements = self.smeshpyD.CreateMeasurements()
2821 aMeasure = aMeasurements.MinDistance(id1, id2)
2822 genObjUnRegister([aMeasurements,id1, id2])
2825 ## Get bounding box of the specified object(s)
2826 # @param objects single source object or list of source objects or list of nodes/elements IDs
2827 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2828 # @c False specifies that @a objects are nodes
2829 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2830 # @sa GetBoundingBox()
2831 # @ingroup l1_measurements
2832 def BoundingBox(self, objects=None, isElem=False):
2833 result = self.GetBoundingBox(objects, isElem)
2837 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2840 ## Get measure structure specifying bounding box data of the specified object(s)
2841 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2842 # @param isElem if @a IDs is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2843 # @c False specifies that @a objects are nodes
2844 # @return Measure structure
2846 # @ingroup l1_measurements
2847 def GetBoundingBox(self, IDs=None, isElem=False):
2850 elif isinstance(IDs, tuple):
2852 if not isinstance(IDs, list):
2854 if len(IDs) > 0 and isinstance(IDs[0], int):
2857 unRegister = genObjUnRegister()
2859 if isinstance(o, Mesh):
2860 srclist.append(o.mesh)
2861 elif hasattr(o, "_narrow"):
2862 src = o._narrow(SMESH.SMESH_IDSource)
2863 if src: srclist.append(src)
2865 elif isinstance(o, list):
2867 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2869 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2870 unRegister.set( srclist[-1] )
2873 aMeasurements = self.smeshpyD.CreateMeasurements()
2874 unRegister.set( aMeasurements )
2875 aMeasure = aMeasurements.BoundingBox(srclist)
2878 # Mesh edition (SMESH_MeshEditor functionality):
2879 # ---------------------------------------------
2881 ## Remove the elements from the mesh by ids
2882 # @param IDsOfElements is a list of ids of elements to remove
2883 # @return True or False
2884 # @ingroup l2_modif_del
2885 def RemoveElements(self, IDsOfElements):
2886 return self.editor.RemoveElements(IDsOfElements)
2888 ## Remove nodes from mesh by ids
2889 # @param IDsOfNodes is a list of ids of nodes to remove
2890 # @return True or False
2891 # @ingroup l2_modif_del
2892 def RemoveNodes(self, IDsOfNodes):
2893 return self.editor.RemoveNodes(IDsOfNodes)
2895 ## Remove all orphan (free) nodes from mesh
2896 # @return number of the removed nodes
2897 # @ingroup l2_modif_del
2898 def RemoveOrphanNodes(self):
2899 return self.editor.RemoveOrphanNodes()
2901 ## Add a node to the mesh by coordinates
2902 # @return Id of the new node
2903 # @ingroup l2_modif_add
2904 def AddNode(self, x, y, z):
2905 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2906 if hasVars: self.mesh.SetParameters(Parameters)
2907 return self.editor.AddNode( x, y, z)
2909 ## Create a 0D element on a node with given number.
2910 # @param IDOfNode the ID of node for creation of the element.
2911 # @param DuplicateElements to add one more 0D element to a node or not
2912 # @return the Id of the new 0D element
2913 # @ingroup l2_modif_add
2914 def Add0DElement( self, IDOfNode, DuplicateElements=True ):
2915 return self.editor.Add0DElement( IDOfNode, DuplicateElements )
2917 ## Create 0D elements on all nodes of the given elements except those
2918 # nodes on which a 0D element already exists.
2919 # @param theObject an object on whose nodes 0D elements will be created.
2920 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2921 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2922 # @param theGroupName optional name of a group to add 0D elements created
2923 # and/or found on nodes of \a theObject.
2924 # @param DuplicateElements to add one more 0D element to a node or not
2925 # @return an object (a new group or a temporary SMESH_IDSource) holding
2926 # IDs of new and/or found 0D elements. IDs of 0D elements
2927 # can be retrieved from the returned object by calling GetIDs()
2928 # @ingroup l2_modif_add
2929 def Add0DElementsToAllNodes(self, theObject, theGroupName="", DuplicateElements=False):
2930 unRegister = genObjUnRegister()
2931 if isinstance( theObject, Mesh ):
2932 theObject = theObject.GetMesh()
2933 elif isinstance( theObject, list ):
2934 theObject = self.GetIDSource( theObject, SMESH.ALL )
2935 unRegister.set( theObject )
2936 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName, DuplicateElements )
2938 ## Create a ball element on a node with given ID.
2939 # @param IDOfNode the ID of node for creation of the element.
2940 # @param diameter the bal diameter.
2941 # @return the Id of the new ball element
2942 # @ingroup l2_modif_add
2943 def AddBall(self, IDOfNode, diameter):
2944 return self.editor.AddBall( IDOfNode, diameter )
2946 ## Create a linear or quadratic edge (this is determined
2947 # by the number of given nodes).
2948 # @param IDsOfNodes the list of node IDs for creation of the element.
2949 # The order of nodes in this list should correspond to the description
2950 # of MED. \n This description is located by the following link:
2951 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2952 # @return the Id of the new edge
2953 # @ingroup l2_modif_add
2954 def AddEdge(self, IDsOfNodes):
2955 return self.editor.AddEdge(IDsOfNodes)
2957 ## Create a linear or quadratic face (this is determined
2958 # by the number of given nodes).
2959 # @param IDsOfNodes the list of node IDs for creation of the element.
2960 # The order of nodes in this list should correspond to the description
2961 # of MED. \n This description is located by the following link:
2962 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2963 # @return the Id of the new face
2964 # @ingroup l2_modif_add
2965 def AddFace(self, IDsOfNodes):
2966 return self.editor.AddFace(IDsOfNodes)
2968 ## Add a polygonal face to the mesh by the list of node IDs
2969 # @param IdsOfNodes the list of node IDs for creation of the element.
2970 # @return the Id of the new face
2971 # @ingroup l2_modif_add
2972 def AddPolygonalFace(self, IdsOfNodes):
2973 return self.editor.AddPolygonalFace(IdsOfNodes)
2975 ## Add a quadratic polygonal face to the mesh by the list of node IDs
2976 # @param IdsOfNodes the list of node IDs for creation of the element;
2977 # corner nodes follow first.
2978 # @return the Id of the new face
2979 # @ingroup l2_modif_add
2980 def AddQuadPolygonalFace(self, IdsOfNodes):
2981 return self.editor.AddQuadPolygonalFace(IdsOfNodes)
2983 ## Create both simple and quadratic volume (this is determined
2984 # by the number of given nodes).
2985 # @param IDsOfNodes the list of node IDs for creation of the element.
2986 # The order of nodes in this list should correspond to the description
2987 # of MED. \n This description is located by the following link:
2988 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2989 # @return the Id of the new volumic element
2990 # @ingroup l2_modif_add
2991 def AddVolume(self, IDsOfNodes):
2992 return self.editor.AddVolume(IDsOfNodes)
2994 ## Create a volume of many faces, giving nodes for each face.
2995 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2996 # @param Quantities the list of integer values, Quantities[i]
2997 # gives the quantity of nodes in face number i.
2998 # @return the Id of the new volumic element
2999 # @ingroup l2_modif_add
3000 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
3001 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
3003 ## Create a volume of many faces, giving the IDs of the existing faces.
3004 # @param IdsOfFaces the list of face IDs for volume creation.
3006 # Note: The created volume will refer only to the nodes
3007 # of the given faces, not to the faces themselves.
3008 # @return the Id of the new volumic element
3009 # @ingroup l2_modif_add
3010 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
3011 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
3014 ## @brief Binds a node to a vertex
3015 # @param NodeID a node ID
3016 # @param Vertex a vertex or vertex ID
3017 # @return True if succeed else raises an exception
3018 # @ingroup l2_modif_add
3019 def SetNodeOnVertex(self, NodeID, Vertex):
3020 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
3021 VertexID = self.geompyD.GetSubShapeID( self.geom, Vertex )
3025 self.editor.SetNodeOnVertex(NodeID, VertexID)
3026 except SALOME.SALOME_Exception as inst:
3027 raise ValueError(inst.details.text)
3031 ## @brief Stores the node position on an edge
3032 # @param NodeID a node ID
3033 # @param Edge an edge or edge ID
3034 # @param paramOnEdge a parameter on the edge where the node is located
3035 # @return True if succeed else raises an exception
3036 # @ingroup l2_modif_add
3037 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
3038 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
3039 EdgeID = self.geompyD.GetSubShapeID( self.geom, Edge )
3043 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
3044 except SALOME.SALOME_Exception as inst:
3045 raise ValueError(inst.details.text)
3048 ## @brief Stores node position on a face
3049 # @param NodeID a node ID
3050 # @param Face a face or face ID
3051 # @param u U parameter on the face where the node is located
3052 # @param v V parameter on the face where the node is located
3053 # @return True if succeed else raises an exception
3054 # @ingroup l2_modif_add
3055 def SetNodeOnFace(self, NodeID, Face, u, v):
3056 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
3057 FaceID = self.geompyD.GetSubShapeID( self.geom, Face )
3061 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
3062 except SALOME.SALOME_Exception as inst:
3063 raise ValueError(inst.details.text)
3066 ## @brief Binds a node to a solid
3067 # @param NodeID a node ID
3068 # @param Solid a solid or solid ID
3069 # @return True if succeed else raises an exception
3070 # @ingroup l2_modif_add
3071 def SetNodeInVolume(self, NodeID, Solid):
3072 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
3073 SolidID = self.geompyD.GetSubShapeID( self.geom, Solid )
3077 self.editor.SetNodeInVolume(NodeID, SolidID)
3078 except SALOME.SALOME_Exception as inst:
3079 raise ValueError(inst.details.text)
3082 ## @brief Bind an element to a shape
3083 # @param ElementID an element ID
3084 # @param Shape a shape or shape ID
3085 # @return True if succeed else raises an exception
3086 # @ingroup l2_modif_add
3087 def SetMeshElementOnShape(self, ElementID, Shape):
3088 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
3089 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
3093 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
3094 except SALOME.SALOME_Exception as inst:
3095 raise ValueError(inst.details.text)
3099 ## Move the node with the given id
3100 # @param NodeID the id of the node
3101 # @param x a new X coordinate
3102 # @param y a new Y coordinate
3103 # @param z a new Z coordinate
3104 # @return True if succeed else False
3105 # @ingroup l2_modif_edit
3106 def MoveNode(self, NodeID, x, y, z):
3107 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
3108 if hasVars: self.mesh.SetParameters(Parameters)
3109 return self.editor.MoveNode(NodeID, x, y, z)
3111 ## Find the node closest to a point and moves it to a point location
3112 # @param x the X coordinate of a point
3113 # @param y the Y coordinate of a point
3114 # @param z the Z coordinate of a point
3115 # @param NodeID if specified (>0), the node with this ID is moved,
3116 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
3117 # @return the ID of a node
3118 # @ingroup l2_modif_edit
3119 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
3120 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
3121 if hasVars: self.mesh.SetParameters(Parameters)
3122 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
3124 ## Find the node closest to a point
3125 # @param x the X coordinate of a point
3126 # @param y the Y coordinate of a point
3127 # @param z the Z coordinate of a point
3128 # @return the ID of a node
3129 # @ingroup l1_meshinfo
3130 def FindNodeClosestTo(self, x, y, z):
3131 #preview = self.mesh.GetMeshEditPreviewer()
3132 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
3133 return self.editor.FindNodeClosestTo(x, y, z)
3135 ## Find the elements where a point lays IN or ON
3136 # @param x the X coordinate of a point
3137 # @param y the Y coordinate of a point
3138 # @param z the Z coordinate of a point
3139 # @param elementType type of elements to find; either of
3140 # (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME); SMESH.ALL type
3141 # means elements of any type excluding nodes, discrete and 0D elements.
3142 # @param meshPart a part of mesh (group, sub-mesh) to search within
3143 # @return list of IDs of found elements
3144 # @ingroup l1_meshinfo
3145 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
3147 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
3149 return self.editor.FindElementsByPoint(x, y, z, elementType)
3151 ## Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
3152 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
3153 # UNKNOWN state means that either mesh is wrong or the analysis fails.
3154 # @ingroup l1_meshinfo
3155 def GetPointState(self, x, y, z):
3156 return self.editor.GetPointState(x, y, z)
3158 ## Find the node closest to a point and moves it to a point location
3159 # @param x the X coordinate of a point
3160 # @param y the Y coordinate of a point
3161 # @param z the Z coordinate of a point
3162 # @return the ID of a moved node
3163 # @ingroup l2_modif_edit
3164 def MeshToPassThroughAPoint(self, x, y, z):
3165 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
3167 ## Replace two neighbour triangles sharing Node1-Node2 link
3168 # with the triangles built on the same 4 nodes but having other common link.
3169 # @param NodeID1 the ID of the first node
3170 # @param NodeID2 the ID of the second node
3171 # @return false if proper faces were not found
3172 # @ingroup l2_modif_cutquadr
3173 def InverseDiag(self, NodeID1, NodeID2):
3174 return self.editor.InverseDiag(NodeID1, NodeID2)
3176 ## Replace two neighbour triangles sharing Node1-Node2 link
3177 # with a quadrangle built on the same 4 nodes.
3178 # @param NodeID1 the ID of the first node
3179 # @param NodeID2 the ID of the second node
3180 # @return false if proper faces were not found
3181 # @ingroup l2_modif_unitetri
3182 def DeleteDiag(self, NodeID1, NodeID2):
3183 return self.editor.DeleteDiag(NodeID1, NodeID2)
3185 ## Reorient elements by ids
3186 # @param IDsOfElements if undefined reorients all mesh elements
3187 # @return True if succeed else False
3188 # @ingroup l2_modif_changori
3189 def Reorient(self, IDsOfElements=None):
3190 if IDsOfElements == None:
3191 IDsOfElements = self.GetElementsId()
3192 return self.editor.Reorient(IDsOfElements)
3194 ## Reorient all elements of the object
3195 # @param theObject mesh, submesh or group
3196 # @return True if succeed else False
3197 # @ingroup l2_modif_changori
3198 def ReorientObject(self, theObject):
3199 if ( isinstance( theObject, Mesh )):
3200 theObject = theObject.GetMesh()
3201 return self.editor.ReorientObject(theObject)
3203 ## Reorient faces contained in \a the2DObject.
3204 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
3205 # @param theDirection is a desired direction of normal of \a theFace.
3206 # It can be either a GEOM vector or a list of coordinates [x,y,z].
3207 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
3208 # compared with theDirection. It can be either ID of face or a point
3209 # by which the face will be found. The point can be given as either
3210 # a GEOM vertex or a list of point coordinates.
3211 # @return number of reoriented faces
3212 # @ingroup l2_modif_changori
3213 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
3214 unRegister = genObjUnRegister()
3216 if isinstance( the2DObject, Mesh ):
3217 the2DObject = the2DObject.GetMesh()
3218 if isinstance( the2DObject, list ):
3219 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
3220 unRegister.set( the2DObject )
3221 # check theDirection
3222 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
3223 theDirection = self.smeshpyD.GetDirStruct( theDirection )
3224 if isinstance( theDirection, list ):
3225 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
3226 # prepare theFace and thePoint
3227 theFace = theFaceOrPoint
3228 thePoint = PointStruct(0,0,0)
3229 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
3230 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
3232 if isinstance( theFaceOrPoint, list ):
3233 thePoint = PointStruct( *theFaceOrPoint )
3235 if isinstance( theFaceOrPoint, PointStruct ):
3236 thePoint = theFaceOrPoint
3238 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
3240 ## Reorient faces according to adjacent volumes.
3241 # @param the2DObject is a mesh, sub-mesh, group or list of
3242 # either IDs of faces or face groups.
3243 # @param the3DObject is a mesh, sub-mesh, group or list of IDs of volumes.
3244 # @param theOutsideNormal to orient faces to have their normals
3245 # pointing either \a outside or \a inside the adjacent volumes.
3246 # @return number of reoriented faces.
3247 # @ingroup l2_modif_changori
3248 def Reorient2DBy3D(self, the2DObject, the3DObject, theOutsideNormal=True ):
3249 unRegister = genObjUnRegister()
3251 if not isinstance( the2DObject, list ):
3252 the2DObject = [ the2DObject ]
3253 elif the2DObject and isinstance( the2DObject[0], int ):
3254 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
3255 unRegister.set( the2DObject )
3256 the2DObject = [ the2DObject ]
3257 for i,obj2D in enumerate( the2DObject ):
3258 if isinstance( obj2D, Mesh ):
3259 the2DObject[i] = obj2D.GetMesh()
3260 if isinstance( obj2D, list ):
3261 the2DObject[i] = self.GetIDSource( obj2D, SMESH.FACE )
3262 unRegister.set( the2DObject[i] )
3264 if isinstance( the3DObject, Mesh ):
3265 the3DObject = the3DObject.GetMesh()
3266 if isinstance( the3DObject, list ):
3267 the3DObject = self.GetIDSource( the3DObject, SMESH.VOLUME )
3268 unRegister.set( the3DObject )
3269 return self.editor.Reorient2DBy3D( the2DObject, the3DObject, theOutsideNormal )
3271 ## Fuse the neighbouring triangles into quadrangles.
3272 # @param IDsOfElements The triangles to be fused.
3273 # @param theCriterion a numerical functor, in terms of enum SMESH.FunctorType, used to
3274 # applied to possible quadrangles to choose a neighbour to fuse with.
3275 # Type SMESH.FunctorType._items in the Python Console to see all items.
3276 # Note that not all items correspond to numerical functors.
3277 # @param MaxAngle is the maximum angle between element normals at which the fusion
3278 # is still performed; theMaxAngle is mesured in radians.
3279 # Also it could be a name of variable which defines angle in degrees.
3280 # @return TRUE in case of success, FALSE otherwise.
3281 # @ingroup l2_modif_unitetri
3282 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
3283 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
3284 self.mesh.SetParameters(Parameters)
3285 if not IDsOfElements:
3286 IDsOfElements = self.GetElementsId()
3287 Functor = self.smeshpyD.GetFunctor(theCriterion)
3288 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
3290 ## Fuse the neighbouring triangles of the object into quadrangles
3291 # @param theObject is mesh, submesh or group
3292 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType,
3293 # applied to possible quadrangles to choose a neighbour to fuse with.
3294 # Type SMESH.FunctorType._items in the Python Console to see all items.
3295 # Note that not all items correspond to numerical functors.
3296 # @param MaxAngle a max angle between element normals at which the fusion
3297 # is still performed; theMaxAngle is mesured in radians.
3298 # @return TRUE in case of success, FALSE otherwise.
3299 # @ingroup l2_modif_unitetri
3300 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
3301 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
3302 self.mesh.SetParameters(Parameters)
3303 if isinstance( theObject, Mesh ):
3304 theObject = theObject.GetMesh()
3305 Functor = self.smeshpyD.GetFunctor(theCriterion)
3306 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
3308 ## Split quadrangles into triangles.
3309 # @param IDsOfElements the faces to be splitted.
3310 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3311 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
3312 # value, then quadrangles will be split by the smallest diagonal.
3313 # Type SMESH.FunctorType._items in the Python Console to see all items.
3314 # Note that not all items correspond to numerical functors.
3315 # @return TRUE in case of success, FALSE otherwise.
3316 # @ingroup l2_modif_cutquadr
3317 def QuadToTri (self, IDsOfElements, theCriterion = None):
3318 if IDsOfElements == []:
3319 IDsOfElements = self.GetElementsId()
3320 if theCriterion is None:
3321 theCriterion = FT_MaxElementLength2D
3322 Functor = self.smeshpyD.GetFunctor(theCriterion)
3323 return self.editor.QuadToTri(IDsOfElements, Functor)
3325 ## Split quadrangles into triangles.
3326 # @param theObject the object from which the list of elements is taken,
3327 # this is mesh, submesh or group
3328 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3329 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
3330 # value, then quadrangles will be split by the smallest diagonal.
3331 # Type SMESH.FunctorType._items in the Python Console to see all items.
3332 # Note that not all items correspond to numerical functors.
3333 # @return TRUE in case of success, FALSE otherwise.
3334 # @ingroup l2_modif_cutquadr
3335 def QuadToTriObject (self, theObject, theCriterion = None):
3336 if ( isinstance( theObject, Mesh )):
3337 theObject = theObject.GetMesh()
3338 if theCriterion is None:
3339 theCriterion = FT_MaxElementLength2D
3340 Functor = self.smeshpyD.GetFunctor(theCriterion)
3341 return self.editor.QuadToTriObject(theObject, Functor)
3343 ## Split each of given quadrangles into 4 triangles. A node is added at the center of
3345 # @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
3346 # group or a list of face IDs. By default all quadrangles are split
3347 # @ingroup l2_modif_cutquadr
3348 def QuadTo4Tri (self, theElements=[]):
3349 unRegister = genObjUnRegister()
3350 if isinstance( theElements, Mesh ):
3351 theElements = theElements.mesh
3352 elif not theElements:
3353 theElements = self.mesh
3354 elif isinstance( theElements, list ):
3355 theElements = self.GetIDSource( theElements, SMESH.FACE )
3356 unRegister.set( theElements )
3357 return self.editor.QuadTo4Tri( theElements )
3359 ## Split quadrangles into triangles.
3360 # @param IDsOfElements the faces to be splitted
3361 # @param Diag13 is used to choose a diagonal for splitting.
3362 # @return TRUE in case of success, FALSE otherwise.
3363 # @ingroup l2_modif_cutquadr
3364 def SplitQuad (self, IDsOfElements, Diag13):
3365 if IDsOfElements == []:
3366 IDsOfElements = self.GetElementsId()
3367 return self.editor.SplitQuad(IDsOfElements, Diag13)
3369 ## Split quadrangles into triangles.
3370 # @param theObject the object from which the list of elements is taken,
3371 # this is mesh, submesh or group
3372 # @param Diag13 is used to choose a diagonal for splitting.
3373 # @return TRUE in case of success, FALSE otherwise.
3374 # @ingroup l2_modif_cutquadr
3375 def SplitQuadObject (self, theObject, Diag13):
3376 if ( isinstance( theObject, Mesh )):
3377 theObject = theObject.GetMesh()
3378 return self.editor.SplitQuadObject(theObject, Diag13)
3380 ## Find a better splitting of the given quadrangle.
3381 # @param IDOfQuad the ID of the quadrangle to be splitted.
3382 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3383 # choose a diagonal for splitting.
3384 # Type SMESH.FunctorType._items in the Python Console to see all items.
3385 # Note that not all items correspond to numerical functors.
3386 # @return 1 if 1-3 diagonal is better, 2 if 2-4
3387 # diagonal is better, 0 if error occurs.
3388 # @ingroup l2_modif_cutquadr
3389 def BestSplit (self, IDOfQuad, theCriterion):
3390 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
3392 ## Split volumic elements into tetrahedrons
3393 # @param elems either a list of elements or a mesh or a group or a submesh or a filter
3394 # @param method flags passing splitting method:
3395 # smesh.Hex_5Tet, smesh.Hex_6Tet, smesh.Hex_24Tet.
3396 # smesh.Hex_5Tet - to split the hexahedron into 5 tetrahedrons, etc.
3397 # @ingroup l2_modif_cutquadr
3398 def SplitVolumesIntoTetra(self, elems, method=smeshBuilder.Hex_5Tet ):
3399 unRegister = genObjUnRegister()
3400 if isinstance( elems, Mesh ):
3401 elems = elems.GetMesh()
3402 if ( isinstance( elems, list )):
3403 elems = self.editor.MakeIDSource(elems, SMESH.VOLUME)
3404 unRegister.set( elems )
3405 self.editor.SplitVolumesIntoTetra(elems, method)
3408 ## Split bi-quadratic elements into linear ones without creation of additional nodes:
3409 # - bi-quadratic triangle will be split into 3 linear quadrangles;
3410 # - bi-quadratic quadrangle will be split into 4 linear quadrangles;
3411 # - tri-quadratic hexahedron will be split into 8 linear hexahedra.
3412 # Quadratic elements of lower dimension adjacent to the split bi-quadratic element
3413 # will be split in order to keep the mesh conformal.
3414 # @param elems - elements to split: sub-meshes, groups, filters or element IDs;
3415 # if None (default), all bi-quadratic elements will be split
3416 # @ingroup l2_modif_cutquadr
3417 def SplitBiQuadraticIntoLinear(self, elems=None):
3418 unRegister = genObjUnRegister()
3419 if elems and isinstance( elems, list ) and isinstance( elems[0], int ):
3420 elems = self.editor.MakeIDSource(elems, SMESH.ALL)
3421 unRegister.set( elems )
3423 elems = [ self.GetMesh() ]
3424 if isinstance( elems, Mesh ):
3425 elems = [ elems.GetMesh() ]
3426 if not isinstance( elems, list ):
3428 self.editor.SplitBiQuadraticIntoLinear( elems )
3430 ## Split hexahedra into prisms
3431 # @param elems either a list of elements or a mesh or a group or a submesh or a filter
3432 # @param startHexPoint a point used to find a hexahedron for which @a facetNormal
3433 # gives a normal vector defining facets to split into triangles.
3434 # @a startHexPoint can be either a triple of coordinates or a vertex.
3435 # @param facetNormal a normal to a facet to split into triangles of a
3436 # hexahedron found by @a startHexPoint.
3437 # @a facetNormal can be either a triple of coordinates or an edge.
3438 # @param method flags passing splitting method: smesh.Hex_2Prisms, smesh.Hex_4Prisms.
3439 # smesh.Hex_2Prisms - to split the hexahedron into 2 prisms, etc.
3440 # @param allDomains if @c False, only hexahedra adjacent to one closest
3441 # to @a startHexPoint are split, else @a startHexPoint
3442 # is used to find the facet to split in all domains present in @a elems.
3443 # @ingroup l2_modif_cutquadr
3444 def SplitHexahedraIntoPrisms(self, elems, startHexPoint, facetNormal,
3445 method=smeshBuilder.Hex_2Prisms, allDomains=False ):
3447 unRegister = genObjUnRegister()
3448 if isinstance( elems, Mesh ):
3449 elems = elems.GetMesh()
3450 if ( isinstance( elems, list )):
3451 elems = self.editor.MakeIDSource(elems, SMESH.VOLUME)
3452 unRegister.set( elems )
3455 if isinstance( startHexPoint, geomBuilder.GEOM._objref_GEOM_Object):
3456 startHexPoint = self.smeshpyD.GetPointStruct( startHexPoint )
3457 elif isinstance( startHexPoint, list ):
3458 startHexPoint = SMESH.PointStruct( startHexPoint[0],
3461 if isinstance( facetNormal, geomBuilder.GEOM._objref_GEOM_Object):
3462 facetNormal = self.smeshpyD.GetDirStruct( facetNormal )
3463 elif isinstance( facetNormal, list ):
3464 facetNormal = self.smeshpyD.MakeDirStruct( facetNormal[0],
3467 self.mesh.SetParameters( startHexPoint.parameters + facetNormal.PS.parameters )
3469 self.editor.SplitHexahedraIntoPrisms(elems, startHexPoint, facetNormal, method, allDomains)
3471 ## Split quadrangle faces near triangular facets of volumes
3473 # @ingroup l2_modif_cutquadr
3474 def SplitQuadsNearTriangularFacets(self):
3475 faces_array = self.GetElementsByType(SMESH.FACE)
3476 for face_id in faces_array:
3477 if self.GetElemNbNodes(face_id) == 4: # quadrangle
3478 quad_nodes = self.mesh.GetElemNodes(face_id)
3479 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
3480 isVolumeFound = False
3481 for node1_elem in node1_elems:
3482 if not isVolumeFound:
3483 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
3484 nb_nodes = self.GetElemNbNodes(node1_elem)
3485 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
3486 volume_elem = node1_elem
3487 volume_nodes = self.mesh.GetElemNodes(volume_elem)
3488 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
3489 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
3490 isVolumeFound = True
3491 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
3492 self.SplitQuad([face_id], False) # diagonal 2-4
3493 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
3494 isVolumeFound = True
3495 self.SplitQuad([face_id], True) # diagonal 1-3
3496 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
3497 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
3498 isVolumeFound = True
3499 self.SplitQuad([face_id], True) # diagonal 1-3
3501 ## @brief Splits hexahedrons into tetrahedrons.
3503 # This operation uses pattern mapping functionality for splitting.
3504 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
3505 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
3506 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
3507 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
3508 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
3509 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
3510 # @return TRUE in case of success, FALSE otherwise.
3511 # @ingroup l2_modif_cutquadr
3512 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
3513 # Pattern: 5.---------.6
3518 # (0,0,1) 4.---------.7 * |
3525 # (0,0,0) 0.---------.3
3526 pattern_tetra = "!!! Nb of points: \n 8 \n\
3536 !!! Indices of points of 6 tetras: \n\
3544 pattern = self.smeshpyD.GetPattern()
3545 isDone = pattern.LoadFromFile(pattern_tetra)
3547 print('Pattern.LoadFromFile :', pattern.GetErrorCode())
3550 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3551 isDone = pattern.MakeMesh(self.mesh, False, False)
3552 if not isDone: print('Pattern.MakeMesh :', pattern.GetErrorCode())
3554 # split quafrangle faces near triangular facets of volumes
3555 self.SplitQuadsNearTriangularFacets()
3559 ## @brief Split hexahedrons into prisms.
3561 # Uses the pattern mapping functionality for splitting.
3562 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
3563 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
3564 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
3565 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
3566 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
3567 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
3568 # @return TRUE in case of success, FALSE otherwise.
3569 # @ingroup l2_modif_cutquadr
3570 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3571 # Pattern: 5.---------.6
3576 # (0,0,1) 4.---------.7 |
3583 # (0,0,0) 0.---------.3
3584 pattern_prism = "!!! Nb of points: \n 8 \n\
3594 !!! Indices of points of 2 prisms: \n\
3598 pattern = self.smeshpyD.GetPattern()
3599 isDone = pattern.LoadFromFile(pattern_prism)
3601 print('Pattern.LoadFromFile :', pattern.GetErrorCode())
3604 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3605 isDone = pattern.MakeMesh(self.mesh, False, False)
3606 if not isDone: print('Pattern.MakeMesh :', pattern.GetErrorCode())
3608 # Split quafrangle faces near triangular facets of volumes
3609 self.SplitQuadsNearTriangularFacets()
3614 # @param IDsOfElements the list if ids of elements to smooth
3615 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3616 # Note that nodes built on edges and boundary nodes are always fixed.
3617 # @param MaxNbOfIterations the maximum number of iterations
3618 # @param MaxAspectRatio varies in range [1.0, inf]
3619 # @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3620 # or Centroidal (smesh.CENTROIDAL_SMOOTH)
3621 # @return TRUE in case of success, FALSE otherwise.
3622 # @ingroup l2_modif_smooth
3623 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3624 MaxNbOfIterations, MaxAspectRatio, Method):
3625 if IDsOfElements == []:
3626 IDsOfElements = self.GetElementsId()
3627 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3628 self.mesh.SetParameters(Parameters)
3629 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3630 MaxNbOfIterations, MaxAspectRatio, Method)
3632 ## Smooth elements which belong to the given object
3633 # @param theObject the object to smooth
3634 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3635 # Note that nodes built on edges and boundary nodes are always fixed.
3636 # @param MaxNbOfIterations the maximum number of iterations
3637 # @param MaxAspectRatio varies in range [1.0, inf]
3638 # @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3639 # or Centroidal (smesh.CENTROIDAL_SMOOTH)
3640 # @return TRUE in case of success, FALSE otherwise.
3641 # @ingroup l2_modif_smooth
3642 def SmoothObject(self, theObject, IDsOfFixedNodes,
3643 MaxNbOfIterations, MaxAspectRatio, Method):
3644 if ( isinstance( theObject, Mesh )):
3645 theObject = theObject.GetMesh()
3646 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3647 MaxNbOfIterations, MaxAspectRatio, Method)
3649 ## Parametrically smooth the given elements
3650 # @param IDsOfElements the list if ids of elements to smooth
3651 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3652 # Note that nodes built on edges and boundary nodes are always fixed.
3653 # @param MaxNbOfIterations the maximum number of iterations
3654 # @param MaxAspectRatio varies in range [1.0, inf]
3655 # @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3656 # or Centroidal (smesh.CENTROIDAL_SMOOTH)
3657 # @return TRUE in case of success, FALSE otherwise.
3658 # @ingroup l2_modif_smooth
3659 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3660 MaxNbOfIterations, MaxAspectRatio, Method):
3661 if IDsOfElements == []:
3662 IDsOfElements = self.GetElementsId()
3663 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3664 self.mesh.SetParameters(Parameters)
3665 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3666 MaxNbOfIterations, MaxAspectRatio, Method)
3668 ## Parametrically smooth the elements which belong to the given object
3669 # @param theObject the object to smooth
3670 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3671 # Note that nodes built on edges and boundary nodes are always fixed.
3672 # @param MaxNbOfIterations the maximum number of iterations
3673 # @param MaxAspectRatio varies in range [1.0, inf]
3674 # @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3675 # or Centroidal (smesh.CENTROIDAL_SMOOTH)
3676 # @return TRUE in case of success, FALSE otherwise.
3677 # @ingroup l2_modif_smooth
3678 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3679 MaxNbOfIterations, MaxAspectRatio, Method):
3680 if ( isinstance( theObject, Mesh )):
3681 theObject = theObject.GetMesh()
3682 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3683 MaxNbOfIterations, MaxAspectRatio, Method)
3685 ## Convert the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3686 # them with quadratic with the same id.
3687 # @param theForce3d new node creation method:
3688 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3689 # 1 - the medium node lies at the middle of the line segments connecting two nodes of a mesh element
3690 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3691 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3692 # @return SMESH.ComputeError which can hold a warning
3693 # @ingroup l2_modif_tofromqu
3694 def ConvertToQuadratic(self, theForce3d=False, theSubMesh=None, theToBiQuad=False):
3695 if isinstance( theSubMesh, Mesh ):
3696 theSubMesh = theSubMesh.mesh
3698 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3701 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3703 self.editor.ConvertToQuadratic(theForce3d)
3704 error = self.editor.GetLastError()
3705 if error and error.comment:
3706 print(error.comment)
3709 ## Convert the mesh from quadratic to ordinary,
3710 # deletes old quadratic elements, \n replacing
3711 # them with ordinary mesh elements with the same id.
3712 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3713 # @ingroup l2_modif_tofromqu
3714 def ConvertFromQuadratic(self, theSubMesh=None):
3716 self.editor.ConvertFromQuadraticObject(theSubMesh)
3718 return self.editor.ConvertFromQuadratic()
3720 ## Create 2D mesh as skin on boundary faces of a 3D mesh
3721 # @return TRUE if operation has been completed successfully, FALSE otherwise
3722 # @ingroup l2_modif_add
3723 def Make2DMeshFrom3D(self):
3724 return self.editor.Make2DMeshFrom3D()
3726 ## Create missing boundary elements
3727 # @param elements - elements whose boundary is to be checked:
3728 # mesh, group, sub-mesh or list of elements
3729 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3730 # @param dimension - defines type of boundary elements to create, either of
3731 # { SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D }
3732 # SMESH.BND_1DFROM3D create mesh edges on all borders of free facets of 3D cells
3733 # @param groupName - a name of group to store created boundary elements in,
3734 # "" means not to create the group
3735 # @param meshName - a name of new mesh to store created boundary elements in,
3736 # "" means not to create the new mesh
3737 # @param toCopyElements - if true, the checked elements will be copied into
3738 # the new mesh else only boundary elements will be copied into the new mesh
3739 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3740 # boundary elements will be copied into the new mesh
3741 # @return tuple (mesh, group) where boundary elements were added to
3742 # @ingroup l2_modif_add
3743 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3744 toCopyElements=False, toCopyExistingBondary=False):
3745 unRegister = genObjUnRegister()
3746 if isinstance( elements, Mesh ):
3747 elements = elements.GetMesh()
3748 if ( isinstance( elements, list )):
3749 elemType = SMESH.ALL
3750 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3751 elements = self.editor.MakeIDSource(elements, elemType)
3752 unRegister.set( elements )
3753 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3754 toCopyElements,toCopyExistingBondary)
3755 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3759 # @brief Create missing boundary elements around either the whole mesh or
3760 # groups of elements
3761 # @param dimension - defines type of boundary elements to create, either of
3762 # { SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D }
3763 # @param groupName - a name of group to store all boundary elements in,
3764 # "" means not to create the group
3765 # @param meshName - a name of a new mesh, which is a copy of the initial
3766 # mesh + created boundary elements; "" means not to create the new mesh
3767 # @param toCopyAll - if true, the whole initial mesh will be copied into
3768 # the new mesh else only boundary elements will be copied into the new mesh
3769 # @param groups - groups of elements to make boundary around
3770 # @retval tuple( long, mesh, groups )
3771 # long - number of added boundary elements
3772 # mesh - the mesh where elements were added to
3773 # group - the group of boundary elements or None
3775 # @ingroup l2_modif_add
3776 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3777 toCopyAll=False, groups=[]):
3778 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3780 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3781 return nb, mesh, group
3783 ## Renumber mesh nodes (Obsolete, does nothing)
3784 # @ingroup l2_modif_renumber
3785 def RenumberNodes(self):
3786 self.editor.RenumberNodes()
3788 ## Renumber mesh elements (Obsole, does nothing)
3789 # @ingroup l2_modif_renumber
3790 def RenumberElements(self):
3791 self.editor.RenumberElements()
3793 ## Private method converting \a arg into a list of SMESH_IdSource's
3794 def _getIdSourceList(self, arg, idType, unRegister):
3795 if arg and isinstance( arg, list ):
3796 if isinstance( arg[0], int ):
3797 arg = self.GetIDSource( arg, idType )
3798 unRegister.set( arg )
3799 elif isinstance( arg[0], Mesh ):
3800 arg[0] = arg[0].GetMesh()
3801 elif isinstance( arg, Mesh ):
3803 if arg and isinstance( arg, SMESH._objref_SMESH_IDSource ):
3807 ## Generate new elements by rotation of the given elements and nodes around the axis
3808 # @param nodes - nodes to revolve: a list including ids, groups, sub-meshes or a mesh
3809 # @param edges - edges to revolve: a list including ids, groups, sub-meshes or a mesh
3810 # @param faces - faces to revolve: a list including ids, groups, sub-meshes or a mesh
3811 # @param Axis the axis of rotation: AxisStruct, line (geom object) or [x,y,z,dx,dy,dz]
3812 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable
3813 # which defines angle in degrees
3814 # @param NbOfSteps the number of steps
3815 # @param Tolerance tolerance
3816 # @param MakeGroups forces the generation of new groups from existing ones
3817 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3818 # of all steps, else - size of each step
3819 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3820 # @ingroup l2_modif_extrurev
3821 def RotationSweepObjects(self, nodes, edges, faces, Axis, AngleInRadians, NbOfSteps, Tolerance,
3822 MakeGroups=False, TotalAngle=False):
3823 unRegister = genObjUnRegister()
3824 nodes = self._getIdSourceList( nodes, SMESH.NODE, unRegister )
3825 edges = self._getIdSourceList( edges, SMESH.EDGE, unRegister )
3826 faces = self._getIdSourceList( faces, SMESH.FACE, unRegister )
3828 if isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object):
3829 Axis = self.smeshpyD.GetAxisStruct( Axis )
3830 if isinstance( Axis, list ):
3831 Axis = SMESH.AxisStruct( *Axis )
3833 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3834 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3835 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3836 self.mesh.SetParameters(Parameters)
3837 if TotalAngle and NbOfSteps:
3838 AngleInRadians /= NbOfSteps
3839 return self.editor.RotationSweepObjects( nodes, edges, faces,
3840 Axis, AngleInRadians,
3841 NbOfSteps, Tolerance, MakeGroups)
3843 ## Generate new elements by rotation of the elements around the axis
3844 # @param IDsOfElements the list of ids of elements to sweep
3845 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3846 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3847 # @param NbOfSteps the number of steps
3848 # @param Tolerance tolerance
3849 # @param MakeGroups forces the generation of new groups from existing ones
3850 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3851 # of all steps, else - size of each step
3852 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3853 # @ingroup l2_modif_extrurev
3854 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3855 MakeGroups=False, TotalAngle=False):
3856 return self.RotationSweepObjects([], IDsOfElements, IDsOfElements, Axis,
3857 AngleInRadians, NbOfSteps, Tolerance,
3858 MakeGroups, TotalAngle)
3860 ## Generate new elements by rotation of the elements of object around the axis
3861 # @param theObject object which elements should be sweeped.
3862 # It can be a mesh, a sub mesh or a group.
3863 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3864 # @param AngleInRadians the angle of Rotation
3865 # @param NbOfSteps number of steps
3866 # @param Tolerance tolerance
3867 # @param MakeGroups forces the generation of new groups from existing ones
3868 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3869 # of all steps, else - size of each step
3870 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3871 # @ingroup l2_modif_extrurev
3872 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3873 MakeGroups=False, TotalAngle=False):
3874 return self.RotationSweepObjects( [], theObject, theObject, Axis,
3875 AngleInRadians, NbOfSteps, Tolerance,
3876 MakeGroups, TotalAngle )
3878 ## Generate new elements by rotation of the elements of object around the axis
3879 # @param theObject object which elements should be sweeped.
3880 # It can be a mesh, a sub mesh or a group.
3881 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3882 # @param AngleInRadians the angle of Rotation
3883 # @param NbOfSteps number of steps
3884 # @param Tolerance tolerance
3885 # @param MakeGroups forces the generation of new groups from existing ones
3886 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3887 # of all steps, else - size of each step
3888 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3889 # @ingroup l2_modif_extrurev
3890 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3891 MakeGroups=False, TotalAngle=False):
3892 return self.RotationSweepObjects([],theObject,[], Axis,
3893 AngleInRadians, NbOfSteps, Tolerance,
3894 MakeGroups, TotalAngle)
3896 ## Generate new elements by rotation of the elements of object around the axis
3897 # @param theObject object which elements should be sweeped.
3898 # It can be a mesh, a sub mesh or a group.
3899 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3900 # @param AngleInRadians the angle of Rotation
3901 # @param NbOfSteps number of steps
3902 # @param Tolerance tolerance
3903 # @param MakeGroups forces the generation of new groups from existing ones
3904 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3905 # of all steps, else - size of each step
3906 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3907 # @ingroup l2_modif_extrurev
3908 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3909 MakeGroups=False, TotalAngle=False):
3910 return self.RotationSweepObjects([],[],theObject, Axis, AngleInRadians,
3911 NbOfSteps, Tolerance, MakeGroups, TotalAngle)
3913 ## Generate new elements by extrusion of the given elements and nodes
3914 # @param nodes nodes to extrude: a list including ids, groups, sub-meshes or a mesh
3915 # @param edges edges to extrude: a list including ids, groups, sub-meshes or a mesh
3916 # @param faces faces to extrude: a list including ids, groups, sub-meshes or a mesh
3917 # @param StepVector vector or DirStruct or 3 vector components, defining
3918 # the direction and value of extrusion for one step (the total extrusion
3919 # length will be NbOfSteps * ||StepVector||)
3920 # @param NbOfSteps the number of steps
3921 # @param MakeGroups forces the generation of new groups from existing ones
3922 # @param scaleFactors optional scale factors to apply during extrusion
3923 # @param linearVariation if @c True, scaleFactors are spread over all @a scaleFactors,
3924 # else scaleFactors[i] is applied to nodes at the i-th extrusion step
3925 # @param basePoint optional scaling center; if not provided, a gravity center of
3926 # nodes and elements being extruded is used as the scaling center.
3928 # - a list of tree components of the point or
3931 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3932 # @ingroup l2_modif_extrurev
3933 def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False,
3934 scaleFactors=[], linearVariation=False, basePoint=[] ):
3935 unRegister = genObjUnRegister()
3936 nodes = self._getIdSourceList( nodes, SMESH.NODE, unRegister )
3937 edges = self._getIdSourceList( edges, SMESH.EDGE, unRegister )
3938 faces = self._getIdSourceList( faces, SMESH.FACE, unRegister )
3940 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3941 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3942 if isinstance( StepVector, list ):
3943 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3945 if isinstance( basePoint, int):
3946 xyz = self.GetNodeXYZ( basePoint )
3948 raise RuntimeError("Invalid node ID: %s" % basePoint)
3950 if isinstance( basePoint, geomBuilder.GEOM._objref_GEOM_Object ):
3951 basePoint = self.geompyD.PointCoordinates( basePoint )
3953 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3954 Parameters = StepVector.PS.parameters + var_separator + Parameters
3955 self.mesh.SetParameters(Parameters)
3957 return self.editor.ExtrusionSweepObjects( nodes, edges, faces,
3958 StepVector, NbOfSteps,
3959 scaleFactors, linearVariation, basePoint,
3963 ## Generate new elements by extrusion of the elements with given ids
3964 # @param IDsOfElements the list of ids of elements or nodes for extrusion
3965 # @param StepVector vector or DirStruct or 3 vector components, defining
3966 # the direction and value of extrusion for one step (the total extrusion
3967 # length will be NbOfSteps * ||StepVector||)
3968 # @param NbOfSteps the number of steps
3969 # @param MakeGroups forces the generation of new groups from existing ones
3970 # @param IsNodes is True if elements with given ids are nodes
3971 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3972 # @ingroup l2_modif_extrurev
3973 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3975 if IsNodes: n = IDsOfElements
3976 else : e,f, = IDsOfElements,IDsOfElements
3977 return self.ExtrusionSweepObjects(n,e,f, StepVector, NbOfSteps, MakeGroups)
3979 ## Generate new elements by extrusion along the normal to a discretized surface or wire
3980 # @param Elements elements to extrude - a list including ids, groups, sub-meshes or a mesh.
3981 # Only faces can be extruded so far. A sub-mesh should be a sub-mesh on geom faces.
3982 # @param StepSize length of one extrusion step (the total extrusion
3983 # length will be \a NbOfSteps * \a StepSize ).
3984 # @param NbOfSteps number of extrusion steps.
3985 # @param ByAverageNormal if True each node is translated by \a StepSize
3986 # along the average of the normal vectors to the faces sharing the node;
3987 # else each node is translated along the same average normal till
3988 # intersection with the plane got by translation of the face sharing
3989 # the node along its own normal by \a StepSize.
3990 # @param UseInputElemsOnly to use only \a Elements when computing extrusion direction
3991 # for every node of \a Elements.
3992 # @param MakeGroups forces generation of new groups from existing ones.
3993 # @param Dim dimension of elements to extrude: 2 - faces or 1 - edges. Extrusion of edges
3994 # is not yet implemented. This parameter is used if \a Elements contains
3995 # both faces and edges, i.e. \a Elements is a Mesh.
3996 # @return the list of created groups (SMESH_GroupBase) if \a MakeGroups=True,
3997 # empty list otherwise.
3998 # @ingroup l2_modif_extrurev
3999 def ExtrusionByNormal(self, Elements, StepSize, NbOfSteps,
4000 ByAverageNormal=False, UseInputElemsOnly=True, MakeGroups=False, Dim = 2):
4001 unRegister = genObjUnRegister()
4002 if isinstance( Elements, Mesh ):
4003 Elements = [ Elements.GetMesh() ]
4004 if isinstance( Elements, list ):
4006 raise RuntimeError("Elements empty!")
4007 if isinstance( Elements[0], int ):
4008 Elements = self.GetIDSource( Elements, SMESH.ALL )
4009 unRegister.set( Elements )
4010 if not isinstance( Elements, list ):
4011 Elements = [ Elements ]
4012 StepSize,NbOfSteps,Parameters,hasVars = ParseParameters(StepSize,NbOfSteps)
4013 self.mesh.SetParameters(Parameters)
4014 return self.editor.ExtrusionByNormal(Elements, StepSize, NbOfSteps,
4015 ByAverageNormal, UseInputElemsOnly, MakeGroups, Dim)
4017 ## Generate new elements by extrusion of the elements or nodes which belong to the object
4018 # @param theObject the object whose elements or nodes should be processed.
4019 # It can be a mesh, a sub-mesh or a group.
4020 # @param StepVector vector or DirStruct or 3 vector components, defining
4021 # the direction and value of extrusion for one step (the total extrusion
4022 # length will be NbOfSteps * ||StepVector||)
4023 # @param NbOfSteps the number of steps
4024 # @param MakeGroups forces the generation of new groups from existing ones
4025 # @param IsNodes is True if elements to extrude are nodes
4026 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4027 # @ingroup l2_modif_extrurev
4028 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
4030 if IsNodes: n = theObject
4031 else : e,f, = theObject,theObject
4032 return self.ExtrusionSweepObjects(n,e,f, StepVector, NbOfSteps, MakeGroups)
4034 ## Generate new elements by extrusion of edges which belong to the object
4035 # @param theObject object whose 1D elements should be processed.
4036 # It can be a mesh, a sub-mesh or a group.
4037 # @param StepVector vector or DirStruct or 3 vector components, defining
4038 # the direction and value of extrusion for one step (the total extrusion
4039 # length will be NbOfSteps * ||StepVector||)
4040 # @param NbOfSteps the number of steps
4041 # @param MakeGroups to generate new groups from existing ones
4042 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4043 # @ingroup l2_modif_extrurev
4044 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
4045 return self.ExtrusionSweepObjects([],theObject,[], StepVector, NbOfSteps, MakeGroups)
4047 ## Generate new elements by extrusion of faces which belong to the object
4048 # @param theObject object whose 2D elements should be processed.
4049 # It can be a mesh, a sub-mesh or a group.
4050 # @param StepVector vector or DirStruct or 3 vector components, defining
4051 # the direction and value of extrusion for one step (the total extrusion
4052 # length will be NbOfSteps * ||StepVector||)
4053 # @param NbOfSteps the number of steps
4054 # @param MakeGroups forces the generation of new groups from existing ones
4055 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4056 # @ingroup l2_modif_extrurev
4057 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
4058 return self.ExtrusionSweepObjects([],[],theObject, StepVector, NbOfSteps, MakeGroups)
4060 ## Generate new elements by extrusion of the elements with given ids
4061 # @param IDsOfElements is ids of elements
4062 # @param StepVector vector or DirStruct or 3 vector components, defining
4063 # the direction and value of extrusion for one step (the total extrusion
4064 # length will be NbOfSteps * ||StepVector||)
4065 # @param NbOfSteps the number of steps
4066 # @param ExtrFlags sets flags for extrusion
4067 # @param SewTolerance uses for comparing locations of nodes if flag
4068 # EXTRUSION_FLAG_SEW is set
4069 # @param MakeGroups forces the generation of new groups from existing ones
4070 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4071 # @ingroup l2_modif_extrurev
4072 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
4073 ExtrFlags, SewTolerance, MakeGroups=False):
4074 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
4075 StepVector = self.smeshpyD.GetDirStruct(StepVector)
4076 if isinstance( StepVector, list ):
4077 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
4078 return self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
4079 ExtrFlags, SewTolerance, MakeGroups)
4081 ## Generate new elements by extrusion of the given elements and nodes along the path.
4082 # The path of extrusion must be a meshed edge.
4083 # @param Nodes nodes to extrude: a list including ids, groups, sub-meshes or a mesh
4084 # @param Edges edges to extrude: a list including ids, groups, sub-meshes or a mesh
4085 # @param Faces faces to extrude: a list including ids, groups, sub-meshes or a mesh
4086 # @param PathMesh 1D mesh or 1D sub-mesh, along which proceeds the extrusion
4087 # @param PathShape shape (edge) defines the sub-mesh of PathMesh if PathMesh
4088 # contains not only path segments, else it can be None
4089 # @param NodeStart the first or the last node on the path. Defines the direction of extrusion
4090 # @param HasAngles allows the shape to be rotated around the path
4091 # to get the resulting mesh in a helical fashion
4092 # @param Angles list of angles
4093 # @param LinearVariation forces the computation of rotation angles as linear
4094 # variation of the given Angles along path steps
4095 # @param HasRefPoint allows using the reference point
4096 # @param RefPoint the point around which the shape is rotated (the mass center of the
4097 # shape by default). The User can specify any point as the Reference Point.
4098 # @param MakeGroups forces the generation of new groups from existing ones
4099 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error
4100 # @ingroup l2_modif_extrurev
4101 def ExtrusionAlongPathObjects(self, Nodes, Edges, Faces, PathMesh, PathShape=None,
4102 NodeStart=1, HasAngles=False, Angles=[], LinearVariation=False,
4103 HasRefPoint=False, RefPoint=[0,0,0], MakeGroups=False):
4104 unRegister = genObjUnRegister()
4105 Nodes = self._getIdSourceList( Nodes, SMESH.NODE, unRegister )
4106 Edges = self._getIdSourceList( Edges, SMESH.EDGE, unRegister )
4107 Faces = self._getIdSourceList( Faces, SMESH.FACE, unRegister )
4109 if isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object):
4110 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
4111 if isinstance( RefPoint, list ):
4112 if not RefPoint: RefPoint = [0,0,0]
4113 RefPoint = SMESH.PointStruct( *RefPoint )
4114 if isinstance( PathMesh, Mesh ):
4115 PathMesh = PathMesh.GetMesh()
4116 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
4117 Parameters = AnglesParameters + var_separator + RefPoint.parameters
4118 self.mesh.SetParameters(Parameters)
4119 return self.editor.ExtrusionAlongPathObjects(Nodes, Edges, Faces,
4120 PathMesh, PathShape, NodeStart,
4121 HasAngles, Angles, LinearVariation,
4122 HasRefPoint, RefPoint, MakeGroups)
4124 ## Generate new elements by extrusion of the given elements
4125 # The path of extrusion must be a meshed edge.
4126 # @param Base mesh or group, or sub-mesh, or list of ids of elements for extrusion
4127 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
4128 # @param NodeStart the start node from Path. Defines the direction of extrusion
4129 # @param HasAngles allows the shape to be rotated around the path
4130 # to get the resulting mesh in a helical fashion
4131 # @param Angles list of angles in radians
4132 # @param LinearVariation forces the computation of rotation angles as linear
4133 # variation of the given Angles along path steps
4134 # @param HasRefPoint allows using the reference point
4135 # @param RefPoint the point around which the elements are rotated (the mass
4136 # center of the elements by default).
4137 # The User can specify any point as the Reference Point.
4138 # RefPoint can be either GEOM Vertex, [x,y,z] or SMESH.PointStruct
4139 # @param MakeGroups forces the generation of new groups from existing ones
4140 # @param ElemType type of elements for extrusion (if param Base is a mesh)
4141 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4142 # only SMESH::Extrusion_Error otherwise
4143 # @ingroup l2_modif_extrurev
4144 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
4145 HasAngles=False, Angles=[], LinearVariation=False,
4146 HasRefPoint=False, RefPoint=[0,0,0], MakeGroups=False,
4147 ElemType=SMESH.FACE):
4149 if ElemType == SMESH.NODE: n = Base
4150 if ElemType == SMESH.EDGE: e = Base
4151 if ElemType == SMESH.FACE: f = Base
4152 gr,er = self.ExtrusionAlongPathObjects(n,e,f, Path, None, NodeStart,
4153 HasAngles, Angles, LinearVariation,
4154 HasRefPoint, RefPoint, MakeGroups)
4155 if MakeGroups: return gr,er
4158 ## Generate new elements by extrusion of the given elements
4159 # The path of extrusion must be a meshed edge.
4160 # @param IDsOfElements ids of elements
4161 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
4162 # @param PathShape shape(edge) defines the sub-mesh for the path
4163 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
4164 # @param HasAngles allows the shape to be rotated around the path
4165 # to get the resulting mesh in a helical fashion
4166 # @param Angles list of angles in radians
4167 # @param HasRefPoint allows using the reference point
4168 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
4169 # The User can specify any point as the Reference Point.
4170 # @param MakeGroups forces the generation of new groups from existing ones
4171 # @param LinearVariation forces the computation of rotation angles as linear
4172 # variation of the given Angles along path steps
4173 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4174 # only SMESH::Extrusion_Error otherwise
4175 # @ingroup l2_modif_extrurev
4176 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
4177 HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
4178 MakeGroups=False, LinearVariation=False):
4179 n,e,f = [],IDsOfElements,IDsOfElements
4180 gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape,
4181 NodeStart, HasAngles, Angles,
4183 HasRefPoint, RefPoint, MakeGroups)
4184 if MakeGroups: return gr,er
4187 ## Generate new elements by extrusion of the elements which belong to the object
4188 # The path of extrusion must be a meshed edge.
4189 # @param theObject the object whose elements should be processed.
4190 # It can be a mesh, a sub-mesh or a group.
4191 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
4192 # @param PathShape shape(edge) defines the sub-mesh for the path
4193 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
4194 # @param HasAngles allows the shape to be rotated around the path
4195 # to get the resulting mesh in a helical fashion
4196 # @param Angles list of angles
4197 # @param HasRefPoint allows using the reference point
4198 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
4199 # The User can specify any point as the Reference Point.
4200 # @param MakeGroups forces the generation of new groups from existing ones
4201 # @param LinearVariation forces the computation of rotation angles as linear
4202 # variation of the given Angles along path steps
4203 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4204 # only SMESH::Extrusion_Error otherwise
4205 # @ingroup l2_modif_extrurev
4206 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
4207 HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
4208 MakeGroups=False, LinearVariation=False):
4209 n,e,f = [],theObject,theObject
4210 gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart,
4211 HasAngles, Angles, LinearVariation,
4212 HasRefPoint, RefPoint, MakeGroups)
4213 if MakeGroups: return gr,er
4216 ## Generate new elements by extrusion of mesh segments which belong to the object
4217 # The path of extrusion must be a meshed edge.
4218 # @param theObject the object whose 1D elements should be processed.
4219 # It can be a mesh, a sub-mesh or a group.
4220 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
4221 # @param PathShape shape(edge) defines the sub-mesh for the path
4222 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
4223 # @param HasAngles allows the shape to be rotated around the path
4224 # to get the resulting mesh in a helical fashion
4225 # @param Angles list of angles
4226 # @param HasRefPoint allows using the reference point
4227 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
4228 # The User can specify any point as the Reference Point.
4229 # @param MakeGroups forces the generation of new groups from existing ones
4230 # @param LinearVariation forces the computation of rotation angles as linear
4231 # variation of the given Angles along path steps
4232 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4233 # only SMESH::Extrusion_Error otherwise
4234 # @ingroup l2_modif_extrurev
4235 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
4236 HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
4237 MakeGroups=False, LinearVariation=False):
4238 n,e,f = [],theObject,[]
4239 gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart,
4240 HasAngles, Angles, LinearVariation,
4241 HasRefPoint, RefPoint, MakeGroups)
4242 if MakeGroups: return gr,er
4245 ## Generate new elements by extrusion of faces which belong to the object
4246 # The path of extrusion must be a meshed edge.
4247 # @param theObject the object whose 2D elements should be processed.
4248 # It can be a mesh, a sub-mesh or a group.
4249 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
4250 # @param PathShape shape(edge) defines the sub-mesh for the path
4251 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
4252 # @param HasAngles allows the shape to be rotated around the path
4253 # to get the resulting mesh in a helical fashion
4254 # @param Angles list of angles
4255 # @param HasRefPoint allows using the reference point
4256 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
4257 # The User can specify any point as the Reference Point.
4258 # @param MakeGroups forces the generation of new groups from existing ones
4259 # @param LinearVariation forces the computation of rotation angles as linear
4260 # variation of the given Angles along path steps
4261 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4262 # only SMESH::Extrusion_Error otherwise
4263 # @ingroup l2_modif_extrurev
4264 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
4265 HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
4266 MakeGroups=False, LinearVariation=False):
4267 n,e,f = [],[],theObject
4268 gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart,
4269 HasAngles, Angles, LinearVariation,
4270 HasRefPoint, RefPoint, MakeGroups)
4271 if MakeGroups: return gr,er
4274 ## Create a symmetrical copy of mesh elements
4275 # @param IDsOfElements list of elements ids
4276 # @param Mirror is AxisStruct or geom object(point, line, plane)
4277 # @param theMirrorType smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE
4278 # If the Mirror is a geom object this parameter is unnecessary
4279 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
4280 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4281 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4282 # @ingroup l2_modif_trsf
4283 def Mirror(self, IDsOfElements, Mirror, theMirrorType=None, Copy=0, MakeGroups=False):
4284 if IDsOfElements == []:
4285 IDsOfElements = self.GetElementsId()
4286 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4287 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
4288 theMirrorType = Mirror._mirrorType
4290 self.mesh.SetParameters(Mirror.parameters)
4291 if Copy and MakeGroups:
4292 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
4293 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
4296 ## Create a new mesh by a symmetrical copy of mesh elements
4297 # @param IDsOfElements the list of elements ids
4298 # @param Mirror is AxisStruct or geom object (point, line, plane)
4299 # @param theMirrorType smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE
4300 # If the Mirror is a geom object this parameter is unnecessary
4301 # @param MakeGroups to generate new groups from existing ones
4302 # @param NewMeshName a name of the new mesh to create
4303 # @return instance of Mesh class
4304 # @ingroup l2_modif_trsf
4305 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType=0, MakeGroups=0, NewMeshName=""):
4306 if IDsOfElements == []:
4307 IDsOfElements = self.GetElementsId()
4308 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4309 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
4310 theMirrorType = Mirror._mirrorType
4312 self.mesh.SetParameters(Mirror.parameters)
4313 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
4314 MakeGroups, NewMeshName)
4315 return Mesh(self.smeshpyD,self.geompyD,mesh)
4317 ## Create a symmetrical copy of the object
4318 # @param theObject mesh, submesh or group
4319 # @param Mirror AxisStruct or geom object (point, line, plane)
4320 # @param theMirrorType smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE
4321 # If the Mirror is a geom object this parameter is unnecessary
4322 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
4323 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4324 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4325 # @ingroup l2_modif_trsf
4326 def MirrorObject (self, theObject, Mirror, theMirrorType=None, Copy=0, MakeGroups=False):
4327 if ( isinstance( theObject, Mesh )):
4328 theObject = theObject.GetMesh()
4329 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4330 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
4331 theMirrorType = Mirror._mirrorType
4333 self.mesh.SetParameters(Mirror.parameters)
4334 if Copy and MakeGroups:
4335 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
4336 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
4339 ## Create a new mesh by a symmetrical copy of the object
4340 # @param theObject mesh, submesh or group
4341 # @param Mirror AxisStruct or geom object (point, line, plane)
4342 # @param theMirrorType smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE
4343 # If the Mirror is a geom object this parameter is unnecessary
4344 # @param MakeGroups forces the generation of new groups from existing ones
4345 # @param NewMeshName the name of the new mesh to create
4346 # @return instance of Mesh class
4347 # @ingroup l2_modif_trsf
4348 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType=0,MakeGroups=0,NewMeshName=""):
4349 if ( isinstance( theObject, Mesh )):
4350 theObject = theObject.GetMesh()
4351 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4352 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
4353 theMirrorType = Mirror._mirrorType
4355 self.mesh.SetParameters(Mirror.parameters)
4356 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
4357 MakeGroups, NewMeshName)
4358 return Mesh( self.smeshpyD,self.geompyD,mesh )
4360 ## Translate the elements
4361 # @param IDsOfElements list of elements ids
4362 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
4363 # @param Copy allows copying the translated elements
4364 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4365 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4366 # @ingroup l2_modif_trsf
4367 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
4368 if IDsOfElements == []:
4369 IDsOfElements = self.GetElementsId()
4370 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
4371 Vector = self.smeshpyD.GetDirStruct(Vector)
4372 if isinstance( Vector, list ):
4373 Vector = self.smeshpyD.MakeDirStruct(*Vector)
4374 self.mesh.SetParameters(Vector.PS.parameters)
4375 if Copy and MakeGroups:
4376 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
4377 self.editor.Translate(IDsOfElements, Vector, Copy)
4380 ## Create a new mesh of translated elements
4381 # @param IDsOfElements list of elements ids
4382 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
4383 # @param MakeGroups forces the generation of new groups from existing ones
4384 # @param NewMeshName the name of the newly created mesh
4385 # @return instance of Mesh class
4386 # @ingroup l2_modif_trsf
4387 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
4388 if IDsOfElements == []:
4389 IDsOfElements = self.GetElementsId()
4390 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
4391 Vector = self.smeshpyD.GetDirStruct(Vector)
4392 if isinstance( Vector, list ):
4393 Vector = self.smeshpyD.MakeDirStruct(*Vector)
4394 self.mesh.SetParameters(Vector.PS.parameters)
4395 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
4396 return Mesh ( self.smeshpyD, self.geompyD, mesh )
4398 ## Translate the object
4399 # @param theObject the object to translate (mesh, submesh, or group)
4400 # @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
4401 # @param Copy allows copying the translated elements
4402 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4403 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4404 # @ingroup l2_modif_trsf
4405 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
4406 if ( isinstance( theObject, Mesh )):
4407 theObject = theObject.GetMesh()
4408 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
4409 Vector = self.smeshpyD.GetDirStruct(Vector)
4410 if isinstance( Vector, list ):
4411 Vector = self.smeshpyD.MakeDirStruct(*Vector)
4412 self.mesh.SetParameters(Vector.PS.parameters)
4413 if Copy and MakeGroups:
4414 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
4415 self.editor.TranslateObject(theObject, Vector, Copy)
4418 ## Create a new mesh from the translated object
4419 # @param theObject the object to translate (mesh, submesh, or group)
4420 # @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
4421 # @param MakeGroups forces the generation of new groups from existing ones
4422 # @param NewMeshName the name of the newly created mesh
4423 # @return instance of Mesh class
4424 # @ingroup l2_modif_trsf
4425 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
4426 if isinstance( theObject, Mesh ):
4427 theObject = theObject.GetMesh()
4428 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
4429 Vector = self.smeshpyD.GetDirStruct(Vector)
4430 if isinstance( Vector, list ):
4431 Vector = self.smeshpyD.MakeDirStruct(*Vector)
4432 self.mesh.SetParameters(Vector.PS.parameters)
4433 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
4434 return Mesh( self.smeshpyD, self.geompyD, mesh )
4439 # @param theObject - the object to translate (mesh, submesh, or group)
4440 # @param thePoint - base point for scale (SMESH.PointStruct or list of 3 coordinates)
4441 # @param theScaleFact - list of 1-3 scale factors for axises
4442 # @param Copy - allows copying the translated elements
4443 # @param MakeGroups - forces the generation of new groups from existing
4445 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
4446 # empty list otherwise
4447 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
4448 unRegister = genObjUnRegister()
4449 if ( isinstance( theObject, Mesh )):
4450 theObject = theObject.GetMesh()
4451 if ( isinstance( theObject, list )):
4452 theObject = self.GetIDSource(theObject, SMESH.ALL)
4453 unRegister.set( theObject )
4454 if ( isinstance( thePoint, list )):
4455 thePoint = PointStruct( thePoint[0], thePoint[1], thePoint[2] )
4456 if ( isinstance( theScaleFact, float )):
4457 theScaleFact = [theScaleFact]
4458 if ( isinstance( theScaleFact, int )):
4459 theScaleFact = [ float(theScaleFact)]
4461 self.mesh.SetParameters(thePoint.parameters)
4463 if Copy and MakeGroups:
4464 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
4465 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
4468 ## Create a new mesh from the translated object
4469 # @param theObject - the object to translate (mesh, submesh, or group)
4470 # @param thePoint - base point for scale (SMESH.PointStruct or list of 3 coordinates)
4471 # @param theScaleFact - list of 1-3 scale factors for axises
4472 # @param MakeGroups - forces the generation of new groups from existing ones
4473 # @param NewMeshName - the name of the newly created mesh
4474 # @return instance of Mesh class
4475 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
4476 unRegister = genObjUnRegister()
4477 if (isinstance(theObject, Mesh)):
4478 theObject = theObject.GetMesh()
4479 if ( isinstance( theObject, list )):
4480 theObject = self.GetIDSource(theObject,SMESH.ALL)
4481 unRegister.set( theObject )
4482 if ( isinstance( thePoint, list )):
4483 thePoint = PointStruct( thePoint[0], thePoint[1], thePoint[2] )
4484 if ( isinstance( theScaleFact, float )):
4485 theScaleFact = [theScaleFact]
4486 if ( isinstance( theScaleFact, int )):
4487 theScaleFact = [ float(theScaleFact)]
4489 self.mesh.SetParameters(thePoint.parameters)
4490 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
4491 MakeGroups, NewMeshName)
4492 return Mesh( self.smeshpyD, self.geompyD, mesh )
4496 ## Rotate the elements
4497 # @param IDsOfElements list of elements ids
4498 # @param Axis the axis of rotation (AxisStruct or geom line)
4499 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4500 # @param Copy allows copying the rotated elements
4501 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4502 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4503 # @ingroup l2_modif_trsf
4504 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
4505 if IDsOfElements == []:
4506 IDsOfElements = self.GetElementsId()
4507 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4508 Axis = self.smeshpyD.GetAxisStruct(Axis)
4509 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4510 Parameters = Axis.parameters + var_separator + Parameters
4511 self.mesh.SetParameters(Parameters)
4512 if Copy and MakeGroups:
4513 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
4514 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
4517 ## Create a new mesh of rotated elements
4518 # @param IDsOfElements list of element ids
4519 # @param Axis the axis of rotation (AxisStruct or geom line)
4520 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4521 # @param MakeGroups forces the generation of new groups from existing ones
4522 # @param NewMeshName the name of the newly created mesh
4523 # @return instance of Mesh class
4524 # @ingroup l2_modif_trsf
4525 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
4526 if IDsOfElements == []:
4527 IDsOfElements = self.GetElementsId()
4528 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4529 Axis = self.smeshpyD.GetAxisStruct(Axis)
4530 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4531 Parameters = Axis.parameters + var_separator + Parameters
4532 self.mesh.SetParameters(Parameters)
4533 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
4534 MakeGroups, NewMeshName)
4535 return Mesh( self.smeshpyD, self.geompyD, mesh )
4537 ## Rotate the object
4538 # @param theObject the object to rotate( mesh, submesh, or group)
4539 # @param Axis the axis of rotation (AxisStruct or geom line)
4540 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4541 # @param Copy allows copying the rotated elements
4542 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4543 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4544 # @ingroup l2_modif_trsf
4545 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
4546 if (isinstance(theObject, Mesh)):
4547 theObject = theObject.GetMesh()
4548 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4549 Axis = self.smeshpyD.GetAxisStruct(Axis)
4550 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4551 Parameters = Axis.parameters + ":" + Parameters
4552 self.mesh.SetParameters(Parameters)
4553 if Copy and MakeGroups:
4554 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
4555 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
4558 ## Create a new mesh from the rotated object
4559 # @param theObject the object to rotate (mesh, submesh, or group)
4560 # @param Axis the axis of rotation (AxisStruct or geom line)
4561 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4562 # @param MakeGroups forces the generation of new groups from existing ones
4563 # @param NewMeshName the name of the newly created mesh
4564 # @return instance of Mesh class
4565 # @ingroup l2_modif_trsf
4566 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
4567 if (isinstance( theObject, Mesh )):
4568 theObject = theObject.GetMesh()
4569 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4570 Axis = self.smeshpyD.GetAxisStruct(Axis)
4571 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4572 Parameters = Axis.parameters + ":" + Parameters
4573 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
4574 MakeGroups, NewMeshName)
4575 self.mesh.SetParameters(Parameters)
4576 return Mesh( self.smeshpyD, self.geompyD, mesh )
4578 ## Find groups of adjacent nodes within Tolerance.
4579 # @param Tolerance the value of tolerance
4580 # @param SeparateCornerAndMediumNodes if @c True, in quadratic mesh puts
4581 # corner and medium nodes in separate groups thus preventing
4582 # their further merge.
4583 # @return the list of groups of nodes IDs (e.g. [[1,12,13],[4,25]])
4584 # @ingroup l2_modif_trsf
4585 def FindCoincidentNodes (self, Tolerance, SeparateCornerAndMediumNodes=False):
4586 return self.editor.FindCoincidentNodes( Tolerance, SeparateCornerAndMediumNodes )
4588 ## Find groups of ajacent nodes within Tolerance.
4589 # @param Tolerance the value of tolerance
4590 # @param SubMeshOrGroup SubMesh, Group or Filter
4591 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
4592 # @param SeparateCornerAndMediumNodes if @c True, in quadratic mesh puts
4593 # corner and medium nodes in separate groups thus preventing
4594 # their further merge.
4595 # @return the list of groups of nodes IDs (e.g. [[1,12,13],[4,25]])
4596 # @ingroup l2_modif_trsf
4597 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance,
4598 exceptNodes=[], SeparateCornerAndMediumNodes=False):
4599 unRegister = genObjUnRegister()
4600 if (isinstance( SubMeshOrGroup, Mesh )):
4601 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
4602 if not isinstance( exceptNodes, list ):
4603 exceptNodes = [ exceptNodes ]
4604 if exceptNodes and isinstance( exceptNodes[0], int ):
4605 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE )]
4606 unRegister.set( exceptNodes )
4607 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,
4608 exceptNodes, SeparateCornerAndMediumNodes)
4611 # @param GroupsOfNodes a list of groups of nodes IDs for merging
4612 # (e.g. [[1,12,13],[25,4]], then nodes 12, 13 and 4 will be removed and replaced
4613 # by nodes 1 and 25 correspondingly in all elements and groups
4614 # @param NodesToKeep nodes to keep in the mesh: a list of groups, sub-meshes or node IDs.
4615 # If @a NodesToKeep does not include a node to keep for some group to merge,
4616 # then the first node in the group is kept.
4617 # @param AvoidMakingHoles prevent merging nodes which cause removal of elements becoming
4619 # @ingroup l2_modif_trsf
4620 def MergeNodes (self, GroupsOfNodes, NodesToKeep=[], AvoidMakingHoles=False):
4621 # NodesToKeep are converted to SMESH_IDSource in meshEditor.MergeNodes()
4622 self.editor.MergeNodes( GroupsOfNodes, NodesToKeep, AvoidMakingHoles )
4624 ## Find the elements built on the same nodes.
4625 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
4626 # @return the list of groups of equal elements IDs (e.g. [[1,12,13],[4,25]])
4627 # @ingroup l2_modif_trsf
4628 def FindEqualElements (self, MeshOrSubMeshOrGroup=None):
4629 if not MeshOrSubMeshOrGroup:
4630 MeshOrSubMeshOrGroup=self.mesh
4631 elif isinstance( MeshOrSubMeshOrGroup, Mesh ):
4632 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4633 return self.editor.FindEqualElements( MeshOrSubMeshOrGroup )
4635 ## Merge elements in each given group.
4636 # @param GroupsOfElementsID a list of groups of elements IDs for merging
4637 # (e.g. [[1,12,13],[25,4]], then elements 12, 13 and 4 will be removed and
4638 # replaced by elements 1 and 25 in all groups)
4639 # @ingroup l2_modif_trsf
4640 def MergeElements(self, GroupsOfElementsID):
4641 self.editor.MergeElements(GroupsOfElementsID)
4643 ## Leave one element and remove all other elements built on the same nodes.
4644 # @ingroup l2_modif_trsf
4645 def MergeEqualElements(self):
4646 self.editor.MergeEqualElements()
4648 ## Return groups of FreeBorder's coincident within the given tolerance.
4649 # @param tolerance the tolerance. If the tolerance <= 0.0 then one tenth of an average
4650 # size of elements adjacent to free borders being compared is used.
4651 # @return SMESH.CoincidentFreeBorders structure
4652 # @ingroup l2_modif_trsf
4653 def FindCoincidentFreeBorders (self, tolerance=0.):
4654 return self.editor.FindCoincidentFreeBorders( tolerance )
4656 ## Sew FreeBorder's of each group
4657 # @param freeBorders either a SMESH.CoincidentFreeBorders structure or a list of lists
4658 # where each enclosed list contains node IDs of a group of coincident free
4659 # borders such that each consequent triple of IDs within a group describes
4660 # a free border in a usual way: n1, n2, nLast - i.e. 1st node, 2nd node and
4661 # last node of a border.
4662 # For example [[1, 2, 10, 20, 21, 40], [11, 12, 15, 55, 54, 41]] describes two
4663 # groups of coincident free borders, each group including two borders.
4664 # @param createPolygons if @c True faces adjacent to free borders are converted to
4665 # polygons if a node of opposite border falls on a face edge, else such
4666 # faces are split into several ones.
4667 # @param createPolyhedra if @c True volumes adjacent to free borders are converted to
4668 # polyhedra if a node of opposite border falls on a volume edge, else such
4669 # volumes, if any, remain intact and the mesh becomes non-conformal.
4670 # @return a number of successfully sewed groups
4671 # @ingroup l2_modif_trsf
4672 def SewCoincidentFreeBorders (self, freeBorders, createPolygons=False, createPolyhedra=False):
4673 if freeBorders and isinstance( freeBorders, list ):
4674 # construct SMESH.CoincidentFreeBorders
4675 if isinstance( freeBorders[0], int ):
4676 freeBorders = [freeBorders]
4678 coincidentGroups = []
4679 for nodeList in freeBorders:
4680 if not nodeList or len( nodeList ) % 3:
4681 raise ValueError("Wrong number of nodes in this group: %s" % nodeList)
4684 group.append ( SMESH.FreeBorderPart( len(borders), 0, 1, 2 ))
4685 borders.append( SMESH.FreeBorder( nodeList[:3] ))
4686 nodeList = nodeList[3:]
4688 coincidentGroups.append( group )
4690 freeBorders = SMESH.CoincidentFreeBorders( borders, coincidentGroups )
4692 return self.editor.SewCoincidentFreeBorders( freeBorders, createPolygons, createPolyhedra )
4695 # @return SMESH::Sew_Error
4696 # @ingroup l2_modif_trsf
4697 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4698 FirstNodeID2, SecondNodeID2, LastNodeID2,
4699 CreatePolygons, CreatePolyedrs):
4700 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4701 FirstNodeID2, SecondNodeID2, LastNodeID2,
4702 CreatePolygons, CreatePolyedrs)
4704 ## Sew conform free borders
4705 # @return SMESH::Sew_Error
4706 # @ingroup l2_modif_trsf
4707 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4708 FirstNodeID2, SecondNodeID2):
4709 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4710 FirstNodeID2, SecondNodeID2)
4712 ## Sew border to side
4713 # @return SMESH::Sew_Error
4714 # @ingroup l2_modif_trsf
4715 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4716 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4717 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4718 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4720 ## Sew two sides of a mesh. The nodes belonging to Side1 are
4721 # merged with the nodes of elements of Side2.
4722 # The number of elements in theSide1 and in theSide2 must be
4723 # equal and they should have similar nodal connectivity.
4724 # The nodes to merge should belong to side borders and
4725 # the first node should be linked to the second.
4726 # @return SMESH::Sew_Error
4727 # @ingroup l2_modif_trsf
4728 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4729 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4730 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4731 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4732 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4733 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4735 ## Set new nodes for the given element.
4736 # @param ide the element id
4737 # @param newIDs nodes ids
4738 # @return If the number of nodes does not correspond to the type of element - return false
4739 # @ingroup l2_modif_edit
4740 def ChangeElemNodes(self, ide, newIDs):
4741 return self.editor.ChangeElemNodes(ide, newIDs)
4743 ## If during the last operation of MeshEditor some nodes were
4744 # created, this method return the list of their IDs, \n
4745 # if new nodes were not created - return empty list
4746 # @return the list of integer values (can be empty)
4747 # @ingroup l2_modif_add
4748 def GetLastCreatedNodes(self):
4749 return self.editor.GetLastCreatedNodes()
4751 ## If during the last operation of MeshEditor some elements were
4752 # created this method return the list of their IDs, \n
4753 # if new elements were not created - return empty list
4754 # @return the list of integer values (can be empty)
4755 # @ingroup l2_modif_add
4756 def GetLastCreatedElems(self):
4757 return self.editor.GetLastCreatedElems()
4759 ## Forget what nodes and elements were created by the last mesh edition operation
4760 # @ingroup l2_modif_add
4761 def ClearLastCreated(self):
4762 self.editor.ClearLastCreated()
4764 ## Create duplicates of given elements, i.e. create new elements based on the
4765 # same nodes as the given ones.
4766 # @param theElements - container of elements to duplicate. It can be a Mesh,
4767 # sub-mesh, group, filter or a list of element IDs. If \a theElements is
4768 # a Mesh, elements of highest dimension are duplicated
4769 # @param theGroupName - a name of group to contain the generated elements.
4770 # If a group with such a name already exists, the new elements
4771 # are added to the existng group, else a new group is created.
4772 # If \a theGroupName is empty, new elements are not added
4774 # @return a group where the new elements are added. None if theGroupName == "".
4775 # @ingroup l2_modif_duplicat
4776 def DoubleElements(self, theElements, theGroupName=""):
4777 unRegister = genObjUnRegister()
4778 if isinstance( theElements, Mesh ):
4779 theElements = theElements.mesh
4780 elif isinstance( theElements, list ):
4781 theElements = self.GetIDSource( theElements, SMESH.ALL )
4782 unRegister.set( theElements )
4783 return self.editor.DoubleElements(theElements, theGroupName)
4785 ## Create a hole in a mesh by doubling the nodes of some particular elements
4786 # @param theNodes identifiers of nodes to be doubled
4787 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4788 # nodes. If list of element identifiers is empty then nodes are doubled but
4789 # they not assigned to elements
4790 # @return TRUE if operation has been completed successfully, FALSE otherwise
4791 # @ingroup l2_modif_duplicat
4792 def DoubleNodes(self, theNodes, theModifiedElems):
4793 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4795 ## Create a hole in a mesh by doubling the nodes of some particular elements
4796 # This method provided for convenience works as DoubleNodes() described above.
4797 # @param theNodeId identifiers of node to be doubled
4798 # @param theModifiedElems identifiers of elements to be updated
4799 # @return TRUE if operation has been completed successfully, FALSE otherwise
4800 # @ingroup l2_modif_duplicat
4801 def DoubleNode(self, theNodeId, theModifiedElems):
4802 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4804 ## Create a hole in a mesh by doubling the nodes of some particular elements
4805 # This method provided for convenience works as DoubleNodes() described above.
4806 # @param theNodes group of nodes to be doubled
4807 # @param theModifiedElems group of elements to be updated.
4808 # @param theMakeGroup forces the generation of a group containing new nodes.
4809 # @return TRUE or a created group if operation has been completed successfully,
4810 # FALSE or None otherwise
4811 # @ingroup l2_modif_duplicat
4812 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4814 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4815 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4817 ## Create a hole in a mesh by doubling the nodes of some particular elements
4818 # This method provided for convenience works as DoubleNodes() described above.
4819 # @param theNodes list of groups of nodes to be doubled
4820 # @param theModifiedElems list of groups of elements to be updated.
4821 # @param theMakeGroup forces the generation of a group containing new nodes.
4822 # @return TRUE if operation has been completed successfully, FALSE otherwise
4823 # @ingroup l2_modif_duplicat
4824 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4826 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4827 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4829 ## Create a hole in a mesh by doubling the nodes of some particular elements
4830 # @param theElems - the list of elements (edges or faces) to be replicated
4831 # The nodes for duplication could be found from these elements
4832 # @param theNodesNot - list of nodes to NOT replicate
4833 # @param theAffectedElems - the list of elements (cells and edges) to which the
4834 # replicated nodes should be associated to.
4835 # @return TRUE if operation has been completed successfully, FALSE otherwise
4836 # @ingroup l2_modif_duplicat
4837 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4838 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4840 ## Create a hole in a mesh by doubling the nodes of some particular elements
4841 # @param theElems - the list of elements (edges or faces) to be replicated
4842 # The nodes for duplication could be found from these elements
4843 # @param theNodesNot - list of nodes to NOT replicate
4844 # @param theShape - shape to detect affected elements (element which geometric center
4845 # located on or inside shape).
4846 # The replicated nodes should be associated to affected elements.
4847 # @return TRUE if operation has been completed successfully, FALSE otherwise
4848 # @ingroup l2_modif_duplicat
4849 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4850 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4852 ## Create a hole in a mesh by doubling the nodes of some particular elements
4853 # This method provided for convenience works as DoubleNodes() described above.
4854 # @param theElems - group of of elements (edges or faces) to be replicated
4855 # @param theNodesNot - group of nodes not to replicated
4856 # @param theAffectedElems - group of elements to which the replicated nodes
4857 # should be associated to.
4858 # @param theMakeGroup forces the generation of a group containing new elements.
4859 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4860 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4861 # FALSE or None otherwise
4862 # @ingroup l2_modif_duplicat
4863 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4864 theMakeGroup=False, theMakeNodeGroup=False):
4865 if theMakeGroup or theMakeNodeGroup:
4866 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4868 theMakeGroup, theMakeNodeGroup)
4869 if theMakeGroup and theMakeNodeGroup:
4872 return twoGroups[ int(theMakeNodeGroup) ]
4873 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4875 ## Create a hole in a mesh by doubling the nodes of some particular elements
4876 # This method provided for convenience works as DoubleNodes() described above.
4877 # @param theElems - group of of elements (edges or faces) to be replicated
4878 # @param theNodesNot - group of nodes not to replicated
4879 # @param theShape - shape to detect affected elements (element which geometric center
4880 # located on or inside shape).
4881 # The replicated nodes should be associated to affected elements.
4882 # @ingroup l2_modif_duplicat
4883 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4884 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4886 ## Create a hole in a mesh by doubling the nodes of some particular elements
4887 # This method provided for convenience works as DoubleNodes() described above.
4888 # @param theElems - list of groups of elements (edges or faces) to be replicated
4889 # @param theNodesNot - list of groups of nodes not to replicated
4890 # @param theAffectedElems - group of elements to which the replicated nodes
4891 # should be associated to.
4892 # @param theMakeGroup forces the generation of a group containing new elements.
4893 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4894 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4895 # FALSE or None otherwise
4896 # @ingroup l2_modif_duplicat
4897 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4898 theMakeGroup=False, theMakeNodeGroup=False):
4899 if theMakeGroup or theMakeNodeGroup:
4900 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4902 theMakeGroup, theMakeNodeGroup)
4903 if theMakeGroup and theMakeNodeGroup:
4906 return twoGroups[ int(theMakeNodeGroup) ]
4907 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4909 ## Create a hole in a mesh by doubling the nodes of some particular elements
4910 # This method provided for convenience works as DoubleNodes() described above.
4911 # @param theElems - list of groups of elements (edges or faces) to be replicated
4912 # @param theNodesNot - list of groups of nodes not to replicated
4913 # @param theShape - shape to detect affected elements (element which geometric center
4914 # located on or inside shape).
4915 # The replicated nodes should be associated to affected elements.
4916 # @return TRUE if operation has been completed successfully, FALSE otherwise
4917 # @ingroup l2_modif_duplicat
4918 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4919 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4921 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4922 # This method is the first step of DoubleNodeElemGroupsInRegion.
4923 # @param theElems - list of groups of elements (edges or faces) to be replicated
4924 # @param theNodesNot - list of groups of nodes not to replicated
4925 # @param theShape - shape to detect affected elements (element which geometric center
4926 # located on or inside shape).
4927 # The replicated nodes should be associated to affected elements.
4928 # @return groups of affected elements
4929 # @ingroup l2_modif_duplicat
4930 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4931 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4933 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4934 # The list of groups must describe a partition of the mesh volumes.
4935 # The nodes of the internal faces at the boundaries of the groups are doubled.
4936 # In option, the internal faces are replaced by flat elements.
4937 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4938 # @param theDomains - list of groups of volumes
4939 # @param createJointElems - if TRUE, create the elements
4940 # @param onAllBoundaries - if TRUE, the nodes and elements are also created on
4941 # the boundary between \a theDomains and the rest mesh
4942 # @return TRUE if operation has been completed successfully, FALSE otherwise
4943 # @ingroup l2_modif_duplicat
4944 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems, onAllBoundaries=False ):
4945 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems, onAllBoundaries )
4947 ## Double nodes on some external faces and create flat elements.
4948 # Flat elements are mainly used by some types of mechanic calculations.
4950 # Each group of the list must be constituted of faces.
4951 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4952 # @param theGroupsOfFaces - list of groups of faces
4953 # @return TRUE if operation has been completed successfully, FALSE otherwise
4954 # @ingroup l2_modif_duplicat
4955 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4956 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4958 ## identify all the elements around a geom shape, get the faces delimiting the hole
4960 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4961 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4963 def _getFunctor(self, funcType ):
4964 fn = self.functors[ EnumToLong(funcType) ]
4966 fn = self.smeshpyD.GetFunctor(funcType)
4967 fn.SetMesh(self.mesh)
4968 self.functors[ EnumToLong(funcType) ] = fn
4971 ## Return value of a functor for a given element
4972 # @param funcType an item of SMESH.FunctorType enum
4973 # Type "SMESH.FunctorType._items" in the Python Console to see all items.
4974 # @param elemId element or node ID
4975 # @param isElem @a elemId is ID of element or node
4976 # @return the functor value or zero in case of invalid arguments
4977 # @ingroup l1_measurements
4978 def FunctorValue(self, funcType, elemId, isElem=True):
4979 fn = self._getFunctor( funcType )
4980 if fn.GetElementType() == self.GetElementType(elemId, isElem):
4981 val = fn.GetValue(elemId)
4986 ## Get length of 1D element or sum of lengths of all 1D mesh elements
4987 # @param elemId mesh element ID (if not defined - sum of length of all 1D elements will be calculated)
4988 # @return element's length value if \a elemId is specified or sum of all 1D mesh elements' lengths otherwise
4989 # @ingroup l1_measurements
4990 def GetLength(self, elemId=None):
4993 length = self.smeshpyD.GetLength(self)
4995 length = self.FunctorValue(SMESH.FT_Length, elemId)
4998 ## Get area of 2D element or sum of areas of all 2D mesh elements
4999 # @param elemId mesh element ID (if not defined - sum of areas of all 2D elements will be calculated)
5000 # @return element's area value if \a elemId is specified or sum of all 2D mesh elements' areas otherwise
5001 # @ingroup l1_measurements
5002 def GetArea(self, elemId=None):
5005 area = self.smeshpyD.GetArea(self)
5007 area = self.FunctorValue(SMESH.FT_Area, elemId)
5010 ## Get volume of 3D element or sum of volumes of all 3D mesh elements
5011 # @param elemId mesh element ID (if not defined - sum of volumes of all 3D elements will be calculated)
5012 # @return element's volume value if \a elemId is specified or sum of all 3D mesh elements' volumes otherwise
5013 # @ingroup l1_measurements
5014 def GetVolume(self, elemId=None):
5017 volume = self.smeshpyD.GetVolume(self)
5019 volume = self.FunctorValue(SMESH.FT_Volume3D, elemId)
5022 ## Get maximum element length.
5023 # @param elemId mesh element ID
5024 # @return element's maximum length value
5025 # @ingroup l1_measurements
5026 def GetMaxElementLength(self, elemId):
5027 if self.GetElementType(elemId, True) == SMESH.VOLUME:
5028 ftype = SMESH.FT_MaxElementLength3D
5030 ftype = SMESH.FT_MaxElementLength2D
5031 return self.FunctorValue(ftype, elemId)
5033 ## Get aspect ratio of 2D or 3D element.
5034 # @param elemId mesh element ID
5035 # @return element's aspect ratio value
5036 # @ingroup l1_measurements
5037 def GetAspectRatio(self, elemId):
5038 if self.GetElementType(elemId, True) == SMESH.VOLUME:
5039 ftype = SMESH.FT_AspectRatio3D
5041 ftype = SMESH.FT_AspectRatio
5042 return self.FunctorValue(ftype, elemId)
5044 ## Get warping angle of 2D element.
5045 # @param elemId mesh element ID
5046 # @return element's warping angle value
5047 # @ingroup l1_measurements
5048 def GetWarping(self, elemId):
5049 return self.FunctorValue(SMESH.FT_Warping, elemId)
5051 ## Get minimum angle of 2D element.
5052 # @param elemId mesh element ID
5053 # @return element's minimum angle value
5054 # @ingroup l1_measurements
5055 def GetMinimumAngle(self, elemId):
5056 return self.FunctorValue(SMESH.FT_MinimumAngle, elemId)
5058 ## Get taper of 2D element.
5059 # @param elemId mesh element ID
5060 # @return element's taper value
5061 # @ingroup l1_measurements
5062 def GetTaper(self, elemId):
5063 return self.FunctorValue(SMESH.FT_Taper, elemId)
5065 ## Get skew of 2D element.
5066 # @param elemId mesh element ID
5067 # @return element's skew value
5068 # @ingroup l1_measurements
5069 def GetSkew(self, elemId):
5070 return self.FunctorValue(SMESH.FT_Skew, elemId)
5072 ## Return minimal and maximal value of a given functor.
5073 # @param funType a functor type, an item of SMESH.FunctorType enum
5074 # (one of SMESH.FunctorType._items)
5075 # @param meshPart a part of mesh (group, sub-mesh) to treat
5076 # @return tuple (min,max)
5077 # @ingroup l1_measurements
5078 def GetMinMax(self, funType, meshPart=None):
5079 unRegister = genObjUnRegister()
5080 if isinstance( meshPart, list ):
5081 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
5082 unRegister.set( meshPart )
5083 if isinstance( meshPart, Mesh ):
5084 meshPart = meshPart.mesh
5085 fun = self._getFunctor( funType )
5088 if hasattr( meshPart, "SetMesh" ):
5089 meshPart.SetMesh( self.mesh ) # set mesh to filter
5090 hist = fun.GetLocalHistogram( 1, False, meshPart )
5092 hist = fun.GetHistogram( 1, False )
5094 return hist[0].min, hist[0].max
5097 pass # end of Mesh class
5100 ## Private class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility
5101 # with old dump scripts which call SMESH_Mesh directly and not via smeshBuilder.Mesh
5103 class meshProxy(SMESH._objref_SMESH_Mesh):
5104 def __init__(self, *args):
5105 SMESH._objref_SMESH_Mesh.__init__(self, *args)
5106 def __deepcopy__(self, memo=None):
5107 new = self.__class__(self)
5109 def CreateDimGroup(self,*args): # 2 args added: nbCommonNodes, underlyingOnly
5110 if len( args ) == 3:
5111 args += SMESH.ALL_NODES, True
5112 return SMESH._objref_SMESH_Mesh.CreateDimGroup( self, *args )
5114 omniORB.registerObjref(SMESH._objref_SMESH_Mesh._NP_RepositoryId, meshProxy)
5117 ## Private class wrapping SMESH.SMESH_SubMesh in order to add Compute()
5119 class submeshProxy(SMESH._objref_SMESH_subMesh):
5120 def __init__(self, *args):
5121 SMESH._objref_SMESH_subMesh.__init__(self, *args)
5123 def __deepcopy__(self, memo=None):
5124 new = self.__class__(self)
5127 ## Compute the sub-mesh and return the status of the computation
5128 # @param refresh if @c True, Object browser is automatically updated (when running in GUI)
5129 # @return True or False
5131 # This is a method of SMESH.SMESH_submesh that can be obtained via Mesh.GetSubMesh() or
5132 # @ref smesh_algorithm.Mesh_Algorithm.GetSubMesh() "Mesh_Algorithm.GetSubMesh()".
5133 # @ingroup l2_submeshes
5134 def Compute(self,refresh=False):
5136 self.mesh = Mesh( smeshBuilder(), None, self.GetMesh())
5138 ok = self.mesh.Compute( self.GetSubShape(),refresh=[] )
5140 if salome.sg.hasDesktop():
5141 smeshgui = salome.ImportComponentGUI("SMESH")
5143 smeshgui.SetMeshIcon( salome.ObjectToID( self ), ok, (self.GetNumberOfElements()==0) )
5144 if refresh: salome.sg.updateObjBrowser()
5149 omniORB.registerObjref(SMESH._objref_SMESH_subMesh._NP_RepositoryId, submeshProxy)
5152 ## Private class used to compensate change of CORBA API of SMESH_MeshEditor for backward
5153 # compatibility with old dump scripts which call SMESH_MeshEditor directly and not via
5156 class meshEditor(SMESH._objref_SMESH_MeshEditor):
5157 def __init__(self, *args):
5158 SMESH._objref_SMESH_MeshEditor.__init__(self, *args)
5160 def __getattr__(self, name ): # method called if an attribute not found
5161 if not self.mesh: # look for name() method in Mesh class
5162 self.mesh = Mesh( None, None, SMESH._objref_SMESH_MeshEditor.GetMesh(self))
5163 if hasattr( self.mesh, name ):
5164 return getattr( self.mesh, name )
5165 if name == "ExtrusionAlongPathObjX":
5166 return getattr( self.mesh, "ExtrusionAlongPathX" ) # other method name
5167 print("meshEditor: attribute '%s' NOT FOUND" % name)
5169 def __deepcopy__(self, memo=None):
5170 new = self.__class__(self)
5172 def FindCoincidentNodes(self,*args): # a 2nd arg added (SeparateCornerAndMediumNodes)
5173 if len( args ) == 1: args += False,
5174 return SMESH._objref_SMESH_MeshEditor.FindCoincidentNodes( self, *args )
5175 def FindCoincidentNodesOnPart(self,*args): # a 3d arg added (SeparateCornerAndMediumNodes)
5176 if len( args ) == 2: args += False,
5177 return SMESH._objref_SMESH_MeshEditor.FindCoincidentNodesOnPart( self, *args )
5178 def MergeNodes(self,*args): # 2 args added (NodesToKeep,AvoidMakingHoles)
5179 if len( args ) == 1:
5180 return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], [], False )
5181 NodesToKeep = args[1]
5182 AvoidMakingHoles = args[2] if len( args ) == 3 else False
5183 unRegister = genObjUnRegister()
5185 if isinstance( NodesToKeep, list ) and isinstance( NodesToKeep[0], int ):
5186 NodesToKeep = self.MakeIDSource( NodesToKeep, SMESH.NODE )
5187 if not isinstance( NodesToKeep, list ):
5188 NodesToKeep = [ NodesToKeep ]
5189 return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], NodesToKeep, AvoidMakingHoles )
5191 omniORB.registerObjref(SMESH._objref_SMESH_MeshEditor._NP_RepositoryId, meshEditor)
5193 ## Private class wrapping SMESH.SMESH_Pattern CORBA class in order to treat Notebook
5194 # variables in some methods
5196 class Pattern(SMESH._objref_SMESH_Pattern):
5198 def LoadFromFile(self, patternTextOrFile ):
5199 text = patternTextOrFile
5200 if os.path.exists( text ):
5201 text = open( patternTextOrFile ).read()
5203 return SMESH._objref_SMESH_Pattern.LoadFromFile( self, text )
5205 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
5206 decrFun = lambda i: i-1
5207 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
5208 theMesh.SetParameters(Parameters)
5209 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
5211 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
5212 decrFun = lambda i: i-1
5213 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
5214 theMesh.SetParameters(Parameters)
5215 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
5217 def MakeMesh(self, mesh, CreatePolygons=False, CreatePolyhedra=False):
5218 if isinstance( mesh, Mesh ):
5219 mesh = mesh.GetMesh()
5220 return SMESH._objref_SMESH_Pattern.MakeMesh( self, mesh, CreatePolygons, CreatePolyhedra )
5222 # Registering the new proxy for Pattern
5223 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
5225 ## Private class used to bind methods creating algorithms to the class Mesh
5228 def __init__(self, method):
5230 self.defaultAlgoType = ""
5231 self.algoTypeToClass = {}
5232 self.method = method
5234 # Store a python class of algorithm
5235 def add(self, algoClass):
5236 if inspect.isclass(algoClass) and \
5237 hasattr(algoClass, "algoType"):
5238 self.algoTypeToClass[ algoClass.algoType ] = algoClass
5239 if not self.defaultAlgoType and \
5240 hasattr( algoClass, "isDefault") and algoClass.isDefault:
5241 self.defaultAlgoType = algoClass.algoType
5242 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
5244 # Create a copy of self and assign mesh to the copy
5245 def copy(self, mesh):
5246 other = algoCreator( self.method )
5247 other.defaultAlgoType = self.defaultAlgoType
5248 other.algoTypeToClass = self.algoTypeToClass
5252 # Create an instance of algorithm
5253 def __call__(self,algo="",geom=0,*args):
5256 if isinstance( algo, str ):
5258 elif ( isinstance( algo, geomBuilder.GEOM._objref_GEOM_Object ) and \
5259 not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object )):
5264 if isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
5266 elif not algoType and isinstance( geom, str ):
5271 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ) and not shape:
5273 elif isinstance( arg, str ) and not algoType:
5276 import traceback, sys
5277 msg = "Warning. Unexpected argument in mesh.%s() ---> %s" % ( self.method, arg )
5278 sys.stderr.write( msg + '\n' )
5279 tb = traceback.extract_stack(None,2)
5280 traceback.print_list( [tb[0]] )
5282 algoType = self.defaultAlgoType
5283 if not algoType and self.algoTypeToClass:
5284 algoType = list(self.algoTypeToClass.keys())[0]
5285 if algoType in self.algoTypeToClass:
5286 #print "Create algo",algoType
5288 return self.algoTypeToClass[ algoType ]( self.mesh, shape )
5289 raise RuntimeError( "No class found for algo type %s" % algoType)
5292 ## Private class used to substitute and store variable parameters of hypotheses.
5294 class hypMethodWrapper:
5295 def __init__(self, hyp, method):
5297 self.method = method
5298 #print "REBIND:", method.__name__
5301 # call a method of hypothesis with calling SetVarParameter() before
5302 def __call__(self,*args):
5304 return self.method( self.hyp, *args ) # hypothesis method with no args
5306 #print "MethWrapper.__call__",self.method.__name__, args
5308 parsed = ParseParameters(*args) # replace variables with their values
5309 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
5310 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
5311 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
5312 # maybe there is a replaced string arg which is not variable
5313 result = self.method( self.hyp, *args )
5314 except ValueError as detail: # raised by ParseParameters()
5316 result = self.method( self.hyp, *args )
5317 except omniORB.CORBA.BAD_PARAM:
5318 raise ValueError(detail) # wrong variable name
5323 ## A helper class that calls UnRegister() of SALOME.GenericObj'es stored in it
5325 class genObjUnRegister:
5327 def __init__(self, genObj=None):
5328 self.genObjList = []
5332 def set(self, genObj):
5333 "Store one or a list of of SALOME.GenericObj'es"
5334 if isinstance( genObj, list ):
5335 self.genObjList.extend( genObj )
5337 self.genObjList.append( genObj )
5341 for genObj in self.genObjList:
5342 if genObj and hasattr( genObj, "UnRegister" ):
5346 ## Bind methods creating mesher plug-ins to the Mesh class
5348 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
5350 #print "pluginName: ", pluginName
5351 pluginBuilderName = pluginName + "Builder"
5353 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
5354 except Exception as e:
5355 from salome_utils import verbose
5356 if verbose(): print("Exception while loading %s: %s" % ( pluginBuilderName, e ))
5358 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
5359 plugin = eval( pluginBuilderName )
5360 #print " plugin:" , str(plugin)
5362 # add methods creating algorithms to Mesh
5363 for k in dir( plugin ):
5364 if k[0] == '_': continue
5365 algo = getattr( plugin, k )
5366 #print " algo:", str(algo)
5367 if inspect.isclass(algo) and hasattr(algo, "meshMethod"):
5368 #print " meshMethod:" , str(algo.meshMethod)
5369 if not hasattr( Mesh, algo.meshMethod ):
5370 setattr( Mesh, algo.meshMethod, algoCreator( algo.meshMethod ))
5372 getattr( Mesh, algo.meshMethod ).add( algo )