1 # Copyright (C) 2007-2015 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
30 ## @defgroup l2_construct Constructing meshes
31 ## @defgroup l2_algorithms Defining Algorithms
33 ## @defgroup l3_algos_basic Basic meshing algorithms
34 ## @defgroup l3_algos_proj Projection Algorithms
35 ## @defgroup l3_algos_radialp Radial Prism
36 ## @defgroup l3_algos_segmarv Segments around Vertex
37 ## @defgroup l3_algos_3dextr 3D extrusion meshing algorithm
40 ## @defgroup l2_hypotheses Defining hypotheses
42 ## @defgroup l3_hypos_1dhyps 1D Meshing Hypotheses
43 ## @defgroup l3_hypos_2dhyps 2D Meshing Hypotheses
44 ## @defgroup l3_hypos_maxvol Max Element Volume hypothesis
45 ## @defgroup l3_hypos_quad Quadrangle Parameters hypothesis
46 ## @defgroup l3_hypos_additi Additional Hypotheses
49 ## @defgroup l2_submeshes Constructing submeshes
50 ## @defgroup l2_compounds Building Compounds
51 ## @defgroup l2_editing Editing Meshes
54 ## @defgroup l1_meshinfo Mesh Information
55 ## @defgroup l1_controls Quality controls and Filtering
56 ## @defgroup l1_grouping Grouping elements
58 ## @defgroup l2_grps_create Creating groups
59 ## @defgroup l2_grps_edit Editing groups
60 ## @defgroup l2_grps_operon Using operations on groups
61 ## @defgroup l2_grps_delete Deleting Groups
64 ## @defgroup l1_modifying Modifying meshes
66 ## @defgroup l2_modif_add Adding nodes and elements
67 ## @defgroup l2_modif_del Removing nodes and elements
68 ## @defgroup l2_modif_edit Modifying nodes and elements
69 ## @defgroup l2_modif_renumber Renumbering nodes and elements
70 ## @defgroup l2_modif_trsf Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging)
71 ## @defgroup l2_modif_movenode Moving nodes
72 ## @defgroup l2_modif_throughp Mesh through point
73 ## @defgroup l2_modif_invdiag Diagonal inversion of elements
74 ## @defgroup l2_modif_unitetri Uniting triangles
75 ## @defgroup l2_modif_changori Changing orientation of elements
76 ## @defgroup l2_modif_cutquadr Cutting elements
77 ## @defgroup l2_modif_smooth Smoothing
78 ## @defgroup l2_modif_extrurev Extrusion and Revolution
79 ## @defgroup l2_modif_patterns Pattern mapping
80 ## @defgroup l2_modif_tofromqu Convert to/from Quadratic Mesh
83 ## @defgroup l1_measurements Measurements
86 from salome.geom import geomBuilder
88 import SMESH # This is necessary for back compatibility
90 from salome.smesh.smesh_algorithm import Mesh_Algorithm
97 def __instancecheck__(cls, inst):
98 """Implement isinstance(inst, cls)."""
99 return any(cls.__subclasscheck__(c)
100 for c in {type(inst), inst.__class__})
102 def __subclasscheck__(cls, sub):
103 """Implement issubclass(sub, cls)."""
104 return type.__subclasscheck__(cls, sub) or (cls.__name__ == sub.__name__ and cls.__module__ == sub.__module__)
106 ## @addtogroup l1_auxiliary
109 ## Converts an angle from degrees to radians
110 def DegreesToRadians(AngleInDegrees):
112 return AngleInDegrees * pi / 180.0
114 import salome_notebook
115 notebook = salome_notebook.notebook
116 # Salome notebook variable separator
119 ## Return list of variable values from salome notebook.
120 # The last argument, if is callable, is used to modify values got from notebook
121 def ParseParameters(*args):
126 if args and callable( args[-1] ):
127 args, varModifFun = args[:-1], args[-1]
128 for parameter in args:
130 Parameters += str(parameter) + var_separator
132 if isinstance(parameter,str):
133 # check if there is an inexistent variable name
134 if not notebook.isVariable(parameter):
135 raise ValueError, "Variable with name '" + parameter + "' doesn't exist!!!"
136 parameter = notebook.get(parameter)
139 parameter = varModifFun(parameter)
142 Result.append(parameter)
145 Parameters = Parameters[:-1]
146 Result.append( Parameters )
147 Result.append( hasVariables )
150 # Parse parameters converting variables to radians
151 def ParseAngles(*args):
152 return ParseParameters( *( args + (DegreesToRadians, )))
154 # Substitute PointStruct.__init__() to create SMESH.PointStruct using notebook variables.
155 # Parameters are stored in PointStruct.parameters attribute
156 def __initPointStruct(point,*args):
157 point.x, point.y, point.z, point.parameters,hasVars = ParseParameters(*args)
159 SMESH.PointStruct.__init__ = __initPointStruct
161 # Substitute AxisStruct.__init__() to create SMESH.AxisStruct using notebook variables.
162 # Parameters are stored in AxisStruct.parameters attribute
163 def __initAxisStruct(ax,*args):
164 ax.x, ax.y, ax.z, ax.vx, ax.vy, ax.vz, ax.parameters,hasVars = ParseParameters(*args)
166 SMESH.AxisStruct.__init__ = __initAxisStruct
168 smeshPrecisionConfusion = 1.e-07
169 def IsEqual(val1, val2, tol=smeshPrecisionConfusion):
170 if abs(val1 - val2) < tol:
180 if isinstance(obj, SALOMEDS._objref_SObject):
184 ior = salome.orb.object_to_string(obj)
189 studies = salome.myStudyManager.GetOpenStudies()
190 for sname in studies:
191 s = salome.myStudyManager.GetStudyByName(sname)
193 sobj = s.FindObjectIOR(ior)
194 if not sobj: continue
195 return sobj.GetName()
196 if hasattr(obj, "GetName"):
197 # unknown CORBA object, having GetName() method
200 # unknown CORBA object, no GetName() method
203 if hasattr(obj, "GetName"):
204 # unknown non-CORBA object, having GetName() method
207 raise RuntimeError, "Null or invalid object"
209 ## Prints error message if a hypothesis was not assigned.
210 def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh):
212 hypType = "algorithm"
214 hypType = "hypothesis"
217 if hasattr( status, "__getitem__" ):
218 status,reason = status[0],status[1]
219 if status == HYP_UNKNOWN_FATAL :
220 reason = "for unknown reason"
221 elif status == HYP_INCOMPATIBLE :
222 reason = "this hypothesis mismatches the algorithm"
223 elif status == HYP_NOTCONFORM :
224 reason = "a non-conform mesh would be built"
225 elif status == HYP_ALREADY_EXIST :
226 if isAlgo: return # it does not influence anything
227 reason = hypType + " of the same dimension is already assigned to this shape"
228 elif status == HYP_BAD_DIM :
229 reason = hypType + " mismatches the shape"
230 elif status == HYP_CONCURENT :
231 reason = "there are concurrent hypotheses on sub-shapes"
232 elif status == HYP_BAD_SUBSHAPE :
233 reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
234 elif status == HYP_BAD_GEOMETRY:
235 reason = "geometry mismatches the expectation of the algorithm"
236 elif status == HYP_HIDDEN_ALGO:
237 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
238 elif status == HYP_HIDING_ALGO:
239 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
240 elif status == HYP_NEED_SHAPE:
241 reason = "algorithm can't work without shape"
242 elif status == HYP_INCOMPAT_HYPS:
248 where = '"%s"' % geomName
250 meshName = GetName( mesh )
251 if meshName and meshName != NO_NAME:
252 where = '"%s" in "%s"' % ( geomName, meshName )
253 if status < HYP_UNKNOWN_FATAL and where:
254 print '"%s" was assigned to %s but %s' %( hypName, where, reason )
256 print '"%s" was not assigned to %s : %s' %( hypName, where, reason )
258 print '"%s" was not assigned : %s' %( hypName, reason )
261 ## Private method. Add geom (sub-shape of the main shape) into the study if not yet there
262 def AssureGeomPublished(mesh, geom, name=''):
263 if not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
265 if not geom.GetStudyEntry() and \
266 mesh.smeshpyD.GetCurrentStudy():
268 studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
269 if studyID != mesh.geompyD.myStudyId:
270 mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
272 if not name and geom.GetShapeType() != geomBuilder.GEOM.COMPOUND:
273 # for all groups SubShapeName() returns "Compound_-1"
274 name = mesh.geompyD.SubShapeName(geom, mesh.geom)
276 name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
278 mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
281 ## Return the first vertex of a geometrical edge by ignoring orientation
282 def FirstVertexOnCurve(mesh, edge):
283 vv = mesh.geompyD.SubShapeAll( edge, geomBuilder.geomBuilder.ShapeType["VERTEX"])
285 raise TypeError, "Given object has no vertices"
286 if len( vv ) == 1: return vv[0]
287 v0 = mesh.geompyD.MakeVertexOnCurve(edge,0.)
288 xyz = mesh.geompyD.PointCoordinates( v0 ) # coords of the first vertex
289 xyz1 = mesh.geompyD.PointCoordinates( vv[0] )
290 xyz2 = mesh.geompyD.PointCoordinates( vv[1] )
293 dist1 += abs( xyz[i] - xyz1[i] )
294 dist2 += abs( xyz[i] - xyz2[i] )
300 # end of l1_auxiliary
304 # Warning: smeshInst is a singleton
310 ## This class allows to create, load or manipulate meshes
311 # It has a set of methods to create load or copy meshes, to combine several meshes.
312 # It also has methods to get infos on meshes.
313 class smeshBuilder(object, SMESH._objref_SMESH_Gen):
315 # MirrorType enumeration
316 POINT = SMESH_MeshEditor.POINT
317 AXIS = SMESH_MeshEditor.AXIS
318 PLANE = SMESH_MeshEditor.PLANE
320 # Smooth_Method enumeration
321 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
322 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
324 PrecisionConfusion = smeshPrecisionConfusion
326 # TopAbs_State enumeration
327 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
329 # Methods of splitting a hexahedron into tetrahedra
330 Hex_5Tet, Hex_6Tet, Hex_24Tet, Hex_2Prisms, Hex_4Prisms = 1, 2, 3, 1, 2
336 #print "==== __new__", engine, smeshInst, doLcc
338 if smeshInst is None:
339 # smesh engine is either retrieved from engine, or created
341 # Following test avoids a recursive loop
343 if smeshInst is not None:
344 # smesh engine not created: existing engine found
348 # FindOrLoadComponent called:
349 # 1. CORBA resolution of server
350 # 2. the __new__ method is called again
351 #print "==== smeshInst = lcc.FindOrLoadComponent ", engine, smeshInst, doLcc
352 smeshInst = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
354 # FindOrLoadComponent not called
355 if smeshInst is None:
356 # smeshBuilder instance is created from lcc.FindOrLoadComponent
357 #print "==== smeshInst = super(smeshBuilder,cls).__new__(cls) ", engine, smeshInst, doLcc
358 smeshInst = super(smeshBuilder,cls).__new__(cls)
360 # smesh engine not created: existing engine found
361 #print "==== existing ", engine, smeshInst, doLcc
363 #print "====1 ", smeshInst
366 #print "====2 ", smeshInst
371 #print "--------------- smeshbuilder __init__ ---", created
374 SMESH._objref_SMESH_Gen.__init__(self)
376 ## Dump component to the Python script
377 # This method overrides IDL function to allow default values for the parameters.
378 def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
379 return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
381 ## Set mode of DumpPython(), \a historical or \a snapshot.
382 # In the \a historical mode, the Python Dump script includes all commands
383 # performed by SMESH engine. In the \a snapshot mode, commands
384 # relating to objects removed from the Study are excluded from the script
385 # as well as commands not influencing the current state of meshes
386 def SetDumpPythonHistorical(self, isHistorical):
387 if isHistorical: val = "true"
389 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
391 ## Sets the current study and Geometry component
392 # @ingroup l1_auxiliary
393 def init_smesh(self,theStudy,geompyD = None):
395 self.SetCurrentStudy(theStudy,geompyD)
398 notebook.myStudy = theStudy
400 ## Creates a mesh. This can be either an empty mesh, possibly having an underlying geometry,
401 # or a mesh wrapping a CORBA mesh given as a parameter.
402 # @param obj either (1) a CORBA mesh (SMESH._objref_SMESH_Mesh) got e.g. by calling
403 # salome.myStudy.FindObjectID("0:1:2:3").GetObject() or
404 # (2) a Geometrical object for meshing or
406 # @param name the name for the new mesh.
407 # @return an instance of Mesh class.
408 # @ingroup l2_construct
409 def Mesh(self, obj=0, name=0):
410 if isinstance(obj,str):
412 return Mesh(self,self.geompyD,obj,name)
414 ## Returns a long value from enumeration
415 # @ingroup l1_controls
416 def EnumToLong(self,theItem):
419 ## Returns a string representation of the color.
420 # To be used with filters.
421 # @param c color value (SALOMEDS.Color)
422 # @ingroup l1_controls
423 def ColorToString(self,c):
425 if isinstance(c, SALOMEDS.Color):
426 val = "%s;%s;%s" % (c.R, c.G, c.B)
427 elif isinstance(c, str):
430 raise ValueError, "Color value should be of string or SALOMEDS.Color type"
433 ## Gets PointStruct from vertex
434 # @param theVertex a GEOM object(vertex)
435 # @return SMESH.PointStruct
436 # @ingroup l1_auxiliary
437 def GetPointStruct(self,theVertex):
438 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
439 return PointStruct(x,y,z)
441 ## Gets DirStruct from vector
442 # @param theVector a GEOM object(vector)
443 # @return SMESH.DirStruct
444 # @ingroup l1_auxiliary
445 def GetDirStruct(self,theVector):
446 vertices = self.geompyD.SubShapeAll( theVector, geomBuilder.geomBuilder.ShapeType["VERTEX"] )
447 if(len(vertices) != 2):
448 print "Error: vector object is incorrect."
450 p1 = self.geompyD.PointCoordinates(vertices[0])
451 p2 = self.geompyD.PointCoordinates(vertices[1])
452 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
453 dirst = DirStruct(pnt)
456 ## Makes DirStruct from a triplet
457 # @param x,y,z vector components
458 # @return SMESH.DirStruct
459 # @ingroup l1_auxiliary
460 def MakeDirStruct(self,x,y,z):
461 pnt = PointStruct(x,y,z)
462 return DirStruct(pnt)
464 ## Get AxisStruct from object
465 # @param theObj a GEOM object (line or plane)
466 # @return SMESH.AxisStruct
467 # @ingroup l1_auxiliary
468 def GetAxisStruct(self,theObj):
470 edges = self.geompyD.SubShapeAll( theObj, geomBuilder.geomBuilder.ShapeType["EDGE"] )
473 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
474 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
475 vertex1 = self.geompyD.PointCoordinates(vertex1)
476 vertex2 = self.geompyD.PointCoordinates(vertex2)
477 vertex3 = self.geompyD.PointCoordinates(vertex3)
478 vertex4 = self.geompyD.PointCoordinates(vertex4)
479 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
480 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
481 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] ]
482 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
483 axis._mirrorType = SMESH.SMESH_MeshEditor.PLANE
484 elif len(edges) == 1:
485 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
486 p1 = self.geompyD.PointCoordinates( vertex1 )
487 p2 = self.geompyD.PointCoordinates( vertex2 )
488 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
489 axis._mirrorType = SMESH.SMESH_MeshEditor.AXIS
490 elif theObj.GetShapeType() == GEOM.VERTEX:
491 x,y,z = self.geompyD.PointCoordinates( theObj )
492 axis = AxisStruct( x,y,z, 1,0,0,)
493 axis._mirrorType = SMESH.SMESH_MeshEditor.POINT
496 # From SMESH_Gen interface:
497 # ------------------------
499 ## Sets the given name to the object
500 # @param obj the object to rename
501 # @param name a new object name
502 # @ingroup l1_auxiliary
503 def SetName(self, obj, name):
504 if isinstance( obj, Mesh ):
506 elif isinstance( obj, Mesh_Algorithm ):
507 obj = obj.GetAlgorithm()
508 ior = salome.orb.object_to_string(obj)
509 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
511 ## Sets the current mode
512 # @ingroup l1_auxiliary
513 def SetEmbeddedMode( self,theMode ):
514 #self.SetEmbeddedMode(theMode)
515 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
517 ## Gets the current mode
518 # @ingroup l1_auxiliary
519 def IsEmbeddedMode(self):
520 #return self.IsEmbeddedMode()
521 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
523 ## Sets the current study
524 # @ingroup l1_auxiliary
525 def SetCurrentStudy( self, theStudy, geompyD = None ):
526 #self.SetCurrentStudy(theStudy)
528 from salome.geom import geomBuilder
529 geompyD = geomBuilder.geom
532 self.SetGeomEngine(geompyD)
533 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
536 notebook = salome_notebook.NoteBook( theStudy )
538 notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
540 sb = theStudy.NewBuilder()
541 sc = theStudy.FindComponent("SMESH")
542 if sc: sb.LoadWith(sc, self)
546 ## Gets the current study
547 # @ingroup l1_auxiliary
548 def GetCurrentStudy(self):
549 #return self.GetCurrentStudy()
550 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
552 ## Creates a Mesh object importing data from the given UNV file
553 # @return an instance of Mesh class
555 def CreateMeshesFromUNV( self,theFileName ):
556 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
557 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
560 ## Creates a Mesh object(s) importing data from the given MED file
561 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
563 def CreateMeshesFromMED( self,theFileName ):
564 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
565 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
566 return aMeshes, aStatus
568 ## Creates a Mesh object(s) importing data from the given SAUV file
569 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
571 def CreateMeshesFromSAUV( self,theFileName ):
572 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
573 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
574 return aMeshes, aStatus
576 ## Creates a Mesh object importing data from the given STL file
577 # @return an instance of Mesh class
579 def CreateMeshesFromSTL( self, theFileName ):
580 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
581 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
584 ## Creates Mesh objects importing data from the given CGNS file
585 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
587 def CreateMeshesFromCGNS( self, theFileName ):
588 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
589 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
590 return aMeshes, aStatus
592 ## Creates a Mesh object importing data from the given GMF file.
593 # GMF files must have .mesh extension for the ASCII format and .meshb for
595 # @return [ an instance of Mesh class, SMESH.ComputeError ]
597 def CreateMeshesFromGMF( self, theFileName ):
598 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
601 if error.comment: print "*** CreateMeshesFromGMF() errors:\n", error.comment
602 return Mesh(self, self.geompyD, aSmeshMesh), error
604 ## Concatenate the given meshes into one mesh.
605 # @return an instance of Mesh class
606 # @param meshes the meshes to combine into one mesh
607 # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
608 # @param mergeNodesAndElements if true, equal nodes and elements aremerged
609 # @param mergeTolerance tolerance for merging nodes
610 # @param allGroups forces creation of groups of all elements
611 # @param name name of a new mesh
612 def Concatenate( self, meshes, uniteIdenticalGroups,
613 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
615 if not meshes: return None
616 for i,m in enumerate(meshes):
617 if isinstance(m, Mesh):
618 meshes[i] = m.GetMesh()
619 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
620 meshes[0].SetParameters(Parameters)
622 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
623 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
625 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
626 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
627 aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
630 ## Create a mesh by copying a part of another mesh.
631 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
632 # to copy nodes or elements not contained in any mesh object,
633 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
634 # @param meshName a name of the new mesh
635 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
636 # @param toKeepIDs to preserve order of the copied elements or not
637 # @return an instance of Mesh class
638 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
639 if (isinstance( meshPart, Mesh )):
640 meshPart = meshPart.GetMesh()
641 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
642 return Mesh(self, self.geompyD, mesh)
644 ## From SMESH_Gen interface
645 # @return the list of integer values
646 # @ingroup l1_auxiliary
647 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
648 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
650 ## From SMESH_Gen interface. Creates a pattern
651 # @return an instance of SMESH_Pattern
653 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
654 # @ingroup l2_modif_patterns
655 def GetPattern(self):
656 return SMESH._objref_SMESH_Gen.GetPattern(self)
658 ## Sets number of segments per diagonal of boundary box of geometry by which
659 # default segment length of appropriate 1D hypotheses is defined.
660 # Default value is 10
661 # @ingroup l1_auxiliary
662 def SetBoundaryBoxSegmentation(self, nbSegments):
663 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
665 # Filtering. Auxiliary functions:
666 # ------------------------------
668 ## Creates an empty criterion
669 # @return SMESH.Filter.Criterion
670 # @ingroup l1_controls
671 def GetEmptyCriterion(self):
672 Type = self.EnumToLong(FT_Undefined)
673 Compare = self.EnumToLong(FT_Undefined)
677 UnaryOp = self.EnumToLong(FT_Undefined)
678 BinaryOp = self.EnumToLong(FT_Undefined)
681 Precision = -1 ##@1e-07
682 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
683 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
685 ## Creates a criterion by the given parameters
686 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
687 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
688 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
689 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
690 # @param Threshold the threshold value (range of ids as string, shape, numeric)
691 # @param UnaryOp FT_LogicalNOT or FT_Undefined
692 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
693 # FT_Undefined (must be for the last criterion of all criteria)
694 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
695 # FT_LyingOnGeom, FT_CoplanarFaces criteria
696 # @return SMESH.Filter.Criterion
698 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
699 # @ingroup l1_controls
700 def GetCriterion(self,elementType,
702 Compare = FT_EqualTo,
704 UnaryOp=FT_Undefined,
705 BinaryOp=FT_Undefined,
707 if not CritType in SMESH.FunctorType._items:
708 raise TypeError, "CritType should be of SMESH.FunctorType"
709 aCriterion = self.GetEmptyCriterion()
710 aCriterion.TypeOfElement = elementType
711 aCriterion.Type = self.EnumToLong(CritType)
712 aCriterion.Tolerance = Tolerance
714 aThreshold = Threshold
716 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
717 aCriterion.Compare = self.EnumToLong(Compare)
718 elif Compare == "=" or Compare == "==":
719 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
721 aCriterion.Compare = self.EnumToLong(FT_LessThan)
723 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
724 elif Compare != FT_Undefined:
725 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
728 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
729 FT_BelongToCylinder, FT_LyingOnGeom]:
730 # Checks that Threshold is GEOM object
731 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object):
732 aCriterion.ThresholdStr = GetName(aThreshold)
733 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
734 if not aCriterion.ThresholdID:
735 name = aCriterion.ThresholdStr
737 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
738 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
739 #raise RuntimeError, "Threshold shape must be published"
741 print "Error: The Threshold should be a shape."
743 if isinstance(UnaryOp,float):
744 aCriterion.Tolerance = UnaryOp
745 UnaryOp = FT_Undefined
747 elif CritType == FT_RangeOfIds:
748 # Checks that Threshold is string
749 if isinstance(aThreshold, str):
750 aCriterion.ThresholdStr = aThreshold
752 print "Error: The Threshold should be a string."
754 elif CritType == FT_CoplanarFaces:
755 # Checks the Threshold
756 if isinstance(aThreshold, int):
757 aCriterion.ThresholdID = str(aThreshold)
758 elif isinstance(aThreshold, str):
761 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
762 aCriterion.ThresholdID = aThreshold
765 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
766 elif CritType == FT_ConnectedElements:
767 # Checks the Threshold
768 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object): # shape
769 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
770 if not aCriterion.ThresholdID:
771 name = aThreshold.GetName()
773 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
774 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
775 elif isinstance(aThreshold, int): # node id
776 aCriterion.Threshold = aThreshold
777 elif isinstance(aThreshold, list): # 3 point coordinates
778 if len( aThreshold ) < 3:
779 raise ValueError, "too few point coordinates, must be 3"
780 aCriterion.ThresholdStr = " ".join( [str(c) for c in aThreshold[:3]] )
781 elif isinstance(aThreshold, str):
782 if aThreshold.isdigit():
783 aCriterion.Threshold = aThreshold # node id
785 aCriterion.ThresholdStr = aThreshold # hope that it's point coordinates
788 "The Threshold should either a VERTEX, or a node ID, "\
789 "or a list of point coordinates and not '%s'"%aThreshold
790 elif CritType == FT_ElemGeomType:
791 # Checks the Threshold
793 aCriterion.Threshold = self.EnumToLong(aThreshold)
794 assert( aThreshold in SMESH.GeometryType._items )
796 if isinstance(aThreshold, int):
797 aCriterion.Threshold = aThreshold
799 print "Error: The Threshold should be an integer or SMESH.GeometryType."
803 elif CritType == FT_EntityType:
804 # Checks the Threshold
806 aCriterion.Threshold = self.EnumToLong(aThreshold)
807 assert( aThreshold in SMESH.EntityType._items )
809 if isinstance(aThreshold, int):
810 aCriterion.Threshold = aThreshold
812 print "Error: The Threshold should be an integer or SMESH.EntityType."
817 elif CritType == FT_GroupColor:
818 # Checks the Threshold
820 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
822 print "Error: The threshold value should be of SALOMEDS.Color type"
825 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
826 FT_LinearOrQuadratic, FT_BadOrientedVolume,
827 FT_BareBorderFace, FT_BareBorderVolume,
828 FT_OverConstrainedFace, FT_OverConstrainedVolume,
829 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
830 # At this point the Threshold is unnecessary
831 if aThreshold == FT_LogicalNOT:
832 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
833 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
834 aCriterion.BinaryOp = aThreshold
838 aThreshold = float(aThreshold)
839 aCriterion.Threshold = aThreshold
841 print "Error: The Threshold should be a number."
844 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
845 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
847 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
848 aCriterion.BinaryOp = self.EnumToLong(Threshold)
850 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
851 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
853 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
854 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
858 ## Creates a filter with the given parameters
859 # @param elementType the type of elements in the group
860 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
861 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
862 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
863 # @param UnaryOp FT_LogicalNOT or FT_Undefined
864 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
865 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
866 # @param mesh the mesh to initialize the filter with
867 # @return SMESH_Filter
869 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
870 # @ingroup l1_controls
871 def GetFilter(self,elementType,
872 CritType=FT_Undefined,
875 UnaryOp=FT_Undefined,
878 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
879 aFilterMgr = self.CreateFilterManager()
880 aFilter = aFilterMgr.CreateFilter()
882 aCriteria.append(aCriterion)
883 aFilter.SetCriteria(aCriteria)
885 if isinstance( mesh, Mesh ): aFilter.SetMesh( mesh.GetMesh() )
886 else : aFilter.SetMesh( mesh )
887 aFilterMgr.UnRegister()
890 ## Creates a filter from criteria
891 # @param criteria a list of criteria
892 # @param binOp binary operator used when binary operator of criteria is undefined
893 # @return SMESH_Filter
895 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
896 # @ingroup l1_controls
897 def GetFilterFromCriteria(self,criteria, binOp=SMESH.FT_LogicalAND):
898 for i in range( len( criteria ) - 1 ):
899 if criteria[i].BinaryOp == self.EnumToLong( SMESH.FT_Undefined ):
900 criteria[i].BinaryOp = self.EnumToLong( binOp )
901 aFilterMgr = self.CreateFilterManager()
902 aFilter = aFilterMgr.CreateFilter()
903 aFilter.SetCriteria(criteria)
904 aFilterMgr.UnRegister()
907 ## Creates a numerical functor by its type
908 # @param theCriterion FT_...; functor type
909 # @return SMESH_NumericalFunctor
910 # @ingroup l1_controls
911 def GetFunctor(self,theCriterion):
912 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
914 aFilterMgr = self.CreateFilterManager()
916 if theCriterion == FT_AspectRatio:
917 functor = aFilterMgr.CreateAspectRatio()
918 elif theCriterion == FT_AspectRatio3D:
919 functor = aFilterMgr.CreateAspectRatio3D()
920 elif theCriterion == FT_Warping:
921 functor = aFilterMgr.CreateWarping()
922 elif theCriterion == FT_MinimumAngle:
923 functor = aFilterMgr.CreateMinimumAngle()
924 elif theCriterion == FT_Taper:
925 functor = aFilterMgr.CreateTaper()
926 elif theCriterion == FT_Skew:
927 functor = aFilterMgr.CreateSkew()
928 elif theCriterion == FT_Area:
929 functor = aFilterMgr.CreateArea()
930 elif theCriterion == FT_Volume3D:
931 functor = aFilterMgr.CreateVolume3D()
932 elif theCriterion == FT_MaxElementLength2D:
933 functor = aFilterMgr.CreateMaxElementLength2D()
934 elif theCriterion == FT_MaxElementLength3D:
935 functor = aFilterMgr.CreateMaxElementLength3D()
936 elif theCriterion == FT_MultiConnection:
937 functor = aFilterMgr.CreateMultiConnection()
938 elif theCriterion == FT_MultiConnection2D:
939 functor = aFilterMgr.CreateMultiConnection2D()
940 elif theCriterion == FT_Length:
941 functor = aFilterMgr.CreateLength()
942 elif theCriterion == FT_Length2D:
943 functor = aFilterMgr.CreateLength2D()
945 print "Error: given parameter is not numerical functor type."
946 aFilterMgr.UnRegister()
949 ## Creates hypothesis
950 # @param theHType mesh hypothesis type (string)
951 # @param theLibName mesh plug-in library name
952 # @return created hypothesis instance
953 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
954 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
956 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
959 # wrap hypothesis methods
960 #print "HYPOTHESIS", theHType
961 for meth_name in dir( hyp.__class__ ):
962 if not meth_name.startswith("Get") and \
963 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
964 method = getattr ( hyp.__class__, meth_name )
966 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
970 ## Gets the mesh statistic
971 # @return dictionary "element type" - "count of elements"
972 # @ingroup l1_meshinfo
973 def GetMeshInfo(self, obj):
974 if isinstance( obj, Mesh ):
977 if hasattr(obj, "GetMeshInfo"):
978 values = obj.GetMeshInfo()
979 for i in range(SMESH.Entity_Last._v):
980 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
984 ## Get minimum distance between two objects
986 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
987 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
989 # @param src1 first source object
990 # @param src2 second source object
991 # @param id1 node/element id from the first source
992 # @param id2 node/element id from the second (or first) source
993 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
994 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
995 # @return minimum distance value
996 # @sa GetMinDistance()
997 # @ingroup l1_measurements
998 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
999 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
1003 result = result.value
1006 ## Get measure structure specifying minimum distance data between two objects
1008 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
1009 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
1011 # @param src1 first source object
1012 # @param src2 second source object
1013 # @param id1 node/element id from the first source
1014 # @param id2 node/element id from the second (or first) source
1015 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
1016 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
1017 # @return Measure structure or None if input data is invalid
1019 # @ingroup l1_measurements
1020 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
1021 if isinstance(src1, Mesh): src1 = src1.mesh
1022 if isinstance(src2, Mesh): src2 = src2.mesh
1023 if src2 is None and id2 != 0: src2 = src1
1024 if not hasattr(src1, "_narrow"): return None
1025 src1 = src1._narrow(SMESH.SMESH_IDSource)
1026 if not src1: return None
1027 unRegister = genObjUnRegister()
1030 e = m.GetMeshEditor()
1032 src1 = e.MakeIDSource([id1], SMESH.FACE)
1034 src1 = e.MakeIDSource([id1], SMESH.NODE)
1035 unRegister.set( src1 )
1037 if hasattr(src2, "_narrow"):
1038 src2 = src2._narrow(SMESH.SMESH_IDSource)
1039 if src2 and id2 != 0:
1041 e = m.GetMeshEditor()
1043 src2 = e.MakeIDSource([id2], SMESH.FACE)
1045 src2 = e.MakeIDSource([id2], SMESH.NODE)
1046 unRegister.set( src2 )
1049 aMeasurements = self.CreateMeasurements()
1050 unRegister.set( aMeasurements )
1051 result = aMeasurements.MinDistance(src1, src2)
1054 ## Get bounding box of the specified object(s)
1055 # @param objects single source object or list of source objects
1056 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
1057 # @sa GetBoundingBox()
1058 # @ingroup l1_measurements
1059 def BoundingBox(self, objects):
1060 result = self.GetBoundingBox(objects)
1064 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
1067 ## Get measure structure specifying bounding box data of the specified object(s)
1068 # @param objects single source object or list of source objects
1069 # @return Measure structure
1071 # @ingroup l1_measurements
1072 def GetBoundingBox(self, objects):
1073 if isinstance(objects, tuple):
1074 objects = list(objects)
1075 if not isinstance(objects, list):
1079 if isinstance(o, Mesh):
1080 srclist.append(o.mesh)
1081 elif hasattr(o, "_narrow"):
1082 src = o._narrow(SMESH.SMESH_IDSource)
1083 if src: srclist.append(src)
1086 aMeasurements = self.CreateMeasurements()
1087 result = aMeasurements.BoundingBox(srclist)
1088 aMeasurements.UnRegister()
1091 ## Get sum of lengths of all 1D elements in the mesh object.
1092 # @param obj mesh, submesh or group
1093 # @return sum of lengths of all 1D elements
1094 # @ingroup l1_measurements
1095 def GetLength(self, obj):
1096 if isinstance(obj, Mesh): obj = obj.mesh
1097 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1098 aMeasurements = self.CreateMeasurements()
1099 value = aMeasurements.Length(obj)
1100 aMeasurements.UnRegister()
1103 ## Get sum of areas of all 2D elements in the mesh object.
1104 # @param obj mesh, submesh or group
1105 # @return sum of areas of all 2D elements
1106 # @ingroup l1_measurements
1107 def GetArea(self, obj):
1108 if isinstance(obj, Mesh): obj = obj.mesh
1109 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1110 aMeasurements = self.CreateMeasurements()
1111 value = aMeasurements.Area(obj)
1112 aMeasurements.UnRegister()
1115 ## Get sum of volumes of all 3D elements in the mesh object.
1116 # @param obj mesh, submesh or group
1117 # @return sum of volumes of all 3D elements
1118 # @ingroup l1_measurements
1119 def GetVolume(self, obj):
1120 if isinstance(obj, Mesh): obj = obj.mesh
1121 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1122 aMeasurements = self.CreateMeasurements()
1123 value = aMeasurements.Volume(obj)
1124 aMeasurements.UnRegister()
1127 pass # end of class smeshBuilder
1130 #Registering the new proxy for SMESH_Gen
1131 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
1133 ## Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1134 # interface to create or load meshes.
1139 # salome.salome_init()
1140 # from salome.smesh import smeshBuilder
1141 # smesh = smeshBuilder.New(theStudy)
1143 # @param study SALOME study, generally obtained by salome.myStudy.
1144 # @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1145 # @return smeshBuilder instance
1147 def New( study, instance=None):
1149 Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1150 interface to create or load meshes.
1154 salome.salome_init()
1155 from salome.smesh import smeshBuilder
1156 smesh = smeshBuilder.New(theStudy)
1159 study SALOME study, generally obtained by salome.myStudy.
1160 instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1162 smeshBuilder instance
1170 smeshInst = smeshBuilder()
1171 assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__
1172 smeshInst.init_smesh(study)
1176 # Public class: Mesh
1177 # ==================
1179 ## This class allows defining and managing a mesh.
1180 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1181 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1182 # new nodes and elements and by changing the existing entities), to get information
1183 # about a mesh and to export a mesh into different formats.
1185 __metaclass__ = MeshMeta
1193 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1194 # sets the GUI name of this mesh to \a name.
1195 # @param smeshpyD an instance of smeshBuilder class
1196 # @param geompyD an instance of geomBuilder class
1197 # @param obj Shape to be meshed or SMESH_Mesh object
1198 # @param name Study name of the mesh
1199 # @ingroup l2_construct
1200 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1201 self.smeshpyD=smeshpyD
1202 self.geompyD=geompyD
1207 if isinstance(obj, geomBuilder.GEOM._objref_GEOM_Object):
1210 # publish geom of mesh (issue 0021122)
1211 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
1213 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
1214 if studyID != geompyD.myStudyId:
1215 geompyD.init_geom( smeshpyD.GetCurrentStudy())
1218 geo_name = name + " shape"
1220 geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1221 geompyD.addToStudy( self.geom, geo_name )
1222 self.SetMesh( self.smeshpyD.CreateMesh(self.geom) )
1224 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1227 self.SetMesh( self.smeshpyD.CreateEmptyMesh() )
1229 self.smeshpyD.SetName(self.mesh, name)
1231 self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1234 self.geom = self.mesh.GetShapeToMesh()
1236 self.editor = self.mesh.GetMeshEditor()
1237 self.functors = [None] * SMESH.FT_Undefined._v
1239 # set self to algoCreator's
1240 for attrName in dir(self):
1241 attr = getattr( self, attrName )
1242 if isinstance( attr, algoCreator ):
1243 #print "algoCreator ", attrName
1244 setattr( self, attrName, attr.copy( self ))
1249 ## Destructor. Clean-up resources
1252 #self.mesh.UnRegister()
1256 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1257 # @param theMesh a SMESH_Mesh object
1258 # @ingroup l2_construct
1259 def SetMesh(self, theMesh):
1260 # do not call Register() as this prevents mesh servant deletion at closing study
1261 #if self.mesh: self.mesh.UnRegister()
1264 #self.mesh.Register()
1265 self.geom = self.mesh.GetShapeToMesh()
1268 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1269 # @return a SMESH_Mesh object
1270 # @ingroup l2_construct
1274 ## Gets the name of the mesh
1275 # @return the name of the mesh as a string
1276 # @ingroup l2_construct
1278 name = GetName(self.GetMesh())
1281 ## Sets a name to the mesh
1282 # @param name a new name of the mesh
1283 # @ingroup l2_construct
1284 def SetName(self, name):
1285 self.smeshpyD.SetName(self.GetMesh(), name)
1287 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1288 # The subMesh object gives access to the IDs of nodes and elements.
1289 # @param geom a geometrical object (shape)
1290 # @param name a name for the submesh
1291 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1292 # @ingroup l2_submeshes
1293 def GetSubMesh(self, geom, name):
1294 AssureGeomPublished( self, geom, name )
1295 submesh = self.mesh.GetSubMesh( geom, name )
1298 ## Returns the shape associated to the mesh
1299 # @return a GEOM_Object
1300 # @ingroup l2_construct
1304 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1305 # @param geom the shape to be meshed (GEOM_Object)
1306 # @ingroup l2_construct
1307 def SetShape(self, geom):
1308 self.mesh = self.smeshpyD.CreateMesh(geom)
1310 ## Loads mesh from the study after opening the study
1314 ## Returns true if the hypotheses are defined well
1315 # @param theSubObject a sub-shape of a mesh shape
1316 # @return True or False
1317 # @ingroup l2_construct
1318 def IsReadyToCompute(self, theSubObject):
1319 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1321 ## Returns errors of hypotheses definition.
1322 # The list of errors is empty if everything is OK.
1323 # @param theSubObject a sub-shape of a mesh shape
1324 # @return a list of errors
1325 # @ingroup l2_construct
1326 def GetAlgoState(self, theSubObject):
1327 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1329 ## Returns a geometrical object on which the given element was built.
1330 # The returned geometrical object, if not nil, is either found in the
1331 # study or published by this method with the given name
1332 # @param theElementID the id of the mesh element
1333 # @param theGeomName the user-defined name of the geometrical object
1334 # @return GEOM::GEOM_Object instance
1335 # @ingroup l2_construct
1336 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1337 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1339 ## Returns the mesh dimension depending on the dimension of the underlying shape
1340 # or, if the mesh is not based on any shape, basing on deimension of elements
1341 # @return mesh dimension as an integer value [0,3]
1342 # @ingroup l1_auxiliary
1343 def MeshDimension(self):
1344 if self.mesh.HasShapeToMesh():
1345 shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
1346 if len( shells ) > 0 :
1348 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1350 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1355 if self.NbVolumes() > 0: return 3
1356 if self.NbFaces() > 0: return 2
1357 if self.NbEdges() > 0: return 1
1360 ## Evaluates size of prospective mesh on a shape
1361 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1362 # To know predicted number of e.g. edges, inquire it this way
1363 # Evaluate()[ EnumToLong( Entity_Edge )]
1364 def Evaluate(self, geom=0):
1365 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1367 geom = self.mesh.GetShapeToMesh()
1370 return self.smeshpyD.Evaluate(self.mesh, geom)
1373 ## Computes the mesh and returns the status of the computation
1374 # @param geom geomtrical shape on which mesh data should be computed
1375 # @param discardModifs if True and the mesh has been edited since
1376 # a last total re-compute and that may prevent successful partial re-compute,
1377 # then the mesh is cleaned before Compute()
1378 # @param refresh if @c True, Object browser is automatically updated (when running in GUI)
1379 # @return True or False
1380 # @ingroup l2_construct
1381 def Compute(self, geom=0, discardModifs=False, refresh=False):
1382 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1384 geom = self.mesh.GetShapeToMesh()
1389 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1391 ok = self.smeshpyD.Compute(self.mesh, geom)
1392 except SALOME.SALOME_Exception, ex:
1393 print "Mesh computation failed, exception caught:"
1394 print " ", ex.details.text
1397 print "Mesh computation failed, exception caught:"
1398 traceback.print_exc()
1402 # Treat compute errors
1403 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1404 for err in computeErrors:
1406 if self.mesh.HasShapeToMesh():
1408 mainIOR = salome.orb.object_to_string(geom)
1409 for sname in salome.myStudyManager.GetOpenStudies():
1410 s = salome.myStudyManager.GetStudyByName(sname)
1412 mainSO = s.FindObjectIOR(mainIOR)
1413 if not mainSO: continue
1414 if err.subShapeID == 1:
1415 shapeText = ' on "%s"' % mainSO.GetName()
1416 subIt = s.NewChildIterator(mainSO)
1418 subSO = subIt.Value()
1420 obj = subSO.GetObject()
1421 if not obj: continue
1422 go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
1424 ids = go.GetSubShapeIndices()
1425 if len(ids) == 1 and ids[0] == err.subShapeID:
1426 shapeText = ' on "%s"' % subSO.GetName()
1429 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1431 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1433 shapeText = " on subshape #%s" % (err.subShapeID)
1435 shapeText = " on subshape #%s" % (err.subShapeID)
1437 stdErrors = ["OK", #COMPERR_OK
1438 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1439 "std::exception", #COMPERR_STD_EXCEPTION
1440 "OCC exception", #COMPERR_OCC_EXCEPTION
1441 "..", #COMPERR_SLM_EXCEPTION
1442 "Unknown exception", #COMPERR_EXCEPTION
1443 "Memory allocation problem", #COMPERR_MEMORY_PB
1444 "Algorithm failed", #COMPERR_ALGO_FAILED
1445 "Unexpected geometry", #COMPERR_BAD_SHAPE
1446 "Warning", #COMPERR_WARNING
1447 "Computation cancelled",#COMPERR_CANCELED
1448 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1450 if err.code < len(stdErrors): errText = stdErrors[err.code]
1452 errText = "code %s" % -err.code
1453 if errText: errText += ". "
1454 errText += err.comment
1455 if allReasons != "":allReasons += "\n"
1457 allReasons += '- "%s"%s - %s' %(err.algoName, shapeText, errText)
1459 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1463 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1465 if err.isGlobalAlgo:
1473 reason = '%s %sD algorithm is missing' % (glob, dim)
1474 elif err.state == HYP_MISSING:
1475 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1476 % (glob, dim, name, dim))
1477 elif err.state == HYP_NOTCONFORM:
1478 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1479 elif err.state == HYP_BAD_PARAMETER:
1480 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1481 % ( glob, dim, name ))
1482 elif err.state == HYP_BAD_GEOMETRY:
1483 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1484 'geometry' % ( glob, dim, name ))
1485 elif err.state == HYP_HIDDEN_ALGO:
1486 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1487 'algorithm of upper dimension generating %sD mesh'
1488 % ( glob, dim, name, glob, dim ))
1490 reason = ("For unknown reason. "
1491 "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1493 if allReasons != "":allReasons += "\n"
1494 allReasons += "- " + reason
1496 if not ok or allReasons != "":
1497 msg = '"' + GetName(self.mesh) + '"'
1498 if ok: msg += " has been computed with warnings"
1499 else: msg += " has not been computed"
1500 if allReasons != "": msg += ":"
1505 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1506 smeshgui = salome.ImportComponentGUI("SMESH")
1507 smeshgui.Init(self.mesh.GetStudyId())
1508 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1509 if refresh: salome.sg.updateObjBrowser(1)
1513 ## Return submesh objects list in meshing order
1514 # @return list of list of submesh objects
1515 # @ingroup l2_construct
1516 def GetMeshOrder(self):
1517 return self.mesh.GetMeshOrder()
1519 ## Return submesh objects list in meshing order
1520 # @return list of list of submesh objects
1521 # @ingroup l2_construct
1522 def SetMeshOrder(self, submeshes):
1523 return self.mesh.SetMeshOrder(submeshes)
1525 ## Removes all nodes and elements
1526 # @refresh if @c True, Object browser is automatically updated (when running in GUI)
1527 # @ingroup l2_construct
1528 def Clear(self, refresh=False):
1530 if ( salome.sg.hasDesktop() and
1531 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() ) ):
1532 smeshgui = salome.ImportComponentGUI("SMESH")
1533 smeshgui.Init(self.mesh.GetStudyId())
1534 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1535 if refresh: salome.sg.updateObjBrowser(1)
1537 ## Removes all nodes and elements of indicated shape
1538 # @refresh if @c True, Object browser is automatically updated (when running in GUI)
1539 # @ingroup l2_construct
1540 def ClearSubMesh(self, geomId, refresh=False):
1541 self.mesh.ClearSubMesh(geomId)
1542 if salome.sg.hasDesktop():
1543 smeshgui = salome.ImportComponentGUI("SMESH")
1544 smeshgui.Init(self.mesh.GetStudyId())
1545 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1546 if refresh: salome.sg.updateObjBrowser(1)
1548 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron
1549 # @param fineness [0.0,1.0] defines mesh fineness
1550 # @return True or False
1551 # @ingroup l3_algos_basic
1552 def AutomaticTetrahedralization(self, fineness=0):
1553 dim = self.MeshDimension()
1555 self.RemoveGlobalHypotheses()
1556 self.Segment().AutomaticLength(fineness)
1558 self.Triangle().LengthFromEdges()
1563 return self.Compute()
1565 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1566 # @param fineness [0.0, 1.0] defines mesh fineness
1567 # @return True or False
1568 # @ingroup l3_algos_basic
1569 def AutomaticHexahedralization(self, fineness=0):
1570 dim = self.MeshDimension()
1571 # assign the hypotheses
1572 self.RemoveGlobalHypotheses()
1573 self.Segment().AutomaticLength(fineness)
1580 return self.Compute()
1582 ## Assigns a hypothesis
1583 # @param hyp a hypothesis to assign
1584 # @param geom a subhape of mesh geometry
1585 # @return SMESH.Hypothesis_Status
1586 # @ingroup l2_hypotheses
1587 def AddHypothesis(self, hyp, geom=0):
1588 if isinstance( hyp, Mesh_Algorithm ):
1589 hyp = hyp.GetAlgorithm()
1594 geom = self.mesh.GetShapeToMesh()
1597 if self.mesh.HasShapeToMesh():
1598 hyp_type = hyp.GetName()
1599 lib_name = hyp.GetLibName()
1600 checkAll = ( not geom.IsSame( self.mesh.GetShapeToMesh() ))
1601 if checkAll and geom:
1602 checkAll = geom.GetType() == 37
1603 isApplicable = self.smeshpyD.IsApplicable(hyp_type, lib_name, geom, checkAll)
1605 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1606 status = self.mesh.AddHypothesis(geom, hyp)
1608 status = HYP_BAD_GEOMETRY,""
1609 hyp_name = GetName( hyp )
1612 geom_name = geom.GetName()
1613 isAlgo = hyp._narrow( SMESH_Algo )
1614 TreatHypoStatus( status, hyp_name, geom_name, isAlgo, self )
1617 ## Return True if an algorithm of hypothesis is assigned to a given shape
1618 # @param hyp a hypothesis to check
1619 # @param geom a subhape of mesh geometry
1620 # @return True of False
1621 # @ingroup l2_hypotheses
1622 def IsUsedHypothesis(self, hyp, geom):
1623 if not hyp: # or not geom
1625 if isinstance( hyp, Mesh_Algorithm ):
1626 hyp = hyp.GetAlgorithm()
1628 hyps = self.GetHypothesisList(geom)
1630 if h.GetId() == hyp.GetId():
1634 ## Unassigns a hypothesis
1635 # @param hyp a hypothesis to unassign
1636 # @param geom a sub-shape of mesh geometry
1637 # @return SMESH.Hypothesis_Status
1638 # @ingroup l2_hypotheses
1639 def RemoveHypothesis(self, hyp, geom=0):
1642 if isinstance( hyp, Mesh_Algorithm ):
1643 hyp = hyp.GetAlgorithm()
1649 if self.IsUsedHypothesis( hyp, shape ):
1650 return self.mesh.RemoveHypothesis( shape, hyp )
1651 hypName = GetName( hyp )
1652 geoName = GetName( shape )
1653 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1656 ## Gets the list of hypotheses added on a geometry
1657 # @param geom a sub-shape of mesh geometry
1658 # @return the sequence of SMESH_Hypothesis
1659 # @ingroup l2_hypotheses
1660 def GetHypothesisList(self, geom):
1661 return self.mesh.GetHypothesisList( geom )
1663 ## Removes all global hypotheses
1664 # @ingroup l2_hypotheses
1665 def RemoveGlobalHypotheses(self):
1666 current_hyps = self.mesh.GetHypothesisList( self.geom )
1667 for hyp in current_hyps:
1668 self.mesh.RemoveHypothesis( self.geom, hyp )
1672 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1673 ## allowing to overwrite the file if it exists or add the exported data to its contents
1674 # @param f is the file name
1675 # @param auto_groups boolean parameter for creating/not creating
1676 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1677 # the typical use is auto_groups=false.
1678 # @param version MED format version(MED_V2_1 or MED_V2_2)
1679 # @param overwrite boolean parameter for overwriting/not overwriting the file
1680 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1681 # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1682 # - 1D if all mesh nodes lie on OX coordinate axis, or
1683 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1684 # - 3D in the rest cases.
1685 # If @a autoDimension is @c False, the space dimension is always 3.
1686 # @param fields : list of GEOM fields defined on the shape to mesh.
1687 # @param geomAssocFields : each character of this string means a need to export a
1688 # corresponding field; correspondence between fields and characters is following:
1689 # - 'v' stands for _vertices_ field;
1690 # - 'e' stands for _edges_ field;
1691 # - 'f' stands for _faces_ field;
1692 # - 's' stands for _solids_ field.
1693 # @ingroup l2_impexp
1694 def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
1695 overwrite=1, meshPart=None, autoDimension=True, fields=[], geomAssocFields=''):
1696 if meshPart or fields or geomAssocFields:
1697 unRegister = genObjUnRegister()
1698 if isinstance( meshPart, list ):
1699 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1700 unRegister.set( meshPart )
1701 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension,
1702 fields, geomAssocFields)
1704 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
1706 ## Exports the mesh in a file in SAUV format
1707 # @param f is the file name
1708 # @param auto_groups boolean parameter for creating/not creating
1709 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1710 # the typical use is auto_groups=false.
1711 # @ingroup l2_impexp
1712 def ExportSAUV(self, f, auto_groups=0):
1713 self.mesh.ExportSAUV(f, auto_groups)
1715 ## Exports the mesh in a file in DAT format
1716 # @param f the file name
1717 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1718 # @ingroup l2_impexp
1719 def ExportDAT(self, f, meshPart=None):
1721 unRegister = genObjUnRegister()
1722 if isinstance( meshPart, list ):
1723 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1724 unRegister.set( meshPart )
1725 self.mesh.ExportPartToDAT( meshPart, f )
1727 self.mesh.ExportDAT(f)
1729 ## Exports the mesh in a file in UNV format
1730 # @param f the file name
1731 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1732 # @ingroup l2_impexp
1733 def ExportUNV(self, f, meshPart=None):
1735 unRegister = genObjUnRegister()
1736 if isinstance( meshPart, list ):
1737 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1738 unRegister.set( meshPart )
1739 self.mesh.ExportPartToUNV( meshPart, f )
1741 self.mesh.ExportUNV(f)
1743 ## Export the mesh in a file in STL format
1744 # @param f the file name
1745 # @param ascii defines the file encoding
1746 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1747 # @ingroup l2_impexp
1748 def ExportSTL(self, f, ascii=1, meshPart=None):
1750 unRegister = genObjUnRegister()
1751 if isinstance( meshPart, list ):
1752 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1753 unRegister.set( meshPart )
1754 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1756 self.mesh.ExportSTL(f, ascii)
1758 ## Exports the mesh in a file in CGNS format
1759 # @param f is the file name
1760 # @param overwrite boolean parameter for overwriting/not overwriting the file
1761 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1762 # @ingroup l2_impexp
1763 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1764 unRegister = genObjUnRegister()
1765 if isinstance( meshPart, list ):
1766 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1767 unRegister.set( meshPart )
1768 if isinstance( meshPart, Mesh ):
1769 meshPart = meshPart.mesh
1771 meshPart = self.mesh
1772 self.mesh.ExportCGNS(meshPart, f, overwrite)
1774 ## Exports the mesh in a file in GMF format.
1775 # GMF files must have .mesh extension for the ASCII format and .meshb for
1776 # the bynary format. Other extensions are not allowed.
1777 # @param f is the file name
1778 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1779 # @ingroup l2_impexp
1780 def ExportGMF(self, f, meshPart=None):
1781 unRegister = genObjUnRegister()
1782 if isinstance( meshPart, list ):
1783 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1784 unRegister.set( meshPart )
1785 if isinstance( meshPart, Mesh ):
1786 meshPart = meshPart.mesh
1788 meshPart = self.mesh
1789 self.mesh.ExportGMF(meshPart, f, True)
1791 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1792 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1793 ## allowing to overwrite the file if it exists or add the exported data to its contents
1794 # @param f the file name
1795 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1796 # @param opt boolean parameter for creating/not creating
1797 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1798 # @param overwrite boolean parameter for overwriting/not overwriting the file
1799 # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1800 # - 1D if all mesh nodes lie on OX coordinate axis, or
1801 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1802 # - 3D in the rest cases.
1804 # If @a autoDimension is @c False, the space dimension is always 3.
1805 # @ingroup l2_impexp
1806 def ExportToMED(self, f, version, opt=0, overwrite=1, autoDimension=True):
1807 self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension)
1809 # Operations with groups:
1810 # ----------------------
1812 ## Creates an empty mesh group
1813 # @param elementType the type of elements in the group
1814 # @param name the name of the mesh group
1815 # @return SMESH_Group
1816 # @ingroup l2_grps_create
1817 def CreateEmptyGroup(self, elementType, name):
1818 return self.mesh.CreateGroup(elementType, name)
1820 ## Creates a mesh group based on the geometric object \a grp
1821 # and gives a \a name, \n if this parameter is not defined
1822 # the name is the same as the geometric group name \n
1823 # Note: Works like GroupOnGeom().
1824 # @param grp a geometric group, a vertex, an edge, a face or a solid
1825 # @param name the name of the mesh group
1826 # @return SMESH_GroupOnGeom
1827 # @ingroup l2_grps_create
1828 def Group(self, grp, name=""):
1829 return self.GroupOnGeom(grp, name)
1831 ## Creates a mesh group based on the geometrical object \a grp
1832 # and gives a \a name, \n if this parameter is not defined
1833 # the name is the same as the geometrical group name
1834 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1835 # @param name the name of the mesh group
1836 # @param typ the type of elements in the group. If not set, it is
1837 # automatically detected by the type of the geometry
1838 # @return SMESH_GroupOnGeom
1839 # @ingroup l2_grps_create
1840 def GroupOnGeom(self, grp, name="", typ=None):
1841 AssureGeomPublished( self, grp, name )
1843 name = grp.GetName()
1845 typ = self._groupTypeFromShape( grp )
1846 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1848 ## Pivate method to get a type of group on geometry
1849 def _groupTypeFromShape( self, shape ):
1850 tgeo = str(shape.GetShapeType())
1851 if tgeo == "VERTEX":
1853 elif tgeo == "EDGE":
1855 elif tgeo == "FACE" or tgeo == "SHELL":
1857 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1859 elif tgeo == "COMPOUND":
1860 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
1862 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1863 return self._groupTypeFromShape( sub[0] )
1866 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1869 ## Creates a mesh group with given \a name based on the \a filter which
1870 ## is a special type of group dynamically updating it's contents during
1871 ## mesh modification
1872 # @param typ the type of elements in the group
1873 # @param name the name of the mesh group
1874 # @param filter the filter defining group contents
1875 # @return SMESH_GroupOnFilter
1876 # @ingroup l2_grps_create
1877 def GroupOnFilter(self, typ, name, filter):
1878 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1880 ## Creates a mesh group by the given ids of elements
1881 # @param groupName the name of the mesh group
1882 # @param elementType the type of elements in the group
1883 # @param elemIDs the list of ids
1884 # @return SMESH_Group
1885 # @ingroup l2_grps_create
1886 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1887 group = self.mesh.CreateGroup(elementType, groupName)
1888 if hasattr( elemIDs, "GetIDs" ):
1889 if hasattr( elemIDs, "SetMesh" ):
1890 elemIDs.SetMesh( self.GetMesh() )
1891 group.AddFrom( elemIDs )
1896 ## Creates a mesh group by the given conditions
1897 # @param groupName the name of the mesh group
1898 # @param elementType the type of elements in the group
1899 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1900 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1901 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1902 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1903 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1904 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1905 # @return SMESH_GroupOnFilter
1906 # @ingroup l2_grps_create
1910 CritType=FT_Undefined,
1913 UnaryOp=FT_Undefined,
1915 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1916 group = self.MakeGroupByCriterion(groupName, aCriterion)
1919 ## Creates a mesh group by the given criterion
1920 # @param groupName the name of the mesh group
1921 # @param Criterion the instance of Criterion class
1922 # @return SMESH_GroupOnFilter
1923 # @ingroup l2_grps_create
1924 def MakeGroupByCriterion(self, groupName, Criterion):
1925 return self.MakeGroupByCriteria( groupName, [Criterion] )
1927 ## Creates a mesh group by the given criteria (list of criteria)
1928 # @param groupName the name of the mesh group
1929 # @param theCriteria the list of criteria
1930 # @param binOp binary operator used when binary operator of criteria is undefined
1931 # @return SMESH_GroupOnFilter
1932 # @ingroup l2_grps_create
1933 def MakeGroupByCriteria(self, groupName, theCriteria, binOp=SMESH.FT_LogicalAND):
1934 aFilter = self.smeshpyD.GetFilterFromCriteria( theCriteria, binOp )
1935 group = self.MakeGroupByFilter(groupName, aFilter)
1938 ## Creates a mesh group by the given filter
1939 # @param groupName the name of the mesh group
1940 # @param theFilter the instance of Filter class
1941 # @return SMESH_GroupOnFilter
1942 # @ingroup l2_grps_create
1943 def MakeGroupByFilter(self, groupName, theFilter):
1944 #group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1945 #theFilter.SetMesh( self.mesh )
1946 #group.AddFrom( theFilter )
1947 group = self.GroupOnFilter( theFilter.GetElementType(), groupName, theFilter )
1951 # @ingroup l2_grps_delete
1952 def RemoveGroup(self, group):
1953 self.mesh.RemoveGroup(group)
1955 ## Removes a group with its contents
1956 # @ingroup l2_grps_delete
1957 def RemoveGroupWithContents(self, group):
1958 self.mesh.RemoveGroupWithContents(group)
1960 ## Gets the list of groups existing in the mesh in the order of creation (starting from the oldest one)
1961 # @return a sequence of SMESH_GroupBase
1962 # @ingroup l2_grps_create
1963 def GetGroups(self):
1964 return self.mesh.GetGroups()
1966 ## Gets the number of groups existing in the mesh
1967 # @return the quantity of groups as an integer value
1968 # @ingroup l2_grps_create
1970 return self.mesh.NbGroups()
1972 ## Gets the list of names of groups existing in the mesh
1973 # @return list of strings
1974 # @ingroup l2_grps_create
1975 def GetGroupNames(self):
1976 groups = self.GetGroups()
1978 for group in groups:
1979 names.append(group.GetName())
1982 ## Produces a union of two groups
1983 # A new group is created. All mesh elements that are
1984 # present in the initial groups are added to the new one
1985 # @return an instance of SMESH_Group
1986 # @ingroup l2_grps_operon
1987 def UnionGroups(self, group1, group2, name):
1988 return self.mesh.UnionGroups(group1, group2, name)
1990 ## Produces a union list of groups
1991 # New group is created. All mesh elements that are present in
1992 # initial groups are added to the new one
1993 # @return an instance of SMESH_Group
1994 # @ingroup l2_grps_operon
1995 def UnionListOfGroups(self, groups, name):
1996 return self.mesh.UnionListOfGroups(groups, name)
1998 ## Prodices an intersection of two groups
1999 # A new group is created. All mesh elements that are common
2000 # for the two initial groups are added to the new one.
2001 # @return an instance of SMESH_Group
2002 # @ingroup l2_grps_operon
2003 def IntersectGroups(self, group1, group2, name):
2004 return self.mesh.IntersectGroups(group1, group2, name)
2006 ## Produces an intersection of groups
2007 # New group is created. All mesh elements that are present in all
2008 # initial groups simultaneously are added to the new one
2009 # @return an instance of SMESH_Group
2010 # @ingroup l2_grps_operon
2011 def IntersectListOfGroups(self, groups, name):
2012 return self.mesh.IntersectListOfGroups(groups, name)
2014 ## Produces a cut of two groups
2015 # A new group is created. All mesh elements that are present in
2016 # the main group but are not present in the tool group are added to the new one
2017 # @return an instance of SMESH_Group
2018 # @ingroup l2_grps_operon
2019 def CutGroups(self, main_group, tool_group, name):
2020 return self.mesh.CutGroups(main_group, tool_group, name)
2022 ## Produces a cut of groups
2023 # A new group is created. All mesh elements that are present in main groups
2024 # but do not present in tool groups are added to the new one
2025 # @return an instance of SMESH_Group
2026 # @ingroup l2_grps_operon
2027 def CutListOfGroups(self, main_groups, tool_groups, name):
2028 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
2030 ## Produces a group of elements of specified type using list of existing groups
2031 # A new group is created. System
2032 # 1) extracts all nodes on which groups elements are built
2033 # 2) combines all elements of specified dimension laying on these nodes
2034 # @return an instance of SMESH_Group
2035 # @ingroup l2_grps_operon
2036 def CreateDimGroup(self, groups, elem_type, name):
2037 return self.mesh.CreateDimGroup(groups, elem_type, name)
2040 ## Convert group on geom into standalone group
2041 # @ingroup l2_grps_delete
2042 def ConvertToStandalone(self, group):
2043 return self.mesh.ConvertToStandalone(group)
2045 # Get some info about mesh:
2046 # ------------------------
2048 ## Returns the log of nodes and elements added or removed
2049 # since the previous clear of the log.
2050 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
2051 # @return list of log_block structures:
2056 # @ingroup l1_auxiliary
2057 def GetLog(self, clearAfterGet):
2058 return self.mesh.GetLog(clearAfterGet)
2060 ## Clears the log of nodes and elements added or removed since the previous
2061 # clear. Must be used immediately after GetLog if clearAfterGet is false.
2062 # @ingroup l1_auxiliary
2064 self.mesh.ClearLog()
2066 ## Toggles auto color mode on the object.
2067 # @param theAutoColor the flag which toggles auto color mode.
2068 # @ingroup l1_auxiliary
2069 def SetAutoColor(self, theAutoColor):
2070 self.mesh.SetAutoColor(theAutoColor)
2072 ## Gets flag of object auto color mode.
2073 # @return True or False
2074 # @ingroup l1_auxiliary
2075 def GetAutoColor(self):
2076 return self.mesh.GetAutoColor()
2078 ## Gets the internal ID
2079 # @return integer value, which is the internal Id of the mesh
2080 # @ingroup l1_auxiliary
2082 return self.mesh.GetId()
2085 # @return integer value, which is the study Id of the mesh
2086 # @ingroup l1_auxiliary
2087 def GetStudyId(self):
2088 return self.mesh.GetStudyId()
2090 ## Checks the group names for duplications.
2091 # Consider the maximum group name length stored in MED file.
2092 # @return True or False
2093 # @ingroup l1_auxiliary
2094 def HasDuplicatedGroupNamesMED(self):
2095 return self.mesh.HasDuplicatedGroupNamesMED()
2097 ## Obtains the mesh editor tool
2098 # @return an instance of SMESH_MeshEditor
2099 # @ingroup l1_modifying
2100 def GetMeshEditor(self):
2103 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
2104 # can be passed as argument to a method accepting mesh, group or sub-mesh
2105 # @return an instance of SMESH_IDSource
2106 # @ingroup l1_auxiliary
2107 def GetIDSource(self, ids, elemType):
2108 return self.editor.MakeIDSource(ids, elemType)
2111 # Get informations about mesh contents:
2112 # ------------------------------------
2114 ## Gets the mesh stattistic
2115 # @return dictionary type element - count of elements
2116 # @ingroup l1_meshinfo
2117 def GetMeshInfo(self, obj = None):
2118 if not obj: obj = self.mesh
2119 return self.smeshpyD.GetMeshInfo(obj)
2121 ## Returns the number of nodes in the mesh
2122 # @return an integer value
2123 # @ingroup l1_meshinfo
2125 return self.mesh.NbNodes()
2127 ## Returns the number of elements in the mesh
2128 # @return an integer value
2129 # @ingroup l1_meshinfo
2130 def NbElements(self):
2131 return self.mesh.NbElements()
2133 ## Returns the number of 0d elements in the mesh
2134 # @return an integer value
2135 # @ingroup l1_meshinfo
2136 def Nb0DElements(self):
2137 return self.mesh.Nb0DElements()
2139 ## Returns the number of ball discrete elements in the mesh
2140 # @return an integer value
2141 # @ingroup l1_meshinfo
2143 return self.mesh.NbBalls()
2145 ## Returns the number of edges in the mesh
2146 # @return an integer value
2147 # @ingroup l1_meshinfo
2149 return self.mesh.NbEdges()
2151 ## Returns the number of edges with the given order in the mesh
2152 # @param elementOrder the order of elements:
2153 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2154 # @return an integer value
2155 # @ingroup l1_meshinfo
2156 def NbEdgesOfOrder(self, elementOrder):
2157 return self.mesh.NbEdgesOfOrder(elementOrder)
2159 ## Returns the number of faces in the mesh
2160 # @return an integer value
2161 # @ingroup l1_meshinfo
2163 return self.mesh.NbFaces()
2165 ## Returns the number of faces with the given order in the mesh
2166 # @param elementOrder the order of elements:
2167 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2168 # @return an integer value
2169 # @ingroup l1_meshinfo
2170 def NbFacesOfOrder(self, elementOrder):
2171 return self.mesh.NbFacesOfOrder(elementOrder)
2173 ## Returns the number of triangles in the mesh
2174 # @return an integer value
2175 # @ingroup l1_meshinfo
2176 def NbTriangles(self):
2177 return self.mesh.NbTriangles()
2179 ## Returns the number of triangles with the given order in the mesh
2180 # @param elementOrder is the order of elements:
2181 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2182 # @return an integer value
2183 # @ingroup l1_meshinfo
2184 def NbTrianglesOfOrder(self, elementOrder):
2185 return self.mesh.NbTrianglesOfOrder(elementOrder)
2187 ## Returns the number of biquadratic triangles in the mesh
2188 # @return an integer value
2189 # @ingroup l1_meshinfo
2190 def NbBiQuadTriangles(self):
2191 return self.mesh.NbBiQuadTriangles()
2193 ## Returns the number of quadrangles in the mesh
2194 # @return an integer value
2195 # @ingroup l1_meshinfo
2196 def NbQuadrangles(self):
2197 return self.mesh.NbQuadrangles()
2199 ## Returns the number of quadrangles with the given order in the mesh
2200 # @param elementOrder the order of elements:
2201 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2202 # @return an integer value
2203 # @ingroup l1_meshinfo
2204 def NbQuadranglesOfOrder(self, elementOrder):
2205 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2207 ## Returns the number of biquadratic quadrangles in the mesh
2208 # @return an integer value
2209 # @ingroup l1_meshinfo
2210 def NbBiQuadQuadrangles(self):
2211 return self.mesh.NbBiQuadQuadrangles()
2213 ## Returns the number of polygons in the mesh
2214 # @return an integer value
2215 # @ingroup l1_meshinfo
2216 def NbPolygons(self):
2217 return self.mesh.NbPolygons()
2219 ## Returns the number of volumes in the mesh
2220 # @return an integer value
2221 # @ingroup l1_meshinfo
2222 def NbVolumes(self):
2223 return self.mesh.NbVolumes()
2225 ## Returns the number of volumes with the given order in the mesh
2226 # @param elementOrder the order of elements:
2227 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2228 # @return an integer value
2229 # @ingroup l1_meshinfo
2230 def NbVolumesOfOrder(self, elementOrder):
2231 return self.mesh.NbVolumesOfOrder(elementOrder)
2233 ## Returns the number of tetrahedrons in the mesh
2234 # @return an integer value
2235 # @ingroup l1_meshinfo
2237 return self.mesh.NbTetras()
2239 ## Returns the number of tetrahedrons with the given order in the mesh
2240 # @param elementOrder the order of elements:
2241 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2242 # @return an integer value
2243 # @ingroup l1_meshinfo
2244 def NbTetrasOfOrder(self, elementOrder):
2245 return self.mesh.NbTetrasOfOrder(elementOrder)
2247 ## Returns the number of hexahedrons in the mesh
2248 # @return an integer value
2249 # @ingroup l1_meshinfo
2251 return self.mesh.NbHexas()
2253 ## Returns the number of hexahedrons with the given order in the mesh
2254 # @param elementOrder the order of elements:
2255 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2256 # @return an integer value
2257 # @ingroup l1_meshinfo
2258 def NbHexasOfOrder(self, elementOrder):
2259 return self.mesh.NbHexasOfOrder(elementOrder)
2261 ## Returns the number of triquadratic hexahedrons in the mesh
2262 # @return an integer value
2263 # @ingroup l1_meshinfo
2264 def NbTriQuadraticHexas(self):
2265 return self.mesh.NbTriQuadraticHexas()
2267 ## Returns the number of pyramids in the mesh
2268 # @return an integer value
2269 # @ingroup l1_meshinfo
2270 def NbPyramids(self):
2271 return self.mesh.NbPyramids()
2273 ## Returns the number of pyramids with the given order in the mesh
2274 # @param elementOrder the order of elements:
2275 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2276 # @return an integer value
2277 # @ingroup l1_meshinfo
2278 def NbPyramidsOfOrder(self, elementOrder):
2279 return self.mesh.NbPyramidsOfOrder(elementOrder)
2281 ## Returns the number of prisms in the mesh
2282 # @return an integer value
2283 # @ingroup l1_meshinfo
2285 return self.mesh.NbPrisms()
2287 ## Returns the number of prisms with the given order in the mesh
2288 # @param elementOrder the order of elements:
2289 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2290 # @return an integer value
2291 # @ingroup l1_meshinfo
2292 def NbPrismsOfOrder(self, elementOrder):
2293 return self.mesh.NbPrismsOfOrder(elementOrder)
2295 ## Returns the number of hexagonal prisms in the mesh
2296 # @return an integer value
2297 # @ingroup l1_meshinfo
2298 def NbHexagonalPrisms(self):
2299 return self.mesh.NbHexagonalPrisms()
2301 ## Returns the number of polyhedrons in the mesh
2302 # @return an integer value
2303 # @ingroup l1_meshinfo
2304 def NbPolyhedrons(self):
2305 return self.mesh.NbPolyhedrons()
2307 ## Returns the number of submeshes in the mesh
2308 # @return an integer value
2309 # @ingroup l1_meshinfo
2310 def NbSubMesh(self):
2311 return self.mesh.NbSubMesh()
2313 ## Returns the list of mesh elements IDs
2314 # @return the list of integer values
2315 # @ingroup l1_meshinfo
2316 def GetElementsId(self):
2317 return self.mesh.GetElementsId()
2319 ## Returns the list of IDs of mesh elements with the given type
2320 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2321 # @return list of integer values
2322 # @ingroup l1_meshinfo
2323 def GetElementsByType(self, elementType):
2324 return self.mesh.GetElementsByType(elementType)
2326 ## Returns the list of mesh nodes IDs
2327 # @return the list of integer values
2328 # @ingroup l1_meshinfo
2329 def GetNodesId(self):
2330 return self.mesh.GetNodesId()
2332 # Get the information about mesh elements:
2333 # ------------------------------------
2335 ## Returns the type of mesh element
2336 # @return the value from SMESH::ElementType enumeration
2337 # @ingroup l1_meshinfo
2338 def GetElementType(self, id, iselem):
2339 return self.mesh.GetElementType(id, iselem)
2341 ## Returns the geometric type of mesh element
2342 # @return the value from SMESH::EntityType enumeration
2343 # @ingroup l1_meshinfo
2344 def GetElementGeomType(self, id):
2345 return self.mesh.GetElementGeomType(id)
2347 ## Returns the shape type of mesh element
2348 # @return the value from SMESH::GeometryType enumeration
2349 # @ingroup l1_meshinfo
2350 def GetElementShape(self, id):
2351 return self.mesh.GetElementShape(id)
2353 ## Returns the list of submesh elements IDs
2354 # @param Shape a geom object(sub-shape) IOR
2355 # Shape must be the sub-shape of a ShapeToMesh()
2356 # @return the list of integer values
2357 # @ingroup l1_meshinfo
2358 def GetSubMeshElementsId(self, Shape):
2359 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2360 ShapeID = Shape.GetSubShapeIndices()[0]
2363 return self.mesh.GetSubMeshElementsId(ShapeID)
2365 ## Returns the list of submesh nodes IDs
2366 # @param Shape a geom object(sub-shape) IOR
2367 # Shape must be the sub-shape of a ShapeToMesh()
2368 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2369 # @return the list of integer values
2370 # @ingroup l1_meshinfo
2371 def GetSubMeshNodesId(self, Shape, all):
2372 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2373 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2376 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2378 ## Returns type of elements on given shape
2379 # @param Shape a geom object(sub-shape) IOR
2380 # Shape must be a sub-shape of a ShapeToMesh()
2381 # @return element type
2382 # @ingroup l1_meshinfo
2383 def GetSubMeshElementType(self, Shape):
2384 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2385 ShapeID = Shape.GetSubShapeIndices()[0]
2388 return self.mesh.GetSubMeshElementType(ShapeID)
2390 ## Gets the mesh description
2391 # @return string value
2392 # @ingroup l1_meshinfo
2394 return self.mesh.Dump()
2397 # Get the information about nodes and elements of a mesh by its IDs:
2398 # -----------------------------------------------------------
2400 ## Gets XYZ coordinates of a node
2401 # \n If there is no nodes for the given ID - returns an empty list
2402 # @return a list of double precision values
2403 # @ingroup l1_meshinfo
2404 def GetNodeXYZ(self, id):
2405 return self.mesh.GetNodeXYZ(id)
2407 ## Returns list of IDs of inverse elements for the given node
2408 # \n If there is no node for the given ID - returns an empty list
2409 # @return a list of integer values
2410 # @ingroup l1_meshinfo
2411 def GetNodeInverseElements(self, id):
2412 return self.mesh.GetNodeInverseElements(id)
2414 ## @brief Returns the position of a node on the shape
2415 # @return SMESH::NodePosition
2416 # @ingroup l1_meshinfo
2417 def GetNodePosition(self,NodeID):
2418 return self.mesh.GetNodePosition(NodeID)
2420 ## @brief Returns the position of an element on the shape
2421 # @return SMESH::ElementPosition
2422 # @ingroup l1_meshinfo
2423 def GetElementPosition(self,ElemID):
2424 return self.mesh.GetElementPosition(ElemID)
2426 ## If the given element is a node, returns the ID of shape
2427 # \n If there is no node for the given ID - returns -1
2428 # @return an integer value
2429 # @ingroup l1_meshinfo
2430 def GetShapeID(self, id):
2431 return self.mesh.GetShapeID(id)
2433 ## Returns the ID of the result shape after
2434 # FindShape() from SMESH_MeshEditor for the given element
2435 # \n If there is no element for the given ID - returns -1
2436 # @return an integer value
2437 # @ingroup l1_meshinfo
2438 def GetShapeIDForElem(self,id):
2439 return self.mesh.GetShapeIDForElem(id)
2441 ## Returns the number of nodes for the given element
2442 # \n If there is no element for the given ID - returns -1
2443 # @return an integer value
2444 # @ingroup l1_meshinfo
2445 def GetElemNbNodes(self, id):
2446 return self.mesh.GetElemNbNodes(id)
2448 ## Returns the node ID the given (zero based) index for the given element
2449 # \n If there is no element for the given ID - returns -1
2450 # \n If there is no node for the given index - returns -2
2451 # @return an integer value
2452 # @ingroup l1_meshinfo
2453 def GetElemNode(self, id, index):
2454 return self.mesh.GetElemNode(id, index)
2456 ## Returns the IDs of nodes of the given element
2457 # @return a list of integer values
2458 # @ingroup l1_meshinfo
2459 def GetElemNodes(self, id):
2460 return self.mesh.GetElemNodes(id)
2462 ## Returns true if the given node is the medium node in the given quadratic element
2463 # @ingroup l1_meshinfo
2464 def IsMediumNode(self, elementID, nodeID):
2465 return self.mesh.IsMediumNode(elementID, nodeID)
2467 ## Returns true if the given node is the medium node in one of quadratic elements
2468 # @ingroup l1_meshinfo
2469 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2470 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2472 ## Returns the number of edges for the given element
2473 # @ingroup l1_meshinfo
2474 def ElemNbEdges(self, id):
2475 return self.mesh.ElemNbEdges(id)
2477 ## Returns the number of faces for the given element
2478 # @ingroup l1_meshinfo
2479 def ElemNbFaces(self, id):
2480 return self.mesh.ElemNbFaces(id)
2482 ## Returns nodes of given face (counted from zero) for given volumic element.
2483 # @ingroup l1_meshinfo
2484 def GetElemFaceNodes(self,elemId, faceIndex):
2485 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2487 ## Returns three components of normal of given mesh face
2488 # (or an empty array in KO case)
2489 # @ingroup l1_meshinfo
2490 def GetFaceNormal(self, faceId, normalized=False):
2491 return self.mesh.GetFaceNormal(faceId,normalized)
2493 ## Returns an element based on all given nodes.
2494 # @ingroup l1_meshinfo
2495 def FindElementByNodes(self,nodes):
2496 return self.mesh.FindElementByNodes(nodes)
2498 ## Returns true if the given element is a polygon
2499 # @ingroup l1_meshinfo
2500 def IsPoly(self, id):
2501 return self.mesh.IsPoly(id)
2503 ## Returns true if the given element is quadratic
2504 # @ingroup l1_meshinfo
2505 def IsQuadratic(self, id):
2506 return self.mesh.IsQuadratic(id)
2508 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2509 # @ingroup l1_meshinfo
2510 def GetBallDiameter(self, id):
2511 return self.mesh.GetBallDiameter(id)
2513 ## Returns XYZ coordinates of the barycenter of the given element
2514 # \n If there is no element for the given ID - returns an empty list
2515 # @return a list of three double values
2516 # @ingroup l1_meshinfo
2517 def BaryCenter(self, id):
2518 return self.mesh.BaryCenter(id)
2520 ## Passes mesh elements through the given filter and return IDs of fitting elements
2521 # @param theFilter SMESH_Filter
2522 # @return a list of ids
2523 # @ingroup l1_controls
2524 def GetIdsFromFilter(self, theFilter):
2525 theFilter.SetMesh( self.mesh )
2526 return theFilter.GetIDs()
2528 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2529 # Returns a list of special structures (borders).
2530 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2531 # @ingroup l1_controls
2532 def GetFreeBorders(self):
2533 aFilterMgr = self.smeshpyD.CreateFilterManager()
2534 aPredicate = aFilterMgr.CreateFreeEdges()
2535 aPredicate.SetMesh(self.mesh)
2536 aBorders = aPredicate.GetBorders()
2537 aFilterMgr.UnRegister()
2541 # Get mesh measurements information:
2542 # ------------------------------------
2544 ## Get minimum distance between two nodes, elements or distance to the origin
2545 # @param id1 first node/element id
2546 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2547 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2548 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2549 # @return minimum distance value
2550 # @sa GetMinDistance()
2551 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2552 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2553 return aMeasure.value
2555 ## Get measure structure specifying minimum distance data between two objects
2556 # @param id1 first node/element id
2557 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2558 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2559 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2560 # @return Measure structure
2562 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2564 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2566 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2569 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2571 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2576 aMeasurements = self.smeshpyD.CreateMeasurements()
2577 aMeasure = aMeasurements.MinDistance(id1, id2)
2578 genObjUnRegister([aMeasurements,id1, id2])
2581 ## Get bounding box of the specified object(s)
2582 # @param objects single source object or list of source objects or list of nodes/elements IDs
2583 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2584 # @c False specifies that @a objects are nodes
2585 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2586 # @sa GetBoundingBox()
2587 def BoundingBox(self, objects=None, isElem=False):
2588 result = self.GetBoundingBox(objects, isElem)
2592 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2595 ## Get measure structure specifying bounding box data of the specified object(s)
2596 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2597 # @param isElem if @a IDs is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2598 # @c False specifies that @a objects are nodes
2599 # @return Measure structure
2601 def GetBoundingBox(self, IDs=None, isElem=False):
2604 elif isinstance(IDs, tuple):
2606 if not isinstance(IDs, list):
2608 if len(IDs) > 0 and isinstance(IDs[0], int):
2611 unRegister = genObjUnRegister()
2613 if isinstance(o, Mesh):
2614 srclist.append(o.mesh)
2615 elif hasattr(o, "_narrow"):
2616 src = o._narrow(SMESH.SMESH_IDSource)
2617 if src: srclist.append(src)
2619 elif isinstance(o, list):
2621 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2623 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2624 unRegister.set( srclist[-1] )
2627 aMeasurements = self.smeshpyD.CreateMeasurements()
2628 unRegister.set( aMeasurements )
2629 aMeasure = aMeasurements.BoundingBox(srclist)
2632 # Mesh edition (SMESH_MeshEditor functionality):
2633 # ---------------------------------------------
2635 ## Removes the elements from the mesh by ids
2636 # @param IDsOfElements is a list of ids of elements to remove
2637 # @return True or False
2638 # @ingroup l2_modif_del
2639 def RemoveElements(self, IDsOfElements):
2640 return self.editor.RemoveElements(IDsOfElements)
2642 ## Removes nodes from mesh by ids
2643 # @param IDsOfNodes is a list of ids of nodes to remove
2644 # @return True or False
2645 # @ingroup l2_modif_del
2646 def RemoveNodes(self, IDsOfNodes):
2647 return self.editor.RemoveNodes(IDsOfNodes)
2649 ## Removes all orphan (free) nodes from mesh
2650 # @return number of the removed nodes
2651 # @ingroup l2_modif_del
2652 def RemoveOrphanNodes(self):
2653 return self.editor.RemoveOrphanNodes()
2655 ## Add a node to the mesh by coordinates
2656 # @return Id of the new node
2657 # @ingroup l2_modif_add
2658 def AddNode(self, x, y, z):
2659 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2660 if hasVars: self.mesh.SetParameters(Parameters)
2661 return self.editor.AddNode( x, y, z)
2663 ## Creates a 0D element on a node with given number.
2664 # @param IDOfNode the ID of node for creation of the element.
2665 # @return the Id of the new 0D element
2666 # @ingroup l2_modif_add
2667 def Add0DElement(self, IDOfNode):
2668 return self.editor.Add0DElement(IDOfNode)
2670 ## Create 0D elements on all nodes of the given elements except those
2671 # nodes on which a 0D element already exists.
2672 # @param theObject an object on whose nodes 0D elements will be created.
2673 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2674 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2675 # @param theGroupName optional name of a group to add 0D elements created
2676 # and/or found on nodes of \a theObject.
2677 # @return an object (a new group or a temporary SMESH_IDSource) holding
2678 # IDs of new and/or found 0D elements. IDs of 0D elements
2679 # can be retrieved from the returned object by calling GetIDs()
2680 # @ingroup l2_modif_add
2681 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2682 unRegister = genObjUnRegister()
2683 if isinstance( theObject, Mesh ):
2684 theObject = theObject.GetMesh()
2685 if isinstance( theObject, list ):
2686 theObject = self.GetIDSource( theObject, SMESH.ALL )
2687 unRegister.set( theObject )
2688 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2690 ## Creates a ball element on a node with given ID.
2691 # @param IDOfNode the ID of node for creation of the element.
2692 # @param diameter the bal diameter.
2693 # @return the Id of the new ball element
2694 # @ingroup l2_modif_add
2695 def AddBall(self, IDOfNode, diameter):
2696 return self.editor.AddBall( IDOfNode, diameter )
2698 ## Creates a linear or quadratic edge (this is determined
2699 # by the number of given nodes).
2700 # @param IDsOfNodes the list of node IDs for creation of the element.
2701 # The order of nodes in this list should correspond to the description
2702 # of MED. \n This description is located by the following link:
2703 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2704 # @return the Id of the new edge
2705 # @ingroup l2_modif_add
2706 def AddEdge(self, IDsOfNodes):
2707 return self.editor.AddEdge(IDsOfNodes)
2709 ## Creates a linear or quadratic face (this is determined
2710 # by the number of given nodes).
2711 # @param IDsOfNodes the list of node IDs for creation of the element.
2712 # The order of nodes in this list should correspond to the description
2713 # of MED. \n This description is located by the following link:
2714 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2715 # @return the Id of the new face
2716 # @ingroup l2_modif_add
2717 def AddFace(self, IDsOfNodes):
2718 return self.editor.AddFace(IDsOfNodes)
2720 ## Adds a polygonal face to the mesh by the list of node IDs
2721 # @param IdsOfNodes the list of node IDs for creation of the element.
2722 # @return the Id of the new face
2723 # @ingroup l2_modif_add
2724 def AddPolygonalFace(self, IdsOfNodes):
2725 return self.editor.AddPolygonalFace(IdsOfNodes)
2727 ## Creates both simple and quadratic volume (this is determined
2728 # by the number of given nodes).
2729 # @param IDsOfNodes the list of node IDs for creation of the element.
2730 # The order of nodes in this list should correspond to the description
2731 # of MED. \n This description is located by the following link:
2732 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2733 # @return the Id of the new volumic element
2734 # @ingroup l2_modif_add
2735 def AddVolume(self, IDsOfNodes):
2736 return self.editor.AddVolume(IDsOfNodes)
2738 ## Creates a volume of many faces, giving nodes for each face.
2739 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2740 # @param Quantities the list of integer values, Quantities[i]
2741 # gives the quantity of nodes in face number i.
2742 # @return the Id of the new volumic element
2743 # @ingroup l2_modif_add
2744 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2745 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2747 ## Creates a volume of many faces, giving the IDs of the existing faces.
2748 # @param IdsOfFaces the list of face IDs for volume creation.
2750 # Note: The created volume will refer only to the nodes
2751 # of the given faces, not to the faces themselves.
2752 # @return the Id of the new volumic element
2753 # @ingroup l2_modif_add
2754 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2755 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2758 ## @brief Binds a node to a vertex
2759 # @param NodeID a node ID
2760 # @param Vertex a vertex or vertex ID
2761 # @return True if succeed else raises an exception
2762 # @ingroup l2_modif_add
2763 def SetNodeOnVertex(self, NodeID, Vertex):
2764 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
2765 VertexID = Vertex.GetSubShapeIndices()[0]
2769 self.editor.SetNodeOnVertex(NodeID, VertexID)
2770 except SALOME.SALOME_Exception, inst:
2771 raise ValueError, inst.details.text
2775 ## @brief Stores the node position on an edge
2776 # @param NodeID a node ID
2777 # @param Edge an edge or edge ID
2778 # @param paramOnEdge a parameter on the edge where the node is located
2779 # @return True if succeed else raises an exception
2780 # @ingroup l2_modif_add
2781 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2782 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
2783 EdgeID = Edge.GetSubShapeIndices()[0]
2787 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2788 except SALOME.SALOME_Exception, inst:
2789 raise ValueError, inst.details.text
2792 ## @brief Stores node position on a face
2793 # @param NodeID a node ID
2794 # @param Face a face or face ID
2795 # @param u U parameter on the face where the node is located
2796 # @param v V parameter on the face where the node is located
2797 # @return True if succeed else raises an exception
2798 # @ingroup l2_modif_add
2799 def SetNodeOnFace(self, NodeID, Face, u, v):
2800 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
2801 FaceID = Face.GetSubShapeIndices()[0]
2805 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2806 except SALOME.SALOME_Exception, inst:
2807 raise ValueError, inst.details.text
2810 ## @brief Binds a node to a solid
2811 # @param NodeID a node ID
2812 # @param Solid a solid or solid ID
2813 # @return True if succeed else raises an exception
2814 # @ingroup l2_modif_add
2815 def SetNodeInVolume(self, NodeID, Solid):
2816 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
2817 SolidID = Solid.GetSubShapeIndices()[0]
2821 self.editor.SetNodeInVolume(NodeID, SolidID)
2822 except SALOME.SALOME_Exception, inst:
2823 raise ValueError, inst.details.text
2826 ## @brief Bind an element to a shape
2827 # @param ElementID an element ID
2828 # @param Shape a shape or shape ID
2829 # @return True if succeed else raises an exception
2830 # @ingroup l2_modif_add
2831 def SetMeshElementOnShape(self, ElementID, Shape):
2832 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2833 ShapeID = Shape.GetSubShapeIndices()[0]
2837 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2838 except SALOME.SALOME_Exception, inst:
2839 raise ValueError, inst.details.text
2843 ## Moves the node with the given id
2844 # @param NodeID the id of the node
2845 # @param x a new X coordinate
2846 # @param y a new Y coordinate
2847 # @param z a new Z coordinate
2848 # @return True if succeed else False
2849 # @ingroup l2_modif_movenode
2850 def MoveNode(self, NodeID, x, y, z):
2851 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2852 if hasVars: self.mesh.SetParameters(Parameters)
2853 return self.editor.MoveNode(NodeID, x, y, z)
2855 ## Finds the node closest to a point and moves it to a point location
2856 # @param x the X coordinate of a point
2857 # @param y the Y coordinate of a point
2858 # @param z the Z coordinate of a point
2859 # @param NodeID if specified (>0), the node with this ID is moved,
2860 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2861 # @return the ID of a node
2862 # @ingroup l2_modif_throughp
2863 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2864 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2865 if hasVars: self.mesh.SetParameters(Parameters)
2866 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2868 ## Finds the node closest to a point
2869 # @param x the X coordinate of a point
2870 # @param y the Y coordinate of a point
2871 # @param z the Z coordinate of a point
2872 # @return the ID of a node
2873 # @ingroup l2_modif_throughp
2874 def FindNodeClosestTo(self, x, y, z):
2875 #preview = self.mesh.GetMeshEditPreviewer()
2876 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2877 return self.editor.FindNodeClosestTo(x, y, z)
2879 ## Finds the elements where a point lays IN or ON
2880 # @param x the X coordinate of a point
2881 # @param y the Y coordinate of a point
2882 # @param z the Z coordinate of a point
2883 # @param elementType type of elements to find (SMESH.ALL type
2884 # means elements of any type excluding nodes, discrete and 0D elements)
2885 # @param meshPart a part of mesh (group, sub-mesh) to search within
2886 # @return list of IDs of found elements
2887 # @ingroup l2_modif_throughp
2888 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2890 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2892 return self.editor.FindElementsByPoint(x, y, z, elementType)
2894 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2895 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2896 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2898 def GetPointState(self, x, y, z):
2899 return self.editor.GetPointState(x, y, z)
2901 ## Finds the node closest to a point and moves it to a point location
2902 # @param x the X coordinate of a point
2903 # @param y the Y coordinate of a point
2904 # @param z the Z coordinate of a point
2905 # @return the ID of a moved node
2906 # @ingroup l2_modif_throughp
2907 def MeshToPassThroughAPoint(self, x, y, z):
2908 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2910 ## Replaces two neighbour triangles sharing Node1-Node2 link
2911 # with the triangles built on the same 4 nodes but having other common link.
2912 # @param NodeID1 the ID of the first node
2913 # @param NodeID2 the ID of the second node
2914 # @return false if proper faces were not found
2915 # @ingroup l2_modif_invdiag
2916 def InverseDiag(self, NodeID1, NodeID2):
2917 return self.editor.InverseDiag(NodeID1, NodeID2)
2919 ## Replaces two neighbour triangles sharing Node1-Node2 link
2920 # with a quadrangle built on the same 4 nodes.
2921 # @param NodeID1 the ID of the first node
2922 # @param NodeID2 the ID of the second node
2923 # @return false if proper faces were not found
2924 # @ingroup l2_modif_unitetri
2925 def DeleteDiag(self, NodeID1, NodeID2):
2926 return self.editor.DeleteDiag(NodeID1, NodeID2)
2928 ## Reorients elements by ids
2929 # @param IDsOfElements if undefined reorients all mesh elements
2930 # @return True if succeed else False
2931 # @ingroup l2_modif_changori
2932 def Reorient(self, IDsOfElements=None):
2933 if IDsOfElements == None:
2934 IDsOfElements = self.GetElementsId()
2935 return self.editor.Reorient(IDsOfElements)
2937 ## Reorients all elements of the object
2938 # @param theObject mesh, submesh or group
2939 # @return True if succeed else False
2940 # @ingroup l2_modif_changori
2941 def ReorientObject(self, theObject):
2942 if ( isinstance( theObject, Mesh )):
2943 theObject = theObject.GetMesh()
2944 return self.editor.ReorientObject(theObject)
2946 ## Reorient faces contained in \a the2DObject.
2947 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2948 # @param theDirection is a desired direction of normal of \a theFace.
2949 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2950 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2951 # compared with theDirection. It can be either ID of face or a point
2952 # by which the face will be found. The point can be given as either
2953 # a GEOM vertex or a list of point coordinates.
2954 # @return number of reoriented faces
2955 # @ingroup l2_modif_changori
2956 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2957 unRegister = genObjUnRegister()
2959 if isinstance( the2DObject, Mesh ):
2960 the2DObject = the2DObject.GetMesh()
2961 if isinstance( the2DObject, list ):
2962 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2963 unRegister.set( the2DObject )
2964 # check theDirection
2965 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
2966 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2967 if isinstance( theDirection, list ):
2968 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2969 # prepare theFace and thePoint
2970 theFace = theFaceOrPoint
2971 thePoint = PointStruct(0,0,0)
2972 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
2973 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2975 if isinstance( theFaceOrPoint, list ):
2976 thePoint = PointStruct( *theFaceOrPoint )
2978 if isinstance( theFaceOrPoint, PointStruct ):
2979 thePoint = theFaceOrPoint
2981 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2983 ## Reorient faces according to adjacent volumes.
2984 # @param the2DObject is a mesh, sub-mesh, group or list of
2985 # either IDs of faces or face groups.
2986 # @param the3DObject is a mesh, sub-mesh, group or list of IDs of volumes.
2987 # @param theOutsideNormal to orient faces to have their normals
2988 # pointing either \a outside or \a inside the adjacent volumes.
2989 # @return number of reoriented faces.
2990 # @ingroup l2_modif_changori
2991 def Reorient2DBy3D(self, the2DObject, the3DObject, theOutsideNormal=True ):
2992 unRegister = genObjUnRegister()
2994 if not isinstance( the2DObject, list ):
2995 the2DObject = [ the2DObject ]
2996 elif the2DObject and isinstance( the2DObject[0], int ):
2997 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2998 unRegister.set( the2DObject )
2999 the2DObject = [ the2DObject ]
3000 for i,obj2D in enumerate( the2DObject ):
3001 if isinstance( obj2D, Mesh ):
3002 the2DObject[i] = obj2D.GetMesh()
3003 if isinstance( obj2D, list ):
3004 the2DObject[i] = self.GetIDSource( obj2D, SMESH.FACE )
3005 unRegister.set( the2DObject[i] )
3007 if isinstance( the3DObject, Mesh ):
3008 the3DObject = the3DObject.GetMesh()
3009 if isinstance( the3DObject, list ):
3010 the3DObject = self.GetIDSource( the3DObject, SMESH.VOLUME )
3011 unRegister.set( the3DObject )
3012 return self.editor.Reorient2DBy3D( the2DObject, the3DObject, theOutsideNormal )
3014 ## Fuses the neighbouring triangles into quadrangles.
3015 # @param IDsOfElements The triangles to be fused,
3016 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3017 # choose a neighbour to fuse with.
3018 # @param MaxAngle is the maximum angle between element normals at which the fusion
3019 # is still performed; theMaxAngle is mesured in radians.
3020 # Also it could be a name of variable which defines angle in degrees.
3021 # @return TRUE in case of success, FALSE otherwise.
3022 # @ingroup l2_modif_unitetri
3023 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
3024 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
3025 self.mesh.SetParameters(Parameters)
3026 if not IDsOfElements:
3027 IDsOfElements = self.GetElementsId()
3028 Functor = self.smeshpyD.GetFunctor(theCriterion)
3029 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
3031 ## Fuses the neighbouring triangles of the object into quadrangles
3032 # @param theObject is mesh, submesh or group
3033 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3034 # choose a neighbour to fuse with.
3035 # @param MaxAngle a max angle between element normals at which the fusion
3036 # is still performed; theMaxAngle is mesured in radians.
3037 # @return TRUE in case of success, FALSE otherwise.
3038 # @ingroup l2_modif_unitetri
3039 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
3040 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
3041 self.mesh.SetParameters(Parameters)
3042 if isinstance( theObject, Mesh ):
3043 theObject = theObject.GetMesh()
3044 Functor = self.smeshpyD.GetFunctor(theCriterion)
3045 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
3047 ## Splits quadrangles into triangles.
3048 # @param IDsOfElements the faces to be splitted.
3049 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3050 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
3051 # value, then quadrangles will be split by the smallest diagonal.
3052 # @return TRUE in case of success, FALSE otherwise.
3053 # @ingroup l2_modif_cutquadr
3054 def QuadToTri (self, IDsOfElements, theCriterion = None):
3055 if IDsOfElements == []:
3056 IDsOfElements = self.GetElementsId()
3057 if theCriterion is None:
3058 theCriterion = FT_MaxElementLength2D
3059 Functor = self.smeshpyD.GetFunctor(theCriterion)
3060 return self.editor.QuadToTri(IDsOfElements, Functor)
3062 ## Splits quadrangles into triangles.
3063 # @param theObject the object from which the list of elements is taken,
3064 # this is mesh, submesh or group
3065 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3066 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
3067 # value, then quadrangles will be split by the smallest diagonal.
3068 # @return TRUE in case of success, FALSE otherwise.
3069 # @ingroup l2_modif_cutquadr
3070 def QuadToTriObject (self, theObject, theCriterion = None):
3071 if ( isinstance( theObject, Mesh )):
3072 theObject = theObject.GetMesh()
3073 if theCriterion is None:
3074 theCriterion = FT_MaxElementLength2D
3075 Functor = self.smeshpyD.GetFunctor(theCriterion)
3076 return self.editor.QuadToTriObject(theObject, Functor)
3078 ## Splits each of given quadrangles into 4 triangles. A node is added at the center of
3080 # @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
3081 # group or a list of face IDs. By default all quadrangles are split
3082 # @ingroup l2_modif_cutquadr
3083 def QuadTo4Tri (self, theElements=[]):
3084 unRegister = genObjUnRegister()
3085 if isinstance( theElements, Mesh ):
3086 theElements = theElements.mesh
3087 elif not theElements:
3088 theElements = self.mesh
3089 elif isinstance( theElements, list ):
3090 theElements = self.GetIDSource( theElements, SMESH.FACE )
3091 unRegister.set( theElements )
3092 return self.editor.QuadTo4Tri( theElements )
3094 ## Splits quadrangles into triangles.
3095 # @param IDsOfElements the faces to be splitted
3096 # @param Diag13 is used to choose a diagonal for splitting.
3097 # @return TRUE in case of success, FALSE otherwise.
3098 # @ingroup l2_modif_cutquadr
3099 def SplitQuad (self, IDsOfElements, Diag13):
3100 if IDsOfElements == []:
3101 IDsOfElements = self.GetElementsId()
3102 return self.editor.SplitQuad(IDsOfElements, Diag13)
3104 ## Splits quadrangles into triangles.
3105 # @param theObject the object from which the list of elements is taken,
3106 # this is mesh, submesh or group
3107 # @param Diag13 is used to choose a diagonal for splitting.
3108 # @return TRUE in case of success, FALSE otherwise.
3109 # @ingroup l2_modif_cutquadr
3110 def SplitQuadObject (self, theObject, Diag13):
3111 if ( isinstance( theObject, Mesh )):
3112 theObject = theObject.GetMesh()
3113 return self.editor.SplitQuadObject(theObject, Diag13)
3115 ## Finds a better splitting of the given quadrangle.
3116 # @param IDOfQuad the ID of the quadrangle to be splitted.
3117 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3118 # choose a diagonal for splitting.
3119 # @return 1 if 1-3 diagonal is better, 2 if 2-4
3120 # diagonal is better, 0 if error occurs.
3121 # @ingroup l2_modif_cutquadr
3122 def BestSplit (self, IDOfQuad, theCriterion):
3123 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
3125 ## Splits volumic elements into tetrahedrons
3126 # @param elems either a list of elements or a mesh or a group or a submesh or a filter
3127 # @param method flags passing splitting method:
3128 # smesh.Hex_5Tet, smesh.Hex_6Tet, smesh.Hex_24Tet.
3129 # smesh.Hex_5Tet - to split the hexahedron into 5 tetrahedrons, etc.
3130 # @ingroup l2_modif_cutquadr
3131 def SplitVolumesIntoTetra(self, elems, method=smeshBuilder.Hex_5Tet ):
3132 unRegister = genObjUnRegister()
3133 if isinstance( elems, Mesh ):
3134 elems = elems.GetMesh()
3135 if ( isinstance( elems, list )):
3136 elems = self.editor.MakeIDSource(elems, SMESH.VOLUME)
3137 unRegister.set( elems )
3138 self.editor.SplitVolumesIntoTetra(elems, method)
3140 ## Splits hexahedra into prisms
3141 # @param elems either a list of elements or a mesh or a group or a submesh or a filter
3142 # @param startHexPoint a point used to find a hexahedron for which @a facetNormal
3143 # gives a normal vector defining facets to split into triangles.
3144 # @a startHexPoint can be either a triple of coordinates or a vertex.
3145 # @param facetNormal a normal to a facet to split into triangles of a
3146 # hexahedron found by @a startHexPoint.
3147 # @a facetNormal can be either a triple of coordinates or an edge.
3148 # @param method flags passing splitting method: smesh.Hex_2Prisms, smesh.Hex_4Prisms.
3149 # smesh.Hex_2Prisms - to split the hexahedron into 2 prisms, etc.
3150 # @param allDomains if @c False, only hexahedra adjacent to one closest
3151 # to @a startHexPoint are split, else @a startHexPoint
3152 # is used to find the facet to split in all domains present in @a elems.
3153 # @ingroup l2_modif_cutquadr
3154 def SplitHexahedraIntoPrisms(self, elems, startHexPoint, facetNormal,
3155 method=smeshBuilder.Hex_2Prisms, allDomains=False ):
3157 unRegister = genObjUnRegister()
3158 if isinstance( elems, Mesh ):
3159 elems = elems.GetMesh()
3160 if ( isinstance( elems, list )):
3161 elems = self.editor.MakeIDSource(elems, SMESH.VOLUME)
3162 unRegister.set( elems )
3165 if isinstance( startHexPoint, geomBuilder.GEOM._objref_GEOM_Object):
3166 startHexPoint = self.smeshpyD.GetPointStruct( startHexPoint )
3167 elif isinstance( startHexPoint, list ):
3168 startHexPoint = SMESH.PointStruct( startHexPoint[0],
3171 if isinstance( facetNormal, geomBuilder.GEOM._objref_GEOM_Object):
3172 facetNormal = self.smeshpyD.GetDirStruct( facetNormal )
3173 elif isinstance( facetNormal, list ):
3174 facetNormal = self.smeshpyD.MakeDirStruct( facetNormal[0],
3177 self.mesh.SetParameters( startHexPoint.parameters + facetNormal.PS.parameters )
3179 self.editor.SplitHexahedraIntoPrisms(elems, startHexPoint, facetNormal, method, allDomains)
3181 ## Splits quadrangle faces near triangular facets of volumes
3183 # @ingroup l1_auxiliary
3184 def SplitQuadsNearTriangularFacets(self):
3185 faces_array = self.GetElementsByType(SMESH.FACE)
3186 for face_id in faces_array:
3187 if self.GetElemNbNodes(face_id) == 4: # quadrangle
3188 quad_nodes = self.mesh.GetElemNodes(face_id)
3189 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
3190 isVolumeFound = False
3191 for node1_elem in node1_elems:
3192 if not isVolumeFound:
3193 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
3194 nb_nodes = self.GetElemNbNodes(node1_elem)
3195 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
3196 volume_elem = node1_elem
3197 volume_nodes = self.mesh.GetElemNodes(volume_elem)
3198 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
3199 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
3200 isVolumeFound = True
3201 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
3202 self.SplitQuad([face_id], False) # diagonal 2-4
3203 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
3204 isVolumeFound = True
3205 self.SplitQuad([face_id], True) # diagonal 1-3
3206 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
3207 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
3208 isVolumeFound = True
3209 self.SplitQuad([face_id], True) # diagonal 1-3
3211 ## @brief Splits hexahedrons into tetrahedrons.
3213 # This operation uses pattern mapping functionality for splitting.
3214 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
3215 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
3216 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
3217 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
3218 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
3219 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
3220 # @return TRUE in case of success, FALSE otherwise.
3221 # @ingroup l1_auxiliary
3222 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
3223 # Pattern: 5.---------.6
3228 # (0,0,1) 4.---------.7 * |
3235 # (0,0,0) 0.---------.3
3236 pattern_tetra = "!!! Nb of points: \n 8 \n\
3246 !!! Indices of points of 6 tetras: \n\
3254 pattern = self.smeshpyD.GetPattern()
3255 isDone = pattern.LoadFromFile(pattern_tetra)
3257 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3260 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3261 isDone = pattern.MakeMesh(self.mesh, False, False)
3262 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3264 # split quafrangle faces near triangular facets of volumes
3265 self.SplitQuadsNearTriangularFacets()
3269 ## @brief Split hexahedrons into prisms.
3271 # Uses the pattern mapping functionality for splitting.
3272 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
3273 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
3274 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
3275 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
3276 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
3277 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
3278 # @return TRUE in case of success, FALSE otherwise.
3279 # @ingroup l1_auxiliary
3280 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3281 # Pattern: 5.---------.6
3286 # (0,0,1) 4.---------.7 |
3293 # (0,0,0) 0.---------.3
3294 pattern_prism = "!!! Nb of points: \n 8 \n\
3304 !!! Indices of points of 2 prisms: \n\
3308 pattern = self.smeshpyD.GetPattern()
3309 isDone = pattern.LoadFromFile(pattern_prism)
3311 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3314 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3315 isDone = pattern.MakeMesh(self.mesh, False, False)
3316 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3318 # Splits quafrangle faces near triangular facets of volumes
3319 self.SplitQuadsNearTriangularFacets()
3323 ## Smoothes elements
3324 # @param IDsOfElements the list if ids of elements to smooth
3325 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3326 # Note that nodes built on edges and boundary nodes are always fixed.
3327 # @param MaxNbOfIterations the maximum number of iterations
3328 # @param MaxAspectRatio varies in range [1.0, inf]
3329 # @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3330 # or Centroidal (smesh.CENTROIDAL_SMOOTH)
3331 # @return TRUE in case of success, FALSE otherwise.
3332 # @ingroup l2_modif_smooth
3333 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3334 MaxNbOfIterations, MaxAspectRatio, Method):
3335 if IDsOfElements == []:
3336 IDsOfElements = self.GetElementsId()
3337 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3338 self.mesh.SetParameters(Parameters)
3339 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3340 MaxNbOfIterations, MaxAspectRatio, Method)
3342 ## Smoothes elements which belong to the given object
3343 # @param theObject the object to smooth
3344 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3345 # Note that nodes built on edges and boundary nodes are always fixed.
3346 # @param MaxNbOfIterations the maximum number of iterations
3347 # @param MaxAspectRatio varies in range [1.0, inf]
3348 # @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3349 # or Centroidal (smesh.CENTROIDAL_SMOOTH)
3350 # @return TRUE in case of success, FALSE otherwise.
3351 # @ingroup l2_modif_smooth
3352 def SmoothObject(self, theObject, IDsOfFixedNodes,
3353 MaxNbOfIterations, MaxAspectRatio, Method):
3354 if ( isinstance( theObject, Mesh )):
3355 theObject = theObject.GetMesh()
3356 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3357 MaxNbOfIterations, MaxAspectRatio, Method)
3359 ## Parametrically smoothes the given elements
3360 # @param IDsOfElements the list if ids of elements to smooth
3361 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3362 # Note that nodes built on edges and boundary nodes are always fixed.
3363 # @param MaxNbOfIterations the maximum number of iterations
3364 # @param MaxAspectRatio varies in range [1.0, inf]
3365 # @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3366 # or Centroidal (smesh.CENTROIDAL_SMOOTH)
3367 # @return TRUE in case of success, FALSE otherwise.
3368 # @ingroup l2_modif_smooth
3369 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3370 MaxNbOfIterations, MaxAspectRatio, Method):
3371 if IDsOfElements == []:
3372 IDsOfElements = self.GetElementsId()
3373 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3374 self.mesh.SetParameters(Parameters)
3375 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3376 MaxNbOfIterations, MaxAspectRatio, Method)
3378 ## Parametrically smoothes the elements which belong to the given object
3379 # @param theObject the object to smooth
3380 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3381 # Note that nodes built on edges and boundary nodes are always fixed.
3382 # @param MaxNbOfIterations the maximum number of iterations
3383 # @param MaxAspectRatio varies in range [1.0, inf]
3384 # @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3385 # or Centroidal (smesh.CENTROIDAL_SMOOTH)
3386 # @return TRUE in case of success, FALSE otherwise.
3387 # @ingroup l2_modif_smooth
3388 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3389 MaxNbOfIterations, MaxAspectRatio, Method):
3390 if ( isinstance( theObject, Mesh )):
3391 theObject = theObject.GetMesh()
3392 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3393 MaxNbOfIterations, MaxAspectRatio, Method)
3395 ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3396 # them with quadratic with the same id.
3397 # @param theForce3d new node creation method:
3398 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3399 # 1 - the medium node lies at the middle of the line segments connecting two nodes of a mesh element
3400 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3401 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3402 # @ingroup l2_modif_tofromqu
3403 def ConvertToQuadratic(self, theForce3d=False, theSubMesh=None, theToBiQuad=False):
3404 if isinstance( theSubMesh, Mesh ):
3405 theSubMesh = theSubMesh.mesh
3407 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3410 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3412 self.editor.ConvertToQuadratic(theForce3d)
3413 error = self.editor.GetLastError()
3414 if error and error.comment:
3417 ## Converts the mesh from quadratic to ordinary,
3418 # deletes old quadratic elements, \n replacing
3419 # them with ordinary mesh elements with the same id.
3420 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3421 # @ingroup l2_modif_tofromqu
3422 def ConvertFromQuadratic(self, theSubMesh=None):
3424 self.editor.ConvertFromQuadraticObject(theSubMesh)
3426 return self.editor.ConvertFromQuadratic()
3428 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3429 # @return TRUE if operation has been completed successfully, FALSE otherwise
3430 # @ingroup l2_modif_edit
3431 def Make2DMeshFrom3D(self):
3432 return self.editor. Make2DMeshFrom3D()
3434 ## Creates missing boundary elements
3435 # @param elements - elements whose boundary is to be checked:
3436 # mesh, group, sub-mesh or list of elements
3437 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3438 # @param dimension - defines type of boundary elements to create:
3439 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3440 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3441 # @param groupName - a name of group to store created boundary elements in,
3442 # "" means not to create the group
3443 # @param meshName - a name of new mesh to store created boundary elements in,
3444 # "" means not to create the new mesh
3445 # @param toCopyElements - if true, the checked elements will be copied into
3446 # the new mesh else only boundary elements will be copied into the new mesh
3447 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3448 # boundary elements will be copied into the new mesh
3449 # @return tuple (mesh, group) where boundary elements were added to
3450 # @ingroup l2_modif_edit
3451 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3452 toCopyElements=False, toCopyExistingBondary=False):
3453 unRegister = genObjUnRegister()
3454 if isinstance( elements, Mesh ):
3455 elements = elements.GetMesh()
3456 if ( isinstance( elements, list )):
3457 elemType = SMESH.ALL
3458 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3459 elements = self.editor.MakeIDSource(elements, elemType)
3460 unRegister.set( elements )
3461 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3462 toCopyElements,toCopyExistingBondary)
3463 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3467 # @brief Creates missing boundary elements around either the whole mesh or
3468 # groups of elements
3469 # @param dimension - defines type of boundary elements to create
3470 # @param groupName - a name of group to store all boundary elements in,
3471 # "" means not to create the group
3472 # @param meshName - a name of a new mesh, which is a copy of the initial
3473 # mesh + created boundary elements; "" means not to create the new mesh
3474 # @param toCopyAll - if true, the whole initial mesh will be copied into
3475 # the new mesh else only boundary elements will be copied into the new mesh
3476 # @param groups - groups of elements to make boundary around
3477 # @retval tuple( long, mesh, groups )
3478 # long - number of added boundary elements
3479 # mesh - the mesh where elements were added to
3480 # group - the group of boundary elements or None
3482 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3483 toCopyAll=False, groups=[]):
3484 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3486 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3487 return nb, mesh, group
3489 ## Renumber mesh nodes (Obsolete, does nothing)
3490 # @ingroup l2_modif_renumber
3491 def RenumberNodes(self):
3492 self.editor.RenumberNodes()
3494 ## Renumber mesh elements (Obsole, does nothing)
3495 # @ingroup l2_modif_renumber
3496 def RenumberElements(self):
3497 self.editor.RenumberElements()
3499 ## Generates new elements by rotation of the elements around the axis
3500 # @param IDsOfElements the list of ids of elements to sweep
3501 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3502 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3503 # @param NbOfSteps the number of steps
3504 # @param Tolerance tolerance
3505 # @param MakeGroups forces the generation of new groups from existing ones
3506 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3507 # of all steps, else - size of each step
3508 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3509 # @ingroup l2_modif_extrurev
3510 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3511 MakeGroups=False, TotalAngle=False):
3512 if IDsOfElements == []:
3513 IDsOfElements = self.GetElementsId()
3514 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3515 Axis = self.smeshpyD.GetAxisStruct(Axis)
3516 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3517 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3518 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3519 self.mesh.SetParameters(Parameters)
3520 if TotalAngle and NbOfSteps:
3521 AngleInRadians /= NbOfSteps
3523 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3524 AngleInRadians, NbOfSteps, Tolerance)
3525 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3528 ## Generates new elements by rotation of the elements of object around the axis
3529 # @param theObject object which elements should be sweeped.
3530 # It can be a mesh, a sub mesh or a group.
3531 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3532 # @param AngleInRadians the angle of Rotation
3533 # @param NbOfSteps number of steps
3534 # @param Tolerance tolerance
3535 # @param MakeGroups forces the generation of new groups from existing ones
3536 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3537 # of all steps, else - size of each step
3538 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3539 # @ingroup l2_modif_extrurev
3540 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3541 MakeGroups=False, TotalAngle=False):
3542 if ( isinstance( theObject, Mesh )):
3543 theObject = theObject.GetMesh()
3544 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3545 Axis = self.smeshpyD.GetAxisStruct(Axis)
3546 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3547 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3548 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3549 self.mesh.SetParameters(Parameters)
3550 if TotalAngle and NbOfSteps:
3551 AngleInRadians /= NbOfSteps
3553 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3554 NbOfSteps, Tolerance)
3555 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3558 ## Generates new elements by rotation of the elements of object around the axis
3559 # @param theObject object which elements should be sweeped.
3560 # It can be a mesh, a sub mesh or a group.
3561 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3562 # @param AngleInRadians the angle of Rotation
3563 # @param NbOfSteps number of steps
3564 # @param Tolerance tolerance
3565 # @param MakeGroups forces the generation of new groups from existing ones
3566 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3567 # of all steps, else - size of each step
3568 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3569 # @ingroup l2_modif_extrurev
3570 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3571 MakeGroups=False, TotalAngle=False):
3572 if ( isinstance( theObject, Mesh )):
3573 theObject = theObject.GetMesh()
3574 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3575 Axis = self.smeshpyD.GetAxisStruct(Axis)
3576 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3577 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3578 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3579 self.mesh.SetParameters(Parameters)
3580 if TotalAngle and NbOfSteps:
3581 AngleInRadians /= NbOfSteps
3583 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3584 NbOfSteps, Tolerance)
3585 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3588 ## Generates new elements by rotation of the elements of object around the axis
3589 # @param theObject object which elements should be sweeped.
3590 # It can be a mesh, a sub mesh or a group.
3591 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3592 # @param AngleInRadians the angle of Rotation
3593 # @param NbOfSteps number of steps
3594 # @param Tolerance tolerance
3595 # @param MakeGroups forces the generation of new groups from existing ones
3596 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3597 # of all steps, else - size of each step
3598 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3599 # @ingroup l2_modif_extrurev
3600 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3601 MakeGroups=False, TotalAngle=False):
3602 if ( isinstance( theObject, Mesh )):
3603 theObject = theObject.GetMesh()
3604 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3605 Axis = self.smeshpyD.GetAxisStruct(Axis)
3606 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3607 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3608 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3609 self.mesh.SetParameters(Parameters)
3610 if TotalAngle and NbOfSteps:
3611 AngleInRadians /= NbOfSteps
3613 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3614 NbOfSteps, Tolerance)
3615 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3618 ## Generates new elements by extrusion of the elements with given ids
3619 # @param IDsOfElements the list of elements ids for extrusion
3620 # @param StepVector vector or DirStruct or 3 vector components, defining
3621 # the direction and value of extrusion for one step (the total extrusion
3622 # length will be NbOfSteps * ||StepVector||)
3623 # @param NbOfSteps the number of steps
3624 # @param MakeGroups forces the generation of new groups from existing ones
3625 # @param IsNodes is True if elements with given ids are nodes
3626 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3627 # @ingroup l2_modif_extrurev
3628 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3629 if IDsOfElements == []:
3630 IDsOfElements = self.GetElementsId()
3631 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3632 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3633 if isinstance( StepVector, list ):
3634 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3635 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3636 Parameters = StepVector.PS.parameters + var_separator + Parameters
3637 self.mesh.SetParameters(Parameters)
3640 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3642 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3644 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3646 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3649 ## Generates new elements by extrusion of the elements with given ids
3650 # @param IDsOfElements is ids of elements
3651 # @param StepVector vector or DirStruct or 3 vector components, defining
3652 # the direction and value of extrusion for one step (the total extrusion
3653 # length will be NbOfSteps * ||StepVector||)
3654 # @param NbOfSteps the number of steps
3655 # @param ExtrFlags sets flags for extrusion
3656 # @param SewTolerance uses for comparing locations of nodes if flag
3657 # EXTRUSION_FLAG_SEW is set
3658 # @param MakeGroups forces the generation of new groups from existing ones
3659 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3660 # @ingroup l2_modif_extrurev
3661 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3662 ExtrFlags, SewTolerance, MakeGroups=False):
3663 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3664 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3665 if isinstance( StepVector, list ):
3666 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3668 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3669 ExtrFlags, SewTolerance)
3670 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3671 ExtrFlags, SewTolerance)
3674 ## Generates new elements by extrusion along the normal to a discretized surface or wire
3675 # @param Elements container of elements to extrude;
3676 # it can be Mesh, Group, Sub-mesh, Filter or list of IDs;
3677 # Only faces can be extruded so far. Sub-mesh sould be a sub-mesh on geom faces.
3678 # @param StepSize length of one extrusion step (the total extrusion
3679 # length will be \a NbOfSteps * \a StepSize ).
3680 # @param NbOfSteps number of extrusion steps.
3681 # @param ByAverageNormal if True each node is translated by \a StepSize
3682 # along the average of the normal vectors to the faces sharing the node;
3683 # else each node is translated along the same average normal till
3684 # intersection with the plane got by translation of the face sharing
3685 # the node along its own normal by \a StepSize.
3686 # @param UseInputElemsOnly to use only \a Elements when computing extrusion direction
3687 # for every node of \a Elements.
3688 # @param MakeGroups forces generation of new groups from existing ones.
3689 # @param Dim dimension of elements to extrude: 2 - faces or 1 - edges. Extrusion of edges
3690 # is not yet implemented. This parameter is used if \a Elements contains
3691 # both faces and edges, i.e. \a Elements is a Mesh.
3692 # @return the list of created groups (SMESH_GroupBase) if \a MakeGroups=True,
3693 # empty list otherwise.
3694 # @ingroup l2_modif_extrurev
3695 def ExtrusionByNormal(self, Elements, StepSize, NbOfSteps,
3696 ByAverageNormal=False, UseInputElemsOnly=True, MakeGroups=False, Dim = 2):
3697 unRegister = genObjUnRegister()
3698 if isinstance( Elements, Mesh ):
3699 Elements = Elements.GetMesh()
3700 if isinstance( Elements, list ):
3702 raise RuntimeError, "List of element IDs is empty!"
3703 if not isinstance( Elements[0], int ):
3704 raise RuntimeError, "List must contain element IDs and not %s"% Elements[0]
3705 Elements = self.GetIDSource( Elements, SMESH.ALL )
3706 unRegister.set( Elements )
3707 StepSize,NbOfSteps,Parameters,hasVars = ParseParameters(StepSize,NbOfSteps)
3708 self.mesh.SetParameters(Parameters)
3709 return self.editor.ExtrusionByNormal(Elements, StepSize, NbOfSteps,
3710 UseInputElemsOnly, ByAverageNormal, MakeGroups, Dim)
3712 ## Generates new elements by extrusion of the elements which belong to the object
3713 # @param theObject the object which elements should be processed.
3714 # It can be a mesh, a sub mesh or a group.
3715 # @param StepVector vector or DirStruct or 3 vector components, defining
3716 # the direction and value of extrusion for one step (the total extrusion
3717 # length will be NbOfSteps * ||StepVector||)
3718 # @param NbOfSteps the number of steps
3719 # @param MakeGroups forces the generation of new groups from existing ones
3720 # @param IsNodes is True if elements which belong to the object are nodes
3721 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3722 # @ingroup l2_modif_extrurev
3723 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3724 if ( isinstance( theObject, Mesh )):
3725 theObject = theObject.GetMesh()
3726 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3727 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3728 if isinstance( StepVector, list ):
3729 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3730 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3731 Parameters = StepVector.PS.parameters + var_separator + Parameters
3732 self.mesh.SetParameters(Parameters)
3735 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3737 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3739 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3741 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3744 ## Generates new elements by extrusion of the elements which belong to the object
3745 # @param theObject object which elements should be processed.
3746 # It can be a mesh, a sub mesh or a group.
3747 # @param StepVector vector or DirStruct or 3 vector components, defining
3748 # the direction and value of extrusion for one step (the total extrusion
3749 # length will be NbOfSteps * ||StepVector||)
3750 # @param NbOfSteps the number of steps
3751 # @param MakeGroups to generate new groups from existing ones
3752 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3753 # @ingroup l2_modif_extrurev
3754 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3755 if ( isinstance( theObject, Mesh )):
3756 theObject = theObject.GetMesh()
3757 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3758 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3759 if isinstance( StepVector, list ):
3760 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3761 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3762 Parameters = StepVector.PS.parameters + var_separator + Parameters
3763 self.mesh.SetParameters(Parameters)
3765 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3766 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3769 ## Generates new elements by extrusion of the elements which belong to the object
3770 # @param theObject object which elements should be processed.
3771 # It can be a mesh, a sub mesh or a group.
3772 # @param StepVector vector or DirStruct or 3 vector components, defining
3773 # the direction and value of extrusion for one step (the total extrusion
3774 # length will be NbOfSteps * ||StepVector||)
3775 # @param NbOfSteps the number of steps
3776 # @param MakeGroups forces the generation of new groups from existing ones
3777 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3778 # @ingroup l2_modif_extrurev
3779 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3780 if ( isinstance( theObject, Mesh )):
3781 theObject = theObject.GetMesh()
3782 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3783 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3784 if isinstance( StepVector, list ):
3785 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3786 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3787 Parameters = StepVector.PS.parameters + var_separator + Parameters
3788 self.mesh.SetParameters(Parameters)
3790 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3791 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3796 ## Generates new elements by extrusion of the given elements
3797 # The path of extrusion must be a meshed edge.
3798 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3799 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3800 # @param NodeStart the start node from Path. Defines the direction of extrusion
3801 # @param HasAngles allows the shape to be rotated around the path
3802 # to get the resulting mesh in a helical fashion
3803 # @param Angles list of angles in radians
3804 # @param LinearVariation forces the computation of rotation angles as linear
3805 # variation of the given Angles along path steps
3806 # @param HasRefPoint allows using the reference point
3807 # @param RefPoint the point around which the elements are rotated (the mass
3808 # center of the elements by default).
3809 # The User can specify any point as the Reference Point.
3810 # RefPoint can be either GEOM Vertex, [x,y,z] or SMESH.PointStruct
3811 # @param MakeGroups forces the generation of new groups from existing ones
3812 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3813 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3814 # only SMESH::Extrusion_Error otherwise
3815 # @ingroup l2_modif_extrurev
3816 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3817 HasAngles, Angles, LinearVariation,
3818 HasRefPoint, RefPoint, MakeGroups, ElemType):
3819 if isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object):
3820 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3822 elif isinstance( RefPoint, list ):
3823 RefPoint = PointStruct(*RefPoint)
3825 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3826 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3827 self.mesh.SetParameters(Parameters)
3829 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3831 if isinstance(Base, list):
3833 if Base == []: IDsOfElements = self.GetElementsId()
3834 else: IDsOfElements = Base
3835 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3836 HasAngles, Angles, LinearVariation,
3837 HasRefPoint, RefPoint, MakeGroups, ElemType)
3839 if isinstance(Base, Mesh): Base = Base.GetMesh()
3840 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3841 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3842 HasAngles, Angles, LinearVariation,
3843 HasRefPoint, RefPoint, MakeGroups, ElemType)
3845 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3848 ## Generates new elements by extrusion of the given elements
3849 # The path of extrusion must be a meshed edge.
3850 # @param IDsOfElements ids of elements
3851 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3852 # @param PathShape shape(edge) defines the sub-mesh for the path
3853 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3854 # @param HasAngles allows the shape to be rotated around the path
3855 # to get the resulting mesh in a helical fashion
3856 # @param Angles list of angles in radians
3857 # @param HasRefPoint allows using the reference point
3858 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3859 # The User can specify any point as the Reference Point.
3860 # @param MakeGroups forces the generation of new groups from existing ones
3861 # @param LinearVariation forces the computation of rotation angles as linear
3862 # variation of the given Angles along path steps
3863 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3864 # only SMESH::Extrusion_Error otherwise
3865 # @ingroup l2_modif_extrurev
3866 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3867 HasAngles, Angles, HasRefPoint, RefPoint,
3868 MakeGroups=False, LinearVariation=False):
3869 if IDsOfElements == []:
3870 IDsOfElements = self.GetElementsId()
3871 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3872 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3874 if ( isinstance( PathMesh, Mesh )):
3875 PathMesh = PathMesh.GetMesh()
3876 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3877 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3878 self.mesh.SetParameters(Parameters)
3879 if HasAngles and Angles and LinearVariation:
3880 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3883 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3884 PathShape, NodeStart, HasAngles,
3885 Angles, HasRefPoint, RefPoint)
3886 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3887 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3889 ## Generates new elements by extrusion of the elements which belong to the object
3890 # The path of extrusion must be a meshed edge.
3891 # @param theObject the object which elements should be processed.
3892 # It can be a mesh, a sub mesh or a group.
3893 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3894 # @param PathShape shape(edge) defines the sub-mesh for the path
3895 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3896 # @param HasAngles allows the shape to be rotated around the path
3897 # to get the resulting mesh in a helical fashion
3898 # @param Angles list of angles
3899 # @param HasRefPoint allows using the reference point
3900 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3901 # The User can specify any point as the Reference Point.
3902 # @param MakeGroups forces the generation of new groups from existing ones
3903 # @param LinearVariation forces the computation of rotation angles as linear
3904 # variation of the given Angles along path steps
3905 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3906 # only SMESH::Extrusion_Error otherwise
3907 # @ingroup l2_modif_extrurev
3908 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3909 HasAngles, Angles, HasRefPoint, RefPoint,
3910 MakeGroups=False, LinearVariation=False):
3911 if ( isinstance( theObject, Mesh )):
3912 theObject = theObject.GetMesh()
3913 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3914 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3915 if ( isinstance( PathMesh, Mesh )):
3916 PathMesh = PathMesh.GetMesh()
3917 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3918 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3919 self.mesh.SetParameters(Parameters)
3920 if HasAngles and Angles and LinearVariation:
3921 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3924 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3925 PathShape, NodeStart, HasAngles,
3926 Angles, HasRefPoint, RefPoint)
3927 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3928 NodeStart, HasAngles, Angles, HasRefPoint,
3931 ## Generates new elements by extrusion of the elements which belong to the object
3932 # The path of extrusion must be a meshed edge.
3933 # @param theObject the object which elements should be processed.
3934 # It can be a mesh, a sub mesh or a group.
3935 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3936 # @param PathShape shape(edge) defines the sub-mesh for the path
3937 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3938 # @param HasAngles allows the shape to be rotated around the path
3939 # to get the resulting mesh in a helical fashion
3940 # @param Angles list of angles
3941 # @param HasRefPoint allows using the reference point
3942 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3943 # The User can specify any point as the Reference Point.
3944 # @param MakeGroups forces the generation of new groups from existing ones
3945 # @param LinearVariation forces the computation of rotation angles as linear
3946 # variation of the given Angles along path steps
3947 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3948 # only SMESH::Extrusion_Error otherwise
3949 # @ingroup l2_modif_extrurev
3950 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3951 HasAngles, Angles, HasRefPoint, RefPoint,
3952 MakeGroups=False, LinearVariation=False):
3953 if ( isinstance( theObject, Mesh )):
3954 theObject = theObject.GetMesh()
3955 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3956 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3957 if ( isinstance( PathMesh, Mesh )):
3958 PathMesh = PathMesh.GetMesh()
3959 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3960 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3961 self.mesh.SetParameters(Parameters)
3962 if HasAngles and Angles and LinearVariation:
3963 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3966 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3967 PathShape, NodeStart, HasAngles,
3968 Angles, HasRefPoint, RefPoint)
3969 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3970 NodeStart, HasAngles, Angles, HasRefPoint,
3973 ## Generates new elements by extrusion of the elements which belong to the object
3974 # The path of extrusion must be a meshed edge.
3975 # @param theObject the object which elements should be processed.
3976 # It can be a mesh, a sub mesh or a group.
3977 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3978 # @param PathShape shape(edge) defines the sub-mesh for the path
3979 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3980 # @param HasAngles allows the shape to be rotated around the path
3981 # to get the resulting mesh in a helical fashion
3982 # @param Angles list of angles
3983 # @param HasRefPoint allows using the reference point
3984 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3985 # The User can specify any point as the Reference Point.
3986 # @param MakeGroups forces the generation of new groups from existing ones
3987 # @param LinearVariation forces the computation of rotation angles as linear
3988 # variation of the given Angles along path steps
3989 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3990 # only SMESH::Extrusion_Error otherwise
3991 # @ingroup l2_modif_extrurev
3992 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3993 HasAngles, Angles, HasRefPoint, RefPoint,
3994 MakeGroups=False, LinearVariation=False):
3995 if ( isinstance( theObject, Mesh )):
3996 theObject = theObject.GetMesh()
3997 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3998 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3999 if ( isinstance( PathMesh, Mesh )):
4000 PathMesh = PathMesh.GetMesh()
4001 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
4002 Parameters = AnglesParameters + var_separator + RefPoint.parameters
4003 self.mesh.SetParameters(Parameters)
4004 if HasAngles and Angles and LinearVariation:
4005 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
4008 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
4009 PathShape, NodeStart, HasAngles,
4010 Angles, HasRefPoint, RefPoint)
4011 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
4012 NodeStart, HasAngles, Angles, HasRefPoint,
4015 ## Creates a symmetrical copy of mesh elements
4016 # @param IDsOfElements list of elements ids
4017 # @param Mirror is AxisStruct or geom object(point, line, plane)
4018 # @param theMirrorType is POINT, AXIS or PLANE
4019 # If the Mirror is a geom object this parameter is unnecessary
4020 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
4021 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4022 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4023 # @ingroup l2_modif_trsf
4024 def Mirror(self, IDsOfElements, Mirror, theMirrorType=None, Copy=0, MakeGroups=False):
4025 if IDsOfElements == []:
4026 IDsOfElements = self.GetElementsId()
4027 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4028 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
4029 theMirrorType = Mirror._mirrorType
4031 self.mesh.SetParameters(Mirror.parameters)
4032 if Copy and MakeGroups:
4033 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
4034 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
4037 ## Creates a new mesh by a symmetrical copy of mesh elements
4038 # @param IDsOfElements the list of elements ids
4039 # @param Mirror is AxisStruct or geom object (point, line, plane)
4040 # @param theMirrorType is POINT, AXIS or PLANE
4041 # If the Mirror is a geom object this parameter is unnecessary
4042 # @param MakeGroups to generate new groups from existing ones
4043 # @param NewMeshName a name of the new mesh to create
4044 # @return instance of Mesh class
4045 # @ingroup l2_modif_trsf
4046 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType=0, MakeGroups=0, NewMeshName=""):
4047 if IDsOfElements == []:
4048 IDsOfElements = self.GetElementsId()
4049 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4050 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
4051 theMirrorType = Mirror._mirrorType
4053 self.mesh.SetParameters(Mirror.parameters)
4054 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
4055 MakeGroups, NewMeshName)
4056 return Mesh(self.smeshpyD,self.geompyD,mesh)
4058 ## Creates a symmetrical copy of the object
4059 # @param theObject mesh, submesh or group
4060 # @param Mirror AxisStruct or geom object (point, line, plane)
4061 # @param theMirrorType is POINT, AXIS or PLANE
4062 # If the Mirror is a geom object this parameter is unnecessary
4063 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
4064 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4065 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4066 # @ingroup l2_modif_trsf
4067 def MirrorObject (self, theObject, Mirror, theMirrorType=None, Copy=0, MakeGroups=False):
4068 if ( isinstance( theObject, Mesh )):
4069 theObject = theObject.GetMesh()
4070 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4071 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
4072 theMirrorType = Mirror._mirrorType
4074 self.mesh.SetParameters(Mirror.parameters)
4075 if Copy and MakeGroups:
4076 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
4077 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
4080 ## Creates a new mesh by a symmetrical copy of the object
4081 # @param theObject mesh, submesh or group
4082 # @param Mirror AxisStruct or geom object (point, line, plane)
4083 # @param theMirrorType POINT, AXIS or PLANE
4084 # If the Mirror is a geom object this parameter is unnecessary
4085 # @param MakeGroups forces the generation of new groups from existing ones
4086 # @param NewMeshName the name of the new mesh to create
4087 # @return instance of Mesh class
4088 # @ingroup l2_modif_trsf
4089 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType=0,MakeGroups=0,NewMeshName=""):
4090 if ( isinstance( theObject, Mesh )):
4091 theObject = theObject.GetMesh()
4092 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4093 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
4094 theMirrorType = Mirror._mirrorType
4096 self.mesh.SetParameters(Mirror.parameters)
4097 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
4098 MakeGroups, NewMeshName)
4099 return Mesh( self.smeshpyD,self.geompyD,mesh )
4101 ## Translates the elements
4102 # @param IDsOfElements list of elements ids
4103 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
4104 # @param Copy allows copying the translated elements
4105 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4106 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4107 # @ingroup l2_modif_trsf
4108 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
4109 if IDsOfElements == []:
4110 IDsOfElements = self.GetElementsId()
4111 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
4112 Vector = self.smeshpyD.GetDirStruct(Vector)
4113 if isinstance( Vector, list ):
4114 Vector = self.smeshpyD.MakeDirStruct(*Vector)
4115 self.mesh.SetParameters(Vector.PS.parameters)
4116 if Copy and MakeGroups:
4117 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
4118 self.editor.Translate(IDsOfElements, Vector, Copy)
4121 ## Creates a new mesh of translated elements
4122 # @param IDsOfElements list of elements ids
4123 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
4124 # @param MakeGroups forces the generation of new groups from existing ones
4125 # @param NewMeshName the name of the newly created mesh
4126 # @return instance of Mesh class
4127 # @ingroup l2_modif_trsf
4128 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
4129 if IDsOfElements == []:
4130 IDsOfElements = self.GetElementsId()
4131 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
4132 Vector = self.smeshpyD.GetDirStruct(Vector)
4133 if isinstance( Vector, list ):
4134 Vector = self.smeshpyD.MakeDirStruct(*Vector)
4135 self.mesh.SetParameters(Vector.PS.parameters)
4136 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
4137 return Mesh ( self.smeshpyD, self.geompyD, mesh )
4139 ## Translates the object
4140 # @param theObject the object to translate (mesh, submesh, or group)
4141 # @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
4142 # @param Copy allows copying the translated elements
4143 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4144 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4145 # @ingroup l2_modif_trsf
4146 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
4147 if ( isinstance( theObject, Mesh )):
4148 theObject = theObject.GetMesh()
4149 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
4150 Vector = self.smeshpyD.GetDirStruct(Vector)
4151 if isinstance( Vector, list ):
4152 Vector = self.smeshpyD.MakeDirStruct(*Vector)
4153 self.mesh.SetParameters(Vector.PS.parameters)
4154 if Copy and MakeGroups:
4155 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
4156 self.editor.TranslateObject(theObject, Vector, Copy)
4159 ## Creates a new mesh from the translated object
4160 # @param theObject the object to translate (mesh, submesh, or group)
4161 # @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
4162 # @param MakeGroups forces the generation of new groups from existing ones
4163 # @param NewMeshName the name of the newly created mesh
4164 # @return instance of Mesh class
4165 # @ingroup l2_modif_trsf
4166 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
4167 if isinstance( theObject, Mesh ):
4168 theObject = theObject.GetMesh()
4169 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
4170 Vector = self.smeshpyD.GetDirStruct(Vector)
4171 if isinstance( Vector, list ):
4172 Vector = self.smeshpyD.MakeDirStruct(*Vector)
4173 self.mesh.SetParameters(Vector.PS.parameters)
4174 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
4175 return Mesh( self.smeshpyD, self.geompyD, mesh )
4179 ## Scales the object
4180 # @param theObject - the object to translate (mesh, submesh, or group)
4181 # @param thePoint - base point for scale (SMESH.PointStruct or list of 3 coordinates)
4182 # @param theScaleFact - list of 1-3 scale factors for axises
4183 # @param Copy - allows copying the translated elements
4184 # @param MakeGroups - forces the generation of new groups from existing
4186 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
4187 # empty list otherwise
4188 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
4189 unRegister = genObjUnRegister()
4190 if ( isinstance( theObject, Mesh )):
4191 theObject = theObject.GetMesh()
4192 if ( isinstance( theObject, list )):
4193 theObject = self.GetIDSource(theObject, SMESH.ALL)
4194 unRegister.set( theObject )
4195 if ( isinstance( thePoint, list )):
4196 thePoint = PointStruct( thePoint[0], thePoint[1], thePoint[2] )
4197 if ( isinstance( theScaleFact, float )):
4198 theScaleFact = [theScaleFact]
4199 if ( isinstance( theScaleFact, int )):
4200 theScaleFact = [ float(theScaleFact)]
4202 self.mesh.SetParameters(thePoint.parameters)
4204 if Copy and MakeGroups:
4205 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
4206 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
4209 ## Creates a new mesh from the translated object
4210 # @param theObject - the object to translate (mesh, submesh, or group)
4211 # @param thePoint - base point for scale (SMESH.PointStruct or list of 3 coordinates)
4212 # @param theScaleFact - list of 1-3 scale factors for axises
4213 # @param MakeGroups - forces the generation of new groups from existing ones
4214 # @param NewMeshName - the name of the newly created mesh
4215 # @return instance of Mesh class
4216 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
4217 unRegister = genObjUnRegister()
4218 if (isinstance(theObject, Mesh)):
4219 theObject = theObject.GetMesh()
4220 if ( isinstance( theObject, list )):
4221 theObject = self.GetIDSource(theObject,SMESH.ALL)
4222 unRegister.set( theObject )
4223 if ( isinstance( thePoint, list )):
4224 thePoint = PointStruct( thePoint[0], thePoint[1], thePoint[2] )
4225 if ( isinstance( theScaleFact, float )):
4226 theScaleFact = [theScaleFact]
4227 if ( isinstance( theScaleFact, int )):
4228 theScaleFact = [ float(theScaleFact)]
4230 self.mesh.SetParameters(thePoint.parameters)
4231 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
4232 MakeGroups, NewMeshName)
4233 return Mesh( self.smeshpyD, self.geompyD, mesh )
4237 ## Rotates the elements
4238 # @param IDsOfElements list of elements ids
4239 # @param Axis the axis of rotation (AxisStruct or geom line)
4240 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4241 # @param Copy allows copying the rotated elements
4242 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4243 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4244 # @ingroup l2_modif_trsf
4245 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
4246 if IDsOfElements == []:
4247 IDsOfElements = self.GetElementsId()
4248 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4249 Axis = self.smeshpyD.GetAxisStruct(Axis)
4250 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4251 Parameters = Axis.parameters + var_separator + Parameters
4252 self.mesh.SetParameters(Parameters)
4253 if Copy and MakeGroups:
4254 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
4255 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
4258 ## Creates a new mesh of rotated elements
4259 # @param IDsOfElements list of element ids
4260 # @param Axis the axis of rotation (AxisStruct or geom line)
4261 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4262 # @param MakeGroups forces the generation of new groups from existing ones
4263 # @param NewMeshName the name of the newly created mesh
4264 # @return instance of Mesh class
4265 # @ingroup l2_modif_trsf
4266 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
4267 if IDsOfElements == []:
4268 IDsOfElements = self.GetElementsId()
4269 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4270 Axis = self.smeshpyD.GetAxisStruct(Axis)
4271 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4272 Parameters = Axis.parameters + var_separator + Parameters
4273 self.mesh.SetParameters(Parameters)
4274 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
4275 MakeGroups, NewMeshName)
4276 return Mesh( self.smeshpyD, self.geompyD, mesh )
4278 ## Rotates the object
4279 # @param theObject the object to rotate( mesh, submesh, or group)
4280 # @param Axis the axis of rotation (AxisStruct or geom line)
4281 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4282 # @param Copy allows copying the rotated elements
4283 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4284 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4285 # @ingroup l2_modif_trsf
4286 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
4287 if (isinstance(theObject, Mesh)):
4288 theObject = theObject.GetMesh()
4289 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4290 Axis = self.smeshpyD.GetAxisStruct(Axis)
4291 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4292 Parameters = Axis.parameters + ":" + Parameters
4293 self.mesh.SetParameters(Parameters)
4294 if Copy and MakeGroups:
4295 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
4296 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
4299 ## Creates a new mesh from the rotated object
4300 # @param theObject the object to rotate (mesh, submesh, or group)
4301 # @param Axis the axis of rotation (AxisStruct or geom line)
4302 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4303 # @param MakeGroups forces the generation of new groups from existing ones
4304 # @param NewMeshName the name of the newly created mesh
4305 # @return instance of Mesh class
4306 # @ingroup l2_modif_trsf
4307 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
4308 if (isinstance( theObject, Mesh )):
4309 theObject = theObject.GetMesh()
4310 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4311 Axis = self.smeshpyD.GetAxisStruct(Axis)
4312 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4313 Parameters = Axis.parameters + ":" + Parameters
4314 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
4315 MakeGroups, NewMeshName)
4316 self.mesh.SetParameters(Parameters)
4317 return Mesh( self.smeshpyD, self.geompyD, mesh )
4319 ## Finds groups of adjacent nodes within Tolerance.
4320 # @param Tolerance the value of tolerance
4321 # @return the list of pairs of nodes IDs (e.g. [[1,12],[25,4]])
4322 # @ingroup l2_modif_trsf
4323 def FindCoincidentNodes (self, Tolerance):
4324 return self.editor.FindCoincidentNodes(Tolerance)
4326 ## Finds groups of ajacent nodes within Tolerance.
4327 # @param Tolerance the value of tolerance
4328 # @param SubMeshOrGroup SubMesh or Group
4329 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
4330 # @return the list of pairs of nodes IDs (e.g. [[1,12],[25,4]])
4331 # @ingroup l2_modif_trsf
4332 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
4333 unRegister = genObjUnRegister()
4334 if (isinstance( SubMeshOrGroup, Mesh )):
4335 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
4336 if not isinstance( exceptNodes, list):
4337 exceptNodes = [ exceptNodes ]
4338 if exceptNodes and isinstance( exceptNodes[0], int):
4339 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
4340 unRegister.set( exceptNodes )
4341 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
4344 # @param GroupsOfNodes a list of pairs of nodes IDs for merging (e.g. [[1,12],[25,4]])
4345 # @ingroup l2_modif_trsf
4346 def MergeNodes (self, GroupsOfNodes):
4347 self.editor.MergeNodes(GroupsOfNodes)
4349 ## Finds the elements built on the same nodes.
4350 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
4351 # @return the list of pairs of equal elements IDs (e.g. [[1,12],[25,4]])
4352 # @ingroup l2_modif_trsf
4353 def FindEqualElements (self, MeshOrSubMeshOrGroup):
4354 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
4355 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4356 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
4358 ## Merges elements in each given group.
4359 # @param GroupsOfElementsID a list of pairs of elements IDs for merging (e.g. [[1,12],[25,4]])
4360 # @ingroup l2_modif_trsf
4361 def MergeElements(self, GroupsOfElementsID):
4362 self.editor.MergeElements(GroupsOfElementsID)
4364 ## Leaves one element and removes all other elements built on the same nodes.
4365 # @ingroup l2_modif_trsf
4366 def MergeEqualElements(self):
4367 self.editor.MergeEqualElements()
4369 ## Sews free borders
4370 # @return SMESH::Sew_Error
4371 # @ingroup l2_modif_trsf
4372 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4373 FirstNodeID2, SecondNodeID2, LastNodeID2,
4374 CreatePolygons, CreatePolyedrs):
4375 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4376 FirstNodeID2, SecondNodeID2, LastNodeID2,
4377 CreatePolygons, CreatePolyedrs)
4379 ## Sews conform free borders
4380 # @return SMESH::Sew_Error
4381 # @ingroup l2_modif_trsf
4382 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4383 FirstNodeID2, SecondNodeID2):
4384 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4385 FirstNodeID2, SecondNodeID2)
4387 ## Sews border to side
4388 # @return SMESH::Sew_Error
4389 # @ingroup l2_modif_trsf
4390 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4391 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4392 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4393 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4395 ## Sews two sides of a mesh. The nodes belonging to Side1 are
4396 # merged with the nodes of elements of Side2.
4397 # The number of elements in theSide1 and in theSide2 must be
4398 # equal and they should have similar nodal connectivity.
4399 # The nodes to merge should belong to side borders and
4400 # the first node should be linked to the second.
4401 # @return SMESH::Sew_Error
4402 # @ingroup l2_modif_trsf
4403 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4404 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4405 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4406 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4407 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4408 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4410 ## Sets new nodes for the given element.
4411 # @param ide the element id
4412 # @param newIDs nodes ids
4413 # @return If the number of nodes does not correspond to the type of element - returns false
4414 # @ingroup l2_modif_edit
4415 def ChangeElemNodes(self, ide, newIDs):
4416 return self.editor.ChangeElemNodes(ide, newIDs)
4418 ## If during the last operation of MeshEditor some nodes were
4419 # created, this method returns the list of their IDs, \n
4420 # if new nodes were not created - returns empty list
4421 # @return the list of integer values (can be empty)
4422 # @ingroup l1_auxiliary
4423 def GetLastCreatedNodes(self):
4424 return self.editor.GetLastCreatedNodes()
4426 ## If during the last operation of MeshEditor some elements were
4427 # created this method returns the list of their IDs, \n
4428 # if new elements were not created - returns empty list
4429 # @return the list of integer values (can be empty)
4430 # @ingroup l1_auxiliary
4431 def GetLastCreatedElems(self):
4432 return self.editor.GetLastCreatedElems()
4434 ## Clears sequences of nodes and elements created by mesh edition oparations
4435 # @ingroup l1_auxiliary
4436 def ClearLastCreated(self):
4437 self.editor.ClearLastCreated()
4439 ## Creates Duplicates given elements, i.e. creates new elements based on the
4440 # same nodes as the given ones.
4441 # @param theElements - container of elements to duplicate. It can be a Mesh,
4442 # sub-mesh, group, filter or a list of element IDs.
4443 # @param theGroupName - a name of group to contain the generated elements.
4444 # If a group with such a name already exists, the new elements
4445 # are added to the existng group, else a new group is created.
4446 # If \a theGroupName is empty, new elements are not added
4448 # @return a group where the new elements are added. None if theGroupName == "".
4449 # @ingroup l2_modif_edit
4450 def DoubleElements(self, theElements, theGroupName=""):
4451 unRegister = genObjUnRegister()
4452 if isinstance( theElements, Mesh ):
4453 theElements = theElements.mesh
4454 elif isinstance( theElements, list ):
4455 theElements = self.GetIDSource( theElements, SMESH.ALL )
4456 unRegister.set( theElements )
4457 return self.editor.DoubleElements(theElements, theGroupName)
4459 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4460 # @param theNodes identifiers of nodes to be doubled
4461 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4462 # nodes. If list of element identifiers is empty then nodes are doubled but
4463 # they not assigned to elements
4464 # @return TRUE if operation has been completed successfully, FALSE otherwise
4465 # @ingroup l2_modif_edit
4466 def DoubleNodes(self, theNodes, theModifiedElems):
4467 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4469 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4470 # This method provided for convenience works as DoubleNodes() described above.
4471 # @param theNodeId identifiers of node to be doubled
4472 # @param theModifiedElems identifiers of elements to be updated
4473 # @return TRUE if operation has been completed successfully, FALSE otherwise
4474 # @ingroup l2_modif_edit
4475 def DoubleNode(self, theNodeId, theModifiedElems):
4476 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4478 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4479 # This method provided for convenience works as DoubleNodes() described above.
4480 # @param theNodes group of nodes to be doubled
4481 # @param theModifiedElems group of elements to be updated.
4482 # @param theMakeGroup forces the generation of a group containing new nodes.
4483 # @return TRUE or a created group if operation has been completed successfully,
4484 # FALSE or None otherwise
4485 # @ingroup l2_modif_edit
4486 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4488 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4489 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4491 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4492 # This method provided for convenience works as DoubleNodes() described above.
4493 # @param theNodes list of groups of nodes to be doubled
4494 # @param theModifiedElems list of groups of elements to be updated.
4495 # @param theMakeGroup forces the generation of a group containing new nodes.
4496 # @return TRUE if operation has been completed successfully, FALSE otherwise
4497 # @ingroup l2_modif_edit
4498 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4500 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4501 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4503 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4504 # @param theElems - the list of elements (edges or faces) to be replicated
4505 # The nodes for duplication could be found from these elements
4506 # @param theNodesNot - list of nodes to NOT replicate
4507 # @param theAffectedElems - the list of elements (cells and edges) to which the
4508 # replicated nodes should be associated to.
4509 # @return TRUE if operation has been completed successfully, FALSE otherwise
4510 # @ingroup l2_modif_edit
4511 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4512 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4514 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4515 # @param theElems - the list of elements (edges or faces) to be replicated
4516 # The nodes for duplication could be found from these elements
4517 # @param theNodesNot - list of nodes to NOT replicate
4518 # @param theShape - shape to detect affected elements (element which geometric center
4519 # located on or inside shape).
4520 # The replicated nodes should be associated to affected elements.
4521 # @return TRUE if operation has been completed successfully, FALSE otherwise
4522 # @ingroup l2_modif_edit
4523 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4524 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4526 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4527 # This method provided for convenience works as DoubleNodes() described above.
4528 # @param theElems - group of of elements (edges or faces) to be replicated
4529 # @param theNodesNot - group of nodes not to replicated
4530 # @param theAffectedElems - group of elements to which the replicated nodes
4531 # should be associated to.
4532 # @param theMakeGroup forces the generation of a group containing new elements.
4533 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4534 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4535 # FALSE or None otherwise
4536 # @ingroup l2_modif_edit
4537 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4538 theMakeGroup=False, theMakeNodeGroup=False):
4539 if theMakeGroup or theMakeNodeGroup:
4540 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4542 theMakeGroup, theMakeNodeGroup)
4543 if theMakeGroup and theMakeNodeGroup:
4546 return twoGroups[ int(theMakeNodeGroup) ]
4547 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4549 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4550 # This method provided for convenience works as DoubleNodes() described above.
4551 # @param theElems - group of of elements (edges or faces) to be replicated
4552 # @param theNodesNot - group of nodes not to replicated
4553 # @param theShape - shape to detect affected elements (element which geometric center
4554 # located on or inside shape).
4555 # The replicated nodes should be associated to affected elements.
4556 # @ingroup l2_modif_edit
4557 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4558 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4560 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4561 # This method provided for convenience works as DoubleNodes() described above.
4562 # @param theElems - list of groups of elements (edges or faces) to be replicated
4563 # @param theNodesNot - list of groups of nodes not to replicated
4564 # @param theAffectedElems - group of elements to which the replicated nodes
4565 # should be associated to.
4566 # @param theMakeGroup forces the generation of a group containing new elements.
4567 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4568 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4569 # FALSE or None otherwise
4570 # @ingroup l2_modif_edit
4571 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4572 theMakeGroup=False, theMakeNodeGroup=False):
4573 if theMakeGroup or theMakeNodeGroup:
4574 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4576 theMakeGroup, theMakeNodeGroup)
4577 if theMakeGroup and theMakeNodeGroup:
4580 return twoGroups[ int(theMakeNodeGroup) ]
4581 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4583 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4584 # This method provided for convenience works as DoubleNodes() described above.
4585 # @param theElems - list of groups of elements (edges or faces) to be replicated
4586 # @param theNodesNot - list of groups of nodes not to replicated
4587 # @param theShape - shape to detect affected elements (element which geometric center
4588 # located on or inside shape).
4589 # The replicated nodes should be associated to affected elements.
4590 # @return TRUE if operation has been completed successfully, FALSE otherwise
4591 # @ingroup l2_modif_edit
4592 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4593 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4595 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4596 # This method is the first step of DoubleNodeElemGroupsInRegion.
4597 # @param theElems - list of groups of elements (edges or faces) to be replicated
4598 # @param theNodesNot - list of groups of nodes not to replicated
4599 # @param theShape - shape to detect affected elements (element which geometric center
4600 # located on or inside shape).
4601 # The replicated nodes should be associated to affected elements.
4602 # @return groups of affected elements
4603 # @ingroup l2_modif_edit
4604 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4605 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4607 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4608 # The list of groups must describe a partition of the mesh volumes.
4609 # The nodes of the internal faces at the boundaries of the groups are doubled.
4610 # In option, the internal faces are replaced by flat elements.
4611 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4612 # @param theDomains - list of groups of volumes
4613 # @param createJointElems - if TRUE, create the elements
4614 # @param onAllBoundaries - if TRUE, the nodes and elements are also created on
4615 # the boundary between \a theDomains and the rest mesh
4616 # @return TRUE if operation has been completed successfully, FALSE otherwise
4617 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems, onAllBoundaries=False ):
4618 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems, onAllBoundaries )
4620 ## Double nodes on some external faces and create flat elements.
4621 # Flat elements are mainly used by some types of mechanic calculations.
4623 # Each group of the list must be constituted of faces.
4624 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4625 # @param theGroupsOfFaces - list of groups of faces
4626 # @return TRUE if operation has been completed successfully, FALSE otherwise
4627 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4628 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4630 ## identify all the elements around a geom shape, get the faces delimiting the hole
4632 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4633 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4635 def _getFunctor(self, funcType ):
4636 fn = self.functors[ funcType._v ]
4638 fn = self.smeshpyD.GetFunctor(funcType)
4639 fn.SetMesh(self.mesh)
4640 self.functors[ funcType._v ] = fn
4643 def _valueFromFunctor(self, funcType, elemId):
4644 fn = self._getFunctor( funcType )
4645 if fn.GetElementType() == self.GetElementType(elemId, True):
4646 val = fn.GetValue(elemId)
4651 ## Get length of 1D element or sum of lengths of all 1D mesh elements
4652 # @param elemId mesh element ID (if not defined - sum of length of all 1D elements will be calculated)
4653 # @return element's length value if \a elemId is specified or sum of all 1D mesh elements' lengths otherwise
4654 # @ingroup l1_measurements
4655 def GetLength(self, elemId=None):
4658 length = self.smeshpyD.GetLength(self)
4660 length = self._valueFromFunctor(SMESH.FT_Length, elemId)
4663 ## Get area of 2D element or sum of areas of all 2D mesh elements
4664 # @param elemId mesh element ID (if not defined - sum of areas of all 2D elements will be calculated)
4665 # @return element's area value if \a elemId is specified or sum of all 2D mesh elements' areas otherwise
4666 # @ingroup l1_measurements
4667 def GetArea(self, elemId=None):
4670 area = self.smeshpyD.GetArea(self)
4672 area = self._valueFromFunctor(SMESH.FT_Area, elemId)
4675 ## Get volume of 3D element or sum of volumes of all 3D mesh elements
4676 # @param elemId mesh element ID (if not defined - sum of volumes of all 3D elements will be calculated)
4677 # @return element's volume value if \a elemId is specified or sum of all 3D mesh elements' volumes otherwise
4678 # @ingroup l1_measurements
4679 def GetVolume(self, elemId=None):
4682 volume = self.smeshpyD.GetVolume(self)
4684 volume = self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4687 ## Get maximum element length.
4688 # @param elemId mesh element ID
4689 # @return element's maximum length value
4690 # @ingroup l1_measurements
4691 def GetMaxElementLength(self, elemId):
4692 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4693 ftype = SMESH.FT_MaxElementLength3D
4695 ftype = SMESH.FT_MaxElementLength2D
4696 return self._valueFromFunctor(ftype, elemId)
4698 ## Get aspect ratio of 2D or 3D element.
4699 # @param elemId mesh element ID
4700 # @return element's aspect ratio value
4701 # @ingroup l1_measurements
4702 def GetAspectRatio(self, elemId):
4703 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4704 ftype = SMESH.FT_AspectRatio3D
4706 ftype = SMESH.FT_AspectRatio
4707 return self._valueFromFunctor(ftype, elemId)
4709 ## Get warping angle of 2D element.
4710 # @param elemId mesh element ID
4711 # @return element's warping angle value
4712 # @ingroup l1_measurements
4713 def GetWarping(self, elemId):
4714 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4716 ## Get minimum angle of 2D element.
4717 # @param elemId mesh element ID
4718 # @return element's minimum angle value
4719 # @ingroup l1_measurements
4720 def GetMinimumAngle(self, elemId):
4721 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4723 ## Get taper of 2D element.
4724 # @param elemId mesh element ID
4725 # @return element's taper value
4726 # @ingroup l1_measurements
4727 def GetTaper(self, elemId):
4728 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4730 ## Get skew of 2D element.
4731 # @param elemId mesh element ID
4732 # @return element's skew value
4733 # @ingroup l1_measurements
4734 def GetSkew(self, elemId):
4735 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4737 ## Return minimal and maximal value of a given functor.
4738 # @param funType a functor type, an item of SMESH.FunctorType enum
4739 # (one of SMESH.FunctorType._items)
4740 # @param meshPart a part of mesh (group, sub-mesh) to treat
4741 # @return tuple (min,max)
4742 # @ingroup l1_measurements
4743 def GetMinMax(self, funType, meshPart=None):
4744 unRegister = genObjUnRegister()
4745 if isinstance( meshPart, list ):
4746 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
4747 unRegister.set( meshPart )
4748 if isinstance( meshPart, Mesh ):
4749 meshPart = meshPart.mesh
4750 fun = self._getFunctor( funType )
4753 hist = fun.GetLocalHistogram( 1, False, meshPart )
4755 hist = fun.GetHistogram( 1, False )
4757 return hist[0].min, hist[0].max
4760 pass # end of Mesh class
4762 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4764 class Pattern(SMESH._objref_SMESH_Pattern):
4766 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4767 decrFun = lambda i: i-1
4768 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4769 theMesh.SetParameters(Parameters)
4770 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4772 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4773 decrFun = lambda i: i-1
4774 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4775 theMesh.SetParameters(Parameters)
4776 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4778 # Registering the new proxy for Pattern
4779 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4781 ## Private class used to bind methods creating algorithms to the class Mesh
4786 self.defaultAlgoType = ""
4787 self.algoTypeToClass = {}
4789 # Stores a python class of algorithm
4790 def add(self, algoClass):
4791 if type( algoClass ).__name__ == 'classobj' and \
4792 hasattr( algoClass, "algoType"):
4793 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4794 if not self.defaultAlgoType and \
4795 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4796 self.defaultAlgoType = algoClass.algoType
4797 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4799 # creates a copy of self and assign mesh to the copy
4800 def copy(self, mesh):
4801 other = algoCreator()
4802 other.defaultAlgoType = self.defaultAlgoType
4803 other.algoTypeToClass = self.algoTypeToClass
4807 # creates an instance of algorithm
4808 def __call__(self,algo="",geom=0,*args):
4809 algoType = self.defaultAlgoType
4810 for arg in args + (algo,geom):
4811 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
4813 if isinstance( arg, str ) and arg:
4815 if not algoType and self.algoTypeToClass:
4816 algoType = self.algoTypeToClass.keys()[0]
4817 if self.algoTypeToClass.has_key( algoType ):
4818 #print "Create algo",algoType
4819 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4820 raise RuntimeError, "No class found for algo type %s" % algoType
4823 # Private class used to substitute and store variable parameters of hypotheses.
4825 class hypMethodWrapper:
4826 def __init__(self, hyp, method):
4828 self.method = method
4829 #print "REBIND:", method.__name__
4832 # call a method of hypothesis with calling SetVarParameter() before
4833 def __call__(self,*args):
4835 return self.method( self.hyp, *args ) # hypothesis method with no args
4837 #print "MethWrapper.__call__",self.method.__name__, args
4839 parsed = ParseParameters(*args) # replace variables with their values
4840 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4841 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4842 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4843 # maybe there is a replaced string arg which is not variable
4844 result = self.method( self.hyp, *args )
4845 except ValueError, detail: # raised by ParseParameters()
4847 result = self.method( self.hyp, *args )
4848 except omniORB.CORBA.BAD_PARAM:
4849 raise ValueError, detail # wrong variable name
4854 # A helper class that call UnRegister() of SALOME.GenericObj'es stored in it
4855 class genObjUnRegister:
4857 def __init__(self, genObj=None):
4858 self.genObjList = []
4862 def set(self, genObj):
4863 "Store one or a list of of SALOME.GenericObj'es"
4864 if isinstance( genObj, list ):
4865 self.genObjList.extend( genObj )
4867 self.genObjList.append( genObj )
4871 for genObj in self.genObjList:
4872 if genObj and hasattr( genObj, "UnRegister" ):
4875 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4877 #print "pluginName: ", pluginName
4878 pluginBuilderName = pluginName + "Builder"
4880 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
4881 except Exception, e:
4882 from salome_utils import verbose
4883 if verbose(): print "Exception while loading %s: %s" % ( pluginBuilderName, e )
4885 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
4886 plugin = eval( pluginBuilderName )
4887 #print " plugin:" , str(plugin)
4889 # add methods creating algorithms to Mesh
4890 for k in dir( plugin ):
4891 if k[0] == '_': continue
4892 algo = getattr( plugin, k )
4893 #print " algo:", str(algo)
4894 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4895 #print " meshMethod:" , str(algo.meshMethod)
4896 if not hasattr( Mesh, algo.meshMethod ):
4897 setattr( Mesh, algo.meshMethod, algoCreator() )
4899 getattr( Mesh, algo.meshMethod ).add( algo )