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 # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1668 # - 1D if all mesh nodes lie on OX coordinate axis, or
1669 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1670 # - 3D in the rest cases.
1672 # If @a autoDimension is @c False, the space dimension is always 3.
1673 # @ingroup l2_impexp
1674 def ExportToMED(self, f, version, opt=0, overwrite=1, autoDimension=True):
1675 self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension)
1677 # Operations with groups:
1678 # ----------------------
1680 ## Creates an empty mesh group
1681 # @param elementType the type of elements in the group
1682 # @param name the name of the mesh group
1683 # @return SMESH_Group
1684 # @ingroup l2_grps_create
1685 def CreateEmptyGroup(self, elementType, name):
1686 return self.mesh.CreateGroup(elementType, name)
1688 ## Creates a mesh group based on the geometric object \a grp
1689 # and gives a \a name, \n if this parameter is not defined
1690 # the name is the same as the geometric group name \n
1691 # Note: Works like GroupOnGeom().
1692 # @param grp a geometric group, a vertex, an edge, a face or a solid
1693 # @param name the name of the mesh group
1694 # @return SMESH_GroupOnGeom
1695 # @ingroup l2_grps_create
1696 def Group(self, grp, name=""):
1697 return self.GroupOnGeom(grp, name)
1699 ## Creates a mesh group based on the geometrical object \a grp
1700 # and gives a \a name, \n if this parameter is not defined
1701 # the name is the same as the geometrical group name
1702 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1703 # @param name the name of the mesh group
1704 # @param typ the type of elements in the group. If not set, it is
1705 # automatically detected by the type of the geometry
1706 # @return SMESH_GroupOnGeom
1707 # @ingroup l2_grps_create
1708 def GroupOnGeom(self, grp, name="", typ=None):
1709 AssureGeomPublished( self, grp, name )
1711 name = grp.GetName()
1713 typ = self._groupTypeFromShape( grp )
1714 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1716 ## Pivate method to get a type of group on geometry
1717 def _groupTypeFromShape( self, shape ):
1718 tgeo = str(shape.GetShapeType())
1719 if tgeo == "VERTEX":
1721 elif tgeo == "EDGE":
1723 elif tgeo == "FACE" or tgeo == "SHELL":
1725 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1727 elif tgeo == "COMPOUND":
1728 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
1730 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1731 return self._groupTypeFromShape( sub[0] )
1734 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1737 ## Creates a mesh group with given \a name based on the \a filter which
1738 ## is a special type of group dynamically updating it's contents during
1739 ## mesh modification
1740 # @param typ the type of elements in the group
1741 # @param name the name of the mesh group
1742 # @param filter the filter defining group contents
1743 # @return SMESH_GroupOnFilter
1744 # @ingroup l2_grps_create
1745 def GroupOnFilter(self, typ, name, filter):
1746 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1748 ## Creates a mesh group by the given ids of elements
1749 # @param groupName the name of the mesh group
1750 # @param elementType the type of elements in the group
1751 # @param elemIDs the list of ids
1752 # @return SMESH_Group
1753 # @ingroup l2_grps_create
1754 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1755 group = self.mesh.CreateGroup(elementType, groupName)
1759 ## Creates a mesh group by the given conditions
1760 # @param groupName the name of the mesh group
1761 # @param elementType the type of elements in the group
1762 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1763 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1764 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1765 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1766 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1767 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1768 # @return SMESH_Group
1769 # @ingroup l2_grps_create
1773 CritType=FT_Undefined,
1776 UnaryOp=FT_Undefined,
1778 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1779 group = self.MakeGroupByCriterion(groupName, aCriterion)
1782 ## Creates a mesh group by the given criterion
1783 # @param groupName the name of the mesh group
1784 # @param Criterion the instance of Criterion class
1785 # @return SMESH_Group
1786 # @ingroup l2_grps_create
1787 def MakeGroupByCriterion(self, groupName, Criterion):
1788 aFilterMgr = self.smeshpyD.CreateFilterManager()
1789 aFilter = aFilterMgr.CreateFilter()
1791 aCriteria.append(Criterion)
1792 aFilter.SetCriteria(aCriteria)
1793 group = self.MakeGroupByFilter(groupName, aFilter)
1794 aFilterMgr.UnRegister()
1797 ## Creates a mesh group by the given criteria (list of criteria)
1798 # @param groupName the name of the mesh group
1799 # @param theCriteria the list of criteria
1800 # @return SMESH_Group
1801 # @ingroup l2_grps_create
1802 def MakeGroupByCriteria(self, groupName, theCriteria):
1803 aFilterMgr = self.smeshpyD.CreateFilterManager()
1804 aFilter = aFilterMgr.CreateFilter()
1805 aFilter.SetCriteria(theCriteria)
1806 group = self.MakeGroupByFilter(groupName, aFilter)
1807 aFilterMgr.UnRegister()
1810 ## Creates a mesh group by the given filter
1811 # @param groupName the name of the mesh group
1812 # @param theFilter the instance of Filter class
1813 # @return SMESH_Group
1814 # @ingroup l2_grps_create
1815 def MakeGroupByFilter(self, groupName, theFilter):
1816 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1817 theFilter.SetMesh( self.mesh )
1818 group.AddFrom( theFilter )
1822 # @ingroup l2_grps_delete
1823 def RemoveGroup(self, group):
1824 self.mesh.RemoveGroup(group)
1826 ## Removes a group with its contents
1827 # @ingroup l2_grps_delete
1828 def RemoveGroupWithContents(self, group):
1829 self.mesh.RemoveGroupWithContents(group)
1831 ## Gets the list of groups existing in the mesh
1832 # @return a sequence of SMESH_GroupBase
1833 # @ingroup l2_grps_create
1834 def GetGroups(self):
1835 return self.mesh.GetGroups()
1837 ## Gets the number of groups existing in the mesh
1838 # @return the quantity of groups as an integer value
1839 # @ingroup l2_grps_create
1841 return self.mesh.NbGroups()
1843 ## Gets the list of names of groups existing in the mesh
1844 # @return list of strings
1845 # @ingroup l2_grps_create
1846 def GetGroupNames(self):
1847 groups = self.GetGroups()
1849 for group in groups:
1850 names.append(group.GetName())
1853 ## Produces a union of two groups
1854 # A new group is created. All mesh elements that are
1855 # present in the initial groups are added to the new one
1856 # @return an instance of SMESH_Group
1857 # @ingroup l2_grps_operon
1858 def UnionGroups(self, group1, group2, name):
1859 return self.mesh.UnionGroups(group1, group2, name)
1861 ## Produces a union list of groups
1862 # New group is created. All mesh elements that are present in
1863 # initial groups are added to the new one
1864 # @return an instance of SMESH_Group
1865 # @ingroup l2_grps_operon
1866 def UnionListOfGroups(self, groups, name):
1867 return self.mesh.UnionListOfGroups(groups, name)
1869 ## Prodices an intersection of two groups
1870 # A new group is created. All mesh elements that are common
1871 # for the two initial groups are added to the new one.
1872 # @return an instance of SMESH_Group
1873 # @ingroup l2_grps_operon
1874 def IntersectGroups(self, group1, group2, name):
1875 return self.mesh.IntersectGroups(group1, group2, name)
1877 ## Produces an intersection of groups
1878 # New group is created. All mesh elements that are present in all
1879 # initial groups simultaneously are added to the new one
1880 # @return an instance of SMESH_Group
1881 # @ingroup l2_grps_operon
1882 def IntersectListOfGroups(self, groups, name):
1883 return self.mesh.IntersectListOfGroups(groups, name)
1885 ## Produces a cut of two groups
1886 # A new group is created. All mesh elements that are present in
1887 # the main group but are not present in the tool group are added to the new one
1888 # @return an instance of SMESH_Group
1889 # @ingroup l2_grps_operon
1890 def CutGroups(self, main_group, tool_group, name):
1891 return self.mesh.CutGroups(main_group, tool_group, name)
1893 ## Produces a cut of groups
1894 # A new group is created. All mesh elements that are present in main groups
1895 # but do not present in tool groups are added to the new one
1896 # @return an instance of SMESH_Group
1897 # @ingroup l2_grps_operon
1898 def CutListOfGroups(self, main_groups, tool_groups, name):
1899 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1901 ## Produces a group of elements of specified type using list of existing groups
1902 # A new group is created. System
1903 # 1) extracts all nodes on which groups elements are built
1904 # 2) combines all elements of specified dimension laying on these nodes
1905 # @return an instance of SMESH_Group
1906 # @ingroup l2_grps_operon
1907 def CreateDimGroup(self, groups, elem_type, name):
1908 return self.mesh.CreateDimGroup(groups, elem_type, name)
1911 ## Convert group on geom into standalone group
1912 # @ingroup l2_grps_delete
1913 def ConvertToStandalone(self, group):
1914 return self.mesh.ConvertToStandalone(group)
1916 # Get some info about mesh:
1917 # ------------------------
1919 ## Returns the log of nodes and elements added or removed
1920 # since the previous clear of the log.
1921 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1922 # @return list of log_block structures:
1927 # @ingroup l1_auxiliary
1928 def GetLog(self, clearAfterGet):
1929 return self.mesh.GetLog(clearAfterGet)
1931 ## Clears the log of nodes and elements added or removed since the previous
1932 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1933 # @ingroup l1_auxiliary
1935 self.mesh.ClearLog()
1937 ## Toggles auto color mode on the object.
1938 # @param theAutoColor the flag which toggles auto color mode.
1939 # @ingroup l1_auxiliary
1940 def SetAutoColor(self, theAutoColor):
1941 self.mesh.SetAutoColor(theAutoColor)
1943 ## Gets flag of object auto color mode.
1944 # @return True or False
1945 # @ingroup l1_auxiliary
1946 def GetAutoColor(self):
1947 return self.mesh.GetAutoColor()
1949 ## Gets the internal ID
1950 # @return integer value, which is the internal Id of the mesh
1951 # @ingroup l1_auxiliary
1953 return self.mesh.GetId()
1956 # @return integer value, which is the study Id of the mesh
1957 # @ingroup l1_auxiliary
1958 def GetStudyId(self):
1959 return self.mesh.GetStudyId()
1961 ## Checks the group names for duplications.
1962 # Consider the maximum group name length stored in MED file.
1963 # @return True or False
1964 # @ingroup l1_auxiliary
1965 def HasDuplicatedGroupNamesMED(self):
1966 return self.mesh.HasDuplicatedGroupNamesMED()
1968 ## Obtains the mesh editor tool
1969 # @return an instance of SMESH_MeshEditor
1970 # @ingroup l1_modifying
1971 def GetMeshEditor(self):
1974 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1975 # can be passed as argument to a method accepting mesh, group or sub-mesh
1976 # @return an instance of SMESH_IDSource
1977 # @ingroup l1_auxiliary
1978 def GetIDSource(self, ids, elemType):
1979 return self.editor.MakeIDSource(ids, elemType)
1982 # Get informations about mesh contents:
1983 # ------------------------------------
1985 ## Gets the mesh stattistic
1986 # @return dictionary type element - count of elements
1987 # @ingroup l1_meshinfo
1988 def GetMeshInfo(self, obj = None):
1989 if not obj: obj = self.mesh
1990 return self.smeshpyD.GetMeshInfo(obj)
1992 ## Returns the number of nodes in the mesh
1993 # @return an integer value
1994 # @ingroup l1_meshinfo
1996 return self.mesh.NbNodes()
1998 ## Returns the number of elements in the mesh
1999 # @return an integer value
2000 # @ingroup l1_meshinfo
2001 def NbElements(self):
2002 return self.mesh.NbElements()
2004 ## Returns the number of 0d elements in the mesh
2005 # @return an integer value
2006 # @ingroup l1_meshinfo
2007 def Nb0DElements(self):
2008 return self.mesh.Nb0DElements()
2010 ## Returns the number of ball discrete elements in the mesh
2011 # @return an integer value
2012 # @ingroup l1_meshinfo
2014 return self.mesh.NbBalls()
2016 ## Returns the number of edges in the mesh
2017 # @return an integer value
2018 # @ingroup l1_meshinfo
2020 return self.mesh.NbEdges()
2022 ## Returns the number of edges with the given order in the mesh
2023 # @param elementOrder the order of elements:
2024 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2025 # @return an integer value
2026 # @ingroup l1_meshinfo
2027 def NbEdgesOfOrder(self, elementOrder):
2028 return self.mesh.NbEdgesOfOrder(elementOrder)
2030 ## Returns the number of faces in the mesh
2031 # @return an integer value
2032 # @ingroup l1_meshinfo
2034 return self.mesh.NbFaces()
2036 ## Returns the number of faces with the given order in the mesh
2037 # @param elementOrder the order of elements:
2038 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2039 # @return an integer value
2040 # @ingroup l1_meshinfo
2041 def NbFacesOfOrder(self, elementOrder):
2042 return self.mesh.NbFacesOfOrder(elementOrder)
2044 ## Returns the number of triangles in the mesh
2045 # @return an integer value
2046 # @ingroup l1_meshinfo
2047 def NbTriangles(self):
2048 return self.mesh.NbTriangles()
2050 ## Returns the number of triangles with the given order in the mesh
2051 # @param elementOrder is the order of elements:
2052 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2053 # @return an integer value
2054 # @ingroup l1_meshinfo
2055 def NbTrianglesOfOrder(self, elementOrder):
2056 return self.mesh.NbTrianglesOfOrder(elementOrder)
2058 ## Returns the number of biquadratic triangles in the mesh
2059 # @return an integer value
2060 # @ingroup l1_meshinfo
2061 def NbBiQuadTriangles(self):
2062 return self.mesh.NbBiQuadTriangles()
2064 ## Returns the number of quadrangles in the mesh
2065 # @return an integer value
2066 # @ingroup l1_meshinfo
2067 def NbQuadrangles(self):
2068 return self.mesh.NbQuadrangles()
2070 ## Returns the number of quadrangles with the given order in the mesh
2071 # @param elementOrder the order of elements:
2072 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2073 # @return an integer value
2074 # @ingroup l1_meshinfo
2075 def NbQuadranglesOfOrder(self, elementOrder):
2076 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2078 ## Returns the number of biquadratic quadrangles in the mesh
2079 # @return an integer value
2080 # @ingroup l1_meshinfo
2081 def NbBiQuadQuadrangles(self):
2082 return self.mesh.NbBiQuadQuadrangles()
2084 ## Returns the number of polygons in the mesh
2085 # @return an integer value
2086 # @ingroup l1_meshinfo
2087 def NbPolygons(self):
2088 return self.mesh.NbPolygons()
2090 ## Returns the number of volumes in the mesh
2091 # @return an integer value
2092 # @ingroup l1_meshinfo
2093 def NbVolumes(self):
2094 return self.mesh.NbVolumes()
2096 ## Returns the number of volumes with the given order in the mesh
2097 # @param elementOrder the order of elements:
2098 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2099 # @return an integer value
2100 # @ingroup l1_meshinfo
2101 def NbVolumesOfOrder(self, elementOrder):
2102 return self.mesh.NbVolumesOfOrder(elementOrder)
2104 ## Returns the number of tetrahedrons in the mesh
2105 # @return an integer value
2106 # @ingroup l1_meshinfo
2108 return self.mesh.NbTetras()
2110 ## Returns the number of tetrahedrons with the given order in the mesh
2111 # @param elementOrder the order of elements:
2112 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2113 # @return an integer value
2114 # @ingroup l1_meshinfo
2115 def NbTetrasOfOrder(self, elementOrder):
2116 return self.mesh.NbTetrasOfOrder(elementOrder)
2118 ## Returns the number of hexahedrons in the mesh
2119 # @return an integer value
2120 # @ingroup l1_meshinfo
2122 return self.mesh.NbHexas()
2124 ## Returns the number of hexahedrons with the given order in the mesh
2125 # @param elementOrder the order of elements:
2126 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2127 # @return an integer value
2128 # @ingroup l1_meshinfo
2129 def NbHexasOfOrder(self, elementOrder):
2130 return self.mesh.NbHexasOfOrder(elementOrder)
2132 ## Returns the number of triquadratic hexahedrons in the mesh
2133 # @return an integer value
2134 # @ingroup l1_meshinfo
2135 def NbTriQuadraticHexas(self):
2136 return self.mesh.NbTriQuadraticHexas()
2138 ## Returns the number of pyramids in the mesh
2139 # @return an integer value
2140 # @ingroup l1_meshinfo
2141 def NbPyramids(self):
2142 return self.mesh.NbPyramids()
2144 ## Returns the number of pyramids with the given order in the mesh
2145 # @param elementOrder the order of elements:
2146 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2147 # @return an integer value
2148 # @ingroup l1_meshinfo
2149 def NbPyramidsOfOrder(self, elementOrder):
2150 return self.mesh.NbPyramidsOfOrder(elementOrder)
2152 ## Returns the number of prisms in the mesh
2153 # @return an integer value
2154 # @ingroup l1_meshinfo
2156 return self.mesh.NbPrisms()
2158 ## Returns the number of prisms with the given order in the mesh
2159 # @param elementOrder the order of elements:
2160 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2161 # @return an integer value
2162 # @ingroup l1_meshinfo
2163 def NbPrismsOfOrder(self, elementOrder):
2164 return self.mesh.NbPrismsOfOrder(elementOrder)
2166 ## Returns the number of hexagonal prisms in the mesh
2167 # @return an integer value
2168 # @ingroup l1_meshinfo
2169 def NbHexagonalPrisms(self):
2170 return self.mesh.NbHexagonalPrisms()
2172 ## Returns the number of polyhedrons in the mesh
2173 # @return an integer value
2174 # @ingroup l1_meshinfo
2175 def NbPolyhedrons(self):
2176 return self.mesh.NbPolyhedrons()
2178 ## Returns the number of submeshes in the mesh
2179 # @return an integer value
2180 # @ingroup l1_meshinfo
2181 def NbSubMesh(self):
2182 return self.mesh.NbSubMesh()
2184 ## Returns the list of mesh elements IDs
2185 # @return the list of integer values
2186 # @ingroup l1_meshinfo
2187 def GetElementsId(self):
2188 return self.mesh.GetElementsId()
2190 ## Returns the list of IDs of mesh elements with the given type
2191 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2192 # @return list of integer values
2193 # @ingroup l1_meshinfo
2194 def GetElementsByType(self, elementType):
2195 return self.mesh.GetElementsByType(elementType)
2197 ## Returns the list of mesh nodes IDs
2198 # @return the list of integer values
2199 # @ingroup l1_meshinfo
2200 def GetNodesId(self):
2201 return self.mesh.GetNodesId()
2203 # Get the information about mesh elements:
2204 # ------------------------------------
2206 ## Returns the type of mesh element
2207 # @return the value from SMESH::ElementType enumeration
2208 # @ingroup l1_meshinfo
2209 def GetElementType(self, id, iselem):
2210 return self.mesh.GetElementType(id, iselem)
2212 ## Returns the geometric type of mesh element
2213 # @return the value from SMESH::EntityType enumeration
2214 # @ingroup l1_meshinfo
2215 def GetElementGeomType(self, id):
2216 return self.mesh.GetElementGeomType(id)
2218 ## Returns the list of submesh elements IDs
2219 # @param Shape a geom object(sub-shape) IOR
2220 # Shape must be the sub-shape of a ShapeToMesh()
2221 # @return the list of integer values
2222 # @ingroup l1_meshinfo
2223 def GetSubMeshElementsId(self, Shape):
2224 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2225 ShapeID = Shape.GetSubShapeIndices()[0]
2228 return self.mesh.GetSubMeshElementsId(ShapeID)
2230 ## Returns the list of submesh nodes IDs
2231 # @param Shape a geom object(sub-shape) IOR
2232 # Shape must be the sub-shape of a ShapeToMesh()
2233 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2234 # @return the list of integer values
2235 # @ingroup l1_meshinfo
2236 def GetSubMeshNodesId(self, Shape, all):
2237 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2238 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2241 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2243 ## Returns type of elements on given shape
2244 # @param Shape a geom object(sub-shape) IOR
2245 # Shape must be a sub-shape of a ShapeToMesh()
2246 # @return element type
2247 # @ingroup l1_meshinfo
2248 def GetSubMeshElementType(self, Shape):
2249 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2250 ShapeID = Shape.GetSubShapeIndices()[0]
2253 return self.mesh.GetSubMeshElementType(ShapeID)
2255 ## Gets the mesh description
2256 # @return string value
2257 # @ingroup l1_meshinfo
2259 return self.mesh.Dump()
2262 # Get the information about nodes and elements of a mesh by its IDs:
2263 # -----------------------------------------------------------
2265 ## Gets XYZ coordinates of a node
2266 # \n If there is no nodes for the given ID - returns an empty list
2267 # @return a list of double precision values
2268 # @ingroup l1_meshinfo
2269 def GetNodeXYZ(self, id):
2270 return self.mesh.GetNodeXYZ(id)
2272 ## Returns list of IDs of inverse elements for the given node
2273 # \n If there is no node for the given ID - returns an empty list
2274 # @return a list of integer values
2275 # @ingroup l1_meshinfo
2276 def GetNodeInverseElements(self, id):
2277 return self.mesh.GetNodeInverseElements(id)
2279 ## @brief Returns the position of a node on the shape
2280 # @return SMESH::NodePosition
2281 # @ingroup l1_meshinfo
2282 def GetNodePosition(self,NodeID):
2283 return self.mesh.GetNodePosition(NodeID)
2285 ## @brief Returns the position of an element on the shape
2286 # @return SMESH::ElementPosition
2287 # @ingroup l1_meshinfo
2288 def GetElementPosition(self,ElemID):
2289 return self.mesh.GetElementPosition(ElemID)
2291 ## If the given element is a node, returns the ID of shape
2292 # \n If there is no node for the given ID - returns -1
2293 # @return an integer value
2294 # @ingroup l1_meshinfo
2295 def GetShapeID(self, id):
2296 return self.mesh.GetShapeID(id)
2298 ## Returns the ID of the result shape after
2299 # FindShape() from SMESH_MeshEditor for the given element
2300 # \n If there is no element for the given ID - returns -1
2301 # @return an integer value
2302 # @ingroup l1_meshinfo
2303 def GetShapeIDForElem(self,id):
2304 return self.mesh.GetShapeIDForElem(id)
2306 ## Returns the number of nodes for the given element
2307 # \n If there is no element for the given ID - returns -1
2308 # @return an integer value
2309 # @ingroup l1_meshinfo
2310 def GetElemNbNodes(self, id):
2311 return self.mesh.GetElemNbNodes(id)
2313 ## Returns the node ID the given (zero based) index for the given element
2314 # \n If there is no element for the given ID - returns -1
2315 # \n If there is no node for the given index - returns -2
2316 # @return an integer value
2317 # @ingroup l1_meshinfo
2318 def GetElemNode(self, id, index):
2319 return self.mesh.GetElemNode(id, index)
2321 ## Returns the IDs of nodes of the given element
2322 # @return a list of integer values
2323 # @ingroup l1_meshinfo
2324 def GetElemNodes(self, id):
2325 return self.mesh.GetElemNodes(id)
2327 ## Returns true if the given node is the medium node in the given quadratic element
2328 # @ingroup l1_meshinfo
2329 def IsMediumNode(self, elementID, nodeID):
2330 return self.mesh.IsMediumNode(elementID, nodeID)
2332 ## Returns true if the given node is the medium node in one of quadratic elements
2333 # @ingroup l1_meshinfo
2334 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2335 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2337 ## Returns the number of edges for the given element
2338 # @ingroup l1_meshinfo
2339 def ElemNbEdges(self, id):
2340 return self.mesh.ElemNbEdges(id)
2342 ## Returns the number of faces for the given element
2343 # @ingroup l1_meshinfo
2344 def ElemNbFaces(self, id):
2345 return self.mesh.ElemNbFaces(id)
2347 ## Returns nodes of given face (counted from zero) for given volumic element.
2348 # @ingroup l1_meshinfo
2349 def GetElemFaceNodes(self,elemId, faceIndex):
2350 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2352 ## Returns an element based on all given nodes.
2353 # @ingroup l1_meshinfo
2354 def FindElementByNodes(self,nodes):
2355 return self.mesh.FindElementByNodes(nodes)
2357 ## Returns true if the given element is a polygon
2358 # @ingroup l1_meshinfo
2359 def IsPoly(self, id):
2360 return self.mesh.IsPoly(id)
2362 ## Returns true if the given element is quadratic
2363 # @ingroup l1_meshinfo
2364 def IsQuadratic(self, id):
2365 return self.mesh.IsQuadratic(id)
2367 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2368 # @ingroup l1_meshinfo
2369 def GetBallDiameter(self, id):
2370 return self.mesh.GetBallDiameter(id)
2372 ## Returns XYZ coordinates of the barycenter of the given element
2373 # \n If there is no element for the given ID - returns an empty list
2374 # @return a list of three double values
2375 # @ingroup l1_meshinfo
2376 def BaryCenter(self, id):
2377 return self.mesh.BaryCenter(id)
2379 ## Passes mesh elements through the given filter and return IDs of fitting elements
2380 # @param theFilter SMESH_Filter
2381 # @return a list of ids
2382 # @ingroup l1_controls
2383 def GetIdsFromFilter(self, theFilter):
2384 theFilter.SetMesh( self.mesh )
2385 return theFilter.GetIDs()
2387 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2388 # Returns a list of special structures (borders).
2389 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2390 # @ingroup l1_controls
2391 def GetFreeBorders(self):
2392 aFilterMgr = self.smeshpyD.CreateFilterManager()
2393 aPredicate = aFilterMgr.CreateFreeEdges()
2394 aPredicate.SetMesh(self.mesh)
2395 aBorders = aPredicate.GetBorders()
2396 aFilterMgr.UnRegister()
2400 # Get mesh measurements information:
2401 # ------------------------------------
2403 ## Get minimum distance between two nodes, elements or distance to the origin
2404 # @param id1 first node/element id
2405 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2406 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2407 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2408 # @return minimum distance value
2409 # @sa GetMinDistance()
2410 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2411 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2412 return aMeasure.value
2414 ## Get measure structure specifying minimum distance data between two objects
2415 # @param id1 first node/element id
2416 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2417 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2418 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2419 # @return Measure structure
2421 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2423 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2425 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2428 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2430 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2435 aMeasurements = self.smeshpyD.CreateMeasurements()
2436 aMeasure = aMeasurements.MinDistance(id1, id2)
2437 aMeasurements.UnRegister()
2440 ## Get bounding box of the specified object(s)
2441 # @param objects single source object or list of source objects or list of nodes/elements IDs
2442 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2443 # @c False specifies that @a objects are nodes
2444 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2445 # @sa GetBoundingBox()
2446 def BoundingBox(self, objects=None, isElem=False):
2447 result = self.GetBoundingBox(objects, isElem)
2451 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2454 ## Get measure structure specifying bounding box data of the specified object(s)
2455 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2456 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2457 # @c False specifies that @a objects are nodes
2458 # @return Measure structure
2460 def GetBoundingBox(self, IDs=None, isElem=False):
2463 elif isinstance(IDs, tuple):
2465 if not isinstance(IDs, list):
2467 if len(IDs) > 0 and isinstance(IDs[0], int):
2471 if isinstance(o, Mesh):
2472 srclist.append(o.mesh)
2473 elif hasattr(o, "_narrow"):
2474 src = o._narrow(SMESH.SMESH_IDSource)
2475 if src: srclist.append(src)
2477 elif isinstance(o, list):
2479 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2481 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2484 aMeasurements = self.smeshpyD.CreateMeasurements()
2485 aMeasure = aMeasurements.BoundingBox(srclist)
2486 aMeasurements.UnRegister()
2489 # Mesh edition (SMESH_MeshEditor functionality):
2490 # ---------------------------------------------
2492 ## Removes the elements from the mesh by ids
2493 # @param IDsOfElements is a list of ids of elements to remove
2494 # @return True or False
2495 # @ingroup l2_modif_del
2496 def RemoveElements(self, IDsOfElements):
2497 return self.editor.RemoveElements(IDsOfElements)
2499 ## Removes nodes from mesh by ids
2500 # @param IDsOfNodes is a list of ids of nodes to remove
2501 # @return True or False
2502 # @ingroup l2_modif_del
2503 def RemoveNodes(self, IDsOfNodes):
2504 return self.editor.RemoveNodes(IDsOfNodes)
2506 ## Removes all orphan (free) nodes from mesh
2507 # @return number of the removed nodes
2508 # @ingroup l2_modif_del
2509 def RemoveOrphanNodes(self):
2510 return self.editor.RemoveOrphanNodes()
2512 ## Add a node to the mesh by coordinates
2513 # @return Id of the new node
2514 # @ingroup l2_modif_add
2515 def AddNode(self, x, y, z):
2516 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2517 if hasVars: self.mesh.SetParameters(Parameters)
2518 return self.editor.AddNode( x, y, z)
2520 ## Creates a 0D element on a node with given number.
2521 # @param IDOfNode the ID of node for creation of the element.
2522 # @return the Id of the new 0D element
2523 # @ingroup l2_modif_add
2524 def Add0DElement(self, IDOfNode):
2525 return self.editor.Add0DElement(IDOfNode)
2527 ## Create 0D elements on all nodes of the given elements except those
2528 # nodes on which a 0D element already exists.
2529 # @param theObject an object on whose nodes 0D elements will be created.
2530 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2531 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2532 # @param theGroupName optional name of a group to add 0D elements created
2533 # and/or found on nodes of \a theObject.
2534 # @return an object (a new group or a temporary SMESH_IDSource) holding
2535 # IDs of new and/or found 0D elements. IDs of 0D elements
2536 # can be retrieved from the returned object by calling GetIDs()
2537 # @ingroup l2_modif_add
2538 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2539 if isinstance( theObject, Mesh ):
2540 theObject = theObject.GetMesh()
2541 if isinstance( theObject, list ):
2542 theObject = self.GetIDSource( theObject, SMESH.ALL )
2543 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2545 ## Creates a ball element on a node with given ID.
2546 # @param IDOfNode the ID of node for creation of the element.
2547 # @param diameter the bal diameter.
2548 # @return the Id of the new ball element
2549 # @ingroup l2_modif_add
2550 def AddBall(self, IDOfNode, diameter):
2551 return self.editor.AddBall( IDOfNode, diameter )
2553 ## Creates a linear or quadratic edge (this is determined
2554 # by the number of given nodes).
2555 # @param IDsOfNodes the list of node IDs for creation of the element.
2556 # The order of nodes in this list should correspond to the description
2557 # of MED. \n This description is located by the following link:
2558 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2559 # @return the Id of the new edge
2560 # @ingroup l2_modif_add
2561 def AddEdge(self, IDsOfNodes):
2562 return self.editor.AddEdge(IDsOfNodes)
2564 ## Creates a linear or quadratic face (this is determined
2565 # by the number of given nodes).
2566 # @param IDsOfNodes the list of node IDs for creation of the element.
2567 # The order of nodes in this list should correspond to the description
2568 # of MED. \n This description is located by the following link:
2569 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2570 # @return the Id of the new face
2571 # @ingroup l2_modif_add
2572 def AddFace(self, IDsOfNodes):
2573 return self.editor.AddFace(IDsOfNodes)
2575 ## Adds a polygonal face to the mesh by the list of node IDs
2576 # @param IdsOfNodes the list of node IDs for creation of the element.
2577 # @return the Id of the new face
2578 # @ingroup l2_modif_add
2579 def AddPolygonalFace(self, IdsOfNodes):
2580 return self.editor.AddPolygonalFace(IdsOfNodes)
2582 ## Creates both simple and quadratic volume (this is determined
2583 # by the number of given nodes).
2584 # @param IDsOfNodes the list of node IDs for creation of the element.
2585 # The order of nodes in this list should correspond to the description
2586 # of MED. \n This description is located by the following link:
2587 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2588 # @return the Id of the new volumic element
2589 # @ingroup l2_modif_add
2590 def AddVolume(self, IDsOfNodes):
2591 return self.editor.AddVolume(IDsOfNodes)
2593 ## Creates a volume of many faces, giving nodes for each face.
2594 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2595 # @param Quantities the list of integer values, Quantities[i]
2596 # gives the quantity of nodes in face number i.
2597 # @return the Id of the new volumic element
2598 # @ingroup l2_modif_add
2599 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2600 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2602 ## Creates a volume of many faces, giving the IDs of the existing faces.
2603 # @param IdsOfFaces the list of face IDs for volume creation.
2605 # Note: The created volume will refer only to the nodes
2606 # of the given faces, not to the faces themselves.
2607 # @return the Id of the new volumic element
2608 # @ingroup l2_modif_add
2609 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2610 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2613 ## @brief Binds a node to a vertex
2614 # @param NodeID a node ID
2615 # @param Vertex a vertex or vertex ID
2616 # @return True if succeed else raises an exception
2617 # @ingroup l2_modif_add
2618 def SetNodeOnVertex(self, NodeID, Vertex):
2619 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
2620 VertexID = Vertex.GetSubShapeIndices()[0]
2624 self.editor.SetNodeOnVertex(NodeID, VertexID)
2625 except SALOME.SALOME_Exception, inst:
2626 raise ValueError, inst.details.text
2630 ## @brief Stores the node position on an edge
2631 # @param NodeID a node ID
2632 # @param Edge an edge or edge ID
2633 # @param paramOnEdge a parameter on the edge where the node is located
2634 # @return True if succeed else raises an exception
2635 # @ingroup l2_modif_add
2636 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2637 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
2638 EdgeID = Edge.GetSubShapeIndices()[0]
2642 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2643 except SALOME.SALOME_Exception, inst:
2644 raise ValueError, inst.details.text
2647 ## @brief Stores node position on a face
2648 # @param NodeID a node ID
2649 # @param Face a face or face ID
2650 # @param u U parameter on the face where the node is located
2651 # @param v V parameter on the face where the node is located
2652 # @return True if succeed else raises an exception
2653 # @ingroup l2_modif_add
2654 def SetNodeOnFace(self, NodeID, Face, u, v):
2655 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
2656 FaceID = Face.GetSubShapeIndices()[0]
2660 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2661 except SALOME.SALOME_Exception, inst:
2662 raise ValueError, inst.details.text
2665 ## @brief Binds a node to a solid
2666 # @param NodeID a node ID
2667 # @param Solid a solid or solid ID
2668 # @return True if succeed else raises an exception
2669 # @ingroup l2_modif_add
2670 def SetNodeInVolume(self, NodeID, Solid):
2671 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
2672 SolidID = Solid.GetSubShapeIndices()[0]
2676 self.editor.SetNodeInVolume(NodeID, SolidID)
2677 except SALOME.SALOME_Exception, inst:
2678 raise ValueError, inst.details.text
2681 ## @brief Bind an element to a shape
2682 # @param ElementID an element ID
2683 # @param Shape a shape or shape ID
2684 # @return True if succeed else raises an exception
2685 # @ingroup l2_modif_add
2686 def SetMeshElementOnShape(self, ElementID, Shape):
2687 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2688 ShapeID = Shape.GetSubShapeIndices()[0]
2692 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2693 except SALOME.SALOME_Exception, inst:
2694 raise ValueError, inst.details.text
2698 ## Moves the node with the given id
2699 # @param NodeID the id of the node
2700 # @param x a new X coordinate
2701 # @param y a new Y coordinate
2702 # @param z a new Z coordinate
2703 # @return True if succeed else False
2704 # @ingroup l2_modif_movenode
2705 def MoveNode(self, NodeID, x, y, z):
2706 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2707 if hasVars: self.mesh.SetParameters(Parameters)
2708 return self.editor.MoveNode(NodeID, x, y, z)
2710 ## Finds the node closest to a point and moves it to a point location
2711 # @param x the X coordinate of a point
2712 # @param y the Y coordinate of a point
2713 # @param z the Z coordinate of a point
2714 # @param NodeID if specified (>0), the node with this ID is moved,
2715 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2716 # @return the ID of a node
2717 # @ingroup l2_modif_throughp
2718 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2719 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2720 if hasVars: self.mesh.SetParameters(Parameters)
2721 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2723 ## Finds the node closest to a point
2724 # @param x the X coordinate of a point
2725 # @param y the Y coordinate of a point
2726 # @param z the Z coordinate of a point
2727 # @return the ID of a node
2728 # @ingroup l2_modif_throughp
2729 def FindNodeClosestTo(self, x, y, z):
2730 #preview = self.mesh.GetMeshEditPreviewer()
2731 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2732 return self.editor.FindNodeClosestTo(x, y, z)
2734 ## Finds the elements where a point lays IN or ON
2735 # @param x the X coordinate of a point
2736 # @param y the Y coordinate of a point
2737 # @param z the Z coordinate of a point
2738 # @param elementType type of elements to find (SMESH.ALL type
2739 # means elements of any type excluding nodes, discrete and 0D elements)
2740 # @param meshPart a part of mesh (group, sub-mesh) to search within
2741 # @return list of IDs of found elements
2742 # @ingroup l2_modif_throughp
2743 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2745 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2747 return self.editor.FindElementsByPoint(x, y, z, elementType)
2749 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2750 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2751 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2753 def GetPointState(self, x, y, z):
2754 return self.editor.GetPointState(x, y, z)
2756 ## Finds the node closest to a point and moves it to a point location
2757 # @param x the X coordinate of a point
2758 # @param y the Y coordinate of a point
2759 # @param z the Z coordinate of a point
2760 # @return the ID of a moved node
2761 # @ingroup l2_modif_throughp
2762 def MeshToPassThroughAPoint(self, x, y, z):
2763 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2765 ## Replaces two neighbour triangles sharing Node1-Node2 link
2766 # with the triangles built on the same 4 nodes but having other common link.
2767 # @param NodeID1 the ID of the first node
2768 # @param NodeID2 the ID of the second node
2769 # @return false if proper faces were not found
2770 # @ingroup l2_modif_invdiag
2771 def InverseDiag(self, NodeID1, NodeID2):
2772 return self.editor.InverseDiag(NodeID1, NodeID2)
2774 ## Replaces two neighbour triangles sharing Node1-Node2 link
2775 # with a quadrangle built on the same 4 nodes.
2776 # @param NodeID1 the ID of the first node
2777 # @param NodeID2 the ID of the second node
2778 # @return false if proper faces were not found
2779 # @ingroup l2_modif_unitetri
2780 def DeleteDiag(self, NodeID1, NodeID2):
2781 return self.editor.DeleteDiag(NodeID1, NodeID2)
2783 ## Reorients elements by ids
2784 # @param IDsOfElements if undefined reorients all mesh elements
2785 # @return True if succeed else False
2786 # @ingroup l2_modif_changori
2787 def Reorient(self, IDsOfElements=None):
2788 if IDsOfElements == None:
2789 IDsOfElements = self.GetElementsId()
2790 return self.editor.Reorient(IDsOfElements)
2792 ## Reorients all elements of the object
2793 # @param theObject mesh, submesh or group
2794 # @return True if succeed else False
2795 # @ingroup l2_modif_changori
2796 def ReorientObject(self, theObject):
2797 if ( isinstance( theObject, Mesh )):
2798 theObject = theObject.GetMesh()
2799 return self.editor.ReorientObject(theObject)
2801 ## Reorient faces contained in \a the2DObject.
2802 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2803 # @param theDirection is a desired direction of normal of \a theFace.
2804 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2805 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2806 # compared with theDirection. It can be either ID of face or a point
2807 # by which the face will be found. The point can be given as either
2808 # a GEOM vertex or a list of point coordinates.
2809 # @return number of reoriented faces
2810 # @ingroup l2_modif_changori
2811 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2813 if isinstance( the2DObject, Mesh ):
2814 the2DObject = the2DObject.GetMesh()
2815 if isinstance( the2DObject, list ):
2816 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2817 # check theDirection
2818 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
2819 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2820 if isinstance( theDirection, list ):
2821 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2822 # prepare theFace and thePoint
2823 theFace = theFaceOrPoint
2824 thePoint = PointStruct(0,0,0)
2825 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
2826 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2828 if isinstance( theFaceOrPoint, list ):
2829 thePoint = PointStruct( *theFaceOrPoint )
2831 if isinstance( theFaceOrPoint, PointStruct ):
2832 thePoint = theFaceOrPoint
2834 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2836 ## Fuses the neighbouring triangles into quadrangles.
2837 # @param IDsOfElements The triangles to be fused,
2838 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2839 # choose a neighbour to fuse with.
2840 # @param MaxAngle is the maximum angle between element normals at which the fusion
2841 # is still performed; theMaxAngle is mesured in radians.
2842 # Also it could be a name of variable which defines angle in degrees.
2843 # @return TRUE in case of success, FALSE otherwise.
2844 # @ingroup l2_modif_unitetri
2845 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2846 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2847 self.mesh.SetParameters(Parameters)
2848 if not IDsOfElements:
2849 IDsOfElements = self.GetElementsId()
2850 Functor = self.smeshpyD.GetFunctor(theCriterion)
2851 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2853 ## Fuses the neighbouring triangles of the object into quadrangles
2854 # @param theObject is mesh, submesh or group
2855 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2856 # choose a neighbour to fuse with.
2857 # @param MaxAngle a max angle between element normals at which the fusion
2858 # is still performed; theMaxAngle is mesured in radians.
2859 # @return TRUE in case of success, FALSE otherwise.
2860 # @ingroup l2_modif_unitetri
2861 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2862 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2863 self.mesh.SetParameters(Parameters)
2864 if isinstance( theObject, Mesh ):
2865 theObject = theObject.GetMesh()
2866 Functor = self.smeshpyD.GetFunctor(theCriterion)
2867 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2869 ## Splits quadrangles into triangles.
2870 # @param IDsOfElements the faces to be splitted.
2871 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2872 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2873 # value, then quadrangles will be split by the smallest diagonal.
2874 # @return TRUE in case of success, FALSE otherwise.
2875 # @ingroup l2_modif_cutquadr
2876 def QuadToTri (self, IDsOfElements, theCriterion = None):
2877 if IDsOfElements == []:
2878 IDsOfElements = self.GetElementsId()
2879 if theCriterion is None:
2880 theCriterion = FT_MaxElementLength2D
2881 Functor = self.smeshpyD.GetFunctor(theCriterion)
2882 return self.editor.QuadToTri(IDsOfElements, Functor)
2884 ## Splits quadrangles into triangles.
2885 # @param theObject the object from which the list of elements is taken,
2886 # this is mesh, submesh or group
2887 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2888 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2889 # value, then quadrangles will be split by the smallest diagonal.
2890 # @return TRUE in case of success, FALSE otherwise.
2891 # @ingroup l2_modif_cutquadr
2892 def QuadToTriObject (self, theObject, theCriterion = None):
2893 if ( isinstance( theObject, Mesh )):
2894 theObject = theObject.GetMesh()
2895 if theCriterion is None:
2896 theCriterion = FT_MaxElementLength2D
2897 Functor = self.smeshpyD.GetFunctor(theCriterion)
2898 return self.editor.QuadToTriObject(theObject, Functor)
2900 ## Splits each of given quadrangles into 4 triangles. A node is added at the center of
2902 # @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
2903 # group or a list of face IDs. By default all quadrangles are split
2904 # @ingroup l2_modif_cutquadr
2905 def QuadTo4Tri (self, theElements=[]):
2906 if isinstance( theElements, Mesh ):
2907 theElements = theElements.mesh
2908 elif not theElements:
2909 theElements = self.mesh
2910 elif isinstance( theElements, list ):
2911 theElements = self.GetIDSource( theElements, SMESH.FACE )
2912 return self.editor.QuadTo4Tri( theElements )
2914 ## Splits quadrangles into triangles.
2915 # @param IDsOfElements the faces to be splitted
2916 # @param Diag13 is used to choose a diagonal for splitting.
2917 # @return TRUE in case of success, FALSE otherwise.
2918 # @ingroup l2_modif_cutquadr
2919 def SplitQuad (self, IDsOfElements, Diag13):
2920 if IDsOfElements == []:
2921 IDsOfElements = self.GetElementsId()
2922 return self.editor.SplitQuad(IDsOfElements, Diag13)
2924 ## Splits quadrangles into triangles.
2925 # @param theObject the object from which the list of elements is taken,
2926 # this is mesh, submesh or group
2927 # @param Diag13 is used to choose a diagonal for splitting.
2928 # @return TRUE in case of success, FALSE otherwise.
2929 # @ingroup l2_modif_cutquadr
2930 def SplitQuadObject (self, theObject, Diag13):
2931 if ( isinstance( theObject, Mesh )):
2932 theObject = theObject.GetMesh()
2933 return self.editor.SplitQuadObject(theObject, Diag13)
2935 ## Finds a better splitting of the given quadrangle.
2936 # @param IDOfQuad the ID of the quadrangle to be splitted.
2937 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2938 # choose a diagonal for splitting.
2939 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2940 # diagonal is better, 0 if error occurs.
2941 # @ingroup l2_modif_cutquadr
2942 def BestSplit (self, IDOfQuad, theCriterion):
2943 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2945 ## Splits volumic elements into tetrahedrons
2946 # @param elemIDs either list of elements or mesh or group or submesh
2947 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2948 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2949 # @ingroup l2_modif_cutquadr
2950 def SplitVolumesIntoTetra(self, elemIDs, method=smeshBuilder.Hex_5Tet ):
2951 if isinstance( elemIDs, Mesh ):
2952 elemIDs = elemIDs.GetMesh()
2953 if ( isinstance( elemIDs, list )):
2954 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2955 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2957 ## Splits quadrangle faces near triangular facets of volumes
2959 # @ingroup l1_auxiliary
2960 def SplitQuadsNearTriangularFacets(self):
2961 faces_array = self.GetElementsByType(SMESH.FACE)
2962 for face_id in faces_array:
2963 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2964 quad_nodes = self.mesh.GetElemNodes(face_id)
2965 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2966 isVolumeFound = False
2967 for node1_elem in node1_elems:
2968 if not isVolumeFound:
2969 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2970 nb_nodes = self.GetElemNbNodes(node1_elem)
2971 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2972 volume_elem = node1_elem
2973 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2974 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2975 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2976 isVolumeFound = True
2977 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2978 self.SplitQuad([face_id], False) # diagonal 2-4
2979 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2980 isVolumeFound = True
2981 self.SplitQuad([face_id], True) # diagonal 1-3
2982 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2983 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2984 isVolumeFound = True
2985 self.SplitQuad([face_id], True) # diagonal 1-3
2987 ## @brief Splits hexahedrons into tetrahedrons.
2989 # This operation uses pattern mapping functionality for splitting.
2990 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2991 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2992 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2993 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2994 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2995 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2996 # @return TRUE in case of success, FALSE otherwise.
2997 # @ingroup l1_auxiliary
2998 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2999 # Pattern: 5.---------.6
3004 # (0,0,1) 4.---------.7 * |
3011 # (0,0,0) 0.---------.3
3012 pattern_tetra = "!!! Nb of points: \n 8 \n\
3022 !!! Indices of points of 6 tetras: \n\
3030 pattern = self.smeshpyD.GetPattern()
3031 isDone = pattern.LoadFromFile(pattern_tetra)
3033 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3036 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3037 isDone = pattern.MakeMesh(self.mesh, False, False)
3038 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3040 # split quafrangle faces near triangular facets of volumes
3041 self.SplitQuadsNearTriangularFacets()
3045 ## @brief Split hexahedrons into prisms.
3047 # Uses the pattern mapping functionality for splitting.
3048 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
3049 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
3050 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
3051 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
3052 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
3053 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
3054 # @return TRUE in case of success, FALSE otherwise.
3055 # @ingroup l1_auxiliary
3056 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3057 # Pattern: 5.---------.6
3062 # (0,0,1) 4.---------.7 |
3069 # (0,0,0) 0.---------.3
3070 pattern_prism = "!!! Nb of points: \n 8 \n\
3080 !!! Indices of points of 2 prisms: \n\
3084 pattern = self.smeshpyD.GetPattern()
3085 isDone = pattern.LoadFromFile(pattern_prism)
3087 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3090 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3091 isDone = pattern.MakeMesh(self.mesh, False, False)
3092 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3094 # Splits quafrangle faces near triangular facets of volumes
3095 self.SplitQuadsNearTriangularFacets()
3099 ## Smoothes elements
3100 # @param IDsOfElements the list if ids of elements to smooth
3101 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3102 # Note that nodes built on edges and boundary nodes are always fixed.
3103 # @param MaxNbOfIterations the maximum number of iterations
3104 # @param MaxAspectRatio varies in range [1.0, inf]
3105 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3106 # @return TRUE in case of success, FALSE otherwise.
3107 # @ingroup l2_modif_smooth
3108 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3109 MaxNbOfIterations, MaxAspectRatio, Method):
3110 if IDsOfElements == []:
3111 IDsOfElements = self.GetElementsId()
3112 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3113 self.mesh.SetParameters(Parameters)
3114 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3115 MaxNbOfIterations, MaxAspectRatio, Method)
3117 ## Smoothes elements which belong to the given object
3118 # @param theObject the object to smooth
3119 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3120 # Note that nodes built on edges and boundary nodes are always fixed.
3121 # @param MaxNbOfIterations the maximum number of iterations
3122 # @param MaxAspectRatio varies in range [1.0, inf]
3123 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3124 # @return TRUE in case of success, FALSE otherwise.
3125 # @ingroup l2_modif_smooth
3126 def SmoothObject(self, theObject, IDsOfFixedNodes,
3127 MaxNbOfIterations, MaxAspectRatio, Method):
3128 if ( isinstance( theObject, Mesh )):
3129 theObject = theObject.GetMesh()
3130 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3131 MaxNbOfIterations, MaxAspectRatio, Method)
3133 ## Parametrically smoothes the given elements
3134 # @param IDsOfElements the list if ids of elements to smooth
3135 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3136 # Note that nodes built on edges and boundary nodes are always fixed.
3137 # @param MaxNbOfIterations the maximum number of iterations
3138 # @param MaxAspectRatio varies in range [1.0, inf]
3139 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3140 # @return TRUE in case of success, FALSE otherwise.
3141 # @ingroup l2_modif_smooth
3142 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3143 MaxNbOfIterations, MaxAspectRatio, Method):
3144 if IDsOfElements == []:
3145 IDsOfElements = self.GetElementsId()
3146 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3147 self.mesh.SetParameters(Parameters)
3148 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3149 MaxNbOfIterations, MaxAspectRatio, Method)
3151 ## Parametrically smoothes the elements which belong to the given object
3152 # @param theObject the object to smooth
3153 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3154 # Note that nodes built on edges and boundary nodes are always fixed.
3155 # @param MaxNbOfIterations the maximum number of iterations
3156 # @param MaxAspectRatio varies in range [1.0, inf]
3157 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3158 # @return TRUE in case of success, FALSE otherwise.
3159 # @ingroup l2_modif_smooth
3160 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3161 MaxNbOfIterations, MaxAspectRatio, Method):
3162 if ( isinstance( theObject, Mesh )):
3163 theObject = theObject.GetMesh()
3164 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3165 MaxNbOfIterations, MaxAspectRatio, Method)
3167 ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3168 # them with quadratic with the same id.
3169 # @param theForce3d new node creation method:
3170 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3171 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3172 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3173 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3174 # @ingroup l2_modif_tofromqu
3175 def ConvertToQuadratic(self, theForce3d, theSubMesh=None, theToBiQuad=False):
3176 if isinstance( theSubMesh, Mesh ):
3177 theSubMesh = theSubMesh.mesh
3179 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3182 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3184 self.editor.ConvertToQuadratic(theForce3d)
3185 error = self.editor.GetLastError()
3186 if error and error.comment:
3189 ## Converts the mesh from quadratic to ordinary,
3190 # deletes old quadratic elements, \n replacing
3191 # them with ordinary mesh elements with the same id.
3192 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3193 # @ingroup l2_modif_tofromqu
3194 def ConvertFromQuadratic(self, theSubMesh=None):
3196 self.editor.ConvertFromQuadraticObject(theSubMesh)
3198 return self.editor.ConvertFromQuadratic()
3200 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3201 # @return TRUE if operation has been completed successfully, FALSE otherwise
3202 # @ingroup l2_modif_edit
3203 def Make2DMeshFrom3D(self):
3204 return self.editor. Make2DMeshFrom3D()
3206 ## Creates missing boundary elements
3207 # @param elements - elements whose boundary is to be checked:
3208 # mesh, group, sub-mesh or list of elements
3209 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3210 # @param dimension - defines type of boundary elements to create:
3211 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3212 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3213 # @param groupName - a name of group to store created boundary elements in,
3214 # "" means not to create the group
3215 # @param meshName - a name of new mesh to store created boundary elements in,
3216 # "" means not to create the new mesh
3217 # @param toCopyElements - if true, the checked elements will be copied into
3218 # the new mesh else only boundary elements will be copied into the new mesh
3219 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3220 # boundary elements will be copied into the new mesh
3221 # @return tuple (mesh, group) where bondary elements were added to
3222 # @ingroup l2_modif_edit
3223 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3224 toCopyElements=False, toCopyExistingBondary=False):
3225 if isinstance( elements, Mesh ):
3226 elements = elements.GetMesh()
3227 if ( isinstance( elements, list )):
3228 elemType = SMESH.ALL
3229 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3230 elements = self.editor.MakeIDSource(elements, elemType)
3231 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3232 toCopyElements,toCopyExistingBondary)
3233 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3237 # @brief Creates missing boundary elements around either the whole mesh or
3238 # groups of 2D elements
3239 # @param dimension - defines type of boundary elements to create
3240 # @param groupName - a name of group to store all boundary elements in,
3241 # "" means not to create the group
3242 # @param meshName - a name of a new mesh, which is a copy of the initial
3243 # mesh + created boundary elements; "" means not to create the new mesh
3244 # @param toCopyAll - if true, the whole initial mesh will be copied into
3245 # the new mesh else only boundary elements will be copied into the new mesh
3246 # @param groups - groups of 2D elements to make boundary around
3247 # @retval tuple( long, mesh, groups )
3248 # long - number of added boundary elements
3249 # mesh - the mesh where elements were added to
3250 # group - the group of boundary elements or None
3252 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3253 toCopyAll=False, groups=[]):
3254 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3256 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3257 return nb, mesh, group
3259 ## Renumber mesh nodes
3260 # @ingroup l2_modif_renumber
3261 def RenumberNodes(self):
3262 self.editor.RenumberNodes()
3264 ## Renumber mesh elements
3265 # @ingroup l2_modif_renumber
3266 def RenumberElements(self):
3267 self.editor.RenumberElements()
3269 ## Generates new elements by rotation of the elements around the axis
3270 # @param IDsOfElements the list of ids of elements to sweep
3271 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3272 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3273 # @param NbOfSteps the number of steps
3274 # @param Tolerance tolerance
3275 # @param MakeGroups forces the generation of new groups from existing ones
3276 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3277 # of all steps, else - size of each step
3278 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3279 # @ingroup l2_modif_extrurev
3280 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3281 MakeGroups=False, TotalAngle=False):
3282 if IDsOfElements == []:
3283 IDsOfElements = self.GetElementsId()
3284 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3285 Axis = self.smeshpyD.GetAxisStruct(Axis)
3286 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3287 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3288 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3289 self.mesh.SetParameters(Parameters)
3290 if TotalAngle and NbOfSteps:
3291 AngleInRadians /= NbOfSteps
3293 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3294 AngleInRadians, NbOfSteps, Tolerance)
3295 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3298 ## Generates new elements by rotation of the elements of object around the axis
3299 # @param theObject object which elements should be sweeped.
3300 # It can be a mesh, a sub mesh or a group.
3301 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3302 # @param AngleInRadians the angle of Rotation
3303 # @param NbOfSteps number of steps
3304 # @param Tolerance tolerance
3305 # @param MakeGroups forces the generation of new groups from existing ones
3306 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3307 # of all steps, else - size of each step
3308 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3309 # @ingroup l2_modif_extrurev
3310 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3311 MakeGroups=False, TotalAngle=False):
3312 if ( isinstance( theObject, Mesh )):
3313 theObject = theObject.GetMesh()
3314 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3315 Axis = self.smeshpyD.GetAxisStruct(Axis)
3316 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3317 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3318 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3319 self.mesh.SetParameters(Parameters)
3320 if TotalAngle and NbOfSteps:
3321 AngleInRadians /= NbOfSteps
3323 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3324 NbOfSteps, Tolerance)
3325 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3328 ## Generates new elements by rotation of the elements of object around the axis
3329 # @param theObject object which elements should be sweeped.
3330 # It can be a mesh, a sub mesh or a group.
3331 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3332 # @param AngleInRadians the angle of Rotation
3333 # @param NbOfSteps number of steps
3334 # @param Tolerance tolerance
3335 # @param MakeGroups forces the generation of new groups from existing ones
3336 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3337 # of all steps, else - size of each step
3338 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3339 # @ingroup l2_modif_extrurev
3340 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3341 MakeGroups=False, TotalAngle=False):
3342 if ( isinstance( theObject, Mesh )):
3343 theObject = theObject.GetMesh()
3344 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3345 Axis = self.smeshpyD.GetAxisStruct(Axis)
3346 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3347 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3348 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3349 self.mesh.SetParameters(Parameters)
3350 if TotalAngle and NbOfSteps:
3351 AngleInRadians /= NbOfSteps
3353 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3354 NbOfSteps, Tolerance)
3355 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3358 ## Generates new elements by rotation of the elements of object around the axis
3359 # @param theObject object which elements should be sweeped.
3360 # It can be a mesh, a sub mesh or a group.
3361 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3362 # @param AngleInRadians the angle of Rotation
3363 # @param NbOfSteps number of steps
3364 # @param Tolerance tolerance
3365 # @param MakeGroups forces the generation of new groups from existing ones
3366 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3367 # of all steps, else - size of each step
3368 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3369 # @ingroup l2_modif_extrurev
3370 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3371 MakeGroups=False, TotalAngle=False):
3372 if ( isinstance( theObject, Mesh )):
3373 theObject = theObject.GetMesh()
3374 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3375 Axis = self.smeshpyD.GetAxisStruct(Axis)
3376 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3377 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3378 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3379 self.mesh.SetParameters(Parameters)
3380 if TotalAngle and NbOfSteps:
3381 AngleInRadians /= NbOfSteps
3383 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3384 NbOfSteps, Tolerance)
3385 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3388 ## Generates new elements by extrusion of the elements with given ids
3389 # @param IDsOfElements the list of elements ids for extrusion
3390 # @param StepVector vector or DirStruct or 3 vector components, defining
3391 # the direction and value of extrusion for one step (the total extrusion
3392 # length will be NbOfSteps * ||StepVector||)
3393 # @param NbOfSteps the number of steps
3394 # @param MakeGroups forces the generation of new groups from existing ones
3395 # @param IsNodes is True if elements with given ids are nodes
3396 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3397 # @ingroup l2_modif_extrurev
3398 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3399 if IDsOfElements == []:
3400 IDsOfElements = self.GetElementsId()
3401 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3402 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3403 if isinstance( StepVector, list ):
3404 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3405 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3406 Parameters = StepVector.PS.parameters + var_separator + Parameters
3407 self.mesh.SetParameters(Parameters)
3410 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3412 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3414 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3416 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3419 ## Generates new elements by extrusion of the elements with given ids
3420 # @param IDsOfElements is ids of elements
3421 # @param StepVector vector or DirStruct or 3 vector components, defining
3422 # the direction and value of extrusion for one step (the total extrusion
3423 # length will be NbOfSteps * ||StepVector||)
3424 # @param NbOfSteps the number of steps
3425 # @param ExtrFlags sets flags for extrusion
3426 # @param SewTolerance uses for comparing locations of nodes if flag
3427 # EXTRUSION_FLAG_SEW is set
3428 # @param MakeGroups forces the generation of new groups from existing ones
3429 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3430 # @ingroup l2_modif_extrurev
3431 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3432 ExtrFlags, SewTolerance, MakeGroups=False):
3433 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3434 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3435 if isinstance( StepVector, list ):
3436 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3438 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3439 ExtrFlags, SewTolerance)
3440 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3441 ExtrFlags, SewTolerance)
3444 ## Generates new elements by extrusion of the elements which belong to the object
3445 # @param theObject the object which elements should be processed.
3446 # It can be a mesh, a sub mesh or a group.
3447 # @param StepVector vector or DirStruct or 3 vector components, defining
3448 # the direction and value of extrusion for one step (the total extrusion
3449 # length will be NbOfSteps * ||StepVector||)
3450 # @param NbOfSteps the number of steps
3451 # @param MakeGroups forces the generation of new groups from existing ones
3452 # @param IsNodes is True if elements which belong to the object are nodes
3453 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3454 # @ingroup l2_modif_extrurev
3455 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3456 if ( isinstance( theObject, Mesh )):
3457 theObject = theObject.GetMesh()
3458 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3459 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3460 if isinstance( StepVector, list ):
3461 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3462 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3463 Parameters = StepVector.PS.parameters + var_separator + Parameters
3464 self.mesh.SetParameters(Parameters)
3467 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3469 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3471 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3473 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3476 ## Generates new elements by extrusion of the elements which belong to the object
3477 # @param theObject object which elements should be processed.
3478 # It can be a mesh, a sub mesh or a group.
3479 # @param StepVector vector or DirStruct or 3 vector components, defining
3480 # the direction and value of extrusion for one step (the total extrusion
3481 # length will be NbOfSteps * ||StepVector||)
3482 # @param NbOfSteps the number of steps
3483 # @param MakeGroups to generate new groups from existing ones
3484 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3485 # @ingroup l2_modif_extrurev
3486 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3487 if ( isinstance( theObject, Mesh )):
3488 theObject = theObject.GetMesh()
3489 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3490 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3491 if isinstance( StepVector, list ):
3492 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3493 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3494 Parameters = StepVector.PS.parameters + var_separator + Parameters
3495 self.mesh.SetParameters(Parameters)
3497 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3498 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3501 ## Generates new elements by extrusion of the elements which belong to the object
3502 # @param theObject object which elements should be processed.
3503 # It can be a mesh, a sub mesh or a group.
3504 # @param StepVector vector or DirStruct or 3 vector components, defining
3505 # the direction and value of extrusion for one step (the total extrusion
3506 # length will be NbOfSteps * ||StepVector||)
3507 # @param NbOfSteps the number of steps
3508 # @param MakeGroups forces the generation of new groups from existing ones
3509 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3510 # @ingroup l2_modif_extrurev
3511 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3512 if ( isinstance( theObject, Mesh )):
3513 theObject = theObject.GetMesh()
3514 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3515 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3516 if isinstance( StepVector, list ):
3517 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3518 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3519 Parameters = StepVector.PS.parameters + var_separator + Parameters
3520 self.mesh.SetParameters(Parameters)
3522 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3523 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3528 ## Generates new elements by extrusion of the given elements
3529 # The path of extrusion must be a meshed edge.
3530 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3531 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3532 # @param NodeStart the start node from Path. Defines the direction of extrusion
3533 # @param HasAngles allows the shape to be rotated around the path
3534 # to get the resulting mesh in a helical fashion
3535 # @param Angles list of angles in radians
3536 # @param LinearVariation forces the computation of rotation angles as linear
3537 # variation of the given Angles along path steps
3538 # @param HasRefPoint allows using the reference point
3539 # @param RefPoint the point around which the elements are rotated (the mass
3540 # center of the elements by default).
3541 # The User can specify any point as the Reference Point.
3542 # RefPoint can be either GEOM Vertex, [x,y,z] or SMESH.PointStruct
3543 # @param MakeGroups forces the generation of new groups from existing ones
3544 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3545 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3546 # only SMESH::Extrusion_Error otherwise
3547 # @ingroup l2_modif_extrurev
3548 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3549 HasAngles, Angles, LinearVariation,
3550 HasRefPoint, RefPoint, MakeGroups, ElemType):
3551 if isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object):
3552 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3554 elif isinstance( RefPoint, list ):
3555 RefPoint = PointStruct(*RefPoint)
3557 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3558 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3559 self.mesh.SetParameters(Parameters)
3561 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3563 if isinstance(Base, list):
3565 if Base == []: IDsOfElements = self.GetElementsId()
3566 else: IDsOfElements = Base
3567 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3568 HasAngles, Angles, LinearVariation,
3569 HasRefPoint, RefPoint, MakeGroups, ElemType)
3571 if isinstance(Base, Mesh): Base = Base.GetMesh()
3572 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3573 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3574 HasAngles, Angles, LinearVariation,
3575 HasRefPoint, RefPoint, MakeGroups, ElemType)
3577 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3580 ## Generates new elements by extrusion of the given elements
3581 # The path of extrusion must be a meshed edge.
3582 # @param IDsOfElements ids of elements
3583 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3584 # @param PathShape shape(edge) defines the sub-mesh for the path
3585 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3586 # @param HasAngles allows the shape to be rotated around the path
3587 # to get the resulting mesh in a helical fashion
3588 # @param Angles list of angles in radians
3589 # @param HasRefPoint allows using the reference point
3590 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3591 # The User can specify any point as the Reference Point.
3592 # @param MakeGroups forces the generation of new groups from existing ones
3593 # @param LinearVariation forces the computation of rotation angles as linear
3594 # variation of the given Angles along path steps
3595 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3596 # only SMESH::Extrusion_Error otherwise
3597 # @ingroup l2_modif_extrurev
3598 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3599 HasAngles, Angles, HasRefPoint, RefPoint,
3600 MakeGroups=False, LinearVariation=False):
3601 if IDsOfElements == []:
3602 IDsOfElements = self.GetElementsId()
3603 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3604 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3606 if ( isinstance( PathMesh, Mesh )):
3607 PathMesh = PathMesh.GetMesh()
3608 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3609 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3610 self.mesh.SetParameters(Parameters)
3611 if HasAngles and Angles and LinearVariation:
3612 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3615 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3616 PathShape, NodeStart, HasAngles,
3617 Angles, HasRefPoint, RefPoint)
3618 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3619 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3621 ## Generates new elements by extrusion of the elements which belong to the object
3622 # The path of extrusion must be a meshed edge.
3623 # @param theObject the object which elements should be processed.
3624 # It can be a mesh, a sub mesh or a group.
3625 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3626 # @param PathShape shape(edge) defines the sub-mesh for the path
3627 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3628 # @param HasAngles allows the shape to be rotated around the path
3629 # to get the resulting mesh in a helical fashion
3630 # @param Angles list of angles
3631 # @param HasRefPoint allows using the reference point
3632 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3633 # The User can specify any point as the Reference Point.
3634 # @param MakeGroups forces the generation of new groups from existing ones
3635 # @param LinearVariation forces the computation of rotation angles as linear
3636 # variation of the given Angles along path steps
3637 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3638 # only SMESH::Extrusion_Error otherwise
3639 # @ingroup l2_modif_extrurev
3640 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3641 HasAngles, Angles, HasRefPoint, RefPoint,
3642 MakeGroups=False, LinearVariation=False):
3643 if ( isinstance( theObject, Mesh )):
3644 theObject = theObject.GetMesh()
3645 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3646 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3647 if ( isinstance( PathMesh, Mesh )):
3648 PathMesh = PathMesh.GetMesh()
3649 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3650 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3651 self.mesh.SetParameters(Parameters)
3652 if HasAngles and Angles and LinearVariation:
3653 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3656 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3657 PathShape, NodeStart, HasAngles,
3658 Angles, HasRefPoint, RefPoint)
3659 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3660 NodeStart, HasAngles, Angles, HasRefPoint,
3663 ## Generates new elements by extrusion of the elements which belong to the object
3664 # The path of extrusion must be a meshed edge.
3665 # @param theObject the object which elements should be processed.
3666 # It can be a mesh, a sub mesh or a group.
3667 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3668 # @param PathShape shape(edge) defines the sub-mesh for the path
3669 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3670 # @param HasAngles allows the shape to be rotated around the path
3671 # to get the resulting mesh in a helical fashion
3672 # @param Angles list of angles
3673 # @param HasRefPoint allows using the reference point
3674 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3675 # The User can specify any point as the Reference Point.
3676 # @param MakeGroups forces the generation of new groups from existing ones
3677 # @param LinearVariation forces the computation of rotation angles as linear
3678 # variation of the given Angles along path steps
3679 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3680 # only SMESH::Extrusion_Error otherwise
3681 # @ingroup l2_modif_extrurev
3682 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3683 HasAngles, Angles, HasRefPoint, RefPoint,
3684 MakeGroups=False, LinearVariation=False):
3685 if ( isinstance( theObject, Mesh )):
3686 theObject = theObject.GetMesh()
3687 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3688 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3689 if ( isinstance( PathMesh, Mesh )):
3690 PathMesh = PathMesh.GetMesh()
3691 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3692 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3693 self.mesh.SetParameters(Parameters)
3694 if HasAngles and Angles and LinearVariation:
3695 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3698 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3699 PathShape, NodeStart, HasAngles,
3700 Angles, HasRefPoint, RefPoint)
3701 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3702 NodeStart, HasAngles, Angles, HasRefPoint,
3705 ## Generates new elements by extrusion of the elements which belong to the object
3706 # The path of extrusion must be a meshed edge.
3707 # @param theObject the object which elements should be processed.
3708 # It can be a mesh, a sub mesh or a group.
3709 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3710 # @param PathShape shape(edge) defines the sub-mesh for the path
3711 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3712 # @param HasAngles allows the shape to be rotated around the path
3713 # to get the resulting mesh in a helical fashion
3714 # @param Angles list of angles
3715 # @param HasRefPoint allows using the reference point
3716 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3717 # The User can specify any point as the Reference Point.
3718 # @param MakeGroups forces the generation of new groups from existing ones
3719 # @param LinearVariation forces the computation of rotation angles as linear
3720 # variation of the given Angles along path steps
3721 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3722 # only SMESH::Extrusion_Error otherwise
3723 # @ingroup l2_modif_extrurev
3724 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3725 HasAngles, Angles, HasRefPoint, RefPoint,
3726 MakeGroups=False, LinearVariation=False):
3727 if ( isinstance( theObject, Mesh )):
3728 theObject = theObject.GetMesh()
3729 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3730 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3731 if ( isinstance( PathMesh, Mesh )):
3732 PathMesh = PathMesh.GetMesh()
3733 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3734 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3735 self.mesh.SetParameters(Parameters)
3736 if HasAngles and Angles and LinearVariation:
3737 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3740 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3741 PathShape, NodeStart, HasAngles,
3742 Angles, HasRefPoint, RefPoint)
3743 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3744 NodeStart, HasAngles, Angles, HasRefPoint,
3747 ## Creates a symmetrical copy of mesh elements
3748 # @param IDsOfElements list of elements ids
3749 # @param Mirror is AxisStruct or geom object(point, line, plane)
3750 # @param theMirrorType is POINT, AXIS or PLANE
3751 # If the Mirror is a geom object this parameter is unnecessary
3752 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3753 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3754 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3755 # @ingroup l2_modif_trsf
3756 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3757 if IDsOfElements == []:
3758 IDsOfElements = self.GetElementsId()
3759 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3760 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3761 self.mesh.SetParameters(Mirror.parameters)
3762 if Copy and MakeGroups:
3763 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3764 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3767 ## Creates a new mesh by a symmetrical copy of mesh elements
3768 # @param IDsOfElements the list of elements ids
3769 # @param Mirror is AxisStruct or geom object (point, line, plane)
3770 # @param theMirrorType is POINT, AXIS or PLANE
3771 # If the Mirror is a geom object this parameter is unnecessary
3772 # @param MakeGroups to generate new groups from existing ones
3773 # @param NewMeshName a name of the new mesh to create
3774 # @return instance of Mesh class
3775 # @ingroup l2_modif_trsf
3776 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3777 if IDsOfElements == []:
3778 IDsOfElements = self.GetElementsId()
3779 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3780 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3781 self.mesh.SetParameters(Mirror.parameters)
3782 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3783 MakeGroups, NewMeshName)
3784 return Mesh(self.smeshpyD,self.geompyD,mesh)
3786 ## Creates a symmetrical copy of the object
3787 # @param theObject mesh, submesh or group
3788 # @param Mirror AxisStruct or geom object (point, line, plane)
3789 # @param theMirrorType is POINT, AXIS or PLANE
3790 # If the Mirror is a geom object this parameter is unnecessary
3791 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3792 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3793 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3794 # @ingroup l2_modif_trsf
3795 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3796 if ( isinstance( theObject, Mesh )):
3797 theObject = theObject.GetMesh()
3798 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3799 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3800 self.mesh.SetParameters(Mirror.parameters)
3801 if Copy and MakeGroups:
3802 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3803 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3806 ## Creates a new mesh by a symmetrical copy of the object
3807 # @param theObject mesh, submesh or group
3808 # @param Mirror AxisStruct or geom object (point, line, plane)
3809 # @param theMirrorType POINT, AXIS or PLANE
3810 # If the Mirror is a geom object this parameter is unnecessary
3811 # @param MakeGroups forces the generation of new groups from existing ones
3812 # @param NewMeshName the name of the new mesh to create
3813 # @return instance of Mesh class
3814 # @ingroup l2_modif_trsf
3815 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3816 if ( isinstance( theObject, Mesh )):
3817 theObject = theObject.GetMesh()
3818 if (isinstance(Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3819 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3820 self.mesh.SetParameters(Mirror.parameters)
3821 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3822 MakeGroups, NewMeshName)
3823 return Mesh( self.smeshpyD,self.geompyD,mesh )
3825 ## Translates the elements
3826 # @param IDsOfElements list of elements ids
3827 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3828 # @param Copy allows copying the translated elements
3829 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3830 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3831 # @ingroup l2_modif_trsf
3832 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3833 if IDsOfElements == []:
3834 IDsOfElements = self.GetElementsId()
3835 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3836 Vector = self.smeshpyD.GetDirStruct(Vector)
3837 if isinstance( Vector, list ):
3838 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3839 self.mesh.SetParameters(Vector.PS.parameters)
3840 if Copy and MakeGroups:
3841 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3842 self.editor.Translate(IDsOfElements, Vector, Copy)
3845 ## Creates a new mesh of translated elements
3846 # @param IDsOfElements list of elements ids
3847 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3848 # @param MakeGroups forces the generation of new groups from existing ones
3849 # @param NewMeshName the name of the newly created mesh
3850 # @return instance of Mesh class
3851 # @ingroup l2_modif_trsf
3852 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3853 if IDsOfElements == []:
3854 IDsOfElements = self.GetElementsId()
3855 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3856 Vector = self.smeshpyD.GetDirStruct(Vector)
3857 if isinstance( Vector, list ):
3858 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3859 self.mesh.SetParameters(Vector.PS.parameters)
3860 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3861 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3863 ## Translates the object
3864 # @param theObject the object to translate (mesh, submesh, or group)
3865 # @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
3866 # @param Copy allows copying the translated elements
3867 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3868 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3869 # @ingroup l2_modif_trsf
3870 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3871 if ( isinstance( theObject, Mesh )):
3872 theObject = theObject.GetMesh()
3873 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3874 Vector = self.smeshpyD.GetDirStruct(Vector)
3875 if isinstance( Vector, list ):
3876 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3877 self.mesh.SetParameters(Vector.PS.parameters)
3878 if Copy and MakeGroups:
3879 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3880 self.editor.TranslateObject(theObject, Vector, Copy)
3883 ## Creates a new mesh from the translated object
3884 # @param theObject the object to translate (mesh, submesh, or group)
3885 # @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
3886 # @param MakeGroups forces the generation of new groups from existing ones
3887 # @param NewMeshName the name of the newly created mesh
3888 # @return instance of Mesh class
3889 # @ingroup l2_modif_trsf
3890 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3891 if isinstance( theObject, Mesh ):
3892 theObject = theObject.GetMesh()
3893 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
3894 Vector = self.smeshpyD.GetDirStruct(Vector)
3895 if isinstance( Vector, list ):
3896 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3897 self.mesh.SetParameters(Vector.PS.parameters)
3898 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3899 return Mesh( self.smeshpyD, self.geompyD, mesh )
3903 ## Scales the object
3904 # @param theObject - the object to translate (mesh, submesh, or group)
3905 # @param thePoint - base point for scale
3906 # @param theScaleFact - list of 1-3 scale factors for axises
3907 # @param Copy - allows copying the translated elements
3908 # @param MakeGroups - forces the generation of new groups from existing
3910 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3911 # empty list otherwise
3912 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3913 if ( isinstance( theObject, Mesh )):
3914 theObject = theObject.GetMesh()
3915 if ( isinstance( theObject, list )):
3916 theObject = self.GetIDSource(theObject, SMESH.ALL)
3917 if ( isinstance( theScaleFact, float )):
3918 theScaleFact = [theScaleFact]
3919 if ( isinstance( theScaleFact, int )):
3920 theScaleFact = [ float(theScaleFact)]
3922 self.mesh.SetParameters(thePoint.parameters)
3924 if Copy and MakeGroups:
3925 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3926 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3929 ## Creates a new mesh from the translated object
3930 # @param theObject - the object to translate (mesh, submesh, or group)
3931 # @param thePoint - base point for scale
3932 # @param theScaleFact - list of 1-3 scale factors for axises
3933 # @param MakeGroups - forces the generation of new groups from existing ones
3934 # @param NewMeshName - the name of the newly created mesh
3935 # @return instance of Mesh class
3936 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3937 if (isinstance(theObject, Mesh)):
3938 theObject = theObject.GetMesh()
3939 if ( isinstance( theObject, list )):
3940 theObject = self.GetIDSource(theObject,SMESH.ALL)
3941 if ( isinstance( theScaleFact, float )):
3942 theScaleFact = [theScaleFact]
3943 if ( isinstance( theScaleFact, int )):
3944 theScaleFact = [ float(theScaleFact)]
3946 self.mesh.SetParameters(thePoint.parameters)
3947 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3948 MakeGroups, NewMeshName)
3949 return Mesh( self.smeshpyD, self.geompyD, mesh )
3953 ## Rotates the elements
3954 # @param IDsOfElements list of elements ids
3955 # @param Axis the axis of rotation (AxisStruct or geom line)
3956 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3957 # @param Copy allows copying the rotated elements
3958 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3959 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3960 # @ingroup l2_modif_trsf
3961 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3962 if IDsOfElements == []:
3963 IDsOfElements = self.GetElementsId()
3964 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3965 Axis = self.smeshpyD.GetAxisStruct(Axis)
3966 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3967 Parameters = Axis.parameters + var_separator + Parameters
3968 self.mesh.SetParameters(Parameters)
3969 if Copy and MakeGroups:
3970 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3971 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3974 ## Creates a new mesh of rotated elements
3975 # @param IDsOfElements list of element ids
3976 # @param Axis the axis of rotation (AxisStruct or geom line)
3977 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3978 # @param MakeGroups forces the generation of new groups from existing ones
3979 # @param NewMeshName the name of the newly created mesh
3980 # @return instance of Mesh class
3981 # @ingroup l2_modif_trsf
3982 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3983 if IDsOfElements == []:
3984 IDsOfElements = self.GetElementsId()
3985 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3986 Axis = self.smeshpyD.GetAxisStruct(Axis)
3987 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3988 Parameters = Axis.parameters + var_separator + Parameters
3989 self.mesh.SetParameters(Parameters)
3990 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3991 MakeGroups, NewMeshName)
3992 return Mesh( self.smeshpyD, self.geompyD, mesh )
3994 ## Rotates the object
3995 # @param theObject the object to rotate( mesh, submesh, or group)
3996 # @param Axis the axis of rotation (AxisStruct or geom line)
3997 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3998 # @param Copy allows copying the rotated elements
3999 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4000 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4001 # @ingroup l2_modif_trsf
4002 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
4003 if (isinstance(theObject, Mesh)):
4004 theObject = theObject.GetMesh()
4005 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4006 Axis = self.smeshpyD.GetAxisStruct(Axis)
4007 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4008 Parameters = Axis.parameters + ":" + Parameters
4009 self.mesh.SetParameters(Parameters)
4010 if Copy and MakeGroups:
4011 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
4012 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
4015 ## Creates a new mesh from the rotated object
4016 # @param theObject the object to rotate (mesh, submesh, or group)
4017 # @param Axis the axis of rotation (AxisStruct or geom line)
4018 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4019 # @param MakeGroups forces the generation of new groups from existing ones
4020 # @param NewMeshName the name of the newly created mesh
4021 # @return instance of Mesh class
4022 # @ingroup l2_modif_trsf
4023 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
4024 if (isinstance( theObject, Mesh )):
4025 theObject = theObject.GetMesh()
4026 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4027 Axis = self.smeshpyD.GetAxisStruct(Axis)
4028 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4029 Parameters = Axis.parameters + ":" + Parameters
4030 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
4031 MakeGroups, NewMeshName)
4032 self.mesh.SetParameters(Parameters)
4033 return Mesh( self.smeshpyD, self.geompyD, mesh )
4035 ## Finds groups of ajacent nodes within Tolerance.
4036 # @param Tolerance the value of tolerance
4037 # @return the list of groups of nodes
4038 # @ingroup l2_modif_trsf
4039 def FindCoincidentNodes (self, Tolerance):
4040 return self.editor.FindCoincidentNodes(Tolerance)
4042 ## Finds groups of ajacent nodes within Tolerance.
4043 # @param Tolerance the value of tolerance
4044 # @param SubMeshOrGroup SubMesh or Group
4045 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
4046 # @return the list of groups of nodes
4047 # @ingroup l2_modif_trsf
4048 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
4049 if (isinstance( SubMeshOrGroup, Mesh )):
4050 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
4051 if not isinstance( exceptNodes, list):
4052 exceptNodes = [ exceptNodes ]
4053 if exceptNodes and isinstance( exceptNodes[0], int):
4054 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
4055 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
4058 # @param GroupsOfNodes the list of groups of nodes
4059 # @ingroup l2_modif_trsf
4060 def MergeNodes (self, GroupsOfNodes):
4061 self.editor.MergeNodes(GroupsOfNodes)
4063 ## Finds the elements built on the same nodes.
4064 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
4065 # @return a list of groups of equal elements
4066 # @ingroup l2_modif_trsf
4067 def FindEqualElements (self, MeshOrSubMeshOrGroup):
4068 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
4069 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4070 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
4072 ## Merges elements in each given group.
4073 # @param GroupsOfElementsID groups of elements for merging
4074 # @ingroup l2_modif_trsf
4075 def MergeElements(self, GroupsOfElementsID):
4076 self.editor.MergeElements(GroupsOfElementsID)
4078 ## Leaves one element and removes all other elements built on the same nodes.
4079 # @ingroup l2_modif_trsf
4080 def MergeEqualElements(self):
4081 self.editor.MergeEqualElements()
4083 ## Sews free borders
4084 # @return SMESH::Sew_Error
4085 # @ingroup l2_modif_trsf
4086 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4087 FirstNodeID2, SecondNodeID2, LastNodeID2,
4088 CreatePolygons, CreatePolyedrs):
4089 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4090 FirstNodeID2, SecondNodeID2, LastNodeID2,
4091 CreatePolygons, CreatePolyedrs)
4093 ## Sews conform free borders
4094 # @return SMESH::Sew_Error
4095 # @ingroup l2_modif_trsf
4096 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4097 FirstNodeID2, SecondNodeID2):
4098 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4099 FirstNodeID2, SecondNodeID2)
4101 ## Sews border to side
4102 # @return SMESH::Sew_Error
4103 # @ingroup l2_modif_trsf
4104 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4105 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4106 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4107 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4109 ## Sews two sides of a mesh. The nodes belonging to Side1 are
4110 # merged with the nodes of elements of Side2.
4111 # The number of elements in theSide1 and in theSide2 must be
4112 # equal and they should have similar nodal connectivity.
4113 # The nodes to merge should belong to side borders and
4114 # the first node should be linked to the second.
4115 # @return SMESH::Sew_Error
4116 # @ingroup l2_modif_trsf
4117 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4118 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4119 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4120 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4121 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4122 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4124 ## Sets new nodes for the given element.
4125 # @param ide the element id
4126 # @param newIDs nodes ids
4127 # @return If the number of nodes does not correspond to the type of element - returns false
4128 # @ingroup l2_modif_edit
4129 def ChangeElemNodes(self, ide, newIDs):
4130 return self.editor.ChangeElemNodes(ide, newIDs)
4132 ## If during the last operation of MeshEditor some nodes were
4133 # created, this method returns the list of their IDs, \n
4134 # if new nodes were not created - returns empty list
4135 # @return the list of integer values (can be empty)
4136 # @ingroup l1_auxiliary
4137 def GetLastCreatedNodes(self):
4138 return self.editor.GetLastCreatedNodes()
4140 ## If during the last operation of MeshEditor some elements were
4141 # created this method returns the list of their IDs, \n
4142 # if new elements were not created - returns empty list
4143 # @return the list of integer values (can be empty)
4144 # @ingroup l1_auxiliary
4145 def GetLastCreatedElems(self):
4146 return self.editor.GetLastCreatedElems()
4148 ## Clears sequences of nodes and elements created by mesh edition oparations
4149 # @ingroup l1_auxiliary
4150 def ClearLastCreated(self):
4151 self.editor.ClearLastCreated()
4153 ## Creates Duplicates given elements, i.e. creates new elements based on the
4154 # same nodes as the given ones.
4155 # @param theElements - container of elements to duplicate. It can be a Mesh,
4156 # sub-mesh, group, filter or a list of element IDs.
4157 # @param theGroupName - a name of group to contain the generated elements.
4158 # If a group with such a name already exists, the new elements
4159 # are added to the existng group, else a new group is created.
4160 # If \a theGroupName is empty, new elements are not added
4162 # @return a group where the new elements are added. None if theGroupName == "".
4163 # @ingroup l2_modif_edit
4164 def DoubleElements(self, theElements, theGroupName=""):
4165 if isinstance( theElements, Mesh ):
4166 theElements = theElements.mesh
4167 elif isinstance( theElements, list ):
4168 theElements = self.GetIDSource( theElements, SMESH.ALL )
4169 return self.editor.DoubleElements(theElements, theGroupName)
4171 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4172 # @param theNodes identifiers of nodes to be doubled
4173 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4174 # nodes. If list of element identifiers is empty then nodes are doubled but
4175 # they not assigned to elements
4176 # @return TRUE if operation has been completed successfully, FALSE otherwise
4177 # @ingroup l2_modif_edit
4178 def DoubleNodes(self, theNodes, theModifiedElems):
4179 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4181 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4182 # This method provided for convenience works as DoubleNodes() described above.
4183 # @param theNodeId identifiers of node to be doubled
4184 # @param theModifiedElems identifiers of elements to be updated
4185 # @return TRUE if operation has been completed successfully, FALSE otherwise
4186 # @ingroup l2_modif_edit
4187 def DoubleNode(self, theNodeId, theModifiedElems):
4188 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4190 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4191 # This method provided for convenience works as DoubleNodes() described above.
4192 # @param theNodes group of nodes to be doubled
4193 # @param theModifiedElems group of elements to be updated.
4194 # @param theMakeGroup forces the generation of a group containing new nodes.
4195 # @return TRUE or a created group if operation has been completed successfully,
4196 # FALSE or None otherwise
4197 # @ingroup l2_modif_edit
4198 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4200 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4201 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4203 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4204 # This method provided for convenience works as DoubleNodes() described above.
4205 # @param theNodes list of groups of nodes to be doubled
4206 # @param theModifiedElems list of groups of elements to be updated.
4207 # @param theMakeGroup forces the generation of a group containing new nodes.
4208 # @return TRUE if operation has been completed successfully, FALSE otherwise
4209 # @ingroup l2_modif_edit
4210 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4212 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4213 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
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 theAffectedElems - the list of elements (cells and edges) to which the
4220 # replicated nodes should be associated to.
4221 # @return TRUE if operation has been completed successfully, FALSE otherwise
4222 # @ingroup l2_modif_edit
4223 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4224 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4226 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4227 # @param theElems - the list of elements (edges or faces) to be replicated
4228 # The nodes for duplication could be found from these elements
4229 # @param theNodesNot - list of nodes to NOT replicate
4230 # @param theShape - shape to detect affected elements (element which geometric center
4231 # located on or inside shape).
4232 # The replicated nodes should be associated to affected elements.
4233 # @return TRUE if operation has been completed successfully, FALSE otherwise
4234 # @ingroup l2_modif_edit
4235 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4236 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4238 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4239 # This method provided for convenience works as DoubleNodes() described above.
4240 # @param theElems - group of of elements (edges or faces) to be replicated
4241 # @param theNodesNot - group of nodes not to replicated
4242 # @param theAffectedElems - group of elements to which the replicated nodes
4243 # should be associated to.
4244 # @param theMakeGroup forces the generation of a group containing new elements.
4245 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4246 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4247 # FALSE or None otherwise
4248 # @ingroup l2_modif_edit
4249 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4250 theMakeGroup=False, theMakeNodeGroup=False):
4251 if theMakeGroup or theMakeNodeGroup:
4252 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4254 theMakeGroup, theMakeNodeGroup)
4255 if theMakeGroup and theMakeNodeGroup:
4258 return twoGroups[ int(theMakeNodeGroup) ]
4259 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
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 - group of of elements (edges or faces) to be replicated
4264 # @param theNodesNot - group of nodes not to replicated
4265 # @param theShape - shape to detect affected elements (element which geometric center
4266 # located on or inside shape).
4267 # The replicated nodes should be associated to affected elements.
4268 # @ingroup l2_modif_edit
4269 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4270 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4272 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4273 # This method provided for convenience works as DoubleNodes() described above.
4274 # @param theElems - list of groups of elements (edges or faces) to be replicated
4275 # @param theNodesNot - list of groups of nodes not to replicated
4276 # @param theAffectedElems - group of elements to which the replicated nodes
4277 # should be associated to.
4278 # @param theMakeGroup forces the generation of a group containing new elements.
4279 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4280 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4281 # FALSE or None otherwise
4282 # @ingroup l2_modif_edit
4283 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4284 theMakeGroup=False, theMakeNodeGroup=False):
4285 if theMakeGroup or theMakeNodeGroup:
4286 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4288 theMakeGroup, theMakeNodeGroup)
4289 if theMakeGroup and theMakeNodeGroup:
4292 return twoGroups[ int(theMakeNodeGroup) ]
4293 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4295 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4296 # This method provided for convenience works as DoubleNodes() described above.
4297 # @param theElems - list of groups of elements (edges or faces) to be replicated
4298 # @param theNodesNot - list of groups of nodes not to replicated
4299 # @param theShape - shape to detect affected elements (element which geometric center
4300 # located on or inside shape).
4301 # The replicated nodes should be associated to affected elements.
4302 # @return TRUE if operation has been completed successfully, FALSE otherwise
4303 # @ingroup l2_modif_edit
4304 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4305 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4307 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4308 # This method is the first step of DoubleNodeElemGroupsInRegion.
4309 # @param theElems - list of groups of elements (edges or faces) to be replicated
4310 # @param theNodesNot - list of groups of nodes not to replicated
4311 # @param theShape - shape to detect affected elements (element which geometric center
4312 # located on or inside shape).
4313 # The replicated nodes should be associated to affected elements.
4314 # @return groups of affected elements
4315 # @ingroup l2_modif_edit
4316 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4317 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4319 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4320 # The list of groups must describe a partition of the mesh volumes.
4321 # The nodes of the internal faces at the boundaries of the groups are doubled.
4322 # In option, the internal faces are replaced by flat elements.
4323 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4324 # @param theDomains - list of groups of volumes
4325 # @param createJointElems - if TRUE, create the elements
4326 # @return TRUE if operation has been completed successfully, FALSE otherwise
4327 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4328 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4330 ## Double nodes on some external faces and create flat elements.
4331 # Flat elements are mainly used by some types of mechanic calculations.
4333 # Each group of the list must be constituted of faces.
4334 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4335 # @param theGroupsOfFaces - list of groups of faces
4336 # @return TRUE if operation has been completed successfully, FALSE otherwise
4337 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4338 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4340 ## identify all the elements around a geom shape, get the faces delimiting the hole
4342 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4343 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4345 def _getFunctor(self, funcType ):
4346 fn = self.functors[ funcType._v ]
4348 fn = self.smeshpyD.GetFunctor(funcType)
4349 fn.SetMesh(self.mesh)
4350 self.functors[ funcType._v ] = fn
4353 def _valueFromFunctor(self, funcType, elemId):
4354 fn = self._getFunctor( funcType )
4355 if fn.GetElementType() == self.GetElementType(elemId, True):
4356 val = fn.GetValue(elemId)
4361 ## Get length of 1D element.
4362 # @param elemId mesh element ID
4363 # @return element's length value
4364 # @ingroup l1_measurements
4365 def GetLength(self, elemId):
4366 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4368 ## Get area of 2D element.
4369 # @param elemId mesh element ID
4370 # @return element's area value
4371 # @ingroup l1_measurements
4372 def GetArea(self, elemId):
4373 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4375 ## Get volume of 3D element.
4376 # @param elemId mesh element ID
4377 # @return element's volume value
4378 # @ingroup l1_measurements
4379 def GetVolume(self, elemId):
4380 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4382 ## Get maximum element length.
4383 # @param elemId mesh element ID
4384 # @return element's maximum length value
4385 # @ingroup l1_measurements
4386 def GetMaxElementLength(self, elemId):
4387 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4388 ftype = SMESH.FT_MaxElementLength3D
4390 ftype = SMESH.FT_MaxElementLength2D
4391 return self._valueFromFunctor(ftype, elemId)
4393 ## Get aspect ratio of 2D or 3D element.
4394 # @param elemId mesh element ID
4395 # @return element's aspect ratio value
4396 # @ingroup l1_measurements
4397 def GetAspectRatio(self, elemId):
4398 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4399 ftype = SMESH.FT_AspectRatio3D
4401 ftype = SMESH.FT_AspectRatio
4402 return self._valueFromFunctor(ftype, elemId)
4404 ## Get warping angle of 2D element.
4405 # @param elemId mesh element ID
4406 # @return element's warping angle value
4407 # @ingroup l1_measurements
4408 def GetWarping(self, elemId):
4409 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4411 ## Get minimum angle of 2D element.
4412 # @param elemId mesh element ID
4413 # @return element's minimum angle value
4414 # @ingroup l1_measurements
4415 def GetMinimumAngle(self, elemId):
4416 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4418 ## Get taper of 2D element.
4419 # @param elemId mesh element ID
4420 # @return element's taper value
4421 # @ingroup l1_measurements
4422 def GetTaper(self, elemId):
4423 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4425 ## Get skew of 2D element.
4426 # @param elemId mesh element ID
4427 # @return element's skew value
4428 # @ingroup l1_measurements
4429 def GetSkew(self, elemId):
4430 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4432 pass # end of Mesh class
4434 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4436 class Pattern(SMESH._objref_SMESH_Pattern):
4438 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4439 decrFun = lambda i: i-1
4440 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4441 theMesh.SetParameters(Parameters)
4442 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4444 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4445 decrFun = lambda i: i-1
4446 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4447 theMesh.SetParameters(Parameters)
4448 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4450 # Registering the new proxy for Pattern
4451 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4453 ## Private class used to bind methods creating algorithms to the class Mesh
4458 self.defaultAlgoType = ""
4459 self.algoTypeToClass = {}
4461 # Stores a python class of algorithm
4462 def add(self, algoClass):
4463 if type( algoClass ).__name__ == 'classobj' and \
4464 hasattr( algoClass, "algoType"):
4465 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4466 if not self.defaultAlgoType and \
4467 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4468 self.defaultAlgoType = algoClass.algoType
4469 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4471 # creates a copy of self and assign mesh to the copy
4472 def copy(self, mesh):
4473 other = algoCreator()
4474 other.defaultAlgoType = self.defaultAlgoType
4475 other.algoTypeToClass = self.algoTypeToClass
4479 # creates an instance of algorithm
4480 def __call__(self,algo="",geom=0,*args):
4481 algoType = self.defaultAlgoType
4482 for arg in args + (algo,geom):
4483 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
4485 if isinstance( arg, str ) and arg:
4487 if not algoType and self.algoTypeToClass:
4488 algoType = self.algoTypeToClass.keys()[0]
4489 if self.algoTypeToClass.has_key( algoType ):
4490 #print "Create algo",algoType
4491 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4492 raise RuntimeError, "No class found for algo type %s" % algoType
4495 # Private class used to substitute and store variable parameters of hypotheses.
4497 class hypMethodWrapper:
4498 def __init__(self, hyp, method):
4500 self.method = method
4501 #print "REBIND:", method.__name__
4504 # call a method of hypothesis with calling SetVarParameter() before
4505 def __call__(self,*args):
4507 return self.method( self.hyp, *args ) # hypothesis method with no args
4509 #print "MethWrapper.__call__",self.method.__name__, args
4511 parsed = ParseParameters(*args) # replace variables with their values
4512 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4513 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4514 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4515 # maybe there is a replaced string arg which is not variable
4516 result = self.method( self.hyp, *args )
4517 except ValueError, detail: # raised by ParseParameters()
4519 result = self.method( self.hyp, *args )
4520 except omniORB.CORBA.BAD_PARAM:
4521 raise ValueError, detail # wrong variable name
4525 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4527 #print "pluginName: ", pluginName
4528 pluginBuilderName = pluginName + "Builder"
4530 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
4531 except Exception, e:
4532 print "Exception while loading %s: %s" % ( pluginBuilderName, e )
4534 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
4535 plugin = eval( pluginBuilderName )
4536 #print " plugin:" , str(plugin)
4538 # add methods creating algorithms to Mesh
4539 for k in dir( plugin ):
4540 if k[0] == '_': continue
4541 algo = getattr( plugin, k )
4542 #print " algo:", str(algo)
4543 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4544 #print " meshMethod:" , str(algo.meshMethod)
4545 if not hasattr( Mesh, algo.meshMethod ):
4546 setattr( Mesh, algo.meshMethod, algoCreator() )
4548 getattr( Mesh, algo.meshMethod ).add( algo )