1 # Copyright (C) 2007-2013 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.
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 quadrangles
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
96 ## @addtogroup l1_auxiliary
99 ## Converts an angle from degrees to radians
100 def DegreesToRadians(AngleInDegrees):
102 return AngleInDegrees * pi / 180.0
104 import salome_notebook
105 notebook = salome_notebook.notebook
106 # Salome notebook variable separator
109 ## Return list of variable values from salome notebook.
110 # The last argument, if is callable, is used to modify values got from notebook
111 def ParseParameters(*args):
116 if args and callable( args[-1] ):
117 args, varModifFun = args[:-1], args[-1]
118 for parameter in args:
120 Parameters += str(parameter) + var_separator
122 if isinstance(parameter,str):
123 # check if there is an inexistent variable name
124 if not notebook.isVariable(parameter):
125 raise ValueError, "Variable with name '" + parameter + "' doesn't exist!!!"
126 parameter = notebook.get(parameter)
129 parameter = varModifFun(parameter)
132 Result.append(parameter)
135 Parameters = Parameters[:-1]
136 Result.append( Parameters )
137 Result.append( hasVariables )
140 # Parse parameters converting variables to radians
141 def ParseAngles(*args):
142 return ParseParameters( *( args + (DegreesToRadians, )))
144 # Substitute PointStruct.__init__() to create SMESH.PointStruct using notebook variables.
145 # Parameters are stored in PointStruct.parameters attribute
146 def __initPointStruct(point,*args):
147 point.x, point.y, point.z, point.parameters,hasVars = ParseParameters(*args)
149 SMESH.PointStruct.__init__ = __initPointStruct
151 # Substitute AxisStruct.__init__() to create SMESH.AxisStruct using notebook variables.
152 # Parameters are stored in AxisStruct.parameters attribute
153 def __initAxisStruct(ax,*args):
154 ax.x, ax.y, ax.z, ax.vx, ax.vy, ax.vz, ax.parameters,hasVars = ParseParameters(*args)
156 SMESH.AxisStruct.__init__ = __initAxisStruct
158 smeshPrecisionConfusion = 1.e-07
159 def IsEqual(val1, val2, tol=smeshPrecisionConfusion):
160 if abs(val1 - val2) < tol:
170 if isinstance(obj, SALOMEDS._objref_SObject):
174 ior = salome.orb.object_to_string(obj)
179 studies = salome.myStudyManager.GetOpenStudies()
180 for sname in studies:
181 s = salome.myStudyManager.GetStudyByName(sname)
183 sobj = s.FindObjectIOR(ior)
184 if not sobj: continue
185 return sobj.GetName()
186 if hasattr(obj, "GetName"):
187 # unknown CORBA object, having GetName() method
190 # unknown CORBA object, no GetName() method
193 if hasattr(obj, "GetName"):
194 # unknown non-CORBA object, having GetName() method
197 raise RuntimeError, "Null or invalid object"
199 ## Prints error message if a hypothesis was not assigned.
200 def TreatHypoStatus(status, hypName, geomName, isAlgo):
202 hypType = "algorithm"
204 hypType = "hypothesis"
206 if status == HYP_UNKNOWN_FATAL :
207 reason = "for unknown reason"
208 elif status == HYP_INCOMPATIBLE :
209 reason = "this hypothesis mismatches the algorithm"
210 elif status == HYP_NOTCONFORM :
211 reason = "a non-conform mesh would be built"
212 elif status == HYP_ALREADY_EXIST :
213 if isAlgo: return # it does not influence anything
214 reason = hypType + " of the same dimension is already assigned to this shape"
215 elif status == HYP_BAD_DIM :
216 reason = hypType + " mismatches the shape"
217 elif status == HYP_CONCURENT :
218 reason = "there are concurrent hypotheses on sub-shapes"
219 elif status == HYP_BAD_SUBSHAPE :
220 reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
221 elif status == HYP_BAD_GEOMETRY:
222 reason = "geometry mismatches the expectation of the algorithm"
223 elif status == HYP_HIDDEN_ALGO:
224 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
225 elif status == HYP_HIDING_ALGO:
226 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
227 elif status == HYP_NEED_SHAPE:
228 reason = "Algorithm can't work without shape"
231 hypName = '"' + hypName + '"'
232 geomName= '"' + geomName+ '"'
233 if status < HYP_UNKNOWN_FATAL and not geomName =='""':
234 print hypName, "was assigned to", geomName,"but", reason
235 elif not geomName == '""':
236 print hypName, "was not assigned to",geomName,":", reason
238 print hypName, "was not assigned:", reason
241 ## Private method. Add geom (sub-shape of the main shape) into the study if not yet there
242 def AssureGeomPublished(mesh, geom, name=''):
243 if not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
245 if not geom.GetStudyEntry() and \
246 mesh.smeshpyD.GetCurrentStudy():
248 studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
249 if studyID != mesh.geompyD.myStudyId:
250 mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
252 if not name and geom.GetShapeType() != geomBuilder.GEOM.COMPOUND:
253 # for all groups SubShapeName() returns "Compound_-1"
254 name = mesh.geompyD.SubShapeName(geom, mesh.geom)
256 name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
258 mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
261 ## Return the first vertex of a geometrical edge by ignoring orientation
262 def FirstVertexOnCurve(mesh, edge):
263 vv = mesh.geompyD.SubShapeAll( edge, geomBuilder.geomBuilder.ShapeType["VERTEX"])
265 raise TypeError, "Given object has no vertices"
266 if len( vv ) == 1: return vv[0]
267 v0 = mesh.geompyD.MakeVertexOnCurve(edge,0.)
268 xyz = mesh.geompyD.PointCoordinates( v0 ) # coords of the first vertex
269 xyz1 = mesh.geompyD.PointCoordinates( vv[0] )
270 xyz2 = mesh.geompyD.PointCoordinates( vv[1] )
273 dist1 += abs( xyz[i] - xyz1[i] )
274 dist2 += abs( xyz[i] - xyz2[i] )
280 # end of l1_auxiliary
284 # Warning: smeshInst is a singleton
290 ## This class allows to create, load or manipulate meshes
291 # It has a set of methods to create load or copy meshes, to combine several meshes.
292 # It also has methods to get infos on meshes.
293 class smeshBuilder(object, SMESH._objref_SMESH_Gen):
295 # MirrorType enumeration
296 POINT = SMESH_MeshEditor.POINT
297 AXIS = SMESH_MeshEditor.AXIS
298 PLANE = SMESH_MeshEditor.PLANE
300 # Smooth_Method enumeration
301 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
302 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
304 PrecisionConfusion = smeshPrecisionConfusion
306 # TopAbs_State enumeration
307 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
309 # Methods of splitting a hexahedron into tetrahedra
310 Hex_5Tet, Hex_6Tet, Hex_24Tet = 1, 2, 3
316 #print "==== __new__", engine, smeshInst, doLcc
318 if smeshInst is None:
319 # smesh engine is either retrieved from engine, or created
321 # Following test avoids a recursive loop
323 if smeshInst is not None:
324 # smesh engine not created: existing engine found
328 # FindOrLoadComponent called:
329 # 1. CORBA resolution of server
330 # 2. the __new__ method is called again
331 #print "==== smeshInst = lcc.FindOrLoadComponent ", engine, smeshInst, doLcc
332 smeshInst = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
334 # FindOrLoadComponent not called
335 if smeshInst is None:
336 # smeshBuilder instance is created from lcc.FindOrLoadComponent
337 #print "==== smeshInst = super(smeshBuilder,cls).__new__(cls) ", engine, smeshInst, doLcc
338 smeshInst = super(smeshBuilder,cls).__new__(cls)
340 # smesh engine not created: existing engine found
341 #print "==== existing ", engine, smeshInst, doLcc
343 #print "====1 ", smeshInst
346 #print "====2 ", smeshInst
351 #print "--------------- smeshbuilder __init__ ---", created
354 SMESH._objref_SMESH_Gen.__init__(self)
356 ## Dump component to the Python script
357 # This method overrides IDL function to allow default values for the parameters.
358 def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
359 return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
361 ## Set mode of DumpPython(), \a historical or \a snapshot.
362 # In the \a historical mode, the Python Dump script includes all commands
363 # performed by SMESH engine. In the \a snapshot mode, commands
364 # relating to objects removed from the Study are excluded from the script
365 # as well as commands not influencing the current state of meshes
366 def SetDumpPythonHistorical(self, isHistorical):
367 if isHistorical: val = "true"
369 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
371 ## Sets the current study and Geometry component
372 # @ingroup l1_auxiliary
373 def init_smesh(self,theStudy,geompyD = None):
375 self.SetCurrentStudy(theStudy,geompyD)
377 ## Creates an empty Mesh. This mesh can have an underlying geometry.
378 # @param obj the Geometrical object on which the mesh is built. If not defined,
379 # the mesh will have no underlying geometry.
380 # @param name the name for the new mesh.
381 # @return an instance of Mesh class.
382 # @ingroup l2_construct
383 def Mesh(self, obj=0, name=0):
384 if isinstance(obj,str):
386 return Mesh(self,self.geompyD,obj,name)
388 ## Returns a long value from enumeration
389 # @ingroup l1_controls
390 def EnumToLong(self,theItem):
393 ## Returns a string representation of the color.
394 # To be used with filters.
395 # @param c color value (SALOMEDS.Color)
396 # @ingroup l1_controls
397 def ColorToString(self,c):
399 if isinstance(c, SALOMEDS.Color):
400 val = "%s;%s;%s" % (c.R, c.G, c.B)
401 elif isinstance(c, str):
404 raise ValueError, "Color value should be of string or SALOMEDS.Color type"
407 ## Gets PointStruct from vertex
408 # @param theVertex a GEOM object(vertex)
409 # @return SMESH.PointStruct
410 # @ingroup l1_auxiliary
411 def GetPointStruct(self,theVertex):
412 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
413 return PointStruct(x,y,z)
415 ## Gets DirStruct from vector
416 # @param theVector a GEOM object(vector)
417 # @return SMESH.DirStruct
418 # @ingroup l1_auxiliary
419 def GetDirStruct(self,theVector):
420 vertices = self.geompyD.SubShapeAll( theVector, geomBuilder.geomBuilder.ShapeType["VERTEX"] )
421 if(len(vertices) != 2):
422 print "Error: vector object is incorrect."
424 p1 = self.geompyD.PointCoordinates(vertices[0])
425 p2 = self.geompyD.PointCoordinates(vertices[1])
426 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
427 dirst = DirStruct(pnt)
430 ## Makes DirStruct from a triplet
431 # @param x,y,z vector components
432 # @return SMESH.DirStruct
433 # @ingroup l1_auxiliary
434 def MakeDirStruct(self,x,y,z):
435 pnt = PointStruct(x,y,z)
436 return DirStruct(pnt)
438 ## Get AxisStruct from object
439 # @param theObj a GEOM object (line or plane)
440 # @return SMESH.AxisStruct
441 # @ingroup l1_auxiliary
442 def GetAxisStruct(self,theObj):
443 edges = self.geompyD.SubShapeAll( theObj, geomBuilder.geomBuilder.ShapeType["EDGE"] )
445 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
446 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
447 vertex1 = self.geompyD.PointCoordinates(vertex1)
448 vertex2 = self.geompyD.PointCoordinates(vertex2)
449 vertex3 = self.geompyD.PointCoordinates(vertex3)
450 vertex4 = self.geompyD.PointCoordinates(vertex4)
451 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
452 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
453 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] ]
454 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
456 elif len(edges) == 1:
457 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
458 p1 = self.geompyD.PointCoordinates( vertex1 )
459 p2 = self.geompyD.PointCoordinates( vertex2 )
460 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
464 # From SMESH_Gen interface:
465 # ------------------------
467 ## Sets the given name to the object
468 # @param obj the object to rename
469 # @param name a new object name
470 # @ingroup l1_auxiliary
471 def SetName(self, obj, name):
472 if isinstance( obj, Mesh ):
474 elif isinstance( obj, Mesh_Algorithm ):
475 obj = obj.GetAlgorithm()
476 ior = salome.orb.object_to_string(obj)
477 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
479 ## Sets the current mode
480 # @ingroup l1_auxiliary
481 def SetEmbeddedMode( self,theMode ):
482 #self.SetEmbeddedMode(theMode)
483 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
485 ## Gets the current mode
486 # @ingroup l1_auxiliary
487 def IsEmbeddedMode(self):
488 #return self.IsEmbeddedMode()
489 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
491 ## Sets the current study
492 # @ingroup l1_auxiliary
493 def SetCurrentStudy( self, theStudy, geompyD = None ):
494 #self.SetCurrentStudy(theStudy)
496 from salome.geom import geomBuilder
497 geompyD = geomBuilder.geom
500 self.SetGeomEngine(geompyD)
501 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
504 notebook = salome_notebook.NoteBook( theStudy )
506 notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
508 ## Gets the current study
509 # @ingroup l1_auxiliary
510 def GetCurrentStudy(self):
511 #return self.GetCurrentStudy()
512 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
514 ## Creates a Mesh object importing data from the given UNV file
515 # @return an instance of Mesh class
517 def CreateMeshesFromUNV( self,theFileName ):
518 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
519 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
522 ## Creates a Mesh object(s) importing data from the given MED file
523 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
525 def CreateMeshesFromMED( self,theFileName ):
526 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
527 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
528 return aMeshes, aStatus
530 ## Creates a Mesh object(s) importing data from the given SAUV file
531 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
533 def CreateMeshesFromSAUV( self,theFileName ):
534 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
535 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
536 return aMeshes, aStatus
538 ## Creates a Mesh object importing data from the given STL file
539 # @return an instance of Mesh class
541 def CreateMeshesFromSTL( self, theFileName ):
542 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
543 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
546 ## Creates Mesh objects importing data from the given CGNS file
547 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
549 def CreateMeshesFromCGNS( self, theFileName ):
550 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
551 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
552 return aMeshes, aStatus
554 ## Creates a Mesh object importing data from the given GMF file
555 # @return [ an instance of Mesh class, SMESH.ComputeError ]
557 def CreateMeshesFromGMF( self, theFileName ):
558 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
561 if error.comment: print "*** CreateMeshesFromGMF() errors:\n", error.comment
562 return Mesh(self, self.geompyD, aSmeshMesh), error
564 ## Concatenate the given meshes into one mesh.
565 # @return an instance of Mesh class
566 # @param meshes the meshes to combine into one mesh
567 # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
568 # @param mergeNodesAndElements if true, equal nodes and elements aremerged
569 # @param mergeTolerance tolerance for merging nodes
570 # @param allGroups forces creation of groups of all elements
571 # @param name name of a new mesh
572 def Concatenate( self, meshes, uniteIdenticalGroups,
573 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
575 if not meshes: return None
576 for i,m in enumerate(meshes):
577 if isinstance(m, Mesh):
578 meshes[i] = m.GetMesh()
579 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
580 meshes[0].SetParameters(Parameters)
582 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
583 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
585 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
586 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
587 aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
590 ## Create a mesh by copying a part of another mesh.
591 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
592 # to copy nodes or elements not contained in any mesh object,
593 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
594 # @param meshName a name of the new mesh
595 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
596 # @param toKeepIDs to preserve IDs of the copied elements or not
597 # @return an instance of Mesh class
598 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
599 if (isinstance( meshPart, Mesh )):
600 meshPart = meshPart.GetMesh()
601 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
602 return Mesh(self, self.geompyD, mesh)
604 ## From SMESH_Gen interface
605 # @return the list of integer values
606 # @ingroup l1_auxiliary
607 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
608 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
610 ## From SMESH_Gen interface. Creates a pattern
611 # @return an instance of SMESH_Pattern
613 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
614 # @ingroup l2_modif_patterns
615 def GetPattern(self):
616 return SMESH._objref_SMESH_Gen.GetPattern(self)
618 ## Sets number of segments per diagonal of boundary box of geometry by which
619 # default segment length of appropriate 1D hypotheses is defined.
620 # Default value is 10
621 # @ingroup l1_auxiliary
622 def SetBoundaryBoxSegmentation(self, nbSegments):
623 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
625 # Filtering. Auxiliary functions:
626 # ------------------------------
628 ## Creates an empty criterion
629 # @return SMESH.Filter.Criterion
630 # @ingroup l1_controls
631 def GetEmptyCriterion(self):
632 Type = self.EnumToLong(FT_Undefined)
633 Compare = self.EnumToLong(FT_Undefined)
637 UnaryOp = self.EnumToLong(FT_Undefined)
638 BinaryOp = self.EnumToLong(FT_Undefined)
641 Precision = -1 ##@1e-07
642 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
643 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
645 ## Creates a criterion by the given parameters
646 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
647 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
648 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
649 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
650 # @param Threshold the threshold value (range of ids as string, shape, numeric)
651 # @param UnaryOp FT_LogicalNOT or FT_Undefined
652 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
653 # FT_Undefined (must be for the last criterion of all criteria)
654 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
655 # FT_LyingOnGeom, FT_CoplanarFaces criteria
656 # @return SMESH.Filter.Criterion
658 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
659 # @ingroup l1_controls
660 def GetCriterion(self,elementType,
662 Compare = FT_EqualTo,
664 UnaryOp=FT_Undefined,
665 BinaryOp=FT_Undefined,
667 if not CritType in SMESH.FunctorType._items:
668 raise TypeError, "CritType should be of SMESH.FunctorType"
669 aCriterion = self.GetEmptyCriterion()
670 aCriterion.TypeOfElement = elementType
671 aCriterion.Type = self.EnumToLong(CritType)
672 aCriterion.Tolerance = Tolerance
674 aThreshold = Threshold
676 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
677 aCriterion.Compare = self.EnumToLong(Compare)
678 elif Compare == "=" or Compare == "==":
679 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
681 aCriterion.Compare = self.EnumToLong(FT_LessThan)
683 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
684 elif Compare != FT_Undefined:
685 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
688 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
689 FT_BelongToCylinder, FT_LyingOnGeom]:
690 # Checks that Threshold is GEOM object
691 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object):
692 aCriterion.ThresholdStr = GetName(aThreshold)
693 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
694 if not aCriterion.ThresholdID:
695 name = aCriterion.ThresholdStr
697 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
698 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
699 #raise RuntimeError, "Threshold shape must be published"
701 print "Error: The Threshold should be a shape."
703 if isinstance(UnaryOp,float):
704 aCriterion.Tolerance = UnaryOp
705 UnaryOp = FT_Undefined
707 elif CritType == FT_RangeOfIds:
708 # Checks that Threshold is string
709 if isinstance(aThreshold, str):
710 aCriterion.ThresholdStr = aThreshold
712 print "Error: The Threshold should be a string."
714 elif CritType == FT_CoplanarFaces:
715 # Checks the Threshold
716 if isinstance(aThreshold, int):
717 aCriterion.ThresholdID = str(aThreshold)
718 elif isinstance(aThreshold, str):
721 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
722 aCriterion.ThresholdID = aThreshold
725 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
726 elif CritType == FT_ConnectedElements:
727 # Checks the Threshold
728 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object): # shape
729 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
730 if not aCriterion.ThresholdID:
731 name = aThreshold.GetName()
733 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
734 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
735 elif isinstance(aThreshold, int): # node id
736 aCriterion.Threshold = aThreshold
737 elif isinstance(aThreshold, list): # 3 point coordinates
738 if len( aThreshold ) < 3:
739 raise ValueError, "too few point coordinates, must be 3"
740 aCriterion.ThresholdStr = " ".join( [str(c) for c in aThreshold[:3]] )
741 elif isinstance(aThreshold, str):
742 if aThreshold.isdigit():
743 aCriterion.Threshold = aThreshold # node id
745 aCriterion.ThresholdStr = aThreshold # hope that it's point coordinates
748 "The Threshold should either a VERTEX, or a node ID, "\
749 "or a list of point coordinates and not '%s'"%aThreshold
750 elif CritType == FT_ElemGeomType:
751 # Checks the Threshold
753 aCriterion.Threshold = self.EnumToLong(aThreshold)
754 assert( aThreshold in SMESH.GeometryType._items )
756 if isinstance(aThreshold, int):
757 aCriterion.Threshold = aThreshold
759 print "Error: The Threshold should be an integer or SMESH.GeometryType."
763 elif CritType == FT_EntityType:
764 # Checks the Threshold
766 aCriterion.Threshold = self.EnumToLong(aThreshold)
767 assert( aThreshold in SMESH.EntityType._items )
769 if isinstance(aThreshold, int):
770 aCriterion.Threshold = aThreshold
772 print "Error: The Threshold should be an integer or SMESH.EntityType."
777 elif CritType == FT_GroupColor:
778 # Checks the Threshold
780 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
782 print "Error: The threshold value should be of SALOMEDS.Color type"
785 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
786 FT_LinearOrQuadratic, FT_BadOrientedVolume,
787 FT_BareBorderFace, FT_BareBorderVolume,
788 FT_OverConstrainedFace, FT_OverConstrainedVolume,
789 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
790 # At this point the Threshold is unnecessary
791 if aThreshold == FT_LogicalNOT:
792 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
793 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
794 aCriterion.BinaryOp = aThreshold
798 aThreshold = float(aThreshold)
799 aCriterion.Threshold = aThreshold
801 print "Error: The Threshold should be a number."
804 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
805 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
807 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
808 aCriterion.BinaryOp = self.EnumToLong(Threshold)
810 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
811 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
813 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
814 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
818 ## Creates a filter with the given parameters
819 # @param elementType the type of elements in the group
820 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
821 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
822 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
823 # @param UnaryOp FT_LogicalNOT or FT_Undefined
824 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
825 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
826 # @param mesh the mesh to initialize the filter with
827 # @return SMESH_Filter
829 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
830 # @ingroup l1_controls
831 def GetFilter(self,elementType,
832 CritType=FT_Undefined,
835 UnaryOp=FT_Undefined,
838 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
839 aFilterMgr = self.CreateFilterManager()
840 aFilter = aFilterMgr.CreateFilter()
842 aCriteria.append(aCriterion)
843 aFilter.SetCriteria(aCriteria)
845 if isinstance( mesh, Mesh ): aFilter.SetMesh( mesh.GetMesh() )
846 else : aFilter.SetMesh( mesh )
847 aFilterMgr.UnRegister()
850 ## Creates a filter from criteria
851 # @param criteria a list of criteria
852 # @return SMESH_Filter
854 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
855 # @ingroup l1_controls
856 def GetFilterFromCriteria(self,criteria):
857 aFilterMgr = self.CreateFilterManager()
858 aFilter = aFilterMgr.CreateFilter()
859 aFilter.SetCriteria(criteria)
860 aFilterMgr.UnRegister()
863 ## Creates a numerical functor by its type
864 # @param theCriterion FT_...; functor type
865 # @return SMESH_NumericalFunctor
866 # @ingroup l1_controls
867 def GetFunctor(self,theCriterion):
868 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
870 aFilterMgr = self.CreateFilterManager()
872 if theCriterion == FT_AspectRatio:
873 functor = aFilterMgr.CreateAspectRatio()
874 elif theCriterion == FT_AspectRatio3D:
875 functor = aFilterMgr.CreateAspectRatio3D()
876 elif theCriterion == FT_Warping:
877 functor = aFilterMgr.CreateWarping()
878 elif theCriterion == FT_MinimumAngle:
879 functor = aFilterMgr.CreateMinimumAngle()
880 elif theCriterion == FT_Taper:
881 functor = aFilterMgr.CreateTaper()
882 elif theCriterion == FT_Skew:
883 functor = aFilterMgr.CreateSkew()
884 elif theCriterion == FT_Area:
885 functor = aFilterMgr.CreateArea()
886 elif theCriterion == FT_Volume3D:
887 functor = aFilterMgr.CreateVolume3D()
888 elif theCriterion == FT_MaxElementLength2D:
889 functor = aFilterMgr.CreateMaxElementLength2D()
890 elif theCriterion == FT_MaxElementLength3D:
891 functor = aFilterMgr.CreateMaxElementLength3D()
892 elif theCriterion == FT_MultiConnection:
893 functor = aFilterMgr.CreateMultiConnection()
894 elif theCriterion == FT_MultiConnection2D:
895 functor = aFilterMgr.CreateMultiConnection2D()
896 elif theCriterion == FT_Length:
897 functor = aFilterMgr.CreateLength()
898 elif theCriterion == FT_Length2D:
899 functor = aFilterMgr.CreateLength2D()
901 print "Error: given parameter is not numerical functor type."
902 aFilterMgr.UnRegister()
905 ## Creates hypothesis
906 # @param theHType mesh hypothesis type (string)
907 # @param theLibName mesh plug-in library name
908 # @return created hypothesis instance
909 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
910 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
912 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
915 # wrap hypothesis methods
916 #print "HYPOTHESIS", theHType
917 for meth_name in dir( hyp.__class__ ):
918 if not meth_name.startswith("Get") and \
919 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
920 method = getattr ( hyp.__class__, meth_name )
922 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
926 ## Gets the mesh statistic
927 # @return dictionary "element type" - "count of elements"
928 # @ingroup l1_meshinfo
929 def GetMeshInfo(self, obj):
930 if isinstance( obj, Mesh ):
933 if hasattr(obj, "GetMeshInfo"):
934 values = obj.GetMeshInfo()
935 for i in range(SMESH.Entity_Last._v):
936 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
940 ## Get minimum distance between two objects
942 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
943 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
945 # @param src1 first source object
946 # @param src2 second source object
947 # @param id1 node/element id from the first source
948 # @param id2 node/element id from the second (or first) source
949 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
950 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
951 # @return minimum distance value
952 # @sa GetMinDistance()
953 # @ingroup l1_measurements
954 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
955 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
959 result = result.value
962 ## Get measure structure specifying minimum distance data between two objects
964 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
965 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
967 # @param src1 first source object
968 # @param src2 second source object
969 # @param id1 node/element id from the first source
970 # @param id2 node/element id from the second (or first) source
971 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
972 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
973 # @return Measure structure or None if input data is invalid
975 # @ingroup l1_measurements
976 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
977 if isinstance(src1, Mesh): src1 = src1.mesh
978 if isinstance(src2, Mesh): src2 = src2.mesh
979 if src2 is None and id2 != 0: src2 = src1
980 if not hasattr(src1, "_narrow"): return None
981 src1 = src1._narrow(SMESH.SMESH_IDSource)
982 if not src1: return None
985 e = m.GetMeshEditor()
987 src1 = e.MakeIDSource([id1], SMESH.FACE)
989 src1 = e.MakeIDSource([id1], SMESH.NODE)
991 if hasattr(src2, "_narrow"):
992 src2 = src2._narrow(SMESH.SMESH_IDSource)
993 if src2 and id2 != 0:
995 e = m.GetMeshEditor()
997 src2 = e.MakeIDSource([id2], SMESH.FACE)
999 src2 = e.MakeIDSource([id2], SMESH.NODE)
1002 aMeasurements = self.CreateMeasurements()
1003 result = aMeasurements.MinDistance(src1, src2)
1004 aMeasurements.UnRegister()
1007 ## Get bounding box of the specified object(s)
1008 # @param objects single source object or list of source objects
1009 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
1010 # @sa GetBoundingBox()
1011 # @ingroup l1_measurements
1012 def BoundingBox(self, objects):
1013 result = self.GetBoundingBox(objects)
1017 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
1020 ## Get measure structure specifying bounding box data of the specified object(s)
1021 # @param objects single source object or list of source objects
1022 # @return Measure structure
1024 # @ingroup l1_measurements
1025 def GetBoundingBox(self, objects):
1026 if isinstance(objects, tuple):
1027 objects = list(objects)
1028 if not isinstance(objects, list):
1032 if isinstance(o, Mesh):
1033 srclist.append(o.mesh)
1034 elif hasattr(o, "_narrow"):
1035 src = o._narrow(SMESH.SMESH_IDSource)
1036 if src: srclist.append(src)
1039 aMeasurements = self.CreateMeasurements()
1040 result = aMeasurements.BoundingBox(srclist)
1041 aMeasurements.UnRegister()
1045 #Registering the new proxy for SMESH_Gen
1046 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
1048 ## Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1049 # interface to create or load meshes.
1054 # salome.salome_init()
1055 # from salome.smesh import smeshBuilder
1056 # smesh = smeshBuilder.New(theStudy)
1058 # @param study SALOME study, generally obtained by salome.myStudy.
1059 # @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1060 # @return smeshBuilder instance
1062 def New( study, instance=None):
1064 Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1065 interface to create or load meshes.
1069 salome.salome_init()
1070 from salome.smesh import smeshBuilder
1071 smesh = smeshBuilder.New(theStudy)
1074 study SALOME study, generally obtained by salome.myStudy.
1075 instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1077 smeshBuilder instance
1085 smeshInst = smeshBuilder()
1086 assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__
1087 smeshInst.init_smesh(study)
1091 # Public class: Mesh
1092 # ==================
1094 ## This class allows defining and managing a mesh.
1095 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1096 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1097 # new nodes and elements and by changing the existing entities), to get information
1098 # about a mesh and to export a mesh into different formats.
1107 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1108 # sets the GUI name of this mesh to \a name.
1109 # @param smeshpyD an instance of smeshBuilder class
1110 # @param geompyD an instance of geomBuilder class
1111 # @param obj Shape to be meshed or SMESH_Mesh object
1112 # @param name Study name of the mesh
1113 # @ingroup l2_construct
1114 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1115 self.smeshpyD=smeshpyD
1116 self.geompyD=geompyD
1121 if isinstance(obj, geomBuilder.GEOM._objref_GEOM_Object):
1124 # publish geom of mesh (issue 0021122)
1125 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
1127 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
1128 if studyID != geompyD.myStudyId:
1129 geompyD.init_geom( smeshpyD.GetCurrentStudy())
1132 geo_name = name + " shape"
1134 geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1135 geompyD.addToStudy( self.geom, geo_name )
1136 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1138 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1141 self.mesh = self.smeshpyD.CreateEmptyMesh()
1143 self.smeshpyD.SetName(self.mesh, name)
1145 self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1148 self.geom = self.mesh.GetShapeToMesh()
1150 self.editor = self.mesh.GetMeshEditor()
1151 self.functors = [None] * SMESH.FT_Undefined._v
1153 # set self to algoCreator's
1154 for attrName in dir(self):
1155 attr = getattr( self, attrName )
1156 if isinstance( attr, algoCreator ):
1157 #print "algoCreator ", attrName
1158 setattr( self, attrName, attr.copy( self ))
1160 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1161 # @param theMesh a SMESH_Mesh object
1162 # @ingroup l2_construct
1163 def SetMesh(self, theMesh):
1164 if self.mesh: self.mesh.UnRegister()
1167 self.mesh.Register()
1168 self.geom = self.mesh.GetShapeToMesh()
1170 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1171 # @return a SMESH_Mesh object
1172 # @ingroup l2_construct
1176 ## Gets the name of the mesh
1177 # @return the name of the mesh as a string
1178 # @ingroup l2_construct
1180 name = GetName(self.GetMesh())
1183 ## Sets a name to the mesh
1184 # @param name a new name of the mesh
1185 # @ingroup l2_construct
1186 def SetName(self, name):
1187 self.smeshpyD.SetName(self.GetMesh(), name)
1189 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1190 # The subMesh object gives access to the IDs of nodes and elements.
1191 # @param geom a geometrical object (shape)
1192 # @param name a name for the submesh
1193 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1194 # @ingroup l2_submeshes
1195 def GetSubMesh(self, geom, name):
1196 AssureGeomPublished( self, geom, name )
1197 submesh = self.mesh.GetSubMesh( geom, name )
1200 ## Returns the shape associated to the mesh
1201 # @return a GEOM_Object
1202 # @ingroup l2_construct
1206 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1207 # @param geom the shape to be meshed (GEOM_Object)
1208 # @ingroup l2_construct
1209 def SetShape(self, geom):
1210 self.mesh = self.smeshpyD.CreateMesh(geom)
1212 ## Loads mesh from the study after opening the study
1216 ## Returns true if the hypotheses are defined well
1217 # @param theSubObject a sub-shape of a mesh shape
1218 # @return True or False
1219 # @ingroup l2_construct
1220 def IsReadyToCompute(self, theSubObject):
1221 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1223 ## Returns errors of hypotheses definition.
1224 # The list of errors is empty if everything is OK.
1225 # @param theSubObject a sub-shape of a mesh shape
1226 # @return a list of errors
1227 # @ingroup l2_construct
1228 def GetAlgoState(self, theSubObject):
1229 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1231 ## Returns a geometrical object on which the given element was built.
1232 # The returned geometrical object, if not nil, is either found in the
1233 # study or published by this method with the given name
1234 # @param theElementID the id of the mesh element
1235 # @param theGeomName the user-defined name of the geometrical object
1236 # @return GEOM::GEOM_Object instance
1237 # @ingroup l2_construct
1238 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1239 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1241 ## Returns the mesh dimension depending on the dimension of the underlying shape
1242 # or, if the mesh is not based on any shape, basing on deimension of elements
1243 # @return mesh dimension as an integer value [0,3]
1244 # @ingroup l1_auxiliary
1245 def MeshDimension(self):
1246 if self.mesh.HasShapeToMesh():
1247 shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
1248 if len( shells ) > 0 :
1250 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1252 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1257 if self.NbVolumes() > 0: return 3
1258 if self.NbFaces() > 0: return 2
1259 if self.NbEdges() > 0: return 1
1262 ## Evaluates size of prospective mesh on a shape
1263 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1264 # To know predicted number of e.g. edges, inquire it this way
1265 # Evaluate()[ EnumToLong( Entity_Edge )]
1266 def Evaluate(self, geom=0):
1267 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1269 geom = self.mesh.GetShapeToMesh()
1272 return self.smeshpyD.Evaluate(self.mesh, geom)
1275 ## Computes the mesh and returns the status of the computation
1276 # @param geom geomtrical shape on which mesh data should be computed
1277 # @param discardModifs if True and the mesh has been edited since
1278 # a last total re-compute and that may prevent successful partial re-compute,
1279 # then the mesh is cleaned before Compute()
1280 # @return True or False
1281 # @ingroup l2_construct
1282 def Compute(self, geom=0, discardModifs=False):
1283 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1285 geom = self.mesh.GetShapeToMesh()
1290 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1292 ok = self.smeshpyD.Compute(self.mesh, geom)
1293 except SALOME.SALOME_Exception, ex:
1294 print "Mesh computation failed, exception caught:"
1295 print " ", ex.details.text
1298 print "Mesh computation failed, exception caught:"
1299 traceback.print_exc()
1303 # Treat compute errors
1304 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1305 for err in computeErrors:
1307 if self.mesh.HasShapeToMesh():
1309 mainIOR = salome.orb.object_to_string(geom)
1310 for sname in salome.myStudyManager.GetOpenStudies():
1311 s = salome.myStudyManager.GetStudyByName(sname)
1313 mainSO = s.FindObjectIOR(mainIOR)
1314 if not mainSO: continue
1315 if err.subShapeID == 1:
1316 shapeText = ' on "%s"' % mainSO.GetName()
1317 subIt = s.NewChildIterator(mainSO)
1319 subSO = subIt.Value()
1321 obj = subSO.GetObject()
1322 if not obj: continue
1323 go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
1325 ids = go.GetSubShapeIndices()
1326 if len(ids) == 1 and ids[0] == err.subShapeID:
1327 shapeText = ' on "%s"' % subSO.GetName()
1330 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1332 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1334 shapeText = " on subshape #%s" % (err.subShapeID)
1336 shapeText = " on subshape #%s" % (err.subShapeID)
1338 stdErrors = ["OK", #COMPERR_OK
1339 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1340 "std::exception", #COMPERR_STD_EXCEPTION
1341 "OCC exception", #COMPERR_OCC_EXCEPTION
1342 "..", #COMPERR_SLM_EXCEPTION
1343 "Unknown exception", #COMPERR_EXCEPTION
1344 "Memory allocation problem", #COMPERR_MEMORY_PB
1345 "Algorithm failed", #COMPERR_ALGO_FAILED
1346 "Unexpected geometry", #COMPERR_BAD_SHAPE
1347 "Warning", #COMPERR_WARNING
1348 "Computation cancelled",#COMPERR_CANCELED
1349 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1351 if err.code < len(stdErrors): errText = stdErrors[err.code]
1353 errText = "code %s" % -err.code
1354 if errText: errText += ". "
1355 errText += err.comment
1356 if allReasons != "":allReasons += "\n"
1358 allReasons += '- "%s"%s - %s' %(err.algoName, shapeText, errText)
1360 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1364 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1366 if err.isGlobalAlgo:
1374 reason = '%s %sD algorithm is missing' % (glob, dim)
1375 elif err.state == HYP_MISSING:
1376 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1377 % (glob, dim, name, dim))
1378 elif err.state == HYP_NOTCONFORM:
1379 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1380 elif err.state == HYP_BAD_PARAMETER:
1381 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1382 % ( glob, dim, name ))
1383 elif err.state == HYP_BAD_GEOMETRY:
1384 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1385 'geometry' % ( glob, dim, name ))
1386 elif err.state == HYP_HIDDEN_ALGO:
1387 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1388 'algorithm of upper dimension generating %sD mesh'
1389 % ( glob, dim, name, glob, dim ))
1391 reason = ("For unknown reason. "
1392 "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1394 if allReasons != "":allReasons += "\n"
1395 allReasons += "- " + reason
1397 if not ok or allReasons != "":
1398 msg = '"' + GetName(self.mesh) + '"'
1399 if ok: msg += " has been computed with warnings"
1400 else: msg += " has not been computed"
1401 if allReasons != "": msg += ":"
1406 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1407 smeshgui = salome.ImportComponentGUI("SMESH")
1408 smeshgui.Init(self.mesh.GetStudyId())
1409 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1410 salome.sg.updateObjBrowser(1)
1414 ## Return submesh objects list in meshing order
1415 # @return list of list of submesh objects
1416 # @ingroup l2_construct
1417 def GetMeshOrder(self):
1418 return self.mesh.GetMeshOrder()
1420 ## Return submesh objects list in meshing order
1421 # @return list of list of submesh objects
1422 # @ingroup l2_construct
1423 def SetMeshOrder(self, submeshes):
1424 return self.mesh.SetMeshOrder(submeshes)
1426 ## Removes all nodes and elements
1427 # @ingroup l2_construct
1430 if ( salome.sg.hasDesktop() and
1431 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1432 smeshgui = salome.ImportComponentGUI("SMESH")
1433 smeshgui.Init(self.mesh.GetStudyId())
1434 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1435 salome.sg.updateObjBrowser(1)
1437 ## Removes all nodes and elements of indicated shape
1438 # @ingroup l2_construct
1439 def ClearSubMesh(self, geomId):
1440 self.mesh.ClearSubMesh(geomId)
1441 if salome.sg.hasDesktop():
1442 smeshgui = salome.ImportComponentGUI("SMESH")
1443 smeshgui.Init(self.mesh.GetStudyId())
1444 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1445 salome.sg.updateObjBrowser(1)
1447 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1448 # @param fineness [0.0,1.0] defines mesh fineness
1449 # @return True or False
1450 # @ingroup l3_algos_basic
1451 def AutomaticTetrahedralization(self, fineness=0):
1452 dim = self.MeshDimension()
1454 self.RemoveGlobalHypotheses()
1455 self.Segment().AutomaticLength(fineness)
1457 self.Triangle().LengthFromEdges()
1460 from salome.NETGENPlugin.NETGENPluginBuilder import NETGEN
1461 self.Tetrahedron(NETGEN)
1463 return self.Compute()
1465 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1466 # @param fineness [0.0, 1.0] defines mesh fineness
1467 # @return True or False
1468 # @ingroup l3_algos_basic
1469 def AutomaticHexahedralization(self, fineness=0):
1470 dim = self.MeshDimension()
1471 # assign the hypotheses
1472 self.RemoveGlobalHypotheses()
1473 self.Segment().AutomaticLength(fineness)
1480 return self.Compute()
1482 ## Assigns a hypothesis
1483 # @param hyp a hypothesis to assign
1484 # @param geom a subhape of mesh geometry
1485 # @return SMESH.Hypothesis_Status
1486 # @ingroup l2_hypotheses
1487 def AddHypothesis(self, hyp, geom=0):
1488 if isinstance( hyp, Mesh_Algorithm ):
1489 hyp = hyp.GetAlgorithm()
1494 geom = self.mesh.GetShapeToMesh()
1496 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1497 status = self.mesh.AddHypothesis(geom, hyp)
1498 isAlgo = hyp._narrow( SMESH_Algo )
1499 hyp_name = GetName( hyp )
1502 geom_name = GetName( geom )
1503 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1506 ## Return True if an algorithm of hypothesis is assigned to a given shape
1507 # @param hyp a hypothesis to check
1508 # @param geom a subhape of mesh geometry
1509 # @return True of False
1510 # @ingroup l2_hypotheses
1511 def IsUsedHypothesis(self, hyp, geom):
1512 if not hyp: # or not geom
1514 if isinstance( hyp, Mesh_Algorithm ):
1515 hyp = hyp.GetAlgorithm()
1517 hyps = self.GetHypothesisList(geom)
1519 if h.GetId() == hyp.GetId():
1523 ## Unassigns a hypothesis
1524 # @param hyp a hypothesis to unassign
1525 # @param geom a sub-shape of mesh geometry
1526 # @return SMESH.Hypothesis_Status
1527 # @ingroup l2_hypotheses
1528 def RemoveHypothesis(self, hyp, geom=0):
1531 if isinstance( hyp, Mesh_Algorithm ):
1532 hyp = hyp.GetAlgorithm()
1538 if self.IsUsedHypothesis( hyp, shape ):
1539 return self.mesh.RemoveHypothesis( shape, hyp )
1540 hypName = GetName( hyp )
1541 geoName = GetName( shape )
1542 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1545 ## Gets the list of hypotheses added on a geometry
1546 # @param geom a sub-shape of mesh geometry
1547 # @return the sequence of SMESH_Hypothesis
1548 # @ingroup l2_hypotheses
1549 def GetHypothesisList(self, geom):
1550 return self.mesh.GetHypothesisList( geom )
1552 ## Removes all global hypotheses
1553 # @ingroup l2_hypotheses
1554 def RemoveGlobalHypotheses(self):
1555 current_hyps = self.mesh.GetHypothesisList( self.geom )
1556 for hyp in current_hyps:
1557 self.mesh.RemoveHypothesis( self.geom, hyp )
1561 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1562 ## allowing to overwrite the file if it exists or add the exported data to its contents
1563 # @param f is the file name
1564 # @param auto_groups boolean parameter for creating/not creating
1565 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1566 # the typical use is auto_groups=false.
1567 # @param version MED format version(MED_V2_1 or MED_V2_2)
1568 # @param overwrite boolean parameter for overwriting/not overwriting the file
1569 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1570 # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1571 # - 1D if all mesh nodes lie on OX coordinate axis, or
1572 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1573 # - 3D in the rest cases.
1575 # If @a autoDimension is @c False, the space dimension is always 3.
1576 # @ingroup l2_impexp
1577 def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
1578 overwrite=1, meshPart=None, autoDimension=True):
1580 if isinstance( meshPart, list ):
1581 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1582 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension)
1584 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
1586 ## Exports the mesh in a file in SAUV format
1587 # @param f is the file name
1588 # @param auto_groups boolean parameter for creating/not creating
1589 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1590 # the typical use is auto_groups=false.
1591 # @ingroup l2_impexp
1592 def ExportSAUV(self, f, auto_groups=0):
1593 self.mesh.ExportSAUV(f, auto_groups)
1595 ## Exports the mesh in a file in DAT format
1596 # @param f the file name
1597 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1598 # @ingroup l2_impexp
1599 def ExportDAT(self, f, meshPart=None):
1601 if isinstance( meshPart, list ):
1602 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1603 self.mesh.ExportPartToDAT( meshPart, f )
1605 self.mesh.ExportDAT(f)
1607 ## Exports the mesh in a file in UNV format
1608 # @param f the file name
1609 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1610 # @ingroup l2_impexp
1611 def ExportUNV(self, f, meshPart=None):
1613 if isinstance( meshPart, list ):
1614 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1615 self.mesh.ExportPartToUNV( meshPart, f )
1617 self.mesh.ExportUNV(f)
1619 ## Export the mesh in a file in STL format
1620 # @param f the file name
1621 # @param ascii defines the file encoding
1622 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1623 # @ingroup l2_impexp
1624 def ExportSTL(self, f, ascii=1, meshPart=None):
1626 if isinstance( meshPart, list ):
1627 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1628 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1630 self.mesh.ExportSTL(f, ascii)
1632 ## Exports the mesh in a file in CGNS format
1633 # @param f is the file name
1634 # @param overwrite boolean parameter for overwriting/not overwriting the file
1635 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1636 # @ingroup l2_impexp
1637 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1638 if isinstance( meshPart, list ):
1639 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1640 if isinstance( meshPart, Mesh ):
1641 meshPart = meshPart.mesh
1643 meshPart = self.mesh
1644 self.mesh.ExportCGNS(meshPart, f, overwrite)
1646 ## Exports the mesh in a file in GMF format
1647 # @param f is the file name
1648 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1649 # @ingroup l2_impexp
1650 def ExportGMF(self, f, meshPart=None):
1651 if isinstance( meshPart, list ):
1652 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1653 if isinstance( meshPart, Mesh ):
1654 meshPart = meshPart.mesh
1656 meshPart = self.mesh
1657 self.mesh.ExportGMF(meshPart, f, True)
1659 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1660 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1661 ## allowing to overwrite the file if it exists or add the exported data to its contents
1662 # @param f the file name
1663 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1664 # @param opt boolean parameter for creating/not creating
1665 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1666 # @param overwrite boolean parameter for overwriting/not overwriting the file
1667 # @ingroup l2_impexp
1668 def ExportToMED(self, f, version, opt=0, overwrite=1):
1669 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1671 # Operations with groups:
1672 # ----------------------
1674 ## Creates an empty mesh group
1675 # @param elementType the type of elements in the group
1676 # @param name the name of the mesh group
1677 # @return SMESH_Group
1678 # @ingroup l2_grps_create
1679 def CreateEmptyGroup(self, elementType, name):
1680 return self.mesh.CreateGroup(elementType, name)
1682 ## Creates a mesh group based on the geometric object \a grp
1683 # and gives a \a name, \n if this parameter is not defined
1684 # the name is the same as the geometric group name \n
1685 # Note: Works like GroupOnGeom().
1686 # @param grp a geometric group, a vertex, an edge, a face or a solid
1687 # @param name the name of the mesh group
1688 # @return SMESH_GroupOnGeom
1689 # @ingroup l2_grps_create
1690 def Group(self, grp, name=""):
1691 return self.GroupOnGeom(grp, name)
1693 ## Creates a mesh group based on the geometrical object \a grp
1694 # and gives a \a name, \n if this parameter is not defined
1695 # the name is the same as the geometrical group name
1696 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1697 # @param name the name of the mesh group
1698 # @param typ the type of elements in the group. If not set, it is
1699 # automatically detected by the type of the geometry
1700 # @return SMESH_GroupOnGeom
1701 # @ingroup l2_grps_create
1702 def GroupOnGeom(self, grp, name="", typ=None):
1703 AssureGeomPublished( self, grp, name )
1705 name = grp.GetName()
1707 typ = self._groupTypeFromShape( grp )
1708 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1710 ## Pivate method to get a type of group on geometry
1711 def _groupTypeFromShape( self, shape ):
1712 tgeo = str(shape.GetShapeType())
1713 if tgeo == "VERTEX":
1715 elif tgeo == "EDGE":
1717 elif tgeo == "FACE" or tgeo == "SHELL":
1719 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1721 elif tgeo == "COMPOUND":
1722 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
1724 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1725 return self._groupTypeFromShape( sub[0] )
1728 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1731 ## Creates a mesh group with given \a name based on the \a filter which
1732 ## is a special type of group dynamically updating it's contents during
1733 ## mesh modification
1734 # @param typ the type of elements in the group
1735 # @param name the name of the mesh group
1736 # @param filter the filter defining group contents
1737 # @return SMESH_GroupOnFilter
1738 # @ingroup l2_grps_create
1739 def GroupOnFilter(self, typ, name, filter):
1740 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1742 ## Creates a mesh group by the given ids of elements
1743 # @param groupName the name of the mesh group
1744 # @param elementType the type of elements in the group
1745 # @param elemIDs the list of ids
1746 # @return SMESH_Group
1747 # @ingroup l2_grps_create
1748 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1749 group = self.mesh.CreateGroup(elementType, groupName)
1753 ## Creates a mesh group by the given conditions
1754 # @param groupName the name of the mesh group
1755 # @param elementType the type of elements in the group
1756 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1757 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1758 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1759 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1760 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1761 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1762 # @return SMESH_Group
1763 # @ingroup l2_grps_create
1767 CritType=FT_Undefined,
1770 UnaryOp=FT_Undefined,
1772 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1773 group = self.MakeGroupByCriterion(groupName, aCriterion)
1776 ## Creates a mesh group by the given criterion
1777 # @param groupName the name of the mesh group
1778 # @param Criterion the instance of Criterion class
1779 # @return SMESH_Group
1780 # @ingroup l2_grps_create
1781 def MakeGroupByCriterion(self, groupName, Criterion):
1782 aFilterMgr = self.smeshpyD.CreateFilterManager()
1783 aFilter = aFilterMgr.CreateFilter()
1785 aCriteria.append(Criterion)
1786 aFilter.SetCriteria(aCriteria)
1787 group = self.MakeGroupByFilter(groupName, aFilter)
1788 aFilterMgr.UnRegister()
1791 ## Creates a mesh group by the given criteria (list of criteria)
1792 # @param groupName the name of the mesh group
1793 # @param theCriteria the list of criteria
1794 # @return SMESH_Group
1795 # @ingroup l2_grps_create
1796 def MakeGroupByCriteria(self, groupName, theCriteria):
1797 aFilterMgr = self.smeshpyD.CreateFilterManager()
1798 aFilter = aFilterMgr.CreateFilter()
1799 aFilter.SetCriteria(theCriteria)
1800 group = self.MakeGroupByFilter(groupName, aFilter)
1801 aFilterMgr.UnRegister()
1804 ## Creates a mesh group by the given filter
1805 # @param groupName the name of the mesh group
1806 # @param theFilter the instance of Filter class
1807 # @return SMESH_Group
1808 # @ingroup l2_grps_create
1809 def MakeGroupByFilter(self, groupName, theFilter):
1810 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1811 theFilter.SetMesh( self.mesh )
1812 group.AddFrom( theFilter )
1816 # @ingroup l2_grps_delete
1817 def RemoveGroup(self, group):
1818 self.mesh.RemoveGroup(group)
1820 ## Removes a group with its contents
1821 # @ingroup l2_grps_delete
1822 def RemoveGroupWithContents(self, group):
1823 self.mesh.RemoveGroupWithContents(group)
1825 ## Gets the list of groups existing in the mesh
1826 # @return a sequence of SMESH_GroupBase
1827 # @ingroup l2_grps_create
1828 def GetGroups(self):
1829 return self.mesh.GetGroups()
1831 ## Gets the number of groups existing in the mesh
1832 # @return the quantity of groups as an integer value
1833 # @ingroup l2_grps_create
1835 return self.mesh.NbGroups()
1837 ## Gets the list of names of groups existing in the mesh
1838 # @return list of strings
1839 # @ingroup l2_grps_create
1840 def GetGroupNames(self):
1841 groups = self.GetGroups()
1843 for group in groups:
1844 names.append(group.GetName())
1847 ## Produces a union of two groups
1848 # A new group is created. All mesh elements that are
1849 # present in the initial groups are added to the new one
1850 # @return an instance of SMESH_Group
1851 # @ingroup l2_grps_operon
1852 def UnionGroups(self, group1, group2, name):
1853 return self.mesh.UnionGroups(group1, group2, name)
1855 ## Produces a union list of groups
1856 # New group is created. All mesh elements that are present in
1857 # initial groups are added to the new one
1858 # @return an instance of SMESH_Group
1859 # @ingroup l2_grps_operon
1860 def UnionListOfGroups(self, groups, name):
1861 return self.mesh.UnionListOfGroups(groups, name)
1863 ## Prodices an intersection of two groups
1864 # A new group is created. All mesh elements that are common
1865 # for the two initial groups are added to the new one.
1866 # @return an instance of SMESH_Group
1867 # @ingroup l2_grps_operon
1868 def IntersectGroups(self, group1, group2, name):
1869 return self.mesh.IntersectGroups(group1, group2, name)
1871 ## Produces an intersection of groups
1872 # New group is created. All mesh elements that are present in all
1873 # initial groups simultaneously are added to the new one
1874 # @return an instance of SMESH_Group
1875 # @ingroup l2_grps_operon
1876 def IntersectListOfGroups(self, groups, name):
1877 return self.mesh.IntersectListOfGroups(groups, name)
1879 ## Produces a cut of two groups
1880 # A new group is created. All mesh elements that are present in
1881 # the main group but are not present in the tool group are added to the new one
1882 # @return an instance of SMESH_Group
1883 # @ingroup l2_grps_operon
1884 def CutGroups(self, main_group, tool_group, name):
1885 return self.mesh.CutGroups(main_group, tool_group, name)
1887 ## Produces a cut of groups
1888 # A new group is created. All mesh elements that are present in main groups
1889 # but do not present in tool groups are added to the new one
1890 # @return an instance of SMESH_Group
1891 # @ingroup l2_grps_operon
1892 def CutListOfGroups(self, main_groups, tool_groups, name):
1893 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1895 ## Produces a group of elements of specified type using list of existing groups
1896 # A new group is created. System
1897 # 1) extracts all nodes on which groups elements are built
1898 # 2) combines all elements of specified dimension laying on these nodes
1899 # @return an instance of SMESH_Group
1900 # @ingroup l2_grps_operon
1901 def CreateDimGroup(self, groups, elem_type, name):
1902 return self.mesh.CreateDimGroup(groups, elem_type, name)
1905 ## Convert group on geom into standalone group
1906 # @ingroup l2_grps_delete
1907 def ConvertToStandalone(self, group):
1908 return self.mesh.ConvertToStandalone(group)
1910 # Get some info about mesh:
1911 # ------------------------
1913 ## Returns the log of nodes and elements added or removed
1914 # since the previous clear of the log.
1915 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1916 # @return list of log_block structures:
1921 # @ingroup l1_auxiliary
1922 def GetLog(self, clearAfterGet):
1923 return self.mesh.GetLog(clearAfterGet)
1925 ## Clears the log of nodes and elements added or removed since the previous
1926 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1927 # @ingroup l1_auxiliary
1929 self.mesh.ClearLog()
1931 ## Toggles auto color mode on the object.
1932 # @param theAutoColor the flag which toggles auto color mode.
1933 # @ingroup l1_auxiliary
1934 def SetAutoColor(self, theAutoColor):
1935 self.mesh.SetAutoColor(theAutoColor)
1937 ## Gets flag of object auto color mode.
1938 # @return True or False
1939 # @ingroup l1_auxiliary
1940 def GetAutoColor(self):
1941 return self.mesh.GetAutoColor()
1943 ## Gets the internal ID
1944 # @return integer value, which is the internal Id of the mesh
1945 # @ingroup l1_auxiliary
1947 return self.mesh.GetId()
1950 # @return integer value, which is the study Id of the mesh
1951 # @ingroup l1_auxiliary
1952 def GetStudyId(self):
1953 return self.mesh.GetStudyId()
1955 ## Checks the group names for duplications.
1956 # Consider the maximum group name length stored in MED file.
1957 # @return True or False
1958 # @ingroup l1_auxiliary
1959 def HasDuplicatedGroupNamesMED(self):
1960 return self.mesh.HasDuplicatedGroupNamesMED()
1962 ## Obtains the mesh editor tool
1963 # @return an instance of SMESH_MeshEditor
1964 # @ingroup l1_modifying
1965 def GetMeshEditor(self):
1968 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1969 # can be passed as argument to a method accepting mesh, group or sub-mesh
1970 # @return an instance of SMESH_IDSource
1971 # @ingroup l1_auxiliary
1972 def GetIDSource(self, ids, elemType):
1973 return self.editor.MakeIDSource(ids, elemType)
1976 # Get informations about mesh contents:
1977 # ------------------------------------
1979 ## Gets the mesh stattistic
1980 # @return dictionary type element - count of elements
1981 # @ingroup l1_meshinfo
1982 def GetMeshInfo(self, obj = None):
1983 if not obj: obj = self.mesh
1984 return self.smeshpyD.GetMeshInfo(obj)
1986 ## Returns the number of nodes in the mesh
1987 # @return an integer value
1988 # @ingroup l1_meshinfo
1990 return self.mesh.NbNodes()
1992 ## Returns the number of elements in the mesh
1993 # @return an integer value
1994 # @ingroup l1_meshinfo
1995 def NbElements(self):
1996 return self.mesh.NbElements()
1998 ## Returns the number of 0d elements in the mesh
1999 # @return an integer value
2000 # @ingroup l1_meshinfo
2001 def Nb0DElements(self):
2002 return self.mesh.Nb0DElements()
2004 ## Returns the number of ball discrete elements in the mesh
2005 # @return an integer value
2006 # @ingroup l1_meshinfo
2008 return self.mesh.NbBalls()
2010 ## Returns the number of edges in the mesh
2011 # @return an integer value
2012 # @ingroup l1_meshinfo
2014 return self.mesh.NbEdges()
2016 ## Returns the number of edges with the given order in the mesh
2017 # @param elementOrder the order of elements:
2018 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2019 # @return an integer value
2020 # @ingroup l1_meshinfo
2021 def NbEdgesOfOrder(self, elementOrder):
2022 return self.mesh.NbEdgesOfOrder(elementOrder)
2024 ## Returns the number of faces in the mesh
2025 # @return an integer value
2026 # @ingroup l1_meshinfo
2028 return self.mesh.NbFaces()
2030 ## Returns the number of faces with the given order in the mesh
2031 # @param elementOrder the order of elements:
2032 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2033 # @return an integer value
2034 # @ingroup l1_meshinfo
2035 def NbFacesOfOrder(self, elementOrder):
2036 return self.mesh.NbFacesOfOrder(elementOrder)
2038 ## Returns the number of triangles in the mesh
2039 # @return an integer value
2040 # @ingroup l1_meshinfo
2041 def NbTriangles(self):
2042 return self.mesh.NbTriangles()
2044 ## Returns the number of triangles with the given order in the mesh
2045 # @param elementOrder is the order of elements:
2046 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2047 # @return an integer value
2048 # @ingroup l1_meshinfo
2049 def NbTrianglesOfOrder(self, elementOrder):
2050 return self.mesh.NbTrianglesOfOrder(elementOrder)
2052 ## Returns the number of biquadratic triangles in the mesh
2053 # @return an integer value
2054 # @ingroup l1_meshinfo
2055 def NbBiQuadTriangles(self):
2056 return self.mesh.NbBiQuadTriangles()
2058 ## Returns the number of quadrangles in the mesh
2059 # @return an integer value
2060 # @ingroup l1_meshinfo
2061 def NbQuadrangles(self):
2062 return self.mesh.NbQuadrangles()
2064 ## Returns the number of quadrangles with the given order in the mesh
2065 # @param elementOrder the order of elements:
2066 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2067 # @return an integer value
2068 # @ingroup l1_meshinfo
2069 def NbQuadranglesOfOrder(self, elementOrder):
2070 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2072 ## Returns the number of biquadratic quadrangles in the mesh
2073 # @return an integer value
2074 # @ingroup l1_meshinfo
2075 def NbBiQuadQuadrangles(self):
2076 return self.mesh.NbBiQuadQuadrangles()
2078 ## Returns the number of polygons in the mesh
2079 # @return an integer value
2080 # @ingroup l1_meshinfo
2081 def NbPolygons(self):
2082 return self.mesh.NbPolygons()
2084 ## Returns the number of volumes in the mesh
2085 # @return an integer value
2086 # @ingroup l1_meshinfo
2087 def NbVolumes(self):
2088 return self.mesh.NbVolumes()
2090 ## Returns the number of volumes with the given order in the mesh
2091 # @param elementOrder the order of elements:
2092 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2093 # @return an integer value
2094 # @ingroup l1_meshinfo
2095 def NbVolumesOfOrder(self, elementOrder):
2096 return self.mesh.NbVolumesOfOrder(elementOrder)
2098 ## Returns the number of tetrahedrons in the mesh
2099 # @return an integer value
2100 # @ingroup l1_meshinfo
2102 return self.mesh.NbTetras()
2104 ## Returns the number of tetrahedrons with the given order in the mesh
2105 # @param elementOrder the order of elements:
2106 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2107 # @return an integer value
2108 # @ingroup l1_meshinfo
2109 def NbTetrasOfOrder(self, elementOrder):
2110 return self.mesh.NbTetrasOfOrder(elementOrder)
2112 ## Returns the number of hexahedrons in the mesh
2113 # @return an integer value
2114 # @ingroup l1_meshinfo
2116 return self.mesh.NbHexas()
2118 ## Returns the number of hexahedrons with the given order in the mesh
2119 # @param elementOrder the order of elements:
2120 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2121 # @return an integer value
2122 # @ingroup l1_meshinfo
2123 def NbHexasOfOrder(self, elementOrder):
2124 return self.mesh.NbHexasOfOrder(elementOrder)
2126 ## Returns the number of triquadratic hexahedrons in the mesh
2127 # @return an integer value
2128 # @ingroup l1_meshinfo
2129 def NbTriQuadraticHexas(self):
2130 return self.mesh.NbTriQuadraticHexas()
2132 ## Returns the number of pyramids in the mesh
2133 # @return an integer value
2134 # @ingroup l1_meshinfo
2135 def NbPyramids(self):
2136 return self.mesh.NbPyramids()
2138 ## Returns the number of pyramids with the given order in the mesh
2139 # @param elementOrder the order of elements:
2140 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2141 # @return an integer value
2142 # @ingroup l1_meshinfo
2143 def NbPyramidsOfOrder(self, elementOrder):
2144 return self.mesh.NbPyramidsOfOrder(elementOrder)
2146 ## Returns the number of prisms in the mesh
2147 # @return an integer value
2148 # @ingroup l1_meshinfo
2150 return self.mesh.NbPrisms()
2152 ## Returns the number of prisms with the given order in the mesh
2153 # @param elementOrder the order of elements:
2154 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2155 # @return an integer value
2156 # @ingroup l1_meshinfo
2157 def NbPrismsOfOrder(self, elementOrder):
2158 return self.mesh.NbPrismsOfOrder(elementOrder)
2160 ## Returns the number of hexagonal prisms in the mesh
2161 # @return an integer value
2162 # @ingroup l1_meshinfo
2163 def NbHexagonalPrisms(self):
2164 return self.mesh.NbHexagonalPrisms()
2166 ## Returns the number of polyhedrons in the mesh
2167 # @return an integer value
2168 # @ingroup l1_meshinfo
2169 def NbPolyhedrons(self):
2170 return self.mesh.NbPolyhedrons()
2172 ## Returns the number of submeshes in the mesh
2173 # @return an integer value
2174 # @ingroup l1_meshinfo
2175 def NbSubMesh(self):
2176 return self.mesh.NbSubMesh()
2178 ## Returns the list of mesh elements IDs
2179 # @return the list of integer values
2180 # @ingroup l1_meshinfo
2181 def GetElementsId(self):
2182 return self.mesh.GetElementsId()
2184 ## Returns the list of IDs of mesh elements with the given type
2185 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2186 # @return list of integer values
2187 # @ingroup l1_meshinfo
2188 def GetElementsByType(self, elementType):
2189 return self.mesh.GetElementsByType(elementType)
2191 ## Returns the list of mesh nodes IDs
2192 # @return the list of integer values
2193 # @ingroup l1_meshinfo
2194 def GetNodesId(self):
2195 return self.mesh.GetNodesId()
2197 # Get the information about mesh elements:
2198 # ------------------------------------
2200 ## Returns the type of mesh element
2201 # @return the value from SMESH::ElementType enumeration
2202 # @ingroup l1_meshinfo
2203 def GetElementType(self, id, iselem):
2204 return self.mesh.GetElementType(id, iselem)
2206 ## Returns the geometric type of mesh element
2207 # @return the value from SMESH::EntityType enumeration
2208 # @ingroup l1_meshinfo
2209 def GetElementGeomType(self, id):
2210 return self.mesh.GetElementGeomType(id)
2212 ## Returns the list of submesh elements IDs
2213 # @param Shape a geom object(sub-shape) IOR
2214 # Shape must be the sub-shape of a ShapeToMesh()
2215 # @return the list of integer values
2216 # @ingroup l1_meshinfo
2217 def GetSubMeshElementsId(self, Shape):
2218 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2219 ShapeID = Shape.GetSubShapeIndices()[0]
2222 return self.mesh.GetSubMeshElementsId(ShapeID)
2224 ## Returns the list of submesh nodes IDs
2225 # @param Shape a geom object(sub-shape) IOR
2226 # Shape must be the sub-shape of a ShapeToMesh()
2227 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2228 # @return the list of integer values
2229 # @ingroup l1_meshinfo
2230 def GetSubMeshNodesId(self, Shape, all):
2231 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2232 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2235 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2237 ## Returns type of elements on given shape
2238 # @param Shape a geom object(sub-shape) IOR
2239 # Shape must be a sub-shape of a ShapeToMesh()
2240 # @return element type
2241 # @ingroup l1_meshinfo
2242 def GetSubMeshElementType(self, Shape):
2243 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2244 ShapeID = Shape.GetSubShapeIndices()[0]
2247 return self.mesh.GetSubMeshElementType(ShapeID)
2249 ## Gets the mesh description
2250 # @return string value
2251 # @ingroup l1_meshinfo
2253 return self.mesh.Dump()
2256 # Get the information about nodes and elements of a mesh by its IDs:
2257 # -----------------------------------------------------------
2259 ## Gets XYZ coordinates of a node
2260 # \n If there is no nodes for the given ID - returns an empty list
2261 # @return a list of double precision values
2262 # @ingroup l1_meshinfo
2263 def GetNodeXYZ(self, id):
2264 return self.mesh.GetNodeXYZ(id)
2266 ## Returns list of IDs of inverse elements for the given node
2267 # \n If there is no node for the given ID - returns an empty list
2268 # @return a list of integer values
2269 # @ingroup l1_meshinfo
2270 def GetNodeInverseElements(self, id):
2271 return self.mesh.GetNodeInverseElements(id)
2273 ## @brief Returns the position of a node on the shape
2274 # @return SMESH::NodePosition
2275 # @ingroup l1_meshinfo
2276 def GetNodePosition(self,NodeID):
2277 return self.mesh.GetNodePosition(NodeID)
2279 ## @brief Returns the position of an element on the shape
2280 # @return SMESH::ElementPosition
2281 # @ingroup l1_meshinfo
2282 def GetElementPosition(self,ElemID):
2283 return self.mesh.GetElementPosition(ElemID)
2285 ## If the given element is a node, returns the ID of shape
2286 # \n If there is no node for the given ID - returns -1
2287 # @return an integer value
2288 # @ingroup l1_meshinfo
2289 def GetShapeID(self, id):
2290 return self.mesh.GetShapeID(id)
2292 ## Returns the ID of the result shape after
2293 # FindShape() from SMESH_MeshEditor for the given element
2294 # \n If there is no element for the given ID - returns -1
2295 # @return an integer value
2296 # @ingroup l1_meshinfo
2297 def GetShapeIDForElem(self,id):
2298 return self.mesh.GetShapeIDForElem(id)
2300 ## Returns the number of nodes for the given element
2301 # \n If there is no element for the given ID - returns -1
2302 # @return an integer value
2303 # @ingroup l1_meshinfo
2304 def GetElemNbNodes(self, id):
2305 return self.mesh.GetElemNbNodes(id)
2307 ## Returns the node ID the given (zero based) index for the given element
2308 # \n If there is no element for the given ID - returns -1
2309 # \n If there is no node for the given index - returns -2
2310 # @return an integer value
2311 # @ingroup l1_meshinfo
2312 def GetElemNode(self, id, index):
2313 return self.mesh.GetElemNode(id, index)
2315 ## Returns the IDs of nodes of the given element
2316 # @return a list of integer values
2317 # @ingroup l1_meshinfo
2318 def GetElemNodes(self, id):
2319 return self.mesh.GetElemNodes(id)
2321 ## Returns true if the given node is the medium node in the given quadratic element
2322 # @ingroup l1_meshinfo
2323 def IsMediumNode(self, elementID, nodeID):
2324 return self.mesh.IsMediumNode(elementID, nodeID)
2326 ## Returns true if the given node is the medium node in one of quadratic elements
2327 # @ingroup l1_meshinfo
2328 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2329 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2331 ## Returns the number of edges for the given element
2332 # @ingroup l1_meshinfo
2333 def ElemNbEdges(self, id):
2334 return self.mesh.ElemNbEdges(id)
2336 ## Returns the number of faces for the given element
2337 # @ingroup l1_meshinfo
2338 def ElemNbFaces(self, id):
2339 return self.mesh.ElemNbFaces(id)
2341 ## Returns nodes of given face (counted from zero) for given volumic element.
2342 # @ingroup l1_meshinfo
2343 def GetElemFaceNodes(self,elemId, faceIndex):
2344 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2346 ## Returns an element based on all given nodes.
2347 # @ingroup l1_meshinfo
2348 def FindElementByNodes(self,nodes):
2349 return self.mesh.FindElementByNodes(nodes)
2351 ## Returns true if the given element is a polygon
2352 # @ingroup l1_meshinfo
2353 def IsPoly(self, id):
2354 return self.mesh.IsPoly(id)
2356 ## Returns true if the given element is quadratic
2357 # @ingroup l1_meshinfo
2358 def IsQuadratic(self, id):
2359 return self.mesh.IsQuadratic(id)
2361 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2362 # @ingroup l1_meshinfo
2363 def GetBallDiameter(self, id):
2364 return self.mesh.GetBallDiameter(id)
2366 ## Returns XYZ coordinates of the barycenter of the given element
2367 # \n If there is no element for the given ID - returns an empty list
2368 # @return a list of three double values
2369 # @ingroup l1_meshinfo
2370 def BaryCenter(self, id):
2371 return self.mesh.BaryCenter(id)
2373 ## Passes mesh elements through the given filter and return IDs of fitting elements
2374 # @param theFilter SMESH_Filter
2375 # @return a list of ids
2376 # @ingroup l1_controls
2377 def GetIdsFromFilter(self, theFilter):
2378 theFilter.SetMesh( self.mesh )
2379 return theFilter.GetIDs()
2381 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2382 # Returns a list of special structures (borders).
2383 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2384 # @ingroup l1_controls
2385 def GetFreeBorders(self):
2386 aFilterMgr = self.smeshpyD.CreateFilterManager()
2387 aPredicate = aFilterMgr.CreateFreeEdges()
2388 aPredicate.SetMesh(self.mesh)
2389 aBorders = aPredicate.GetBorders()
2390 aFilterMgr.UnRegister()
2394 # Get mesh measurements information:
2395 # ------------------------------------
2397 ## Get minimum distance between two nodes, elements or distance to the origin
2398 # @param id1 first node/element id
2399 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2400 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2401 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2402 # @return minimum distance value
2403 # @sa GetMinDistance()
2404 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2405 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2406 return aMeasure.value
2408 ## Get measure structure specifying minimum distance data between two objects
2409 # @param id1 first node/element id
2410 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2411 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2412 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2413 # @return Measure structure
2415 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2417 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2419 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2422 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2424 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2429 aMeasurements = self.smeshpyD.CreateMeasurements()
2430 aMeasure = aMeasurements.MinDistance(id1, id2)
2431 aMeasurements.UnRegister()
2434 ## Get bounding box of the specified object(s)
2435 # @param objects single source object or list of source objects or list of nodes/elements IDs
2436 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2437 # @c False specifies that @a objects are nodes
2438 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2439 # @sa GetBoundingBox()
2440 def BoundingBox(self, objects=None, isElem=False):
2441 result = self.GetBoundingBox(objects, isElem)
2445 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2448 ## Get measure structure specifying bounding box data of the specified object(s)
2449 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2450 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2451 # @c False specifies that @a objects are nodes
2452 # @return Measure structure
2454 def GetBoundingBox(self, IDs=None, isElem=False):
2457 elif isinstance(IDs, tuple):
2459 if not isinstance(IDs, list):
2461 if len(IDs) > 0 and isinstance(IDs[0], int):
2465 if isinstance(o, Mesh):
2466 srclist.append(o.mesh)
2467 elif hasattr(o, "_narrow"):
2468 src = o._narrow(SMESH.SMESH_IDSource)
2469 if src: srclist.append(src)
2471 elif isinstance(o, list):
2473 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2475 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2478 aMeasurements = self.smeshpyD.CreateMeasurements()
2479 aMeasure = aMeasurements.BoundingBox(srclist)
2480 aMeasurements.UnRegister()
2483 # Mesh edition (SMESH_MeshEditor functionality):
2484 # ---------------------------------------------
2486 ## Removes the elements from the mesh by ids
2487 # @param IDsOfElements is a list of ids of elements to remove
2488 # @return True or False
2489 # @ingroup l2_modif_del
2490 def RemoveElements(self, IDsOfElements):
2491 return self.editor.RemoveElements(IDsOfElements)
2493 ## Removes nodes from mesh by ids
2494 # @param IDsOfNodes is a list of ids of nodes to remove
2495 # @return True or False
2496 # @ingroup l2_modif_del
2497 def RemoveNodes(self, IDsOfNodes):
2498 return self.editor.RemoveNodes(IDsOfNodes)
2500 ## Removes all orphan (free) nodes from mesh
2501 # @return number of the removed nodes
2502 # @ingroup l2_modif_del
2503 def RemoveOrphanNodes(self):
2504 return self.editor.RemoveOrphanNodes()
2506 ## Add a node to the mesh by coordinates
2507 # @return Id of the new node
2508 # @ingroup l2_modif_add
2509 def AddNode(self, x, y, z):
2510 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2511 if hasVars: self.mesh.SetParameters(Parameters)
2512 return self.editor.AddNode( x, y, z)
2514 ## Creates a 0D element on a node with given number.
2515 # @param IDOfNode the ID of node for creation of the element.
2516 # @return the Id of the new 0D element
2517 # @ingroup l2_modif_add
2518 def Add0DElement(self, IDOfNode):
2519 return self.editor.Add0DElement(IDOfNode)
2521 ## Create 0D elements on all nodes of the given elements except those
2522 # nodes on which a 0D element already exists.
2523 # @param theObject an object on whose nodes 0D elements will be created.
2524 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2525 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2526 # @param theGroupName optional name of a group to add 0D elements created
2527 # and/or found on nodes of \a theObject.
2528 # @return an object (a new group or a temporary SMESH_IDSource) holding
2529 # IDs of new and/or found 0D elements. IDs of 0D elements
2530 # can be retrieved from the returned object by calling GetIDs()
2531 # @ingroup l2_modif_add
2532 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2533 if isinstance( theObject, Mesh ):
2534 theObject = theObject.GetMesh()
2535 if isinstance( theObject, list ):
2536 theObject = self.GetIDSource( theObject, SMESH.ALL )
2537 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2539 ## Creates a ball element on a node with given ID.
2540 # @param IDOfNode the ID of node for creation of the element.
2541 # @param diameter the bal diameter.
2542 # @return the Id of the new ball element
2543 # @ingroup l2_modif_add
2544 def AddBall(self, IDOfNode, diameter):
2545 return self.editor.AddBall( IDOfNode, diameter )
2547 ## Creates a linear or quadratic edge (this is determined
2548 # by the number of given nodes).
2549 # @param IDsOfNodes the list of node IDs for creation of the element.
2550 # The order of nodes in this list should correspond to the description
2551 # of MED. \n This description is located by the following link:
2552 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2553 # @return the Id of the new edge
2554 # @ingroup l2_modif_add
2555 def AddEdge(self, IDsOfNodes):
2556 return self.editor.AddEdge(IDsOfNodes)
2558 ## Creates a linear or quadratic face (this is determined
2559 # by the number of given nodes).
2560 # @param IDsOfNodes the list of node IDs for creation of the element.
2561 # The order of nodes in this list should correspond to the description
2562 # of MED. \n This description is located by the following link:
2563 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2564 # @return the Id of the new face
2565 # @ingroup l2_modif_add
2566 def AddFace(self, IDsOfNodes):
2567 return self.editor.AddFace(IDsOfNodes)
2569 ## Adds a polygonal face to the mesh by the list of node IDs
2570 # @param IdsOfNodes the list of node IDs for creation of the element.
2571 # @return the Id of the new face
2572 # @ingroup l2_modif_add
2573 def AddPolygonalFace(self, IdsOfNodes):
2574 return self.editor.AddPolygonalFace(IdsOfNodes)
2576 ## Creates both simple and quadratic volume (this is determined
2577 # by the number of given nodes).
2578 # @param IDsOfNodes the list of node IDs for creation of the element.
2579 # The order of nodes in this list should correspond to the description
2580 # of MED. \n This description is located by the following link:
2581 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2582 # @return the Id of the new volumic element
2583 # @ingroup l2_modif_add
2584 def AddVolume(self, IDsOfNodes):
2585 return self.editor.AddVolume(IDsOfNodes)
2587 ## Creates a volume of many faces, giving nodes for each face.
2588 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2589 # @param Quantities the list of integer values, Quantities[i]
2590 # gives the quantity of nodes in face number i.
2591 # @return the Id of the new volumic element
2592 # @ingroup l2_modif_add
2593 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2594 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2596 ## Creates a volume of many faces, giving the IDs of the existing faces.
2597 # @param IdsOfFaces the list of face IDs for volume creation.
2599 # Note: The created volume will refer only to the nodes
2600 # of the given faces, not to the faces themselves.
2601 # @return the Id of the new volumic element
2602 # @ingroup l2_modif_add
2603 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2604 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2607 ## @brief Binds a node to a vertex
2608 # @param NodeID a node ID
2609 # @param Vertex a vertex or vertex ID
2610 # @return True if succeed else raises an exception
2611 # @ingroup l2_modif_add
2612 def SetNodeOnVertex(self, NodeID, Vertex):
2613 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
2614 VertexID = Vertex.GetSubShapeIndices()[0]
2618 self.editor.SetNodeOnVertex(NodeID, VertexID)
2619 except SALOME.SALOME_Exception, inst:
2620 raise ValueError, inst.details.text
2624 ## @brief Stores the node position on an edge
2625 # @param NodeID a node ID
2626 # @param Edge an edge or edge ID
2627 # @param paramOnEdge a parameter on the edge where the node is located
2628 # @return True if succeed else raises an exception
2629 # @ingroup l2_modif_add
2630 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2631 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
2632 EdgeID = Edge.GetSubShapeIndices()[0]
2636 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2637 except SALOME.SALOME_Exception, inst:
2638 raise ValueError, inst.details.text
2641 ## @brief Stores node position on a face
2642 # @param NodeID a node ID
2643 # @param Face a face or face ID
2644 # @param u U parameter on the face where the node is located
2645 # @param v V parameter on the face where the node is located
2646 # @return True if succeed else raises an exception
2647 # @ingroup l2_modif_add
2648 def SetNodeOnFace(self, NodeID, Face, u, v):
2649 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
2650 FaceID = Face.GetSubShapeIndices()[0]
2654 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2655 except SALOME.SALOME_Exception, inst:
2656 raise ValueError, inst.details.text
2659 ## @brief Binds a node to a solid
2660 # @param NodeID a node ID
2661 # @param Solid a solid or solid ID
2662 # @return True if succeed else raises an exception
2663 # @ingroup l2_modif_add
2664 def SetNodeInVolume(self, NodeID, Solid):
2665 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
2666 SolidID = Solid.GetSubShapeIndices()[0]
2670 self.editor.SetNodeInVolume(NodeID, SolidID)
2671 except SALOME.SALOME_Exception, inst:
2672 raise ValueError, inst.details.text
2675 ## @brief Bind an element to a shape
2676 # @param ElementID an element ID
2677 # @param Shape a shape or shape ID
2678 # @return True if succeed else raises an exception
2679 # @ingroup l2_modif_add
2680 def SetMeshElementOnShape(self, ElementID, Shape):
2681 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2682 ShapeID = Shape.GetSubShapeIndices()[0]
2686 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2687 except SALOME.SALOME_Exception, inst:
2688 raise ValueError, inst.details.text
2692 ## Moves the node with the given id
2693 # @param NodeID the id of the node
2694 # @param x a new X coordinate
2695 # @param y a new Y coordinate
2696 # @param z a new Z coordinate
2697 # @return True if succeed else False
2698 # @ingroup l2_modif_movenode
2699 def MoveNode(self, NodeID, x, y, z):
2700 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2701 if hasVars: self.mesh.SetParameters(Parameters)
2702 return self.editor.MoveNode(NodeID, x, y, z)
2704 ## Finds the node closest to a point and moves it to a point location
2705 # @param x the X coordinate of a point
2706 # @param y the Y coordinate of a point
2707 # @param z the Z coordinate of a point
2708 # @param NodeID if specified (>0), the node with this ID is moved,
2709 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2710 # @return the ID of a node
2711 # @ingroup l2_modif_throughp
2712 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2713 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2714 if hasVars: self.mesh.SetParameters(Parameters)
2715 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2717 ## Finds the node closest to a point
2718 # @param x the X coordinate of a point
2719 # @param y the Y coordinate of a point
2720 # @param z the Z coordinate of a point
2721 # @return the ID of a node
2722 # @ingroup l2_modif_throughp
2723 def FindNodeClosestTo(self, x, y, z):
2724 #preview = self.mesh.GetMeshEditPreviewer()
2725 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2726 return self.editor.FindNodeClosestTo(x, y, z)
2728 ## Finds the elements where a point lays IN or ON
2729 # @param x the X coordinate of a point
2730 # @param y the Y coordinate of a point
2731 # @param z the Z coordinate of a point
2732 # @param elementType type of elements to find (SMESH.ALL type
2733 # means elements of any type excluding nodes, discrete and 0D elements)
2734 # @param meshPart a part of mesh (group, sub-mesh) to search within
2735 # @return list of IDs of found elements
2736 # @ingroup l2_modif_throughp
2737 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2739 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2741 return self.editor.FindElementsByPoint(x, y, z, elementType)
2743 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2744 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2745 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2747 def GetPointState(self, x, y, z):
2748 return self.editor.GetPointState(x, y, z)
2750 ## Finds the node closest to a point and moves it to a point location
2751 # @param x the X coordinate of a point
2752 # @param y the Y coordinate of a point
2753 # @param z the Z coordinate of a point
2754 # @return the ID of a moved node
2755 # @ingroup l2_modif_throughp
2756 def MeshToPassThroughAPoint(self, x, y, z):
2757 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2759 ## Replaces two neighbour triangles sharing Node1-Node2 link
2760 # with the triangles built on the same 4 nodes but having other common link.
2761 # @param NodeID1 the ID of the first node
2762 # @param NodeID2 the ID of the second node
2763 # @return false if proper faces were not found
2764 # @ingroup l2_modif_invdiag
2765 def InverseDiag(self, NodeID1, NodeID2):
2766 return self.editor.InverseDiag(NodeID1, NodeID2)
2768 ## Replaces two neighbour triangles sharing Node1-Node2 link
2769 # with a quadrangle built on the same 4 nodes.
2770 # @param NodeID1 the ID of the first node
2771 # @param NodeID2 the ID of the second node
2772 # @return false if proper faces were not found
2773 # @ingroup l2_modif_unitetri
2774 def DeleteDiag(self, NodeID1, NodeID2):
2775 return self.editor.DeleteDiag(NodeID1, NodeID2)
2777 ## Reorients elements by ids
2778 # @param IDsOfElements if undefined reorients all mesh elements
2779 # @return True if succeed else False
2780 # @ingroup l2_modif_changori
2781 def Reorient(self, IDsOfElements=None):
2782 if IDsOfElements == None:
2783 IDsOfElements = self.GetElementsId()
2784 return self.editor.Reorient(IDsOfElements)
2786 ## Reorients all elements of the object
2787 # @param theObject mesh, submesh or group
2788 # @return True if succeed else False
2789 # @ingroup l2_modif_changori
2790 def ReorientObject(self, theObject):
2791 if ( isinstance( theObject, Mesh )):
2792 theObject = theObject.GetMesh()
2793 return self.editor.ReorientObject(theObject)
2795 ## Reorient faces contained in \a the2DObject.
2796 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2797 # @param theDirection is a desired direction of normal of \a theFace.
2798 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2799 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2800 # compared with theDirection. It can be either ID of face or a point
2801 # by which the face will be found. The point can be given as either
2802 # a GEOM vertex or a list of point coordinates.
2803 # @return number of reoriented faces
2804 # @ingroup l2_modif_changori
2805 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2807 if isinstance( the2DObject, Mesh ):
2808 the2DObject = the2DObject.GetMesh()
2809 if isinstance( the2DObject, list ):
2810 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2811 # check theDirection
2812 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
2813 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2814 if isinstance( theDirection, list ):
2815 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2816 # prepare theFace and thePoint
2817 theFace = theFaceOrPoint
2818 thePoint = PointStruct(0,0,0)
2819 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
2820 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2822 if isinstance( theFaceOrPoint, list ):
2823 thePoint = PointStruct( *theFaceOrPoint )
2825 if isinstance( theFaceOrPoint, PointStruct ):
2826 thePoint = theFaceOrPoint
2828 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2830 ## Fuses the neighbouring triangles into quadrangles.
2831 # @param IDsOfElements The triangles to be fused,
2832 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2833 # choose a neighbour to fuse with.
2834 # @param MaxAngle is the maximum angle between element normals at which the fusion
2835 # is still performed; theMaxAngle is mesured in radians.
2836 # Also it could be a name of variable which defines angle in degrees.
2837 # @return TRUE in case of success, FALSE otherwise.
2838 # @ingroup l2_modif_unitetri
2839 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2840 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2841 self.mesh.SetParameters(Parameters)
2842 if not IDsOfElements:
2843 IDsOfElements = self.GetElementsId()
2844 Functor = self.smeshpyD.GetFunctor(theCriterion)
2845 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2847 ## Fuses the neighbouring triangles of the object into quadrangles
2848 # @param theObject is mesh, submesh or group
2849 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2850 # choose a neighbour to fuse with.
2851 # @param MaxAngle a max angle between element normals at which the fusion
2852 # is still performed; theMaxAngle is mesured in radians.
2853 # @return TRUE in case of success, FALSE otherwise.
2854 # @ingroup l2_modif_unitetri
2855 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2856 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2857 self.mesh.SetParameters(Parameters)
2858 if isinstance( theObject, Mesh ):
2859 theObject = theObject.GetMesh()
2860 Functor = self.smeshpyD.GetFunctor(theCriterion)
2861 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2863 ## Splits quadrangles into triangles.
2864 # @param IDsOfElements the faces to be splitted.
2865 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2866 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2867 # value, then quadrangles will be split by the smallest diagonal.
2868 # @return TRUE in case of success, FALSE otherwise.
2869 # @ingroup l2_modif_cutquadr
2870 def QuadToTri (self, IDsOfElements, theCriterion = None):
2871 if IDsOfElements == []:
2872 IDsOfElements = self.GetElementsId()
2873 if theCriterion is None:
2874 theCriterion = FT_MaxElementLength2D
2875 Functor = self.smeshpyD.GetFunctor(theCriterion)
2876 return self.editor.QuadToTri(IDsOfElements, Functor)
2878 ## Splits quadrangles into triangles.
2879 # @param theObject the object from which the list of elements is taken,
2880 # this is mesh, submesh or group
2881 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2882 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2883 # value, then quadrangles will be split by the smallest diagonal.
2884 # @return TRUE in case of success, FALSE otherwise.
2885 # @ingroup l2_modif_cutquadr
2886 def QuadToTriObject (self, theObject, theCriterion = None):
2887 if ( isinstance( theObject, Mesh )):
2888 theObject = theObject.GetMesh()
2889 if theCriterion is None:
2890 theCriterion = FT_MaxElementLength2D
2891 Functor = self.smeshpyD.GetFunctor(theCriterion)
2892 return self.editor.QuadToTriObject(theObject, Functor)
2894 ## Splits each of given quadrangles into 4 triangles. A node is added at the center of
2896 # @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
2897 # group or a list of face IDs. By default all quadrangles are split
2898 # @ingroup l2_modif_cutquadr
2899 def QuadTo4Tri (self, theElements=[]):
2900 if isinstance( theElements, Mesh ):
2901 theElements = theElements.mesh
2902 elif not theElements:
2903 theElements = self.mesh
2904 elif isinstance( theElements, list ):
2905 theElements = self.GetIDSource( theElements, SMESH.FACE )
2906 return self.editor.QuadTo4Tri( theElements )
2908 ## Splits quadrangles into triangles.
2909 # @param IDsOfElements the faces to be splitted
2910 # @param Diag13 is used to choose a diagonal for splitting.
2911 # @return TRUE in case of success, FALSE otherwise.
2912 # @ingroup l2_modif_cutquadr
2913 def SplitQuad (self, IDsOfElements, Diag13):
2914 if IDsOfElements == []:
2915 IDsOfElements = self.GetElementsId()
2916 return self.editor.SplitQuad(IDsOfElements, Diag13)
2918 ## Splits quadrangles into triangles.
2919 # @param theObject the object from which the list of elements is taken,
2920 # this is mesh, submesh or group
2921 # @param Diag13 is used to choose a diagonal for splitting.
2922 # @return TRUE in case of success, FALSE otherwise.
2923 # @ingroup l2_modif_cutquadr
2924 def SplitQuadObject (self, theObject, Diag13):
2925 if ( isinstance( theObject, Mesh )):
2926 theObject = theObject.GetMesh()
2927 return self.editor.SplitQuadObject(theObject, Diag13)
2929 ## Finds a better splitting of the given quadrangle.
2930 # @param IDOfQuad the ID of the quadrangle to be splitted.
2931 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2932 # choose a diagonal for splitting.
2933 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2934 # diagonal is better, 0 if error occurs.
2935 # @ingroup l2_modif_cutquadr
2936 def BestSplit (self, IDOfQuad, theCriterion):
2937 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2939 ## Splits volumic elements into tetrahedrons
2940 # @param elemIDs either list of elements or mesh or group or submesh
2941 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2942 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2943 # @ingroup l2_modif_cutquadr
2944 def SplitVolumesIntoTetra(self, elemIDs, method=smeshBuilder.Hex_5Tet ):
2945 if isinstance( elemIDs, Mesh ):
2946 elemIDs = elemIDs.GetMesh()
2947 if ( isinstance( elemIDs, list )):
2948 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2949 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2951 ## Splits quadrangle faces near triangular facets of volumes
2953 # @ingroup l1_auxiliary
2954 def SplitQuadsNearTriangularFacets(self):
2955 faces_array = self.GetElementsByType(SMESH.FACE)
2956 for face_id in faces_array:
2957 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2958 quad_nodes = self.mesh.GetElemNodes(face_id)
2959 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2960 isVolumeFound = False
2961 for node1_elem in node1_elems:
2962 if not isVolumeFound:
2963 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2964 nb_nodes = self.GetElemNbNodes(node1_elem)
2965 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2966 volume_elem = node1_elem
2967 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2968 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2969 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2970 isVolumeFound = True
2971 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2972 self.SplitQuad([face_id], False) # diagonal 2-4
2973 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2974 isVolumeFound = True
2975 self.SplitQuad([face_id], True) # diagonal 1-3
2976 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2977 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2978 isVolumeFound = True
2979 self.SplitQuad([face_id], True) # diagonal 1-3
2981 ## @brief Splits hexahedrons into tetrahedrons.
2983 # This operation uses pattern mapping functionality for splitting.
2984 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2985 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2986 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2987 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2988 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2989 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2990 # @return TRUE in case of success, FALSE otherwise.
2991 # @ingroup l1_auxiliary
2992 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2993 # Pattern: 5.---------.6
2998 # (0,0,1) 4.---------.7 * |
3005 # (0,0,0) 0.---------.3
3006 pattern_tetra = "!!! Nb of points: \n 8 \n\
3016 !!! Indices of points of 6 tetras: \n\
3024 pattern = self.smeshpyD.GetPattern()
3025 isDone = pattern.LoadFromFile(pattern_tetra)
3027 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3030 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3031 isDone = pattern.MakeMesh(self.mesh, False, False)
3032 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3034 # split quafrangle faces near triangular facets of volumes
3035 self.SplitQuadsNearTriangularFacets()
3039 ## @brief Split hexahedrons into prisms.
3041 # Uses the pattern mapping functionality for splitting.
3042 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
3043 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
3044 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
3045 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
3046 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
3047 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
3048 # @return TRUE in case of success, FALSE otherwise.
3049 # @ingroup l1_auxiliary
3050 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3051 # Pattern: 5.---------.6
3056 # (0,0,1) 4.---------.7 |
3063 # (0,0,0) 0.---------.3
3064 pattern_prism = "!!! Nb of points: \n 8 \n\
3074 !!! Indices of points of 2 prisms: \n\
3078 pattern = self.smeshpyD.GetPattern()
3079 isDone = pattern.LoadFromFile(pattern_prism)
3081 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3084 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3085 isDone = pattern.MakeMesh(self.mesh, False, False)
3086 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3088 # Splits quafrangle faces near triangular facets of volumes
3089 self.SplitQuadsNearTriangularFacets()
3093 ## Smoothes elements
3094 # @param IDsOfElements the list if ids of elements to smooth
3095 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3096 # Note that nodes built on edges and boundary nodes are always fixed.
3097 # @param MaxNbOfIterations the maximum number of iterations
3098 # @param MaxAspectRatio varies in range [1.0, inf]
3099 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3100 # @return TRUE in case of success, FALSE otherwise.
3101 # @ingroup l2_modif_smooth
3102 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3103 MaxNbOfIterations, MaxAspectRatio, Method):
3104 if IDsOfElements == []:
3105 IDsOfElements = self.GetElementsId()
3106 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3107 self.mesh.SetParameters(Parameters)
3108 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3109 MaxNbOfIterations, MaxAspectRatio, Method)
3111 ## Smoothes elements which belong to the given object
3112 # @param theObject the object to smooth
3113 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3114 # Note that nodes built on edges and boundary nodes are always fixed.
3115 # @param MaxNbOfIterations the maximum number of iterations
3116 # @param MaxAspectRatio varies in range [1.0, inf]
3117 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3118 # @return TRUE in case of success, FALSE otherwise.
3119 # @ingroup l2_modif_smooth
3120 def SmoothObject(self, theObject, IDsOfFixedNodes,
3121 MaxNbOfIterations, MaxAspectRatio, Method):
3122 if ( isinstance( theObject, Mesh )):
3123 theObject = theObject.GetMesh()
3124 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3125 MaxNbOfIterations, MaxAspectRatio, Method)
3127 ## Parametrically smoothes the given elements
3128 # @param IDsOfElements the list if ids of elements to smooth
3129 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3130 # Note that nodes built on edges and boundary nodes are always fixed.
3131 # @param MaxNbOfIterations the maximum number of iterations
3132 # @param MaxAspectRatio varies in range [1.0, inf]
3133 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3134 # @return TRUE in case of success, FALSE otherwise.
3135 # @ingroup l2_modif_smooth
3136 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3137 MaxNbOfIterations, MaxAspectRatio, Method):
3138 if IDsOfElements == []:
3139 IDsOfElements = self.GetElementsId()
3140 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3141 self.mesh.SetParameters(Parameters)
3142 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3143 MaxNbOfIterations, MaxAspectRatio, Method)
3145 ## Parametrically smoothes the elements which belong to the given object
3146 # @param theObject the object to smooth
3147 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3148 # Note that nodes built on edges and boundary nodes are always fixed.
3149 # @param MaxNbOfIterations the maximum number of iterations
3150 # @param MaxAspectRatio varies in range [1.0, inf]
3151 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3152 # @return TRUE in case of success, FALSE otherwise.
3153 # @ingroup l2_modif_smooth
3154 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3155 MaxNbOfIterations, MaxAspectRatio, Method):
3156 if ( isinstance( theObject, Mesh )):
3157 theObject = theObject.GetMesh()
3158 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3159 MaxNbOfIterations, MaxAspectRatio, Method)
3161 ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3162 # them with quadratic with the same id.
3163 # @param theForce3d new node creation method:
3164 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3165 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3166 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3167 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3168 # @ingroup l2_modif_tofromqu
3169 def ConvertToQuadratic(self, theForce3d, theSubMesh=None, theToBiQuad=False):
3170 if isinstance( theSubMesh, Mesh ):
3171 theSubMesh = theSubMesh.mesh
3173 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3176 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3178 self.editor.ConvertToQuadratic(theForce3d)
3179 error = self.editor.GetLastError()
3180 if error and error.comment:
3183 ## Converts the mesh from quadratic to ordinary,
3184 # deletes old quadratic elements, \n replacing
3185 # them with ordinary mesh elements with the same id.
3186 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3187 # @ingroup l2_modif_tofromqu
3188 def ConvertFromQuadratic(self, theSubMesh=None):
3190 self.editor.ConvertFromQuadraticObject(theSubMesh)
3192 return self.editor.ConvertFromQuadratic()
3194 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3195 # @return TRUE if operation has been completed successfully, FALSE otherwise
3196 # @ingroup l2_modif_edit
3197 def Make2DMeshFrom3D(self):
3198 return self.editor. Make2DMeshFrom3D()
3200 ## Creates missing boundary elements
3201 # @param elements - elements whose boundary is to be checked:
3202 # mesh, group, sub-mesh or list of elements
3203 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3204 # @param dimension - defines type of boundary elements to create:
3205 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3206 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3207 # @param groupName - a name of group to store created boundary elements in,
3208 # "" means not to create the group
3209 # @param meshName - a name of new mesh to store created boundary elements in,
3210 # "" means not to create the new mesh
3211 # @param toCopyElements - if true, the checked elements will be copied into
3212 # the new mesh else only boundary elements will be copied into the new mesh
3213 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3214 # boundary elements will be copied into the new mesh
3215 # @return tuple (mesh, group) where bondary elements were added to
3216 # @ingroup l2_modif_edit
3217 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3218 toCopyElements=False, toCopyExistingBondary=False):
3219 if isinstance( elements, Mesh ):
3220 elements = elements.GetMesh()
3221 if ( isinstance( elements, list )):
3222 elemType = SMESH.ALL
3223 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3224 elements = self.editor.MakeIDSource(elements, elemType)
3225 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3226 toCopyElements,toCopyExistingBondary)
3227 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3231 # @brief Creates missing boundary elements around either the whole mesh or
3232 # groups of 2D elements
3233 # @param dimension - defines type of boundary elements to create
3234 # @param groupName - a name of group to store all boundary elements in,
3235 # "" means not to create the group
3236 # @param meshName - a name of a new mesh, which is a copy of the initial
3237 # mesh + created boundary elements; "" means not to create the new mesh
3238 # @param toCopyAll - if true, the whole initial mesh will be copied into
3239 # the new mesh else only boundary elements will be copied into the new mesh
3240 # @param groups - groups of 2D elements to make boundary around
3241 # @retval tuple( long, mesh, groups )
3242 # long - number of added boundary elements
3243 # mesh - the mesh where elements were added to
3244 # group - the group of boundary elements or None
3246 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3247 toCopyAll=False, groups=[]):
3248 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3250 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3251 return nb, mesh, group
3253 ## Renumber mesh nodes
3254 # @ingroup l2_modif_renumber
3255 def RenumberNodes(self):
3256 self.editor.RenumberNodes()
3258 ## Renumber mesh elements
3259 # @ingroup l2_modif_renumber
3260 def RenumberElements(self):
3261 self.editor.RenumberElements()
3263 ## Generates new elements by rotation of the elements around the axis
3264 # @param IDsOfElements the list of ids of elements to sweep
3265 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3266 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3267 # @param NbOfSteps the number of steps
3268 # @param Tolerance tolerance
3269 # @param MakeGroups forces the generation of new groups from existing ones
3270 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3271 # of all steps, else - size of each step
3272 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3273 # @ingroup l2_modif_extrurev
3274 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3275 MakeGroups=False, TotalAngle=False):
3276 if IDsOfElements == []:
3277 IDsOfElements = self.GetElementsId()
3278 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3279 Axis = self.smeshpyD.GetAxisStruct(Axis)
3280 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3281 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3282 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3283 self.mesh.SetParameters(Parameters)
3284 if TotalAngle and NbOfSteps:
3285 AngleInRadians /= NbOfSteps
3287 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3288 AngleInRadians, NbOfSteps, Tolerance)
3289 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3292 ## Generates new elements by rotation of the elements of object around the axis
3293 # @param theObject object which elements should be sweeped.
3294 # It can be a mesh, a sub mesh or a group.
3295 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3296 # @param AngleInRadians the angle of Rotation
3297 # @param NbOfSteps number of steps
3298 # @param Tolerance tolerance
3299 # @param MakeGroups forces the generation of new groups from existing ones
3300 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3301 # of all steps, else - size of each step
3302 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3303 # @ingroup l2_modif_extrurev
3304 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3305 MakeGroups=False, TotalAngle=False):
3306 if ( isinstance( theObject, Mesh )):
3307 theObject = theObject.GetMesh()
3308 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3309 Axis = self.smeshpyD.GetAxisStruct(Axis)
3310 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3311 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3312 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3313 self.mesh.SetParameters(Parameters)
3314 if TotalAngle and NbOfSteps:
3315 AngleInRadians /= NbOfSteps
3317 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3318 NbOfSteps, Tolerance)
3319 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3322 ## Generates new elements by rotation of the elements of object around the axis
3323 # @param theObject object which elements should be sweeped.
3324 # It can be a mesh, a sub mesh or a group.
3325 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3326 # @param AngleInRadians the angle of Rotation
3327 # @param NbOfSteps number of steps
3328 # @param Tolerance tolerance
3329 # @param MakeGroups forces the generation of new groups from existing ones
3330 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3331 # of all steps, else - size of each step
3332 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3333 # @ingroup l2_modif_extrurev
3334 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3335 MakeGroups=False, TotalAngle=False):
3336 if ( isinstance( theObject, Mesh )):
3337 theObject = theObject.GetMesh()
3338 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3339 Axis = self.smeshpyD.GetAxisStruct(Axis)
3340 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3341 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3342 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3343 self.mesh.SetParameters(Parameters)
3344 if TotalAngle and NbOfSteps:
3345 AngleInRadians /= NbOfSteps
3347 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3348 NbOfSteps, Tolerance)
3349 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3352 ## Generates new elements by rotation of the elements of object around the axis
3353 # @param theObject object which elements should be sweeped.
3354 # It can be a mesh, a sub mesh or a group.
3355 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3356 # @param AngleInRadians the angle of Rotation
3357 # @param NbOfSteps number of steps
3358 # @param Tolerance tolerance
3359 # @param MakeGroups forces the generation of new groups from existing ones
3360 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3361 # of all steps, else - size of each step
3362 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3363 # @ingroup l2_modif_extrurev
3364 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3365 MakeGroups=False, TotalAngle=False):
3366 if ( isinstance( theObject, Mesh )):
3367 theObject = theObject.GetMesh()
3368 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3369 Axis = self.smeshpyD.GetAxisStruct(Axis)
3370 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3371 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3372 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3373 self.mesh.SetParameters(Parameters)
3374 if TotalAngle and NbOfSteps:
3375 AngleInRadians /= NbOfSteps
3377 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3378 NbOfSteps, Tolerance)
3379 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3382 ## Generates new elements by extrusion of the elements with given ids
3383 # @param IDsOfElements the list of elements ids for extrusion
3384 # @param StepVector vector or DirStruct or 3 vector components, defining
3385 # the direction and value of extrusion for one step (the total extrusion
3386 # length will be NbOfSteps * ||StepVector||)
3387 # @param NbOfSteps the number of steps
3388 # @param MakeGroups forces the generation of new groups from existing ones
3389 # @param IsNodes is True if elements with given ids are nodes
3390 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3391 # @ingroup l2_modif_extrurev
3392 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3393 if IDsOfElements == []:
3394 IDsOfElements = self.GetElementsId()
3395 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3396 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3397 if isinstance( StepVector, list ):
3398 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3399 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3400 Parameters = StepVector.PS.parameters + var_separator + Parameters
3401 self.mesh.SetParameters(Parameters)
3404 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3406 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3408 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3410 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3413 ## Generates new elements by extrusion of the elements with given ids
3414 # @param IDsOfElements is ids of elements
3415 # @param StepVector vector or DirStruct or 3 vector components, defining
3416 # the direction and value of extrusion for one step (the total extrusion
3417 # length will be NbOfSteps * ||StepVector||)
3418 # @param NbOfSteps the number of steps
3419 # @param ExtrFlags sets flags for extrusion
3420 # @param SewTolerance uses for comparing locations of nodes if flag
3421 # EXTRUSION_FLAG_SEW is set
3422 # @param MakeGroups forces the generation of new groups from existing ones
3423 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3424 # @ingroup l2_modif_extrurev
3425 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3426 ExtrFlags, SewTolerance, MakeGroups=False):
3427 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3428 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3429 if isinstance( StepVector, list ):
3430 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3432 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3433 ExtrFlags, SewTolerance)
3434 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3435 ExtrFlags, SewTolerance)
3438 ## Generates new elements by extrusion of the elements which belong to the object
3439 # @param theObject the object which elements should be processed.
3440 # It can be a mesh, a sub mesh or a group.
3441 # @param StepVector vector or DirStruct or 3 vector components, defining
3442 # the direction and value of extrusion for one step (the total extrusion
3443 # length will be NbOfSteps * ||StepVector||)
3444 # @param NbOfSteps the number of steps
3445 # @param MakeGroups forces the generation of new groups from existing ones
3446 # @param IsNodes is True if elements which belong to the object are nodes
3447 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3448 # @ingroup l2_modif_extrurev
3449 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3450 if ( isinstance( theObject, Mesh )):
3451 theObject = theObject.GetMesh()
3452 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3453 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3454 if isinstance( StepVector, list ):
3455 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3456 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3457 Parameters = StepVector.PS.parameters + var_separator + Parameters
3458 self.mesh.SetParameters(Parameters)
3461 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3463 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3465 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3467 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3470 ## Generates new elements by extrusion of the elements which belong to the object
3471 # @param theObject object which elements should be processed.
3472 # It can be a mesh, a sub mesh or a group.
3473 # @param StepVector vector or DirStruct or 3 vector components, defining
3474 # the direction and value of extrusion for one step (the total extrusion
3475 # length will be NbOfSteps * ||StepVector||)
3476 # @param NbOfSteps the number of steps
3477 # @param MakeGroups to generate new groups from existing ones
3478 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3479 # @ingroup l2_modif_extrurev
3480 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3481 if ( isinstance( theObject, Mesh )):
3482 theObject = theObject.GetMesh()
3483 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3484 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3485 if isinstance( StepVector, list ):
3486 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3487 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3488 Parameters = StepVector.PS.parameters + var_separator + Parameters
3489 self.mesh.SetParameters(Parameters)
3491 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3492 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3495 ## Generates new elements by extrusion of the elements which belong to the object
3496 # @param theObject object which elements should be processed.
3497 # It can be a mesh, a sub mesh or a group.
3498 # @param StepVector vector or DirStruct or 3 vector components, defining
3499 # the direction and value of extrusion for one step (the total extrusion
3500 # length will be NbOfSteps * ||StepVector||)
3501 # @param NbOfSteps the number of steps
3502 # @param MakeGroups forces the generation of new groups from existing ones
3503 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3504 # @ingroup l2_modif_extrurev
3505 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3506 if ( isinstance( theObject, Mesh )):
3507 theObject = theObject.GetMesh()
3508 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3509 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3510 if isinstance( StepVector, list ):
3511 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3512 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3513 Parameters = StepVector.PS.parameters + var_separator + Parameters
3514 self.mesh.SetParameters(Parameters)
3516 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3517 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3522 ## Generates new elements by extrusion of the given elements
3523 # The path of extrusion must be a meshed edge.
3524 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3525 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3526 # @param NodeStart the start node from Path. Defines the direction of extrusion
3527 # @param HasAngles allows the shape to be rotated around the path
3528 # to get the resulting mesh in a helical fashion
3529 # @param Angles list of angles in radians
3530 # @param LinearVariation forces the computation of rotation angles as linear
3531 # variation of the given Angles along path steps
3532 # @param HasRefPoint allows using the reference point
3533 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3534 # The User can specify any point as the Reference Point.
3535 # @param MakeGroups forces the generation of new groups from existing ones
3536 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3537 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3538 # only SMESH::Extrusion_Error otherwise
3539 # @ingroup l2_modif_extrurev
3540 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3541 HasAngles, Angles, LinearVariation,
3542 HasRefPoint, RefPoint, MakeGroups, ElemType):
3543 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3544 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3546 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3547 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3548 self.mesh.SetParameters(Parameters)
3550 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3552 if isinstance(Base, list):
3554 if Base == []: IDsOfElements = self.GetElementsId()
3555 else: IDsOfElements = Base
3556 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3557 HasAngles, Angles, LinearVariation,
3558 HasRefPoint, RefPoint, MakeGroups, ElemType)
3560 if isinstance(Base, Mesh): Base = Base.GetMesh()
3561 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3562 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3563 HasAngles, Angles, LinearVariation,
3564 HasRefPoint, RefPoint, MakeGroups, ElemType)
3566 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3569 ## Generates new elements by extrusion of the given elements
3570 # The path of extrusion must be a meshed edge.
3571 # @param IDsOfElements ids of elements
3572 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3573 # @param PathShape shape(edge) defines the sub-mesh for the path
3574 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3575 # @param HasAngles allows the shape to be rotated around the path
3576 # to get the resulting mesh in a helical fashion
3577 # @param Angles list of angles in radians
3578 # @param HasRefPoint allows using the reference point
3579 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3580 # The User can specify any point as the Reference Point.
3581 # @param MakeGroups forces the generation of new groups from existing ones
3582 # @param LinearVariation forces the computation of rotation angles as linear
3583 # variation of the given Angles along path steps
3584 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3585 # only SMESH::Extrusion_Error otherwise
3586 # @ingroup l2_modif_extrurev
3587 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3588 HasAngles, Angles, HasRefPoint, RefPoint,
3589 MakeGroups=False, LinearVariation=False):
3590 if IDsOfElements == []:
3591 IDsOfElements = self.GetElementsId()
3592 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3593 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3595 if ( isinstance( PathMesh, Mesh )):
3596 PathMesh = PathMesh.GetMesh()
3597 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3598 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3599 self.mesh.SetParameters(Parameters)
3600 if HasAngles and Angles and LinearVariation:
3601 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3604 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3605 PathShape, NodeStart, HasAngles,
3606 Angles, HasRefPoint, RefPoint)
3607 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3608 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3610 ## Generates new elements by extrusion of the elements which belong to the object
3611 # The path of extrusion must be a meshed edge.
3612 # @param theObject the object which elements should be processed.
3613 # It can be a mesh, a sub mesh or a group.
3614 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3615 # @param PathShape shape(edge) defines the sub-mesh for the path
3616 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3617 # @param HasAngles allows the shape to be rotated around the path
3618 # to get the resulting mesh in a helical fashion
3619 # @param Angles list of angles
3620 # @param HasRefPoint allows using the reference point
3621 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3622 # The User can specify any point as the Reference Point.
3623 # @param MakeGroups forces the generation of new groups from existing ones
3624 # @param LinearVariation forces the computation of rotation angles as linear
3625 # variation of the given Angles along path steps
3626 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3627 # only SMESH::Extrusion_Error otherwise
3628 # @ingroup l2_modif_extrurev
3629 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3630 HasAngles, Angles, HasRefPoint, RefPoint,
3631 MakeGroups=False, LinearVariation=False):
3632 if ( isinstance( theObject, Mesh )):
3633 theObject = theObject.GetMesh()
3634 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3635 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3636 if ( isinstance( PathMesh, Mesh )):
3637 PathMesh = PathMesh.GetMesh()
3638 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3639 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3640 self.mesh.SetParameters(Parameters)
3641 if HasAngles and Angles and LinearVariation:
3642 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3645 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3646 PathShape, NodeStart, HasAngles,
3647 Angles, HasRefPoint, RefPoint)
3648 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3649 NodeStart, HasAngles, Angles, HasRefPoint,
3652 ## Generates new elements by extrusion of the elements which belong to the object
3653 # The path of extrusion must be a meshed edge.
3654 # @param theObject the object which elements should be processed.
3655 # It can be a mesh, a sub mesh or a group.
3656 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3657 # @param PathShape shape(edge) defines the sub-mesh for the path
3658 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3659 # @param HasAngles allows the shape to be rotated around the path
3660 # to get the resulting mesh in a helical fashion
3661 # @param Angles list of angles
3662 # @param HasRefPoint allows using the reference point
3663 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3664 # The User can specify any point as the Reference Point.
3665 # @param MakeGroups forces the generation of new groups from existing ones
3666 # @param LinearVariation forces the computation of rotation angles as linear
3667 # variation of the given Angles along path steps
3668 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3669 # only SMESH::Extrusion_Error otherwise
3670 # @ingroup l2_modif_extrurev
3671 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3672 HasAngles, Angles, HasRefPoint, RefPoint,
3673 MakeGroups=False, LinearVariation=False):
3674 if ( isinstance( theObject, Mesh )):
3675 theObject = theObject.GetMesh()
3676 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3677 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3678 if ( isinstance( PathMesh, Mesh )):
3679 PathMesh = PathMesh.GetMesh()
3680 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3681 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3682 self.mesh.SetParameters(Parameters)
3683 if HasAngles and Angles and LinearVariation:
3684 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3687 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3688 PathShape, NodeStart, HasAngles,
3689 Angles, HasRefPoint, RefPoint)
3690 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3691 NodeStart, HasAngles, Angles, HasRefPoint,
3694 ## Generates new elements by extrusion of the elements which belong to the object
3695 # The path of extrusion must be a meshed edge.
3696 # @param theObject the object which elements should be processed.
3697 # It can be a mesh, a sub mesh or a group.
3698 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3699 # @param PathShape shape(edge) defines the sub-mesh for the path
3700 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3701 # @param HasAngles allows the shape to be rotated around the path
3702 # to get the resulting mesh in a helical fashion
3703 # @param Angles list of angles
3704 # @param HasRefPoint allows using the reference point
3705 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3706 # The User can specify any point as the Reference Point.
3707 # @param MakeGroups forces the generation of new groups from existing ones
3708 # @param LinearVariation forces the computation of rotation angles as linear
3709 # variation of the given Angles along path steps
3710 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3711 # only SMESH::Extrusion_Error otherwise
3712 # @ingroup l2_modif_extrurev
3713 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3714 HasAngles, Angles, HasRefPoint, RefPoint,
3715 MakeGroups=False, LinearVariation=False):
3716 if ( isinstance( theObject, Mesh )):
3717 theObject = theObject.GetMesh()
3718 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3719 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3720 if ( isinstance( PathMesh, Mesh )):
3721 PathMesh = PathMesh.GetMesh()
3722 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3723 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3724 self.mesh.SetParameters(Parameters)
3725 if HasAngles and Angles and LinearVariation:
3726 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3729 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3730 PathShape, NodeStart, HasAngles,
3731 Angles, HasRefPoint, RefPoint)
3732 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3733 NodeStart, HasAngles, Angles, HasRefPoint,
3736 ## Creates a symmetrical copy of mesh elements
3737 # @param IDsOfElements list of elements ids
3738 # @param Mirror is AxisStruct or geom object(point, line, plane)
3739 # @param theMirrorType is POINT, AXIS or PLANE
3740 # If the Mirror is a geom object this parameter is unnecessary
3741 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3742 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3743 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3744 # @ingroup l2_modif_trsf
3745 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3746 if IDsOfElements == []:
3747 IDsOfElements = self.GetElementsId()
3748 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3749 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3750 self.mesh.SetParameters(Mirror.parameters)
3751 if Copy and MakeGroups:
3752 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3753 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3756 ## Creates a new mesh by a symmetrical copy of mesh elements
3757 # @param IDsOfElements the list of elements ids
3758 # @param Mirror is AxisStruct or geom object (point, line, plane)
3759 # @param theMirrorType is POINT, AXIS or PLANE
3760 # If the Mirror is a geom object this parameter is unnecessary
3761 # @param MakeGroups to generate new groups from existing ones
3762 # @param NewMeshName a name of the new mesh to create
3763 # @return instance of Mesh class
3764 # @ingroup l2_modif_trsf
3765 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3766 if IDsOfElements == []:
3767 IDsOfElements = self.GetElementsId()
3768 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3769 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3770 self.mesh.SetParameters(Mirror.parameters)
3771 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3772 MakeGroups, NewMeshName)
3773 return Mesh(self.smeshpyD,self.geompyD,mesh)
3775 ## Creates a symmetrical copy of the object
3776 # @param theObject mesh, submesh or group
3777 # @param Mirror AxisStruct or geom object (point, line, plane)
3778 # @param theMirrorType is POINT, AXIS or PLANE
3779 # If the Mirror is a geom object this parameter is unnecessary
3780 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3781 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3782 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3783 # @ingroup l2_modif_trsf
3784 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3785 if ( isinstance( theObject, Mesh )):
3786 theObject = theObject.GetMesh()
3787 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3788 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3789 self.mesh.SetParameters(Mirror.parameters)
3790 if Copy and MakeGroups:
3791 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3792 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3795 ## Creates a new mesh by a symmetrical copy of the object
3796 # @param theObject mesh, submesh or group
3797 # @param Mirror AxisStruct or geom object (point, line, plane)
3798 # @param theMirrorType POINT, AXIS or PLANE
3799 # If the Mirror is a geom object this parameter is unnecessary
3800 # @param MakeGroups forces the generation of new groups from existing ones
3801 # @param NewMeshName the name of the new mesh to create
3802 # @return instance of Mesh class
3803 # @ingroup l2_modif_trsf
3804 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3805 if ( isinstance( theObject, Mesh )):
3806 theObject = theObject.GetMesh()
3807 if (isinstance(Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3808 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3809 self.mesh.SetParameters(Mirror.parameters)
3810 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3811 MakeGroups, NewMeshName)
3812 return Mesh( self.smeshpyD,self.geompyD,mesh )
3814 ## Translates the elements
3815 # @param IDsOfElements list of elements ids
3816 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3817 # @param Copy allows copying the translated elements
3818 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3819 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3820 # @ingroup l2_modif_trsf
3821 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3822 if IDsOfElements == []:
3823 IDsOfElements = self.GetElementsId()
3824 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3825 Vector = self.smeshpyD.GetDirStruct(Vector)
3826 if isinstance( Vector, list ):
3827 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3828 self.mesh.SetParameters(Vector.PS.parameters)
3829 if Copy and MakeGroups:
3830 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3831 self.editor.Translate(IDsOfElements, Vector, Copy)
3834 ## Creates a new mesh of translated elements
3835 # @param IDsOfElements list of elements ids
3836 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3837 # @param MakeGroups forces the generation of new groups from existing ones
3838 # @param NewMeshName the name of the newly created mesh
3839 # @return instance of Mesh class
3840 # @ingroup l2_modif_trsf
3841 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3842 if IDsOfElements == []:
3843 IDsOfElements = self.GetElementsId()
3844 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3845 Vector = self.smeshpyD.GetDirStruct(Vector)
3846 if isinstance( Vector, list ):
3847 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3848 self.mesh.SetParameters(Vector.PS.parameters)
3849 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3850 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3852 ## Translates the object
3853 # @param theObject the object to translate (mesh, submesh, or group)
3854 # @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
3855 # @param Copy allows copying the translated elements
3856 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3857 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3858 # @ingroup l2_modif_trsf
3859 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3860 if ( isinstance( theObject, Mesh )):
3861 theObject = theObject.GetMesh()
3862 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3863 Vector = self.smeshpyD.GetDirStruct(Vector)
3864 if isinstance( Vector, list ):
3865 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3866 self.mesh.SetParameters(Vector.PS.parameters)
3867 if Copy and MakeGroups:
3868 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3869 self.editor.TranslateObject(theObject, Vector, Copy)
3872 ## Creates a new mesh from the translated object
3873 # @param theObject the object to translate (mesh, submesh, or group)
3874 # @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
3875 # @param MakeGroups forces the generation of new groups from existing ones
3876 # @param NewMeshName the name of the newly created mesh
3877 # @return instance of Mesh class
3878 # @ingroup l2_modif_trsf
3879 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3880 if isinstance( theObject, Mesh ):
3881 theObject = theObject.GetMesh()
3882 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
3883 Vector = self.smeshpyD.GetDirStruct(Vector)
3884 if isinstance( Vector, list ):
3885 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3886 self.mesh.SetParameters(Vector.PS.parameters)
3887 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3888 return Mesh( self.smeshpyD, self.geompyD, mesh )
3892 ## Scales the object
3893 # @param theObject - the object to translate (mesh, submesh, or group)
3894 # @param thePoint - base point for scale
3895 # @param theScaleFact - list of 1-3 scale factors for axises
3896 # @param Copy - allows copying the translated elements
3897 # @param MakeGroups - forces the generation of new groups from existing
3899 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3900 # empty list otherwise
3901 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3902 if ( isinstance( theObject, Mesh )):
3903 theObject = theObject.GetMesh()
3904 if ( isinstance( theObject, list )):
3905 theObject = self.GetIDSource(theObject, SMESH.ALL)
3906 if ( isinstance( theScaleFact, float )):
3907 theScaleFact = [theScaleFact]
3908 if ( isinstance( theScaleFact, int )):
3909 theScaleFact = [ float(theScaleFact)]
3911 self.mesh.SetParameters(thePoint.parameters)
3913 if Copy and MakeGroups:
3914 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3915 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3918 ## Creates a new mesh from the translated object
3919 # @param theObject - the object to translate (mesh, submesh, or group)
3920 # @param thePoint - base point for scale
3921 # @param theScaleFact - list of 1-3 scale factors for axises
3922 # @param MakeGroups - forces the generation of new groups from existing ones
3923 # @param NewMeshName - the name of the newly created mesh
3924 # @return instance of Mesh class
3925 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3926 if (isinstance(theObject, Mesh)):
3927 theObject = theObject.GetMesh()
3928 if ( isinstance( theObject, list )):
3929 theObject = self.GetIDSource(theObject,SMESH.ALL)
3930 if ( isinstance( theScaleFact, float )):
3931 theScaleFact = [theScaleFact]
3932 if ( isinstance( theScaleFact, int )):
3933 theScaleFact = [ float(theScaleFact)]
3935 self.mesh.SetParameters(thePoint.parameters)
3936 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3937 MakeGroups, NewMeshName)
3938 return Mesh( self.smeshpyD, self.geompyD, mesh )
3942 ## Rotates the elements
3943 # @param IDsOfElements list of elements ids
3944 # @param Axis the axis of rotation (AxisStruct or geom line)
3945 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3946 # @param Copy allows copying the rotated elements
3947 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3948 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3949 # @ingroup l2_modif_trsf
3950 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3951 if IDsOfElements == []:
3952 IDsOfElements = self.GetElementsId()
3953 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3954 Axis = self.smeshpyD.GetAxisStruct(Axis)
3955 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3956 Parameters = Axis.parameters + var_separator + Parameters
3957 self.mesh.SetParameters(Parameters)
3958 if Copy and MakeGroups:
3959 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3960 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3963 ## Creates a new mesh of rotated elements
3964 # @param IDsOfElements list of element ids
3965 # @param Axis the axis of rotation (AxisStruct or geom line)
3966 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3967 # @param MakeGroups forces the generation of new groups from existing ones
3968 # @param NewMeshName the name of the newly created mesh
3969 # @return instance of Mesh class
3970 # @ingroup l2_modif_trsf
3971 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3972 if IDsOfElements == []:
3973 IDsOfElements = self.GetElementsId()
3974 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3975 Axis = self.smeshpyD.GetAxisStruct(Axis)
3976 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3977 Parameters = Axis.parameters + var_separator + Parameters
3978 self.mesh.SetParameters(Parameters)
3979 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3980 MakeGroups, NewMeshName)
3981 return Mesh( self.smeshpyD, self.geompyD, mesh )
3983 ## Rotates the object
3984 # @param theObject the object to rotate( mesh, submesh, or group)
3985 # @param Axis the axis of rotation (AxisStruct or geom line)
3986 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3987 # @param Copy allows copying the rotated elements
3988 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3989 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3990 # @ingroup l2_modif_trsf
3991 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3992 if (isinstance(theObject, Mesh)):
3993 theObject = theObject.GetMesh()
3994 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3995 Axis = self.smeshpyD.GetAxisStruct(Axis)
3996 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3997 Parameters = Axis.parameters + ":" + Parameters
3998 self.mesh.SetParameters(Parameters)
3999 if Copy and MakeGroups:
4000 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
4001 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
4004 ## Creates a new mesh from the rotated object
4005 # @param theObject the object to rotate (mesh, submesh, or group)
4006 # @param Axis the axis of rotation (AxisStruct or geom line)
4007 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4008 # @param MakeGroups forces the generation of new groups from existing ones
4009 # @param NewMeshName the name of the newly created mesh
4010 # @return instance of Mesh class
4011 # @ingroup l2_modif_trsf
4012 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
4013 if (isinstance( theObject, Mesh )):
4014 theObject = theObject.GetMesh()
4015 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4016 Axis = self.smeshpyD.GetAxisStruct(Axis)
4017 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4018 Parameters = Axis.parameters + ":" + Parameters
4019 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
4020 MakeGroups, NewMeshName)
4021 self.mesh.SetParameters(Parameters)
4022 return Mesh( self.smeshpyD, self.geompyD, mesh )
4024 ## Finds groups of ajacent nodes within Tolerance.
4025 # @param Tolerance the value of tolerance
4026 # @return the list of groups of nodes
4027 # @ingroup l2_modif_trsf
4028 def FindCoincidentNodes (self, Tolerance):
4029 return self.editor.FindCoincidentNodes(Tolerance)
4031 ## Finds groups of ajacent nodes within Tolerance.
4032 # @param Tolerance the value of tolerance
4033 # @param SubMeshOrGroup SubMesh or Group
4034 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
4035 # @return the list of groups of nodes
4036 # @ingroup l2_modif_trsf
4037 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
4038 if (isinstance( SubMeshOrGroup, Mesh )):
4039 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
4040 if not isinstance( exceptNodes, list):
4041 exceptNodes = [ exceptNodes ]
4042 if exceptNodes and isinstance( exceptNodes[0], int):
4043 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
4044 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
4047 # @param GroupsOfNodes the list of groups of nodes
4048 # @ingroup l2_modif_trsf
4049 def MergeNodes (self, GroupsOfNodes):
4050 self.editor.MergeNodes(GroupsOfNodes)
4052 ## Finds the elements built on the same nodes.
4053 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
4054 # @return a list of groups of equal elements
4055 # @ingroup l2_modif_trsf
4056 def FindEqualElements (self, MeshOrSubMeshOrGroup):
4057 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
4058 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4059 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
4061 ## Merges elements in each given group.
4062 # @param GroupsOfElementsID groups of elements for merging
4063 # @ingroup l2_modif_trsf
4064 def MergeElements(self, GroupsOfElementsID):
4065 self.editor.MergeElements(GroupsOfElementsID)
4067 ## Leaves one element and removes all other elements built on the same nodes.
4068 # @ingroup l2_modif_trsf
4069 def MergeEqualElements(self):
4070 self.editor.MergeEqualElements()
4072 ## Sews free borders
4073 # @return SMESH::Sew_Error
4074 # @ingroup l2_modif_trsf
4075 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4076 FirstNodeID2, SecondNodeID2, LastNodeID2,
4077 CreatePolygons, CreatePolyedrs):
4078 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4079 FirstNodeID2, SecondNodeID2, LastNodeID2,
4080 CreatePolygons, CreatePolyedrs)
4082 ## Sews conform free borders
4083 # @return SMESH::Sew_Error
4084 # @ingroup l2_modif_trsf
4085 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4086 FirstNodeID2, SecondNodeID2):
4087 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4088 FirstNodeID2, SecondNodeID2)
4090 ## Sews border to side
4091 # @return SMESH::Sew_Error
4092 # @ingroup l2_modif_trsf
4093 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4094 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4095 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4096 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4098 ## Sews two sides of a mesh. The nodes belonging to Side1 are
4099 # merged with the nodes of elements of Side2.
4100 # The number of elements in theSide1 and in theSide2 must be
4101 # equal and they should have similar nodal connectivity.
4102 # The nodes to merge should belong to side borders and
4103 # the first node should be linked to the second.
4104 # @return SMESH::Sew_Error
4105 # @ingroup l2_modif_trsf
4106 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4107 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4108 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4109 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4110 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4111 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4113 ## Sets new nodes for the given element.
4114 # @param ide the element id
4115 # @param newIDs nodes ids
4116 # @return If the number of nodes does not correspond to the type of element - returns false
4117 # @ingroup l2_modif_edit
4118 def ChangeElemNodes(self, ide, newIDs):
4119 return self.editor.ChangeElemNodes(ide, newIDs)
4121 ## If during the last operation of MeshEditor some nodes were
4122 # created, this method returns the list of their IDs, \n
4123 # if new nodes were not created - returns empty list
4124 # @return the list of integer values (can be empty)
4125 # @ingroup l1_auxiliary
4126 def GetLastCreatedNodes(self):
4127 return self.editor.GetLastCreatedNodes()
4129 ## If during the last operation of MeshEditor some elements were
4130 # created this method returns the list of their IDs, \n
4131 # if new elements were not created - returns empty list
4132 # @return the list of integer values (can be empty)
4133 # @ingroup l1_auxiliary
4134 def GetLastCreatedElems(self):
4135 return self.editor.GetLastCreatedElems()
4137 ## Clears sequences of nodes and elements created by mesh edition oparations
4138 # @ingroup l1_auxiliary
4139 def ClearLastCreated(self):
4140 self.editor.ClearLastCreated()
4142 ## Creates Duplicates given elements, i.e. creates new elements based on the
4143 # same nodes as the given ones.
4144 # @param theElements - container of elements to duplicate. It can be a Mesh,
4145 # sub-mesh, group, filter or a list of element IDs.
4146 # @param theGroupName - a name of group to contain the generated elements.
4147 # If a group with such a name already exists, the new elements
4148 # are added to the existng group, else a new group is created.
4149 # If \a theGroupName is empty, new elements are not added
4151 # @return a group where the new elements are added. None if theGroupName == "".
4152 # @ingroup l2_modif_edit
4153 def DoubleElements(self, theElements, theGroupName=""):
4154 if isinstance( theElements, Mesh ):
4155 theElements = theElements.mesh
4156 elif isinstance( theElements, list ):
4157 theElements = self.GetIDSource( theElements, SMESH.ALL )
4158 return self.editor.DoubleElements(theElements, theGroupName)
4160 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4161 # @param theNodes identifiers of nodes to be doubled
4162 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4163 # nodes. If list of element identifiers is empty then nodes are doubled but
4164 # they not assigned to elements
4165 # @return TRUE if operation has been completed successfully, FALSE otherwise
4166 # @ingroup l2_modif_edit
4167 def DoubleNodes(self, theNodes, theModifiedElems):
4168 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4170 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4171 # This method provided for convenience works as DoubleNodes() described above.
4172 # @param theNodeId identifiers of node to be doubled
4173 # @param theModifiedElems identifiers of elements to be updated
4174 # @return TRUE if operation has been completed successfully, FALSE otherwise
4175 # @ingroup l2_modif_edit
4176 def DoubleNode(self, theNodeId, theModifiedElems):
4177 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4179 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4180 # This method provided for convenience works as DoubleNodes() described above.
4181 # @param theNodes group of nodes to be doubled
4182 # @param theModifiedElems group of elements to be updated.
4183 # @param theMakeGroup forces the generation of a group containing new nodes.
4184 # @return TRUE or a created group if operation has been completed successfully,
4185 # FALSE or None otherwise
4186 # @ingroup l2_modif_edit
4187 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4189 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4190 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4192 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4193 # This method provided for convenience works as DoubleNodes() described above.
4194 # @param theNodes list of groups of nodes to be doubled
4195 # @param theModifiedElems list of groups of elements to be updated.
4196 # @param theMakeGroup forces the generation of a group containing new nodes.
4197 # @return TRUE if operation has been completed successfully, FALSE otherwise
4198 # @ingroup l2_modif_edit
4199 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4201 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4202 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4204 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4205 # @param theElems - the list of elements (edges or faces) to be replicated
4206 # The nodes for duplication could be found from these elements
4207 # @param theNodesNot - list of nodes to NOT replicate
4208 # @param theAffectedElems - the list of elements (cells and edges) to which the
4209 # replicated nodes should be associated to.
4210 # @return TRUE if operation has been completed successfully, FALSE otherwise
4211 # @ingroup l2_modif_edit
4212 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4213 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4215 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4216 # @param theElems - the list of elements (edges or faces) to be replicated
4217 # The nodes for duplication could be found from these elements
4218 # @param theNodesNot - list of nodes to NOT replicate
4219 # @param theShape - shape to detect affected elements (element which geometric center
4220 # located on or inside shape).
4221 # The replicated nodes should be associated to affected elements.
4222 # @return TRUE if operation has been completed successfully, FALSE otherwise
4223 # @ingroup l2_modif_edit
4224 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4225 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4227 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4228 # This method provided for convenience works as DoubleNodes() described above.
4229 # @param theElems - group of of elements (edges or faces) to be replicated
4230 # @param theNodesNot - group of nodes not to replicated
4231 # @param theAffectedElems - group of elements to which the replicated nodes
4232 # should be associated to.
4233 # @param theMakeGroup forces the generation of a group containing new elements.
4234 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4235 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4236 # FALSE or None otherwise
4237 # @ingroup l2_modif_edit
4238 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4239 theMakeGroup=False, theMakeNodeGroup=False):
4240 if theMakeGroup or theMakeNodeGroup:
4241 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4243 theMakeGroup, theMakeNodeGroup)
4244 if theMakeGroup and theMakeNodeGroup:
4247 return twoGroups[ int(theMakeNodeGroup) ]
4248 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4250 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4251 # This method provided for convenience works as DoubleNodes() described above.
4252 # @param theElems - group of of elements (edges or faces) to be replicated
4253 # @param theNodesNot - group of nodes not to replicated
4254 # @param theShape - shape to detect affected elements (element which geometric center
4255 # located on or inside shape).
4256 # The replicated nodes should be associated to affected elements.
4257 # @ingroup l2_modif_edit
4258 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4259 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4261 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4262 # This method provided for convenience works as DoubleNodes() described above.
4263 # @param theElems - list of groups of elements (edges or faces) to be replicated
4264 # @param theNodesNot - list of groups of nodes not to replicated
4265 # @param theAffectedElems - group of elements to which the replicated nodes
4266 # should be associated to.
4267 # @param theMakeGroup forces the generation of a group containing new elements.
4268 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4269 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4270 # FALSE or None otherwise
4271 # @ingroup l2_modif_edit
4272 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4273 theMakeGroup=False, theMakeNodeGroup=False):
4274 if theMakeGroup or theMakeNodeGroup:
4275 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4277 theMakeGroup, theMakeNodeGroup)
4278 if theMakeGroup and theMakeNodeGroup:
4281 return twoGroups[ int(theMakeNodeGroup) ]
4282 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4284 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4285 # This method provided for convenience works as DoubleNodes() described above.
4286 # @param theElems - list of groups of elements (edges or faces) to be replicated
4287 # @param theNodesNot - list of groups of nodes not to replicated
4288 # @param theShape - shape to detect affected elements (element which geometric center
4289 # located on or inside shape).
4290 # The replicated nodes should be associated to affected elements.
4291 # @return TRUE if operation has been completed successfully, FALSE otherwise
4292 # @ingroup l2_modif_edit
4293 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4294 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4296 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4297 # This method is the first step of DoubleNodeElemGroupsInRegion.
4298 # @param theElems - list of groups of elements (edges or faces) to be replicated
4299 # @param theNodesNot - list of groups of nodes not to replicated
4300 # @param theShape - shape to detect affected elements (element which geometric center
4301 # located on or inside shape).
4302 # The replicated nodes should be associated to affected elements.
4303 # @return groups of affected elements
4304 # @ingroup l2_modif_edit
4305 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4306 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4308 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4309 # The list of groups must describe a partition of the mesh volumes.
4310 # The nodes of the internal faces at the boundaries of the groups are doubled.
4311 # In option, the internal faces are replaced by flat elements.
4312 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4313 # @param theDomains - list of groups of volumes
4314 # @param createJointElems - if TRUE, create the elements
4315 # @return TRUE if operation has been completed successfully, FALSE otherwise
4316 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4317 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4319 ## Double nodes on some external faces and create flat elements.
4320 # Flat elements are mainly used by some types of mechanic calculations.
4322 # Each group of the list must be constituted of faces.
4323 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4324 # @param theGroupsOfFaces - list of groups of faces
4325 # @return TRUE if operation has been completed successfully, FALSE otherwise
4326 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4327 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4329 ## identify all the elements around a geom shape, get the faces delimiting the hole
4331 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4332 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4334 def _getFunctor(self, funcType ):
4335 fn = self.functors[ funcType._v ]
4337 fn = self.smeshpyD.GetFunctor(funcType)
4338 fn.SetMesh(self.mesh)
4339 self.functors[ funcType._v ] = fn
4342 def _valueFromFunctor(self, funcType, elemId):
4343 fn = self._getFunctor( funcType )
4344 if fn.GetElementType() == self.GetElementType(elemId, True):
4345 val = fn.GetValue(elemId)
4350 ## Get length of 1D element.
4351 # @param elemId mesh element ID
4352 # @return element's length value
4353 # @ingroup l1_measurements
4354 def GetLength(self, elemId):
4355 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4357 ## Get area of 2D element.
4358 # @param elemId mesh element ID
4359 # @return element's area value
4360 # @ingroup l1_measurements
4361 def GetArea(self, elemId):
4362 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4364 ## Get volume of 3D element.
4365 # @param elemId mesh element ID
4366 # @return element's volume value
4367 # @ingroup l1_measurements
4368 def GetVolume(self, elemId):
4369 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4371 ## Get maximum element length.
4372 # @param elemId mesh element ID
4373 # @return element's maximum length value
4374 # @ingroup l1_measurements
4375 def GetMaxElementLength(self, elemId):
4376 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4377 ftype = SMESH.FT_MaxElementLength3D
4379 ftype = SMESH.FT_MaxElementLength2D
4380 return self._valueFromFunctor(ftype, elemId)
4382 ## Get aspect ratio of 2D or 3D element.
4383 # @param elemId mesh element ID
4384 # @return element's aspect ratio value
4385 # @ingroup l1_measurements
4386 def GetAspectRatio(self, elemId):
4387 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4388 ftype = SMESH.FT_AspectRatio3D
4390 ftype = SMESH.FT_AspectRatio
4391 return self._valueFromFunctor(ftype, elemId)
4393 ## Get warping angle of 2D element.
4394 # @param elemId mesh element ID
4395 # @return element's warping angle value
4396 # @ingroup l1_measurements
4397 def GetWarping(self, elemId):
4398 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4400 ## Get minimum angle of 2D element.
4401 # @param elemId mesh element ID
4402 # @return element's minimum angle value
4403 # @ingroup l1_measurements
4404 def GetMinimumAngle(self, elemId):
4405 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4407 ## Get taper of 2D element.
4408 # @param elemId mesh element ID
4409 # @return element's taper value
4410 # @ingroup l1_measurements
4411 def GetTaper(self, elemId):
4412 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4414 ## Get skew of 2D element.
4415 # @param elemId mesh element ID
4416 # @return element's skew value
4417 # @ingroup l1_measurements
4418 def GetSkew(self, elemId):
4419 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4421 pass # end of Mesh class
4423 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4425 class Pattern(SMESH._objref_SMESH_Pattern):
4427 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4428 decrFun = lambda i: i-1
4429 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4430 theMesh.SetParameters(Parameters)
4431 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4433 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4434 decrFun = lambda i: i-1
4435 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4436 theMesh.SetParameters(Parameters)
4437 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4439 # Registering the new proxy for Pattern
4440 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4442 ## Private class used to bind methods creating algorithms to the class Mesh
4447 self.defaultAlgoType = ""
4448 self.algoTypeToClass = {}
4450 # Stores a python class of algorithm
4451 def add(self, algoClass):
4452 if type( algoClass ).__name__ == 'classobj' and \
4453 hasattr( algoClass, "algoType"):
4454 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4455 if not self.defaultAlgoType and \
4456 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4457 self.defaultAlgoType = algoClass.algoType
4458 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4460 # creates a copy of self and assign mesh to the copy
4461 def copy(self, mesh):
4462 other = algoCreator()
4463 other.defaultAlgoType = self.defaultAlgoType
4464 other.algoTypeToClass = self.algoTypeToClass
4468 # creates an instance of algorithm
4469 def __call__(self,algo="",geom=0,*args):
4470 algoType = self.defaultAlgoType
4471 for arg in args + (algo,geom):
4472 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
4474 if isinstance( arg, str ) and arg:
4476 if not algoType and self.algoTypeToClass:
4477 algoType = self.algoTypeToClass.keys()[0]
4478 if self.algoTypeToClass.has_key( algoType ):
4479 #print "Create algo",algoType
4480 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4481 raise RuntimeError, "No class found for algo type %s" % algoType
4484 # Private class used to substitute and store variable parameters of hypotheses.
4486 class hypMethodWrapper:
4487 def __init__(self, hyp, method):
4489 self.method = method
4490 #print "REBIND:", method.__name__
4493 # call a method of hypothesis with calling SetVarParameter() before
4494 def __call__(self,*args):
4496 return self.method( self.hyp, *args ) # hypothesis method with no args
4498 #print "MethWrapper.__call__",self.method.__name__, args
4500 parsed = ParseParameters(*args) # replace variables with their values
4501 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4502 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4503 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4504 # maybe there is a replaced string arg which is not variable
4505 result = self.method( self.hyp, *args )
4506 except ValueError, detail: # raised by ParseParameters()
4508 result = self.method( self.hyp, *args )
4509 except omniORB.CORBA.BAD_PARAM:
4510 raise ValueError, detail # wrong variable name
4514 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4516 #print "pluginName: ", pluginName
4517 pluginBuilderName = pluginName + "Builder"
4519 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
4520 except Exception, e:
4521 print "Exception while loading %s: %s" % ( pluginBuilderName, e )
4523 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
4524 plugin = eval( pluginBuilderName )
4525 #print " plugin:" , str(plugin)
4527 # add methods creating algorithms to Mesh
4528 for k in dir( plugin ):
4529 if k[0] == '_': continue
4530 algo = getattr( plugin, k )
4531 #print " algo:", str(algo)
4532 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4533 #print " meshMethod:" , str(algo.meshMethod)
4534 if not hasattr( Mesh, algo.meshMethod ):
4535 setattr( Mesh, algo.meshMethod, algoCreator() )
4537 getattr( Mesh, algo.meshMethod ).add( algo )