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 # GMF files must have .mesh extension for the ASCII format and .meshb for
557 # @return [ an instance of Mesh class, SMESH.ComputeError ]
559 def CreateMeshesFromGMF( self, theFileName ):
560 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
563 if error.comment: print "*** CreateMeshesFromGMF() errors:\n", error.comment
564 return Mesh(self, self.geompyD, aSmeshMesh), error
566 ## Concatenate the given meshes into one mesh.
567 # @return an instance of Mesh class
568 # @param meshes the meshes to combine into one mesh
569 # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
570 # @param mergeNodesAndElements if true, equal nodes and elements aremerged
571 # @param mergeTolerance tolerance for merging nodes
572 # @param allGroups forces creation of groups of all elements
573 # @param name name of a new mesh
574 def Concatenate( self, meshes, uniteIdenticalGroups,
575 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
577 if not meshes: return None
578 for i,m in enumerate(meshes):
579 if isinstance(m, Mesh):
580 meshes[i] = m.GetMesh()
581 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
582 meshes[0].SetParameters(Parameters)
584 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
585 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
587 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
588 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
589 aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
592 ## Create a mesh by copying a part of another mesh.
593 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
594 # to copy nodes or elements not contained in any mesh object,
595 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
596 # @param meshName a name of the new mesh
597 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
598 # @param toKeepIDs to preserve IDs of the copied elements or not
599 # @return an instance of Mesh class
600 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
601 if (isinstance( meshPart, Mesh )):
602 meshPart = meshPart.GetMesh()
603 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
604 return Mesh(self, self.geompyD, mesh)
606 ## From SMESH_Gen interface
607 # @return the list of integer values
608 # @ingroup l1_auxiliary
609 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
610 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
612 ## From SMESH_Gen interface. Creates a pattern
613 # @return an instance of SMESH_Pattern
615 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
616 # @ingroup l2_modif_patterns
617 def GetPattern(self):
618 return SMESH._objref_SMESH_Gen.GetPattern(self)
620 ## Sets number of segments per diagonal of boundary box of geometry by which
621 # default segment length of appropriate 1D hypotheses is defined.
622 # Default value is 10
623 # @ingroup l1_auxiliary
624 def SetBoundaryBoxSegmentation(self, nbSegments):
625 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
627 # Filtering. Auxiliary functions:
628 # ------------------------------
630 ## Creates an empty criterion
631 # @return SMESH.Filter.Criterion
632 # @ingroup l1_controls
633 def GetEmptyCriterion(self):
634 Type = self.EnumToLong(FT_Undefined)
635 Compare = self.EnumToLong(FT_Undefined)
639 UnaryOp = self.EnumToLong(FT_Undefined)
640 BinaryOp = self.EnumToLong(FT_Undefined)
643 Precision = -1 ##@1e-07
644 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
645 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
647 ## Creates a criterion by the given parameters
648 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
649 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
650 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
651 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
652 # @param Threshold the threshold value (range of ids as string, shape, numeric)
653 # @param UnaryOp FT_LogicalNOT or FT_Undefined
654 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
655 # FT_Undefined (must be for the last criterion of all criteria)
656 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
657 # FT_LyingOnGeom, FT_CoplanarFaces criteria
658 # @return SMESH.Filter.Criterion
660 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
661 # @ingroup l1_controls
662 def GetCriterion(self,elementType,
664 Compare = FT_EqualTo,
666 UnaryOp=FT_Undefined,
667 BinaryOp=FT_Undefined,
669 if not CritType in SMESH.FunctorType._items:
670 raise TypeError, "CritType should be of SMESH.FunctorType"
671 aCriterion = self.GetEmptyCriterion()
672 aCriterion.TypeOfElement = elementType
673 aCriterion.Type = self.EnumToLong(CritType)
674 aCriterion.Tolerance = Tolerance
676 aThreshold = Threshold
678 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
679 aCriterion.Compare = self.EnumToLong(Compare)
680 elif Compare == "=" or Compare == "==":
681 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
683 aCriterion.Compare = self.EnumToLong(FT_LessThan)
685 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
686 elif Compare != FT_Undefined:
687 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
690 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
691 FT_BelongToCylinder, FT_LyingOnGeom]:
692 # Checks that Threshold is GEOM object
693 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object):
694 aCriterion.ThresholdStr = GetName(aThreshold)
695 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
696 if not aCriterion.ThresholdID:
697 name = aCriterion.ThresholdStr
699 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
700 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
701 #raise RuntimeError, "Threshold shape must be published"
703 print "Error: The Threshold should be a shape."
705 if isinstance(UnaryOp,float):
706 aCriterion.Tolerance = UnaryOp
707 UnaryOp = FT_Undefined
709 elif CritType == FT_RangeOfIds:
710 # Checks that Threshold is string
711 if isinstance(aThreshold, str):
712 aCriterion.ThresholdStr = aThreshold
714 print "Error: The Threshold should be a string."
716 elif CritType == FT_CoplanarFaces:
717 # Checks the Threshold
718 if isinstance(aThreshold, int):
719 aCriterion.ThresholdID = str(aThreshold)
720 elif isinstance(aThreshold, str):
723 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
724 aCriterion.ThresholdID = aThreshold
727 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
728 elif CritType == FT_ConnectedElements:
729 # Checks the Threshold
730 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object): # shape
731 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
732 if not aCriterion.ThresholdID:
733 name = aThreshold.GetName()
735 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
736 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
737 elif isinstance(aThreshold, int): # node id
738 aCriterion.Threshold = aThreshold
739 elif isinstance(aThreshold, list): # 3 point coordinates
740 if len( aThreshold ) < 3:
741 raise ValueError, "too few point coordinates, must be 3"
742 aCriterion.ThresholdStr = " ".join( [str(c) for c in aThreshold[:3]] )
743 elif isinstance(aThreshold, str):
744 if aThreshold.isdigit():
745 aCriterion.Threshold = aThreshold # node id
747 aCriterion.ThresholdStr = aThreshold # hope that it's point coordinates
750 "The Threshold should either a VERTEX, or a node ID, "\
751 "or a list of point coordinates and not '%s'"%aThreshold
752 elif CritType == FT_ElemGeomType:
753 # Checks the Threshold
755 aCriterion.Threshold = self.EnumToLong(aThreshold)
756 assert( aThreshold in SMESH.GeometryType._items )
758 if isinstance(aThreshold, int):
759 aCriterion.Threshold = aThreshold
761 print "Error: The Threshold should be an integer or SMESH.GeometryType."
765 elif CritType == FT_EntityType:
766 # Checks the Threshold
768 aCriterion.Threshold = self.EnumToLong(aThreshold)
769 assert( aThreshold in SMESH.EntityType._items )
771 if isinstance(aThreshold, int):
772 aCriterion.Threshold = aThreshold
774 print "Error: The Threshold should be an integer or SMESH.EntityType."
779 elif CritType == FT_GroupColor:
780 # Checks the Threshold
782 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
784 print "Error: The threshold value should be of SALOMEDS.Color type"
787 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
788 FT_LinearOrQuadratic, FT_BadOrientedVolume,
789 FT_BareBorderFace, FT_BareBorderVolume,
790 FT_OverConstrainedFace, FT_OverConstrainedVolume,
791 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
792 # At this point the Threshold is unnecessary
793 if aThreshold == FT_LogicalNOT:
794 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
795 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
796 aCriterion.BinaryOp = aThreshold
800 aThreshold = float(aThreshold)
801 aCriterion.Threshold = aThreshold
803 print "Error: The Threshold should be a number."
806 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
807 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
809 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
810 aCriterion.BinaryOp = self.EnumToLong(Threshold)
812 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
813 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
815 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
816 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
820 ## Creates a filter with the given parameters
821 # @param elementType the type of elements in the group
822 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
823 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
824 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
825 # @param UnaryOp FT_LogicalNOT or FT_Undefined
826 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
827 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
828 # @param mesh the mesh to initialize the filter with
829 # @return SMESH_Filter
831 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
832 # @ingroup l1_controls
833 def GetFilter(self,elementType,
834 CritType=FT_Undefined,
837 UnaryOp=FT_Undefined,
840 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
841 aFilterMgr = self.CreateFilterManager()
842 aFilter = aFilterMgr.CreateFilter()
844 aCriteria.append(aCriterion)
845 aFilter.SetCriteria(aCriteria)
847 if isinstance( mesh, Mesh ): aFilter.SetMesh( mesh.GetMesh() )
848 else : aFilter.SetMesh( mesh )
849 aFilterMgr.UnRegister()
852 ## Creates a filter from criteria
853 # @param criteria a list of criteria
854 # @return SMESH_Filter
856 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
857 # @ingroup l1_controls
858 def GetFilterFromCriteria(self,criteria):
859 aFilterMgr = self.CreateFilterManager()
860 aFilter = aFilterMgr.CreateFilter()
861 aFilter.SetCriteria(criteria)
862 aFilterMgr.UnRegister()
865 ## Creates a numerical functor by its type
866 # @param theCriterion FT_...; functor type
867 # @return SMESH_NumericalFunctor
868 # @ingroup l1_controls
869 def GetFunctor(self,theCriterion):
870 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
872 aFilterMgr = self.CreateFilterManager()
874 if theCriterion == FT_AspectRatio:
875 functor = aFilterMgr.CreateAspectRatio()
876 elif theCriterion == FT_AspectRatio3D:
877 functor = aFilterMgr.CreateAspectRatio3D()
878 elif theCriterion == FT_Warping:
879 functor = aFilterMgr.CreateWarping()
880 elif theCriterion == FT_MinimumAngle:
881 functor = aFilterMgr.CreateMinimumAngle()
882 elif theCriterion == FT_Taper:
883 functor = aFilterMgr.CreateTaper()
884 elif theCriterion == FT_Skew:
885 functor = aFilterMgr.CreateSkew()
886 elif theCriterion == FT_Area:
887 functor = aFilterMgr.CreateArea()
888 elif theCriterion == FT_Volume3D:
889 functor = aFilterMgr.CreateVolume3D()
890 elif theCriterion == FT_MaxElementLength2D:
891 functor = aFilterMgr.CreateMaxElementLength2D()
892 elif theCriterion == FT_MaxElementLength3D:
893 functor = aFilterMgr.CreateMaxElementLength3D()
894 elif theCriterion == FT_MultiConnection:
895 functor = aFilterMgr.CreateMultiConnection()
896 elif theCriterion == FT_MultiConnection2D:
897 functor = aFilterMgr.CreateMultiConnection2D()
898 elif theCriterion == FT_Length:
899 functor = aFilterMgr.CreateLength()
900 elif theCriterion == FT_Length2D:
901 functor = aFilterMgr.CreateLength2D()
903 print "Error: given parameter is not numerical functor type."
904 aFilterMgr.UnRegister()
907 ## Creates hypothesis
908 # @param theHType mesh hypothesis type (string)
909 # @param theLibName mesh plug-in library name
910 # @return created hypothesis instance
911 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
912 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
914 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
917 # wrap hypothesis methods
918 #print "HYPOTHESIS", theHType
919 for meth_name in dir( hyp.__class__ ):
920 if not meth_name.startswith("Get") and \
921 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
922 method = getattr ( hyp.__class__, meth_name )
924 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
928 ## Gets the mesh statistic
929 # @return dictionary "element type" - "count of elements"
930 # @ingroup l1_meshinfo
931 def GetMeshInfo(self, obj):
932 if isinstance( obj, Mesh ):
935 if hasattr(obj, "GetMeshInfo"):
936 values = obj.GetMeshInfo()
937 for i in range(SMESH.Entity_Last._v):
938 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
942 ## Get minimum distance between two objects
944 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
945 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
947 # @param src1 first source object
948 # @param src2 second source object
949 # @param id1 node/element id from the first source
950 # @param id2 node/element id from the second (or first) source
951 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
952 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
953 # @return minimum distance value
954 # @sa GetMinDistance()
955 # @ingroup l1_measurements
956 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
957 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
961 result = result.value
964 ## Get measure structure specifying minimum distance data between two objects
966 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
967 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
969 # @param src1 first source object
970 # @param src2 second source object
971 # @param id1 node/element id from the first source
972 # @param id2 node/element id from the second (or first) source
973 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
974 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
975 # @return Measure structure or None if input data is invalid
977 # @ingroup l1_measurements
978 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
979 if isinstance(src1, Mesh): src1 = src1.mesh
980 if isinstance(src2, Mesh): src2 = src2.mesh
981 if src2 is None and id2 != 0: src2 = src1
982 if not hasattr(src1, "_narrow"): return None
983 src1 = src1._narrow(SMESH.SMESH_IDSource)
984 if not src1: return None
985 unRegister = genObjUnRegister()
988 e = m.GetMeshEditor()
990 src1 = e.MakeIDSource([id1], SMESH.FACE)
992 src1 = e.MakeIDSource([id1], SMESH.NODE)
993 unRegister.set( src1 )
995 if hasattr(src2, "_narrow"):
996 src2 = src2._narrow(SMESH.SMESH_IDSource)
997 if src2 and id2 != 0:
999 e = m.GetMeshEditor()
1001 src2 = e.MakeIDSource([id2], SMESH.FACE)
1003 src2 = e.MakeIDSource([id2], SMESH.NODE)
1004 unRegister.set( src2 )
1007 aMeasurements = self.CreateMeasurements()
1008 unRegister.set( aMeasurements )
1009 result = aMeasurements.MinDistance(src1, src2)
1012 ## Get bounding box of the specified object(s)
1013 # @param objects single source object or list of source objects
1014 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
1015 # @sa GetBoundingBox()
1016 # @ingroup l1_measurements
1017 def BoundingBox(self, objects):
1018 result = self.GetBoundingBox(objects)
1022 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
1025 ## Get measure structure specifying bounding box data of the specified object(s)
1026 # @param objects single source object or list of source objects
1027 # @return Measure structure
1029 # @ingroup l1_measurements
1030 def GetBoundingBox(self, objects):
1031 if isinstance(objects, tuple):
1032 objects = list(objects)
1033 if not isinstance(objects, list):
1037 if isinstance(o, Mesh):
1038 srclist.append(o.mesh)
1039 elif hasattr(o, "_narrow"):
1040 src = o._narrow(SMESH.SMESH_IDSource)
1041 if src: srclist.append(src)
1044 aMeasurements = self.CreateMeasurements()
1045 result = aMeasurements.BoundingBox(srclist)
1046 aMeasurements.UnRegister()
1049 ## Get sum of lengths of all 1D elements in the mesh object.
1050 # @param elemId obj mesh, submesh or group
1051 # @return sum of lengths of all 1D elements
1052 # @ingroup l1_measurements
1053 def GetLength(self, obj):
1054 if isinstance(obj, Mesh): obj = obj.mesh
1055 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1056 aMeasurements = self.CreateMeasurements()
1057 value = aMeasurements.Length(obj)
1058 aMeasurements.UnRegister()
1061 ## Get sum of areas of all 2D elements in the mesh object.
1062 # @param elemId obj mesh, submesh or group
1063 # @return sum of areas of all 2D elements
1064 # @ingroup l1_measurements
1065 def GetArea(self, obj):
1066 if isinstance(obj, Mesh): obj = obj.mesh
1067 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1068 aMeasurements = self.CreateMeasurements()
1069 value = aMeasurements.Area(obj)
1070 aMeasurements.UnRegister()
1073 ## Get sum of volumes of all 3D elements in the mesh object.
1074 # @param elemId obj mesh, submesh or group
1075 # @return sum of volumes of all 3D elements
1076 # @ingroup l1_measurements
1077 def GetVolume(self, obj):
1078 if isinstance(obj, Mesh): obj = obj.mesh
1079 if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1080 aMeasurements = self.CreateMeasurements()
1081 value = aMeasurements.Volume(obj)
1082 aMeasurements.UnRegister()
1085 pass # end of class smeshBuilder
1088 #Registering the new proxy for SMESH_Gen
1089 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
1091 ## Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1092 # interface to create or load meshes.
1097 # salome.salome_init()
1098 # from salome.smesh import smeshBuilder
1099 # smesh = smeshBuilder.New(theStudy)
1101 # @param study SALOME study, generally obtained by salome.myStudy.
1102 # @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1103 # @return smeshBuilder instance
1105 def New( study, instance=None):
1107 Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1108 interface to create or load meshes.
1112 salome.salome_init()
1113 from salome.smesh import smeshBuilder
1114 smesh = smeshBuilder.New(theStudy)
1117 study SALOME study, generally obtained by salome.myStudy.
1118 instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1120 smeshBuilder instance
1128 smeshInst = smeshBuilder()
1129 assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__
1130 smeshInst.init_smesh(study)
1134 # Public class: Mesh
1135 # ==================
1137 ## This class allows defining and managing a mesh.
1138 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1139 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1140 # new nodes and elements and by changing the existing entities), to get information
1141 # about a mesh and to export a mesh into different formats.
1150 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1151 # sets the GUI name of this mesh to \a name.
1152 # @param smeshpyD an instance of smeshBuilder class
1153 # @param geompyD an instance of geomBuilder class
1154 # @param obj Shape to be meshed or SMESH_Mesh object
1155 # @param name Study name of the mesh
1156 # @ingroup l2_construct
1157 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1158 self.smeshpyD=smeshpyD
1159 self.geompyD=geompyD
1164 if isinstance(obj, geomBuilder.GEOM._objref_GEOM_Object):
1167 # publish geom of mesh (issue 0021122)
1168 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
1170 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
1171 if studyID != geompyD.myStudyId:
1172 geompyD.init_geom( smeshpyD.GetCurrentStudy())
1175 geo_name = name + " shape"
1177 geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1178 geompyD.addToStudy( self.geom, geo_name )
1179 self.SetMesh( self.smeshpyD.CreateMesh(self.geom) )
1181 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1184 self.mesh = self.smeshpyD.CreateEmptyMesh()
1186 self.smeshpyD.SetName(self.mesh, name)
1188 self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1191 self.geom = self.mesh.GetShapeToMesh()
1193 self.editor = self.mesh.GetMeshEditor()
1194 self.functors = [None] * SMESH.FT_Undefined._v
1196 # set self to algoCreator's
1197 for attrName in dir(self):
1198 attr = getattr( self, attrName )
1199 if isinstance( attr, algoCreator ):
1200 #print "algoCreator ", attrName
1201 setattr( self, attrName, attr.copy( self ))
1206 ## Destructor. Clean-up resources
1209 self.mesh.UnRegister()
1213 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1214 # @param theMesh a SMESH_Mesh object
1215 # @ingroup l2_construct
1216 def SetMesh(self, theMesh):
1217 if self.mesh: self.mesh.UnRegister()
1220 self.mesh.Register()
1221 self.geom = self.mesh.GetShapeToMesh()
1223 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1224 # @return a SMESH_Mesh object
1225 # @ingroup l2_construct
1229 ## Gets the name of the mesh
1230 # @return the name of the mesh as a string
1231 # @ingroup l2_construct
1233 name = GetName(self.GetMesh())
1236 ## Sets a name to the mesh
1237 # @param name a new name of the mesh
1238 # @ingroup l2_construct
1239 def SetName(self, name):
1240 self.smeshpyD.SetName(self.GetMesh(), name)
1242 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1243 # The subMesh object gives access to the IDs of nodes and elements.
1244 # @param geom a geometrical object (shape)
1245 # @param name a name for the submesh
1246 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1247 # @ingroup l2_submeshes
1248 def GetSubMesh(self, geom, name):
1249 AssureGeomPublished( self, geom, name )
1250 submesh = self.mesh.GetSubMesh( geom, name )
1253 ## Returns the shape associated to the mesh
1254 # @return a GEOM_Object
1255 # @ingroup l2_construct
1259 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1260 # @param geom the shape to be meshed (GEOM_Object)
1261 # @ingroup l2_construct
1262 def SetShape(self, geom):
1263 self.mesh = self.smeshpyD.CreateMesh(geom)
1265 ## Loads mesh from the study after opening the study
1269 ## Returns true if the hypotheses are defined well
1270 # @param theSubObject a sub-shape of a mesh shape
1271 # @return True or False
1272 # @ingroup l2_construct
1273 def IsReadyToCompute(self, theSubObject):
1274 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1276 ## Returns errors of hypotheses definition.
1277 # The list of errors is empty if everything is OK.
1278 # @param theSubObject a sub-shape of a mesh shape
1279 # @return a list of errors
1280 # @ingroup l2_construct
1281 def GetAlgoState(self, theSubObject):
1282 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1284 ## Returns a geometrical object on which the given element was built.
1285 # The returned geometrical object, if not nil, is either found in the
1286 # study or published by this method with the given name
1287 # @param theElementID the id of the mesh element
1288 # @param theGeomName the user-defined name of the geometrical object
1289 # @return GEOM::GEOM_Object instance
1290 # @ingroup l2_construct
1291 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1292 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1294 ## Returns the mesh dimension depending on the dimension of the underlying shape
1295 # or, if the mesh is not based on any shape, basing on deimension of elements
1296 # @return mesh dimension as an integer value [0,3]
1297 # @ingroup l1_auxiliary
1298 def MeshDimension(self):
1299 if self.mesh.HasShapeToMesh():
1300 shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
1301 if len( shells ) > 0 :
1303 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1305 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1310 if self.NbVolumes() > 0: return 3
1311 if self.NbFaces() > 0: return 2
1312 if self.NbEdges() > 0: return 1
1315 ## Evaluates size of prospective mesh on a shape
1316 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1317 # To know predicted number of e.g. edges, inquire it this way
1318 # Evaluate()[ EnumToLong( Entity_Edge )]
1319 def Evaluate(self, geom=0):
1320 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1322 geom = self.mesh.GetShapeToMesh()
1325 return self.smeshpyD.Evaluate(self.mesh, geom)
1328 ## Computes the mesh and returns the status of the computation
1329 # @param geom geomtrical shape on which mesh data should be computed
1330 # @param discardModifs if True and the mesh has been edited since
1331 # a last total re-compute and that may prevent successful partial re-compute,
1332 # then the mesh is cleaned before Compute()
1333 # @return True or False
1334 # @ingroup l2_construct
1335 def Compute(self, geom=0, discardModifs=False):
1336 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1338 geom = self.mesh.GetShapeToMesh()
1343 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1345 ok = self.smeshpyD.Compute(self.mesh, geom)
1346 except SALOME.SALOME_Exception, ex:
1347 print "Mesh computation failed, exception caught:"
1348 print " ", ex.details.text
1351 print "Mesh computation failed, exception caught:"
1352 traceback.print_exc()
1356 # Treat compute errors
1357 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1358 for err in computeErrors:
1360 if self.mesh.HasShapeToMesh():
1362 mainIOR = salome.orb.object_to_string(geom)
1363 for sname in salome.myStudyManager.GetOpenStudies():
1364 s = salome.myStudyManager.GetStudyByName(sname)
1366 mainSO = s.FindObjectIOR(mainIOR)
1367 if not mainSO: continue
1368 if err.subShapeID == 1:
1369 shapeText = ' on "%s"' % mainSO.GetName()
1370 subIt = s.NewChildIterator(mainSO)
1372 subSO = subIt.Value()
1374 obj = subSO.GetObject()
1375 if not obj: continue
1376 go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
1378 ids = go.GetSubShapeIndices()
1379 if len(ids) == 1 and ids[0] == err.subShapeID:
1380 shapeText = ' on "%s"' % subSO.GetName()
1383 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1385 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1387 shapeText = " on subshape #%s" % (err.subShapeID)
1389 shapeText = " on subshape #%s" % (err.subShapeID)
1391 stdErrors = ["OK", #COMPERR_OK
1392 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1393 "std::exception", #COMPERR_STD_EXCEPTION
1394 "OCC exception", #COMPERR_OCC_EXCEPTION
1395 "..", #COMPERR_SLM_EXCEPTION
1396 "Unknown exception", #COMPERR_EXCEPTION
1397 "Memory allocation problem", #COMPERR_MEMORY_PB
1398 "Algorithm failed", #COMPERR_ALGO_FAILED
1399 "Unexpected geometry", #COMPERR_BAD_SHAPE
1400 "Warning", #COMPERR_WARNING
1401 "Computation cancelled",#COMPERR_CANCELED
1402 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1404 if err.code < len(stdErrors): errText = stdErrors[err.code]
1406 errText = "code %s" % -err.code
1407 if errText: errText += ". "
1408 errText += err.comment
1409 if allReasons != "":allReasons += "\n"
1411 allReasons += '- "%s"%s - %s' %(err.algoName, shapeText, errText)
1413 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1417 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1419 if err.isGlobalAlgo:
1427 reason = '%s %sD algorithm is missing' % (glob, dim)
1428 elif err.state == HYP_MISSING:
1429 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1430 % (glob, dim, name, dim))
1431 elif err.state == HYP_NOTCONFORM:
1432 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1433 elif err.state == HYP_BAD_PARAMETER:
1434 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1435 % ( glob, dim, name ))
1436 elif err.state == HYP_BAD_GEOMETRY:
1437 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1438 'geometry' % ( glob, dim, name ))
1439 elif err.state == HYP_HIDDEN_ALGO:
1440 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1441 'algorithm of upper dimension generating %sD mesh'
1442 % ( glob, dim, name, glob, dim ))
1444 reason = ("For unknown reason. "
1445 "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1447 if allReasons != "":allReasons += "\n"
1448 allReasons += "- " + reason
1450 if not ok or allReasons != "":
1451 msg = '"' + GetName(self.mesh) + '"'
1452 if ok: msg += " has been computed with warnings"
1453 else: msg += " has not been computed"
1454 if allReasons != "": msg += ":"
1459 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1460 smeshgui = salome.ImportComponentGUI("SMESH")
1461 smeshgui.Init(self.mesh.GetStudyId())
1462 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1463 salome.sg.updateObjBrowser(1)
1467 ## Return submesh objects list in meshing order
1468 # @return list of list of submesh objects
1469 # @ingroup l2_construct
1470 def GetMeshOrder(self):
1471 return self.mesh.GetMeshOrder()
1473 ## Return submesh objects list in meshing order
1474 # @return list of list of submesh objects
1475 # @ingroup l2_construct
1476 def SetMeshOrder(self, submeshes):
1477 return self.mesh.SetMeshOrder(submeshes)
1479 ## Removes all nodes and elements
1480 # @ingroup l2_construct
1483 if ( salome.sg.hasDesktop() and
1484 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1485 smeshgui = salome.ImportComponentGUI("SMESH")
1486 smeshgui.Init(self.mesh.GetStudyId())
1487 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1488 salome.sg.updateObjBrowser(1)
1490 ## Removes all nodes and elements of indicated shape
1491 # @ingroup l2_construct
1492 def ClearSubMesh(self, geomId):
1493 self.mesh.ClearSubMesh(geomId)
1494 if salome.sg.hasDesktop():
1495 smeshgui = salome.ImportComponentGUI("SMESH")
1496 smeshgui.Init(self.mesh.GetStudyId())
1497 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1498 salome.sg.updateObjBrowser(1)
1500 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1501 # @param fineness [0.0,1.0] defines mesh fineness
1502 # @return True or False
1503 # @ingroup l3_algos_basic
1504 def AutomaticTetrahedralization(self, fineness=0):
1505 dim = self.MeshDimension()
1507 self.RemoveGlobalHypotheses()
1508 self.Segment().AutomaticLength(fineness)
1510 self.Triangle().LengthFromEdges()
1513 from salome.NETGENPlugin.NETGENPluginBuilder import NETGEN
1514 self.Tetrahedron(NETGEN)
1516 return self.Compute()
1518 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1519 # @param fineness [0.0, 1.0] defines mesh fineness
1520 # @return True or False
1521 # @ingroup l3_algos_basic
1522 def AutomaticHexahedralization(self, fineness=0):
1523 dim = self.MeshDimension()
1524 # assign the hypotheses
1525 self.RemoveGlobalHypotheses()
1526 self.Segment().AutomaticLength(fineness)
1533 return self.Compute()
1535 ## Assigns a hypothesis
1536 # @param hyp a hypothesis to assign
1537 # @param geom a subhape of mesh geometry
1538 # @return SMESH.Hypothesis_Status
1539 # @ingroup l2_hypotheses
1540 def AddHypothesis(self, hyp, geom=0):
1541 if isinstance( hyp, Mesh_Algorithm ):
1542 hyp = hyp.GetAlgorithm()
1547 geom = self.mesh.GetShapeToMesh()
1549 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1550 status = self.mesh.AddHypothesis(geom, hyp)
1551 isAlgo = hyp._narrow( SMESH_Algo )
1552 hyp_name = GetName( hyp )
1555 geom_name = GetName( geom )
1556 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1559 ## Return True if an algorithm of hypothesis is assigned to a given shape
1560 # @param hyp a hypothesis to check
1561 # @param geom a subhape of mesh geometry
1562 # @return True of False
1563 # @ingroup l2_hypotheses
1564 def IsUsedHypothesis(self, hyp, geom):
1565 if not hyp: # or not geom
1567 if isinstance( hyp, Mesh_Algorithm ):
1568 hyp = hyp.GetAlgorithm()
1570 hyps = self.GetHypothesisList(geom)
1572 if h.GetId() == hyp.GetId():
1576 ## Unassigns a hypothesis
1577 # @param hyp a hypothesis to unassign
1578 # @param geom a sub-shape of mesh geometry
1579 # @return SMESH.Hypothesis_Status
1580 # @ingroup l2_hypotheses
1581 def RemoveHypothesis(self, hyp, geom=0):
1584 if isinstance( hyp, Mesh_Algorithm ):
1585 hyp = hyp.GetAlgorithm()
1591 if self.IsUsedHypothesis( hyp, shape ):
1592 return self.mesh.RemoveHypothesis( shape, hyp )
1593 hypName = GetName( hyp )
1594 geoName = GetName( shape )
1595 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1598 ## Gets the list of hypotheses added on a geometry
1599 # @param geom a sub-shape of mesh geometry
1600 # @return the sequence of SMESH_Hypothesis
1601 # @ingroup l2_hypotheses
1602 def GetHypothesisList(self, geom):
1603 return self.mesh.GetHypothesisList( geom )
1605 ## Removes all global hypotheses
1606 # @ingroup l2_hypotheses
1607 def RemoveGlobalHypotheses(self):
1608 current_hyps = self.mesh.GetHypothesisList( self.geom )
1609 for hyp in current_hyps:
1610 self.mesh.RemoveHypothesis( self.geom, hyp )
1614 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1615 ## allowing to overwrite the file if it exists or add the exported data to its contents
1616 # @param f is the file name
1617 # @param auto_groups boolean parameter for creating/not creating
1618 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1619 # the typical use is auto_groups=false.
1620 # @param version MED format version(MED_V2_1 or MED_V2_2)
1621 # @param overwrite boolean parameter for overwriting/not overwriting the file
1622 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1623 # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1624 # - 1D if all mesh nodes lie on OX coordinate axis, or
1625 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1626 # - 3D in the rest cases.
1628 # If @a autoDimension is @c False, the space dimension is always 3.
1629 # @ingroup l2_impexp
1630 def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
1631 overwrite=1, meshPart=None, autoDimension=True):
1633 unRegister = genObjUnRegister()
1634 if isinstance( meshPart, list ):
1635 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1636 unRegister.set( meshPart )
1637 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension)
1639 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
1641 ## Exports the mesh in a file in SAUV format
1642 # @param f is the file name
1643 # @param auto_groups boolean parameter for creating/not creating
1644 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1645 # the typical use is auto_groups=false.
1646 # @ingroup l2_impexp
1647 def ExportSAUV(self, f, auto_groups=0):
1648 self.mesh.ExportSAUV(f, auto_groups)
1650 ## Exports the mesh in a file in DAT format
1651 # @param f the file name
1652 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1653 # @ingroup l2_impexp
1654 def ExportDAT(self, f, meshPart=None):
1656 unRegister = genObjUnRegister()
1657 if isinstance( meshPart, list ):
1658 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1659 unRegister.set( meshPart )
1660 self.mesh.ExportPartToDAT( meshPart, f )
1662 self.mesh.ExportDAT(f)
1664 ## Exports the mesh in a file in UNV format
1665 # @param f the file name
1666 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1667 # @ingroup l2_impexp
1668 def ExportUNV(self, f, meshPart=None):
1670 unRegister = genObjUnRegister()
1671 if isinstance( meshPart, list ):
1672 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1673 unRegister.set( meshPart )
1674 self.mesh.ExportPartToUNV( meshPart, f )
1676 self.mesh.ExportUNV(f)
1678 ## Export the mesh in a file in STL format
1679 # @param f the file name
1680 # @param ascii defines the file encoding
1681 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1682 # @ingroup l2_impexp
1683 def ExportSTL(self, f, ascii=1, meshPart=None):
1685 unRegister = genObjUnRegister()
1686 if isinstance( meshPart, list ):
1687 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1688 unRegister.set( meshPart )
1689 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1691 self.mesh.ExportSTL(f, ascii)
1693 ## Exports the mesh in a file in CGNS format
1694 # @param f is the file name
1695 # @param overwrite boolean parameter for overwriting/not overwriting the file
1696 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1697 # @ingroup l2_impexp
1698 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1699 unRegister = genObjUnRegister()
1700 if isinstance( meshPart, list ):
1701 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1702 unRegister.set( meshPart )
1703 if isinstance( meshPart, Mesh ):
1704 meshPart = meshPart.mesh
1706 meshPart = self.mesh
1707 self.mesh.ExportCGNS(meshPart, f, overwrite)
1709 ## Exports the mesh in a file in GMF format.
1710 # GMF files must have .mesh extension for the ASCII format and .meshb for
1711 # the bynary format. Other extensions are not allowed.
1712 # @param f is the file name
1713 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1714 # @ingroup l2_impexp
1715 def ExportGMF(self, f, meshPart=None):
1716 unRegister = genObjUnRegister()
1717 if isinstance( meshPart, list ):
1718 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1719 unRegister.set( meshPart )
1720 if isinstance( meshPart, Mesh ):
1721 meshPart = meshPart.mesh
1723 meshPart = self.mesh
1724 self.mesh.ExportGMF(meshPart, f, True)
1726 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1727 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1728 ## allowing to overwrite the file if it exists or add the exported data to its contents
1729 # @param f the file name
1730 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1731 # @param opt boolean parameter for creating/not creating
1732 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1733 # @param overwrite boolean parameter for overwriting/not overwriting the file
1734 # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1735 # - 1D if all mesh nodes lie on OX coordinate axis, or
1736 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1737 # - 3D in the rest cases.
1739 # If @a autoDimension is @c False, the space dimension is always 3.
1740 # @ingroup l2_impexp
1741 def ExportToMED(self, f, version, opt=0, overwrite=1, autoDimension=True):
1742 self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension)
1744 # Operations with groups:
1745 # ----------------------
1747 ## Creates an empty mesh group
1748 # @param elementType the type of elements in the group
1749 # @param name the name of the mesh group
1750 # @return SMESH_Group
1751 # @ingroup l2_grps_create
1752 def CreateEmptyGroup(self, elementType, name):
1753 return self.mesh.CreateGroup(elementType, name)
1755 ## Creates a mesh group based on the geometric object \a grp
1756 # and gives a \a name, \n if this parameter is not defined
1757 # the name is the same as the geometric group name \n
1758 # Note: Works like GroupOnGeom().
1759 # @param grp a geometric group, a vertex, an edge, a face or a solid
1760 # @param name the name of the mesh group
1761 # @return SMESH_GroupOnGeom
1762 # @ingroup l2_grps_create
1763 def Group(self, grp, name=""):
1764 return self.GroupOnGeom(grp, name)
1766 ## Creates a mesh group based on the geometrical object \a grp
1767 # and gives a \a name, \n if this parameter is not defined
1768 # the name is the same as the geometrical group name
1769 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1770 # @param name the name of the mesh group
1771 # @param typ the type of elements in the group. If not set, it is
1772 # automatically detected by the type of the geometry
1773 # @return SMESH_GroupOnGeom
1774 # @ingroup l2_grps_create
1775 def GroupOnGeom(self, grp, name="", typ=None):
1776 AssureGeomPublished( self, grp, name )
1778 name = grp.GetName()
1780 typ = self._groupTypeFromShape( grp )
1781 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1783 ## Pivate method to get a type of group on geometry
1784 def _groupTypeFromShape( self, shape ):
1785 tgeo = str(shape.GetShapeType())
1786 if tgeo == "VERTEX":
1788 elif tgeo == "EDGE":
1790 elif tgeo == "FACE" or tgeo == "SHELL":
1792 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1794 elif tgeo == "COMPOUND":
1795 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
1797 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1798 return self._groupTypeFromShape( sub[0] )
1801 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1804 ## Creates a mesh group with given \a name based on the \a filter which
1805 ## is a special type of group dynamically updating it's contents during
1806 ## mesh modification
1807 # @param typ the type of elements in the group
1808 # @param name the name of the mesh group
1809 # @param filter the filter defining group contents
1810 # @return SMESH_GroupOnFilter
1811 # @ingroup l2_grps_create
1812 def GroupOnFilter(self, typ, name, filter):
1813 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1815 ## Creates a mesh group by the given ids of elements
1816 # @param groupName the name of the mesh group
1817 # @param elementType the type of elements in the group
1818 # @param elemIDs the list of ids
1819 # @return SMESH_Group
1820 # @ingroup l2_grps_create
1821 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1822 group = self.mesh.CreateGroup(elementType, groupName)
1826 ## Creates a mesh group by the given conditions
1827 # @param groupName the name of the mesh group
1828 # @param elementType the type of elements in the group
1829 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1830 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1831 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1832 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1833 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1834 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1835 # @return SMESH_Group
1836 # @ingroup l2_grps_create
1840 CritType=FT_Undefined,
1843 UnaryOp=FT_Undefined,
1845 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1846 group = self.MakeGroupByCriterion(groupName, aCriterion)
1849 ## Creates a mesh group by the given criterion
1850 # @param groupName the name of the mesh group
1851 # @param Criterion the instance of Criterion class
1852 # @return SMESH_Group
1853 # @ingroup l2_grps_create
1854 def MakeGroupByCriterion(self, groupName, Criterion):
1855 aFilterMgr = self.smeshpyD.CreateFilterManager()
1856 aFilter = aFilterMgr.CreateFilter()
1858 aCriteria.append(Criterion)
1859 aFilter.SetCriteria(aCriteria)
1860 group = self.MakeGroupByFilter(groupName, aFilter)
1861 aFilterMgr.UnRegister()
1864 ## Creates a mesh group by the given criteria (list of criteria)
1865 # @param groupName the name of the mesh group
1866 # @param theCriteria the list of criteria
1867 # @return SMESH_Group
1868 # @ingroup l2_grps_create
1869 def MakeGroupByCriteria(self, groupName, theCriteria):
1870 aFilterMgr = self.smeshpyD.CreateFilterManager()
1871 aFilter = aFilterMgr.CreateFilter()
1872 aFilter.SetCriteria(theCriteria)
1873 group = self.MakeGroupByFilter(groupName, aFilter)
1874 aFilterMgr.UnRegister()
1877 ## Creates a mesh group by the given filter
1878 # @param groupName the name of the mesh group
1879 # @param theFilter the instance of Filter class
1880 # @return SMESH_Group
1881 # @ingroup l2_grps_create
1882 def MakeGroupByFilter(self, groupName, theFilter):
1883 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1884 theFilter.SetMesh( self.mesh )
1885 group.AddFrom( theFilter )
1889 # @ingroup l2_grps_delete
1890 def RemoveGroup(self, group):
1891 self.mesh.RemoveGroup(group)
1893 ## Removes a group with its contents
1894 # @ingroup l2_grps_delete
1895 def RemoveGroupWithContents(self, group):
1896 self.mesh.RemoveGroupWithContents(group)
1898 ## Gets the list of groups existing in the mesh
1899 # @return a sequence of SMESH_GroupBase
1900 # @ingroup l2_grps_create
1901 def GetGroups(self):
1902 return self.mesh.GetGroups()
1904 ## Gets the number of groups existing in the mesh
1905 # @return the quantity of groups as an integer value
1906 # @ingroup l2_grps_create
1908 return self.mesh.NbGroups()
1910 ## Gets the list of names of groups existing in the mesh
1911 # @return list of strings
1912 # @ingroup l2_grps_create
1913 def GetGroupNames(self):
1914 groups = self.GetGroups()
1916 for group in groups:
1917 names.append(group.GetName())
1920 ## Produces a union of two groups
1921 # A new group is created. All mesh elements that are
1922 # present in the initial groups are added to the new one
1923 # @return an instance of SMESH_Group
1924 # @ingroup l2_grps_operon
1925 def UnionGroups(self, group1, group2, name):
1926 return self.mesh.UnionGroups(group1, group2, name)
1928 ## Produces a union list of groups
1929 # New group is created. All mesh elements that are present in
1930 # initial groups are added to the new one
1931 # @return an instance of SMESH_Group
1932 # @ingroup l2_grps_operon
1933 def UnionListOfGroups(self, groups, name):
1934 return self.mesh.UnionListOfGroups(groups, name)
1936 ## Prodices an intersection of two groups
1937 # A new group is created. All mesh elements that are common
1938 # for the two initial groups are added to the new one.
1939 # @return an instance of SMESH_Group
1940 # @ingroup l2_grps_operon
1941 def IntersectGroups(self, group1, group2, name):
1942 return self.mesh.IntersectGroups(group1, group2, name)
1944 ## Produces an intersection of groups
1945 # New group is created. All mesh elements that are present in all
1946 # initial groups simultaneously are added to the new one
1947 # @return an instance of SMESH_Group
1948 # @ingroup l2_grps_operon
1949 def IntersectListOfGroups(self, groups, name):
1950 return self.mesh.IntersectListOfGroups(groups, name)
1952 ## Produces a cut of two groups
1953 # A new group is created. All mesh elements that are present in
1954 # the main group but are not present in the tool group are added to the new one
1955 # @return an instance of SMESH_Group
1956 # @ingroup l2_grps_operon
1957 def CutGroups(self, main_group, tool_group, name):
1958 return self.mesh.CutGroups(main_group, tool_group, name)
1960 ## Produces a cut of groups
1961 # A new group is created. All mesh elements that are present in main groups
1962 # but do not present in tool groups are added to the new one
1963 # @return an instance of SMESH_Group
1964 # @ingroup l2_grps_operon
1965 def CutListOfGroups(self, main_groups, tool_groups, name):
1966 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1968 ## Produces a group of elements of specified type using list of existing groups
1969 # A new group is created. System
1970 # 1) extracts all nodes on which groups elements are built
1971 # 2) combines all elements of specified dimension laying on these nodes
1972 # @return an instance of SMESH_Group
1973 # @ingroup l2_grps_operon
1974 def CreateDimGroup(self, groups, elem_type, name):
1975 return self.mesh.CreateDimGroup(groups, elem_type, name)
1978 ## Convert group on geom into standalone group
1979 # @ingroup l2_grps_delete
1980 def ConvertToStandalone(self, group):
1981 return self.mesh.ConvertToStandalone(group)
1983 # Get some info about mesh:
1984 # ------------------------
1986 ## Returns the log of nodes and elements added or removed
1987 # since the previous clear of the log.
1988 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1989 # @return list of log_block structures:
1994 # @ingroup l1_auxiliary
1995 def GetLog(self, clearAfterGet):
1996 return self.mesh.GetLog(clearAfterGet)
1998 ## Clears the log of nodes and elements added or removed since the previous
1999 # clear. Must be used immediately after GetLog if clearAfterGet is false.
2000 # @ingroup l1_auxiliary
2002 self.mesh.ClearLog()
2004 ## Toggles auto color mode on the object.
2005 # @param theAutoColor the flag which toggles auto color mode.
2006 # @ingroup l1_auxiliary
2007 def SetAutoColor(self, theAutoColor):
2008 self.mesh.SetAutoColor(theAutoColor)
2010 ## Gets flag of object auto color mode.
2011 # @return True or False
2012 # @ingroup l1_auxiliary
2013 def GetAutoColor(self):
2014 return self.mesh.GetAutoColor()
2016 ## Gets the internal ID
2017 # @return integer value, which is the internal Id of the mesh
2018 # @ingroup l1_auxiliary
2020 return self.mesh.GetId()
2023 # @return integer value, which is the study Id of the mesh
2024 # @ingroup l1_auxiliary
2025 def GetStudyId(self):
2026 return self.mesh.GetStudyId()
2028 ## Checks the group names for duplications.
2029 # Consider the maximum group name length stored in MED file.
2030 # @return True or False
2031 # @ingroup l1_auxiliary
2032 def HasDuplicatedGroupNamesMED(self):
2033 return self.mesh.HasDuplicatedGroupNamesMED()
2035 ## Obtains the mesh editor tool
2036 # @return an instance of SMESH_MeshEditor
2037 # @ingroup l1_modifying
2038 def GetMeshEditor(self):
2041 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
2042 # can be passed as argument to a method accepting mesh, group or sub-mesh
2043 # @return an instance of SMESH_IDSource
2044 # @ingroup l1_auxiliary
2045 def GetIDSource(self, ids, elemType):
2046 return self.editor.MakeIDSource(ids, elemType)
2049 # Get informations about mesh contents:
2050 # ------------------------------------
2052 ## Gets the mesh stattistic
2053 # @return dictionary type element - count of elements
2054 # @ingroup l1_meshinfo
2055 def GetMeshInfo(self, obj = None):
2056 if not obj: obj = self.mesh
2057 return self.smeshpyD.GetMeshInfo(obj)
2059 ## Returns the number of nodes in the mesh
2060 # @return an integer value
2061 # @ingroup l1_meshinfo
2063 return self.mesh.NbNodes()
2065 ## Returns the number of elements in the mesh
2066 # @return an integer value
2067 # @ingroup l1_meshinfo
2068 def NbElements(self):
2069 return self.mesh.NbElements()
2071 ## Returns the number of 0d elements in the mesh
2072 # @return an integer value
2073 # @ingroup l1_meshinfo
2074 def Nb0DElements(self):
2075 return self.mesh.Nb0DElements()
2077 ## Returns the number of ball discrete elements in the mesh
2078 # @return an integer value
2079 # @ingroup l1_meshinfo
2081 return self.mesh.NbBalls()
2083 ## Returns the number of edges in the mesh
2084 # @return an integer value
2085 # @ingroup l1_meshinfo
2087 return self.mesh.NbEdges()
2089 ## Returns the number of edges with the given order in the mesh
2090 # @param elementOrder the order of elements:
2091 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2092 # @return an integer value
2093 # @ingroup l1_meshinfo
2094 def NbEdgesOfOrder(self, elementOrder):
2095 return self.mesh.NbEdgesOfOrder(elementOrder)
2097 ## Returns the number of faces in the mesh
2098 # @return an integer value
2099 # @ingroup l1_meshinfo
2101 return self.mesh.NbFaces()
2103 ## Returns the number of faces with the given order in the mesh
2104 # @param elementOrder the order of elements:
2105 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2106 # @return an integer value
2107 # @ingroup l1_meshinfo
2108 def NbFacesOfOrder(self, elementOrder):
2109 return self.mesh.NbFacesOfOrder(elementOrder)
2111 ## Returns the number of triangles in the mesh
2112 # @return an integer value
2113 # @ingroup l1_meshinfo
2114 def NbTriangles(self):
2115 return self.mesh.NbTriangles()
2117 ## Returns the number of triangles with the given order in the mesh
2118 # @param elementOrder is the order of elements:
2119 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2120 # @return an integer value
2121 # @ingroup l1_meshinfo
2122 def NbTrianglesOfOrder(self, elementOrder):
2123 return self.mesh.NbTrianglesOfOrder(elementOrder)
2125 ## Returns the number of biquadratic triangles in the mesh
2126 # @return an integer value
2127 # @ingroup l1_meshinfo
2128 def NbBiQuadTriangles(self):
2129 return self.mesh.NbBiQuadTriangles()
2131 ## Returns the number of quadrangles in the mesh
2132 # @return an integer value
2133 # @ingroup l1_meshinfo
2134 def NbQuadrangles(self):
2135 return self.mesh.NbQuadrangles()
2137 ## Returns the number of quadrangles with the given order in the mesh
2138 # @param elementOrder the order of elements:
2139 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2140 # @return an integer value
2141 # @ingroup l1_meshinfo
2142 def NbQuadranglesOfOrder(self, elementOrder):
2143 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2145 ## Returns the number of biquadratic quadrangles in the mesh
2146 # @return an integer value
2147 # @ingroup l1_meshinfo
2148 def NbBiQuadQuadrangles(self):
2149 return self.mesh.NbBiQuadQuadrangles()
2151 ## Returns the number of polygons in the mesh
2152 # @return an integer value
2153 # @ingroup l1_meshinfo
2154 def NbPolygons(self):
2155 return self.mesh.NbPolygons()
2157 ## Returns the number of volumes in the mesh
2158 # @return an integer value
2159 # @ingroup l1_meshinfo
2160 def NbVolumes(self):
2161 return self.mesh.NbVolumes()
2163 ## Returns the number of volumes with the given order in the mesh
2164 # @param elementOrder the order of elements:
2165 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2166 # @return an integer value
2167 # @ingroup l1_meshinfo
2168 def NbVolumesOfOrder(self, elementOrder):
2169 return self.mesh.NbVolumesOfOrder(elementOrder)
2171 ## Returns the number of tetrahedrons in the mesh
2172 # @return an integer value
2173 # @ingroup l1_meshinfo
2175 return self.mesh.NbTetras()
2177 ## Returns the number of tetrahedrons with the given order in the mesh
2178 # @param elementOrder the order of elements:
2179 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2180 # @return an integer value
2181 # @ingroup l1_meshinfo
2182 def NbTetrasOfOrder(self, elementOrder):
2183 return self.mesh.NbTetrasOfOrder(elementOrder)
2185 ## Returns the number of hexahedrons in the mesh
2186 # @return an integer value
2187 # @ingroup l1_meshinfo
2189 return self.mesh.NbHexas()
2191 ## Returns the number of hexahedrons with the given order in the mesh
2192 # @param elementOrder the order of elements:
2193 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2194 # @return an integer value
2195 # @ingroup l1_meshinfo
2196 def NbHexasOfOrder(self, elementOrder):
2197 return self.mesh.NbHexasOfOrder(elementOrder)
2199 ## Returns the number of triquadratic hexahedrons in the mesh
2200 # @return an integer value
2201 # @ingroup l1_meshinfo
2202 def NbTriQuadraticHexas(self):
2203 return self.mesh.NbTriQuadraticHexas()
2205 ## Returns the number of pyramids in the mesh
2206 # @return an integer value
2207 # @ingroup l1_meshinfo
2208 def NbPyramids(self):
2209 return self.mesh.NbPyramids()
2211 ## Returns the number of pyramids with the given order in the mesh
2212 # @param elementOrder the order of elements:
2213 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2214 # @return an integer value
2215 # @ingroup l1_meshinfo
2216 def NbPyramidsOfOrder(self, elementOrder):
2217 return self.mesh.NbPyramidsOfOrder(elementOrder)
2219 ## Returns the number of prisms in the mesh
2220 # @return an integer value
2221 # @ingroup l1_meshinfo
2223 return self.mesh.NbPrisms()
2225 ## Returns the number of prisms with the given order in the mesh
2226 # @param elementOrder the order of elements:
2227 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2228 # @return an integer value
2229 # @ingroup l1_meshinfo
2230 def NbPrismsOfOrder(self, elementOrder):
2231 return self.mesh.NbPrismsOfOrder(elementOrder)
2233 ## Returns the number of hexagonal prisms in the mesh
2234 # @return an integer value
2235 # @ingroup l1_meshinfo
2236 def NbHexagonalPrisms(self):
2237 return self.mesh.NbHexagonalPrisms()
2239 ## Returns the number of polyhedrons in the mesh
2240 # @return an integer value
2241 # @ingroup l1_meshinfo
2242 def NbPolyhedrons(self):
2243 return self.mesh.NbPolyhedrons()
2245 ## Returns the number of submeshes in the mesh
2246 # @return an integer value
2247 # @ingroup l1_meshinfo
2248 def NbSubMesh(self):
2249 return self.mesh.NbSubMesh()
2251 ## Returns the list of mesh elements IDs
2252 # @return the list of integer values
2253 # @ingroup l1_meshinfo
2254 def GetElementsId(self):
2255 return self.mesh.GetElementsId()
2257 ## Returns the list of IDs of mesh elements with the given type
2258 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2259 # @return list of integer values
2260 # @ingroup l1_meshinfo
2261 def GetElementsByType(self, elementType):
2262 return self.mesh.GetElementsByType(elementType)
2264 ## Returns the list of mesh nodes IDs
2265 # @return the list of integer values
2266 # @ingroup l1_meshinfo
2267 def GetNodesId(self):
2268 return self.mesh.GetNodesId()
2270 # Get the information about mesh elements:
2271 # ------------------------------------
2273 ## Returns the type of mesh element
2274 # @return the value from SMESH::ElementType enumeration
2275 # @ingroup l1_meshinfo
2276 def GetElementType(self, id, iselem):
2277 return self.mesh.GetElementType(id, iselem)
2279 ## Returns the geometric type of mesh element
2280 # @return the value from SMESH::EntityType enumeration
2281 # @ingroup l1_meshinfo
2282 def GetElementGeomType(self, id):
2283 return self.mesh.GetElementGeomType(id)
2285 ## Returns the list of submesh elements IDs
2286 # @param Shape a geom object(sub-shape) IOR
2287 # Shape must be the sub-shape of a ShapeToMesh()
2288 # @return the list of integer values
2289 # @ingroup l1_meshinfo
2290 def GetSubMeshElementsId(self, Shape):
2291 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2292 ShapeID = Shape.GetSubShapeIndices()[0]
2295 return self.mesh.GetSubMeshElementsId(ShapeID)
2297 ## Returns the list of submesh nodes IDs
2298 # @param Shape a geom object(sub-shape) IOR
2299 # Shape must be the sub-shape of a ShapeToMesh()
2300 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2301 # @return the list of integer values
2302 # @ingroup l1_meshinfo
2303 def GetSubMeshNodesId(self, Shape, all):
2304 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2305 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2308 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2310 ## Returns type of elements on given shape
2311 # @param Shape a geom object(sub-shape) IOR
2312 # Shape must be a sub-shape of a ShapeToMesh()
2313 # @return element type
2314 # @ingroup l1_meshinfo
2315 def GetSubMeshElementType(self, Shape):
2316 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2317 ShapeID = Shape.GetSubShapeIndices()[0]
2320 return self.mesh.GetSubMeshElementType(ShapeID)
2322 ## Gets the mesh description
2323 # @return string value
2324 # @ingroup l1_meshinfo
2326 return self.mesh.Dump()
2329 # Get the information about nodes and elements of a mesh by its IDs:
2330 # -----------------------------------------------------------
2332 ## Gets XYZ coordinates of a node
2333 # \n If there is no nodes for the given ID - returns an empty list
2334 # @return a list of double precision values
2335 # @ingroup l1_meshinfo
2336 def GetNodeXYZ(self, id):
2337 return self.mesh.GetNodeXYZ(id)
2339 ## Returns list of IDs of inverse elements for the given node
2340 # \n If there is no node for the given ID - returns an empty list
2341 # @return a list of integer values
2342 # @ingroup l1_meshinfo
2343 def GetNodeInverseElements(self, id):
2344 return self.mesh.GetNodeInverseElements(id)
2346 ## @brief Returns the position of a node on the shape
2347 # @return SMESH::NodePosition
2348 # @ingroup l1_meshinfo
2349 def GetNodePosition(self,NodeID):
2350 return self.mesh.GetNodePosition(NodeID)
2352 ## @brief Returns the position of an element on the shape
2353 # @return SMESH::ElementPosition
2354 # @ingroup l1_meshinfo
2355 def GetElementPosition(self,ElemID):
2356 return self.mesh.GetElementPosition(ElemID)
2358 ## If the given element is a node, returns the ID of shape
2359 # \n If there is no node for the given ID - returns -1
2360 # @return an integer value
2361 # @ingroup l1_meshinfo
2362 def GetShapeID(self, id):
2363 return self.mesh.GetShapeID(id)
2365 ## Returns the ID of the result shape after
2366 # FindShape() from SMESH_MeshEditor for the given element
2367 # \n If there is no element for the given ID - returns -1
2368 # @return an integer value
2369 # @ingroup l1_meshinfo
2370 def GetShapeIDForElem(self,id):
2371 return self.mesh.GetShapeIDForElem(id)
2373 ## Returns the number of nodes for the given element
2374 # \n If there is no element for the given ID - returns -1
2375 # @return an integer value
2376 # @ingroup l1_meshinfo
2377 def GetElemNbNodes(self, id):
2378 return self.mesh.GetElemNbNodes(id)
2380 ## Returns the node ID the given (zero based) index for the given element
2381 # \n If there is no element for the given ID - returns -1
2382 # \n If there is no node for the given index - returns -2
2383 # @return an integer value
2384 # @ingroup l1_meshinfo
2385 def GetElemNode(self, id, index):
2386 return self.mesh.GetElemNode(id, index)
2388 ## Returns the IDs of nodes of the given element
2389 # @return a list of integer values
2390 # @ingroup l1_meshinfo
2391 def GetElemNodes(self, id):
2392 return self.mesh.GetElemNodes(id)
2394 ## Returns true if the given node is the medium node in the given quadratic element
2395 # @ingroup l1_meshinfo
2396 def IsMediumNode(self, elementID, nodeID):
2397 return self.mesh.IsMediumNode(elementID, nodeID)
2399 ## Returns true if the given node is the medium node in one of quadratic elements
2400 # @ingroup l1_meshinfo
2401 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2402 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2404 ## Returns the number of edges for the given element
2405 # @ingroup l1_meshinfo
2406 def ElemNbEdges(self, id):
2407 return self.mesh.ElemNbEdges(id)
2409 ## Returns the number of faces for the given element
2410 # @ingroup l1_meshinfo
2411 def ElemNbFaces(self, id):
2412 return self.mesh.ElemNbFaces(id)
2414 ## Returns nodes of given face (counted from zero) for given volumic element.
2415 # @ingroup l1_meshinfo
2416 def GetElemFaceNodes(self,elemId, faceIndex):
2417 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2419 ## Returns an element based on all given nodes.
2420 # @ingroup l1_meshinfo
2421 def FindElementByNodes(self,nodes):
2422 return self.mesh.FindElementByNodes(nodes)
2424 ## Returns true if the given element is a polygon
2425 # @ingroup l1_meshinfo
2426 def IsPoly(self, id):
2427 return self.mesh.IsPoly(id)
2429 ## Returns true if the given element is quadratic
2430 # @ingroup l1_meshinfo
2431 def IsQuadratic(self, id):
2432 return self.mesh.IsQuadratic(id)
2434 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2435 # @ingroup l1_meshinfo
2436 def GetBallDiameter(self, id):
2437 return self.mesh.GetBallDiameter(id)
2439 ## Returns XYZ coordinates of the barycenter of the given element
2440 # \n If there is no element for the given ID - returns an empty list
2441 # @return a list of three double values
2442 # @ingroup l1_meshinfo
2443 def BaryCenter(self, id):
2444 return self.mesh.BaryCenter(id)
2446 ## Passes mesh elements through the given filter and return IDs of fitting elements
2447 # @param theFilter SMESH_Filter
2448 # @return a list of ids
2449 # @ingroup l1_controls
2450 def GetIdsFromFilter(self, theFilter):
2451 theFilter.SetMesh( self.mesh )
2452 return theFilter.GetIDs()
2454 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2455 # Returns a list of special structures (borders).
2456 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2457 # @ingroup l1_controls
2458 def GetFreeBorders(self):
2459 aFilterMgr = self.smeshpyD.CreateFilterManager()
2460 aPredicate = aFilterMgr.CreateFreeEdges()
2461 aPredicate.SetMesh(self.mesh)
2462 aBorders = aPredicate.GetBorders()
2463 aFilterMgr.UnRegister()
2467 # Get mesh measurements information:
2468 # ------------------------------------
2470 ## Get minimum distance between two nodes, elements or distance to the origin
2471 # @param id1 first node/element id
2472 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2473 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2474 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2475 # @return minimum distance value
2476 # @sa GetMinDistance()
2477 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2478 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2479 return aMeasure.value
2481 ## Get measure structure specifying minimum distance data between two objects
2482 # @param id1 first node/element id
2483 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2484 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2485 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2486 # @return Measure structure
2488 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2490 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2492 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2495 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2497 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2502 aMeasurements = self.smeshpyD.CreateMeasurements()
2503 aMeasure = aMeasurements.MinDistance(id1, id2)
2504 genObjUnRegister([aMeasurements,id1, id2])
2507 ## Get bounding box of the specified object(s)
2508 # @param objects single source object or list of source objects or list of nodes/elements IDs
2509 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2510 # @c False specifies that @a objects are nodes
2511 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2512 # @sa GetBoundingBox()
2513 def BoundingBox(self, objects=None, isElem=False):
2514 result = self.GetBoundingBox(objects, isElem)
2518 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2521 ## Get measure structure specifying bounding box data of the specified object(s)
2522 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2523 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2524 # @c False specifies that @a objects are nodes
2525 # @return Measure structure
2527 def GetBoundingBox(self, IDs=None, isElem=False):
2530 elif isinstance(IDs, tuple):
2532 if not isinstance(IDs, list):
2534 if len(IDs) > 0 and isinstance(IDs[0], int):
2537 unRegister = genObjUnRegister()
2539 if isinstance(o, Mesh):
2540 srclist.append(o.mesh)
2541 elif hasattr(o, "_narrow"):
2542 src = o._narrow(SMESH.SMESH_IDSource)
2543 if src: srclist.append(src)
2545 elif isinstance(o, list):
2547 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2549 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2550 unRegister.set( srclist[-1] )
2553 aMeasurements = self.smeshpyD.CreateMeasurements()
2554 unRegister.set( aMeasurements )
2555 aMeasure = aMeasurements.BoundingBox(srclist)
2558 # Mesh edition (SMESH_MeshEditor functionality):
2559 # ---------------------------------------------
2561 ## Removes the elements from the mesh by ids
2562 # @param IDsOfElements is a list of ids of elements to remove
2563 # @return True or False
2564 # @ingroup l2_modif_del
2565 def RemoveElements(self, IDsOfElements):
2566 return self.editor.RemoveElements(IDsOfElements)
2568 ## Removes nodes from mesh by ids
2569 # @param IDsOfNodes is a list of ids of nodes to remove
2570 # @return True or False
2571 # @ingroup l2_modif_del
2572 def RemoveNodes(self, IDsOfNodes):
2573 return self.editor.RemoveNodes(IDsOfNodes)
2575 ## Removes all orphan (free) nodes from mesh
2576 # @return number of the removed nodes
2577 # @ingroup l2_modif_del
2578 def RemoveOrphanNodes(self):
2579 return self.editor.RemoveOrphanNodes()
2581 ## Add a node to the mesh by coordinates
2582 # @return Id of the new node
2583 # @ingroup l2_modif_add
2584 def AddNode(self, x, y, z):
2585 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2586 if hasVars: self.mesh.SetParameters(Parameters)
2587 return self.editor.AddNode( x, y, z)
2589 ## Creates a 0D element on a node with given number.
2590 # @param IDOfNode the ID of node for creation of the element.
2591 # @return the Id of the new 0D element
2592 # @ingroup l2_modif_add
2593 def Add0DElement(self, IDOfNode):
2594 return self.editor.Add0DElement(IDOfNode)
2596 ## Create 0D elements on all nodes of the given elements except those
2597 # nodes on which a 0D element already exists.
2598 # @param theObject an object on whose nodes 0D elements will be created.
2599 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2600 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2601 # @param theGroupName optional name of a group to add 0D elements created
2602 # and/or found on nodes of \a theObject.
2603 # @return an object (a new group or a temporary SMESH_IDSource) holding
2604 # IDs of new and/or found 0D elements. IDs of 0D elements
2605 # can be retrieved from the returned object by calling GetIDs()
2606 # @ingroup l2_modif_add
2607 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2608 unRegister = genObjUnRegister()
2609 if isinstance( theObject, Mesh ):
2610 theObject = theObject.GetMesh()
2611 if isinstance( theObject, list ):
2612 theObject = self.GetIDSource( theObject, SMESH.ALL )
2613 unRegister.set( theObject )
2614 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2616 ## Creates a ball element on a node with given ID.
2617 # @param IDOfNode the ID of node for creation of the element.
2618 # @param diameter the bal diameter.
2619 # @return the Id of the new ball element
2620 # @ingroup l2_modif_add
2621 def AddBall(self, IDOfNode, diameter):
2622 return self.editor.AddBall( IDOfNode, diameter )
2624 ## Creates a linear or quadratic edge (this is determined
2625 # by the number of given nodes).
2626 # @param IDsOfNodes the list of node IDs for creation of the element.
2627 # The order of nodes in this list should correspond to the description
2628 # of MED. \n This description is located by the following link:
2629 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2630 # @return the Id of the new edge
2631 # @ingroup l2_modif_add
2632 def AddEdge(self, IDsOfNodes):
2633 return self.editor.AddEdge(IDsOfNodes)
2635 ## Creates a linear or quadratic face (this is determined
2636 # by the number of given nodes).
2637 # @param IDsOfNodes the list of node IDs for creation of the element.
2638 # The order of nodes in this list should correspond to the description
2639 # of MED. \n This description is located by the following link:
2640 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2641 # @return the Id of the new face
2642 # @ingroup l2_modif_add
2643 def AddFace(self, IDsOfNodes):
2644 return self.editor.AddFace(IDsOfNodes)
2646 ## Adds a polygonal face to the mesh by the list of node IDs
2647 # @param IdsOfNodes the list of node IDs for creation of the element.
2648 # @return the Id of the new face
2649 # @ingroup l2_modif_add
2650 def AddPolygonalFace(self, IdsOfNodes):
2651 return self.editor.AddPolygonalFace(IdsOfNodes)
2653 ## Creates both simple and quadratic volume (this is determined
2654 # by the number of given nodes).
2655 # @param IDsOfNodes the list of node IDs for creation of the element.
2656 # The order of nodes in this list should correspond to the description
2657 # of MED. \n This description is located by the following link:
2658 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2659 # @return the Id of the new volumic element
2660 # @ingroup l2_modif_add
2661 def AddVolume(self, IDsOfNodes):
2662 return self.editor.AddVolume(IDsOfNodes)
2664 ## Creates a volume of many faces, giving nodes for each face.
2665 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2666 # @param Quantities the list of integer values, Quantities[i]
2667 # gives the quantity of nodes in face number i.
2668 # @return the Id of the new volumic element
2669 # @ingroup l2_modif_add
2670 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2671 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2673 ## Creates a volume of many faces, giving the IDs of the existing faces.
2674 # @param IdsOfFaces the list of face IDs for volume creation.
2676 # Note: The created volume will refer only to the nodes
2677 # of the given faces, not to the faces themselves.
2678 # @return the Id of the new volumic element
2679 # @ingroup l2_modif_add
2680 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2681 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2684 ## @brief Binds a node to a vertex
2685 # @param NodeID a node ID
2686 # @param Vertex a vertex or vertex ID
2687 # @return True if succeed else raises an exception
2688 # @ingroup l2_modif_add
2689 def SetNodeOnVertex(self, NodeID, Vertex):
2690 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
2691 VertexID = Vertex.GetSubShapeIndices()[0]
2695 self.editor.SetNodeOnVertex(NodeID, VertexID)
2696 except SALOME.SALOME_Exception, inst:
2697 raise ValueError, inst.details.text
2701 ## @brief Stores the node position on an edge
2702 # @param NodeID a node ID
2703 # @param Edge an edge or edge ID
2704 # @param paramOnEdge a parameter on the edge where the node is located
2705 # @return True if succeed else raises an exception
2706 # @ingroup l2_modif_add
2707 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2708 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
2709 EdgeID = Edge.GetSubShapeIndices()[0]
2713 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2714 except SALOME.SALOME_Exception, inst:
2715 raise ValueError, inst.details.text
2718 ## @brief Stores node position on a face
2719 # @param NodeID a node ID
2720 # @param Face a face or face ID
2721 # @param u U parameter on the face where the node is located
2722 # @param v V parameter on the face where the node is located
2723 # @return True if succeed else raises an exception
2724 # @ingroup l2_modif_add
2725 def SetNodeOnFace(self, NodeID, Face, u, v):
2726 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
2727 FaceID = Face.GetSubShapeIndices()[0]
2731 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2732 except SALOME.SALOME_Exception, inst:
2733 raise ValueError, inst.details.text
2736 ## @brief Binds a node to a solid
2737 # @param NodeID a node ID
2738 # @param Solid a solid or solid ID
2739 # @return True if succeed else raises an exception
2740 # @ingroup l2_modif_add
2741 def SetNodeInVolume(self, NodeID, Solid):
2742 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
2743 SolidID = Solid.GetSubShapeIndices()[0]
2747 self.editor.SetNodeInVolume(NodeID, SolidID)
2748 except SALOME.SALOME_Exception, inst:
2749 raise ValueError, inst.details.text
2752 ## @brief Bind an element to a shape
2753 # @param ElementID an element ID
2754 # @param Shape a shape or shape ID
2755 # @return True if succeed else raises an exception
2756 # @ingroup l2_modif_add
2757 def SetMeshElementOnShape(self, ElementID, Shape):
2758 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2759 ShapeID = Shape.GetSubShapeIndices()[0]
2763 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2764 except SALOME.SALOME_Exception, inst:
2765 raise ValueError, inst.details.text
2769 ## Moves the node with the given id
2770 # @param NodeID the id of the node
2771 # @param x a new X coordinate
2772 # @param y a new Y coordinate
2773 # @param z a new Z coordinate
2774 # @return True if succeed else False
2775 # @ingroup l2_modif_movenode
2776 def MoveNode(self, NodeID, x, y, z):
2777 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2778 if hasVars: self.mesh.SetParameters(Parameters)
2779 return self.editor.MoveNode(NodeID, x, y, z)
2781 ## Finds the node closest to a point and moves it to a point location
2782 # @param x the X coordinate of a point
2783 # @param y the Y coordinate of a point
2784 # @param z the Z coordinate of a point
2785 # @param NodeID if specified (>0), the node with this ID is moved,
2786 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2787 # @return the ID of a node
2788 # @ingroup l2_modif_throughp
2789 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2790 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2791 if hasVars: self.mesh.SetParameters(Parameters)
2792 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2794 ## Finds the node closest to a point
2795 # @param x the X coordinate of a point
2796 # @param y the Y coordinate of a point
2797 # @param z the Z coordinate of a point
2798 # @return the ID of a node
2799 # @ingroup l2_modif_throughp
2800 def FindNodeClosestTo(self, x, y, z):
2801 #preview = self.mesh.GetMeshEditPreviewer()
2802 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2803 return self.editor.FindNodeClosestTo(x, y, z)
2805 ## Finds the elements where a point lays IN or ON
2806 # @param x the X coordinate of a point
2807 # @param y the Y coordinate of a point
2808 # @param z the Z coordinate of a point
2809 # @param elementType type of elements to find (SMESH.ALL type
2810 # means elements of any type excluding nodes, discrete and 0D elements)
2811 # @param meshPart a part of mesh (group, sub-mesh) to search within
2812 # @return list of IDs of found elements
2813 # @ingroup l2_modif_throughp
2814 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2816 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2818 return self.editor.FindElementsByPoint(x, y, z, elementType)
2820 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2821 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2822 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2824 def GetPointState(self, x, y, z):
2825 return self.editor.GetPointState(x, y, z)
2827 ## Finds the node closest to a point and moves it to a point location
2828 # @param x the X coordinate of a point
2829 # @param y the Y coordinate of a point
2830 # @param z the Z coordinate of a point
2831 # @return the ID of a moved node
2832 # @ingroup l2_modif_throughp
2833 def MeshToPassThroughAPoint(self, x, y, z):
2834 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2836 ## Replaces two neighbour triangles sharing Node1-Node2 link
2837 # with the triangles built on the same 4 nodes but having other common link.
2838 # @param NodeID1 the ID of the first node
2839 # @param NodeID2 the ID of the second node
2840 # @return false if proper faces were not found
2841 # @ingroup l2_modif_invdiag
2842 def InverseDiag(self, NodeID1, NodeID2):
2843 return self.editor.InverseDiag(NodeID1, NodeID2)
2845 ## Replaces two neighbour triangles sharing Node1-Node2 link
2846 # with a quadrangle built on the same 4 nodes.
2847 # @param NodeID1 the ID of the first node
2848 # @param NodeID2 the ID of the second node
2849 # @return false if proper faces were not found
2850 # @ingroup l2_modif_unitetri
2851 def DeleteDiag(self, NodeID1, NodeID2):
2852 return self.editor.DeleteDiag(NodeID1, NodeID2)
2854 ## Reorients elements by ids
2855 # @param IDsOfElements if undefined reorients all mesh elements
2856 # @return True if succeed else False
2857 # @ingroup l2_modif_changori
2858 def Reorient(self, IDsOfElements=None):
2859 if IDsOfElements == None:
2860 IDsOfElements = self.GetElementsId()
2861 return self.editor.Reorient(IDsOfElements)
2863 ## Reorients all elements of the object
2864 # @param theObject mesh, submesh or group
2865 # @return True if succeed else False
2866 # @ingroup l2_modif_changori
2867 def ReorientObject(self, theObject):
2868 if ( isinstance( theObject, Mesh )):
2869 theObject = theObject.GetMesh()
2870 return self.editor.ReorientObject(theObject)
2872 ## Reorient faces contained in \a the2DObject.
2873 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2874 # @param theDirection is a desired direction of normal of \a theFace.
2875 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2876 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2877 # compared with theDirection. It can be either ID of face or a point
2878 # by which the face will be found. The point can be given as either
2879 # a GEOM vertex or a list of point coordinates.
2880 # @return number of reoriented faces
2881 # @ingroup l2_modif_changori
2882 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2883 unRegister = genObjUnRegister()
2885 if isinstance( the2DObject, Mesh ):
2886 the2DObject = the2DObject.GetMesh()
2887 if isinstance( the2DObject, list ):
2888 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2889 unRegister.set( the2DObject )
2890 # check theDirection
2891 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
2892 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2893 if isinstance( theDirection, list ):
2894 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2895 # prepare theFace and thePoint
2896 theFace = theFaceOrPoint
2897 thePoint = PointStruct(0,0,0)
2898 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
2899 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2901 if isinstance( theFaceOrPoint, list ):
2902 thePoint = PointStruct( *theFaceOrPoint )
2904 if isinstance( theFaceOrPoint, PointStruct ):
2905 thePoint = theFaceOrPoint
2907 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2909 ## Fuses the neighbouring triangles into quadrangles.
2910 # @param IDsOfElements The triangles to be fused,
2911 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2912 # choose a neighbour to fuse with.
2913 # @param MaxAngle is the maximum angle between element normals at which the fusion
2914 # is still performed; theMaxAngle is mesured in radians.
2915 # Also it could be a name of variable which defines angle in degrees.
2916 # @return TRUE in case of success, FALSE otherwise.
2917 # @ingroup l2_modif_unitetri
2918 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2919 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2920 self.mesh.SetParameters(Parameters)
2921 if not IDsOfElements:
2922 IDsOfElements = self.GetElementsId()
2923 Functor = self.smeshpyD.GetFunctor(theCriterion)
2924 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2926 ## Fuses the neighbouring triangles of the object into quadrangles
2927 # @param theObject is mesh, submesh or group
2928 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2929 # choose a neighbour to fuse with.
2930 # @param MaxAngle a max angle between element normals at which the fusion
2931 # is still performed; theMaxAngle is mesured in radians.
2932 # @return TRUE in case of success, FALSE otherwise.
2933 # @ingroup l2_modif_unitetri
2934 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2935 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2936 self.mesh.SetParameters(Parameters)
2937 if isinstance( theObject, Mesh ):
2938 theObject = theObject.GetMesh()
2939 Functor = self.smeshpyD.GetFunctor(theCriterion)
2940 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2942 ## Splits quadrangles into triangles.
2943 # @param IDsOfElements the faces to be splitted.
2944 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2945 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2946 # value, then quadrangles will be split by the smallest diagonal.
2947 # @return TRUE in case of success, FALSE otherwise.
2948 # @ingroup l2_modif_cutquadr
2949 def QuadToTri (self, IDsOfElements, theCriterion = None):
2950 if IDsOfElements == []:
2951 IDsOfElements = self.GetElementsId()
2952 if theCriterion is None:
2953 theCriterion = FT_MaxElementLength2D
2954 Functor = self.smeshpyD.GetFunctor(theCriterion)
2955 return self.editor.QuadToTri(IDsOfElements, Functor)
2957 ## Splits quadrangles into triangles.
2958 # @param theObject the object from which the list of elements is taken,
2959 # this is mesh, submesh or group
2960 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2961 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2962 # value, then quadrangles will be split by the smallest diagonal.
2963 # @return TRUE in case of success, FALSE otherwise.
2964 # @ingroup l2_modif_cutquadr
2965 def QuadToTriObject (self, theObject, theCriterion = None):
2966 if ( isinstance( theObject, Mesh )):
2967 theObject = theObject.GetMesh()
2968 if theCriterion is None:
2969 theCriterion = FT_MaxElementLength2D
2970 Functor = self.smeshpyD.GetFunctor(theCriterion)
2971 return self.editor.QuadToTriObject(theObject, Functor)
2973 ## Splits each of given quadrangles into 4 triangles. A node is added at the center of
2975 # @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
2976 # group or a list of face IDs. By default all quadrangles are split
2977 # @ingroup l2_modif_cutquadr
2978 def QuadTo4Tri (self, theElements=[]):
2979 unRegister = genObjUnRegister()
2980 if isinstance( theElements, Mesh ):
2981 theElements = theElements.mesh
2982 elif not theElements:
2983 theElements = self.mesh
2984 elif isinstance( theElements, list ):
2985 theElements = self.GetIDSource( theElements, SMESH.FACE )
2986 unRegister.set( theElements )
2987 return self.editor.QuadTo4Tri( theElements )
2989 ## Splits quadrangles into triangles.
2990 # @param IDsOfElements the faces to be splitted
2991 # @param Diag13 is used to choose a diagonal for splitting.
2992 # @return TRUE in case of success, FALSE otherwise.
2993 # @ingroup l2_modif_cutquadr
2994 def SplitQuad (self, IDsOfElements, Diag13):
2995 if IDsOfElements == []:
2996 IDsOfElements = self.GetElementsId()
2997 return self.editor.SplitQuad(IDsOfElements, Diag13)
2999 ## Splits quadrangles into triangles.
3000 # @param theObject the object from which the list of elements is taken,
3001 # this is mesh, submesh or group
3002 # @param Diag13 is used to choose a diagonal for splitting.
3003 # @return TRUE in case of success, FALSE otherwise.
3004 # @ingroup l2_modif_cutquadr
3005 def SplitQuadObject (self, theObject, Diag13):
3006 if ( isinstance( theObject, Mesh )):
3007 theObject = theObject.GetMesh()
3008 return self.editor.SplitQuadObject(theObject, Diag13)
3010 ## Finds a better splitting of the given quadrangle.
3011 # @param IDOfQuad the ID of the quadrangle to be splitted.
3012 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3013 # choose a diagonal for splitting.
3014 # @return 1 if 1-3 diagonal is better, 2 if 2-4
3015 # diagonal is better, 0 if error occurs.
3016 # @ingroup l2_modif_cutquadr
3017 def BestSplit (self, IDOfQuad, theCriterion):
3018 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
3020 ## Splits volumic elements into tetrahedrons
3021 # @param elemIDs either list of elements or mesh or group or submesh
3022 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
3023 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
3024 # @ingroup l2_modif_cutquadr
3025 def SplitVolumesIntoTetra(self, elemIDs, method=smeshBuilder.Hex_5Tet ):
3026 unRegister = genObjUnRegister()
3027 if isinstance( elemIDs, Mesh ):
3028 elemIDs = elemIDs.GetMesh()
3029 if ( isinstance( elemIDs, list )):
3030 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
3031 unRegister.set( elemIDs )
3032 self.editor.SplitVolumesIntoTetra(elemIDs, method)
3034 ## Splits quadrangle faces near triangular facets of volumes
3036 # @ingroup l1_auxiliary
3037 def SplitQuadsNearTriangularFacets(self):
3038 faces_array = self.GetElementsByType(SMESH.FACE)
3039 for face_id in faces_array:
3040 if self.GetElemNbNodes(face_id) == 4: # quadrangle
3041 quad_nodes = self.mesh.GetElemNodes(face_id)
3042 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
3043 isVolumeFound = False
3044 for node1_elem in node1_elems:
3045 if not isVolumeFound:
3046 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
3047 nb_nodes = self.GetElemNbNodes(node1_elem)
3048 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
3049 volume_elem = node1_elem
3050 volume_nodes = self.mesh.GetElemNodes(volume_elem)
3051 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
3052 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
3053 isVolumeFound = True
3054 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
3055 self.SplitQuad([face_id], False) # diagonal 2-4
3056 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
3057 isVolumeFound = True
3058 self.SplitQuad([face_id], True) # diagonal 1-3
3059 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
3060 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
3061 isVolumeFound = True
3062 self.SplitQuad([face_id], True) # diagonal 1-3
3064 ## @brief Splits hexahedrons into tetrahedrons.
3066 # This operation uses pattern mapping functionality for splitting.
3067 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
3068 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
3069 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
3070 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
3071 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
3072 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
3073 # @return TRUE in case of success, FALSE otherwise.
3074 # @ingroup l1_auxiliary
3075 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
3076 # Pattern: 5.---------.6
3081 # (0,0,1) 4.---------.7 * |
3088 # (0,0,0) 0.---------.3
3089 pattern_tetra = "!!! Nb of points: \n 8 \n\
3099 !!! Indices of points of 6 tetras: \n\
3107 pattern = self.smeshpyD.GetPattern()
3108 isDone = pattern.LoadFromFile(pattern_tetra)
3110 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3113 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3114 isDone = pattern.MakeMesh(self.mesh, False, False)
3115 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3117 # split quafrangle faces near triangular facets of volumes
3118 self.SplitQuadsNearTriangularFacets()
3122 ## @brief Split hexahedrons into prisms.
3124 # Uses the pattern mapping functionality for splitting.
3125 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
3126 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
3127 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
3128 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
3129 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
3130 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
3131 # @return TRUE in case of success, FALSE otherwise.
3132 # @ingroup l1_auxiliary
3133 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3134 # Pattern: 5.---------.6
3139 # (0,0,1) 4.---------.7 |
3146 # (0,0,0) 0.---------.3
3147 pattern_prism = "!!! Nb of points: \n 8 \n\
3157 !!! Indices of points of 2 prisms: \n\
3161 pattern = self.smeshpyD.GetPattern()
3162 isDone = pattern.LoadFromFile(pattern_prism)
3164 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3167 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3168 isDone = pattern.MakeMesh(self.mesh, False, False)
3169 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3171 # Splits quafrangle faces near triangular facets of volumes
3172 self.SplitQuadsNearTriangularFacets()
3176 ## Smoothes elements
3177 # @param IDsOfElements the list if ids of elements to smooth
3178 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3179 # Note that nodes built on edges and boundary nodes are always fixed.
3180 # @param MaxNbOfIterations the maximum number of iterations
3181 # @param MaxAspectRatio varies in range [1.0, inf]
3182 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3183 # @return TRUE in case of success, FALSE otherwise.
3184 # @ingroup l2_modif_smooth
3185 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3186 MaxNbOfIterations, MaxAspectRatio, Method):
3187 if IDsOfElements == []:
3188 IDsOfElements = self.GetElementsId()
3189 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3190 self.mesh.SetParameters(Parameters)
3191 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3192 MaxNbOfIterations, MaxAspectRatio, Method)
3194 ## Smoothes elements which belong to the given object
3195 # @param theObject the object to smooth
3196 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3197 # Note that nodes built on edges and boundary nodes are always fixed.
3198 # @param MaxNbOfIterations the maximum number of iterations
3199 # @param MaxAspectRatio varies in range [1.0, inf]
3200 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3201 # @return TRUE in case of success, FALSE otherwise.
3202 # @ingroup l2_modif_smooth
3203 def SmoothObject(self, theObject, IDsOfFixedNodes,
3204 MaxNbOfIterations, MaxAspectRatio, Method):
3205 if ( isinstance( theObject, Mesh )):
3206 theObject = theObject.GetMesh()
3207 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3208 MaxNbOfIterations, MaxAspectRatio, Method)
3210 ## Parametrically smoothes the given elements
3211 # @param IDsOfElements the list if ids of elements to smooth
3212 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3213 # Note that nodes built on edges and boundary nodes are always fixed.
3214 # @param MaxNbOfIterations the maximum number of iterations
3215 # @param MaxAspectRatio varies in range [1.0, inf]
3216 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3217 # @return TRUE in case of success, FALSE otherwise.
3218 # @ingroup l2_modif_smooth
3219 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3220 MaxNbOfIterations, MaxAspectRatio, Method):
3221 if IDsOfElements == []:
3222 IDsOfElements = self.GetElementsId()
3223 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3224 self.mesh.SetParameters(Parameters)
3225 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3226 MaxNbOfIterations, MaxAspectRatio, Method)
3228 ## Parametrically smoothes the elements which belong to the given object
3229 # @param theObject the object to smooth
3230 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3231 # Note that nodes built on edges and boundary nodes are always fixed.
3232 # @param MaxNbOfIterations the maximum number of iterations
3233 # @param MaxAspectRatio varies in range [1.0, inf]
3234 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3235 # @return TRUE in case of success, FALSE otherwise.
3236 # @ingroup l2_modif_smooth
3237 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3238 MaxNbOfIterations, MaxAspectRatio, Method):
3239 if ( isinstance( theObject, Mesh )):
3240 theObject = theObject.GetMesh()
3241 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3242 MaxNbOfIterations, MaxAspectRatio, Method)
3244 ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3245 # them with quadratic with the same id.
3246 # @param theForce3d new node creation method:
3247 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3248 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3249 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3250 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3251 # @ingroup l2_modif_tofromqu
3252 def ConvertToQuadratic(self, theForce3d, theSubMesh=None, theToBiQuad=False):
3253 if isinstance( theSubMesh, Mesh ):
3254 theSubMesh = theSubMesh.mesh
3256 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3259 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3261 self.editor.ConvertToQuadratic(theForce3d)
3262 error = self.editor.GetLastError()
3263 if error and error.comment:
3266 ## Converts the mesh from quadratic to ordinary,
3267 # deletes old quadratic elements, \n replacing
3268 # them with ordinary mesh elements with the same id.
3269 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3270 # @ingroup l2_modif_tofromqu
3271 def ConvertFromQuadratic(self, theSubMesh=None):
3273 self.editor.ConvertFromQuadraticObject(theSubMesh)
3275 return self.editor.ConvertFromQuadratic()
3277 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3278 # @return TRUE if operation has been completed successfully, FALSE otherwise
3279 # @ingroup l2_modif_edit
3280 def Make2DMeshFrom3D(self):
3281 return self.editor. Make2DMeshFrom3D()
3283 ## Creates missing boundary elements
3284 # @param elements - elements whose boundary is to be checked:
3285 # mesh, group, sub-mesh or list of elements
3286 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3287 # @param dimension - defines type of boundary elements to create:
3288 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3289 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3290 # @param groupName - a name of group to store created boundary elements in,
3291 # "" means not to create the group
3292 # @param meshName - a name of new mesh to store created boundary elements in,
3293 # "" means not to create the new mesh
3294 # @param toCopyElements - if true, the checked elements will be copied into
3295 # the new mesh else only boundary elements will be copied into the new mesh
3296 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3297 # boundary elements will be copied into the new mesh
3298 # @return tuple (mesh, group) where boundary elements were added to
3299 # @ingroup l2_modif_edit
3300 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3301 toCopyElements=False, toCopyExistingBondary=False):
3302 unRegister = genObjUnRegister()
3303 if isinstance( elements, Mesh ):
3304 elements = elements.GetMesh()
3305 if ( isinstance( elements, list )):
3306 elemType = SMESH.ALL
3307 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3308 elements = self.editor.MakeIDSource(elements, elemType)
3309 unRegister.set( elements )
3310 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3311 toCopyElements,toCopyExistingBondary)
3312 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3316 # @brief Creates missing boundary elements around either the whole mesh or
3317 # groups of 2D elements
3318 # @param dimension - defines type of boundary elements to create
3319 # @param groupName - a name of group to store all boundary elements in,
3320 # "" means not to create the group
3321 # @param meshName - a name of a new mesh, which is a copy of the initial
3322 # mesh + created boundary elements; "" means not to create the new mesh
3323 # @param toCopyAll - if true, the whole initial mesh will be copied into
3324 # the new mesh else only boundary elements will be copied into the new mesh
3325 # @param groups - groups of 2D elements to make boundary around
3326 # @retval tuple( long, mesh, groups )
3327 # long - number of added boundary elements
3328 # mesh - the mesh where elements were added to
3329 # group - the group of boundary elements or None
3331 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3332 toCopyAll=False, groups=[]):
3333 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3335 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3336 return nb, mesh, group
3338 ## Renumber mesh nodes
3339 # @ingroup l2_modif_renumber
3340 def RenumberNodes(self):
3341 self.editor.RenumberNodes()
3343 ## Renumber mesh elements
3344 # @ingroup l2_modif_renumber
3345 def RenumberElements(self):
3346 self.editor.RenumberElements()
3348 ## Generates new elements by rotation of the elements around the axis
3349 # @param IDsOfElements the list of ids of elements to sweep
3350 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3351 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3352 # @param NbOfSteps the number of steps
3353 # @param Tolerance tolerance
3354 # @param MakeGroups forces the generation of new groups from existing ones
3355 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3356 # of all steps, else - size of each step
3357 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3358 # @ingroup l2_modif_extrurev
3359 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3360 MakeGroups=False, TotalAngle=False):
3361 if IDsOfElements == []:
3362 IDsOfElements = self.GetElementsId()
3363 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3364 Axis = self.smeshpyD.GetAxisStruct(Axis)
3365 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3366 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3367 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3368 self.mesh.SetParameters(Parameters)
3369 if TotalAngle and NbOfSteps:
3370 AngleInRadians /= NbOfSteps
3372 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3373 AngleInRadians, NbOfSteps, Tolerance)
3374 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3377 ## Generates new elements by rotation of the elements of object around the axis
3378 # @param theObject object which elements should be sweeped.
3379 # It can be a mesh, a sub mesh or a group.
3380 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3381 # @param AngleInRadians the angle of Rotation
3382 # @param NbOfSteps number of steps
3383 # @param Tolerance tolerance
3384 # @param MakeGroups forces the generation of new groups from existing ones
3385 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3386 # of all steps, else - size of each step
3387 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3388 # @ingroup l2_modif_extrurev
3389 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3390 MakeGroups=False, TotalAngle=False):
3391 if ( isinstance( theObject, Mesh )):
3392 theObject = theObject.GetMesh()
3393 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3394 Axis = self.smeshpyD.GetAxisStruct(Axis)
3395 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3396 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3397 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3398 self.mesh.SetParameters(Parameters)
3399 if TotalAngle and NbOfSteps:
3400 AngleInRadians /= NbOfSteps
3402 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3403 NbOfSteps, Tolerance)
3404 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3407 ## Generates new elements by rotation of the elements of object around the axis
3408 # @param theObject object which elements should be sweeped.
3409 # It can be a mesh, a sub mesh or a group.
3410 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3411 # @param AngleInRadians the angle of Rotation
3412 # @param NbOfSteps number of steps
3413 # @param Tolerance tolerance
3414 # @param MakeGroups forces the generation of new groups from existing ones
3415 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3416 # of all steps, else - size of each step
3417 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3418 # @ingroup l2_modif_extrurev
3419 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3420 MakeGroups=False, TotalAngle=False):
3421 if ( isinstance( theObject, Mesh )):
3422 theObject = theObject.GetMesh()
3423 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3424 Axis = self.smeshpyD.GetAxisStruct(Axis)
3425 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3426 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3427 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3428 self.mesh.SetParameters(Parameters)
3429 if TotalAngle and NbOfSteps:
3430 AngleInRadians /= NbOfSteps
3432 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3433 NbOfSteps, Tolerance)
3434 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3437 ## Generates new elements by rotation of the elements of object around the axis
3438 # @param theObject object which elements should be sweeped.
3439 # It can be a mesh, a sub mesh or a group.
3440 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3441 # @param AngleInRadians the angle of Rotation
3442 # @param NbOfSteps number of steps
3443 # @param Tolerance tolerance
3444 # @param MakeGroups forces the generation of new groups from existing ones
3445 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3446 # of all steps, else - size of each step
3447 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3448 # @ingroup l2_modif_extrurev
3449 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3450 MakeGroups=False, TotalAngle=False):
3451 if ( isinstance( theObject, Mesh )):
3452 theObject = theObject.GetMesh()
3453 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3454 Axis = self.smeshpyD.GetAxisStruct(Axis)
3455 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3456 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3457 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3458 self.mesh.SetParameters(Parameters)
3459 if TotalAngle and NbOfSteps:
3460 AngleInRadians /= NbOfSteps
3462 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3463 NbOfSteps, Tolerance)
3464 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3467 ## Generates new elements by extrusion of the elements with given ids
3468 # @param IDsOfElements the list of elements ids for extrusion
3469 # @param StepVector vector or DirStruct or 3 vector components, defining
3470 # the direction and value of extrusion for one step (the total extrusion
3471 # length will be NbOfSteps * ||StepVector||)
3472 # @param NbOfSteps the number of steps
3473 # @param MakeGroups forces the generation of new groups from existing ones
3474 # @param IsNodes is True if elements with given ids are nodes
3475 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3476 # @ingroup l2_modif_extrurev
3477 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3478 if IDsOfElements == []:
3479 IDsOfElements = self.GetElementsId()
3480 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3481 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3482 if isinstance( StepVector, list ):
3483 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3484 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3485 Parameters = StepVector.PS.parameters + var_separator + Parameters
3486 self.mesh.SetParameters(Parameters)
3489 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3491 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3493 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3495 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3498 ## Generates new elements by extrusion of the elements with given ids
3499 # @param IDsOfElements is ids of elements
3500 # @param StepVector vector or DirStruct or 3 vector components, defining
3501 # the direction and value of extrusion for one step (the total extrusion
3502 # length will be NbOfSteps * ||StepVector||)
3503 # @param NbOfSteps the number of steps
3504 # @param ExtrFlags sets flags for extrusion
3505 # @param SewTolerance uses for comparing locations of nodes if flag
3506 # EXTRUSION_FLAG_SEW is set
3507 # @param MakeGroups forces the generation of new groups from existing ones
3508 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3509 # @ingroup l2_modif_extrurev
3510 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3511 ExtrFlags, SewTolerance, MakeGroups=False):
3512 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3513 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3514 if isinstance( StepVector, list ):
3515 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3517 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3518 ExtrFlags, SewTolerance)
3519 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3520 ExtrFlags, SewTolerance)
3523 ## Generates new elements by extrusion of the elements which belong to the object
3524 # @param theObject the object which elements should be processed.
3525 # It can be a mesh, a sub mesh or a group.
3526 # @param StepVector vector or DirStruct or 3 vector components, defining
3527 # the direction and value of extrusion for one step (the total extrusion
3528 # length will be NbOfSteps * ||StepVector||)
3529 # @param NbOfSteps the number of steps
3530 # @param MakeGroups forces the generation of new groups from existing ones
3531 # @param IsNodes is True if elements which belong to the object are nodes
3532 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3533 # @ingroup l2_modif_extrurev
3534 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3535 if ( isinstance( theObject, Mesh )):
3536 theObject = theObject.GetMesh()
3537 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3538 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3539 if isinstance( StepVector, list ):
3540 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3541 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3542 Parameters = StepVector.PS.parameters + var_separator + Parameters
3543 self.mesh.SetParameters(Parameters)
3546 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3548 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3550 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3552 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3555 ## Generates new elements by extrusion of the elements which belong to the object
3556 # @param theObject object which elements should be processed.
3557 # It can be a mesh, a sub mesh or a group.
3558 # @param StepVector vector or DirStruct or 3 vector components, defining
3559 # the direction and value of extrusion for one step (the total extrusion
3560 # length will be NbOfSteps * ||StepVector||)
3561 # @param NbOfSteps the number of steps
3562 # @param MakeGroups to generate new groups from existing ones
3563 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3564 # @ingroup l2_modif_extrurev
3565 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3566 if ( isinstance( theObject, Mesh )):
3567 theObject = theObject.GetMesh()
3568 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3569 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3570 if isinstance( StepVector, list ):
3571 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3572 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3573 Parameters = StepVector.PS.parameters + var_separator + Parameters
3574 self.mesh.SetParameters(Parameters)
3576 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3577 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3580 ## Generates new elements by extrusion of the elements which belong to the object
3581 # @param theObject object which elements should be processed.
3582 # It can be a mesh, a sub mesh or a group.
3583 # @param StepVector vector or DirStruct or 3 vector components, defining
3584 # the direction and value of extrusion for one step (the total extrusion
3585 # length will be NbOfSteps * ||StepVector||)
3586 # @param NbOfSteps the number of steps
3587 # @param MakeGroups forces the generation of new groups from existing ones
3588 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3589 # @ingroup l2_modif_extrurev
3590 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3591 if ( isinstance( theObject, Mesh )):
3592 theObject = theObject.GetMesh()
3593 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3594 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3595 if isinstance( StepVector, list ):
3596 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3597 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3598 Parameters = StepVector.PS.parameters + var_separator + Parameters
3599 self.mesh.SetParameters(Parameters)
3601 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3602 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3607 ## Generates new elements by extrusion of the given elements
3608 # The path of extrusion must be a meshed edge.
3609 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3610 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3611 # @param NodeStart the start node from Path. Defines the direction of extrusion
3612 # @param HasAngles allows the shape to be rotated around the path
3613 # to get the resulting mesh in a helical fashion
3614 # @param Angles list of angles in radians
3615 # @param LinearVariation forces the computation of rotation angles as linear
3616 # variation of the given Angles along path steps
3617 # @param HasRefPoint allows using the reference point
3618 # @param RefPoint the point around which the elements are rotated (the mass
3619 # center of the elements by default).
3620 # The User can specify any point as the Reference Point.
3621 # RefPoint can be either GEOM Vertex, [x,y,z] or SMESH.PointStruct
3622 # @param MakeGroups forces the generation of new groups from existing ones
3623 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3624 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3625 # only SMESH::Extrusion_Error otherwise
3626 # @ingroup l2_modif_extrurev
3627 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3628 HasAngles, Angles, LinearVariation,
3629 HasRefPoint, RefPoint, MakeGroups, ElemType):
3630 if isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object):
3631 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3633 elif isinstance( RefPoint, list ):
3634 RefPoint = PointStruct(*RefPoint)
3636 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3637 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3638 self.mesh.SetParameters(Parameters)
3640 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3642 if isinstance(Base, list):
3644 if Base == []: IDsOfElements = self.GetElementsId()
3645 else: IDsOfElements = Base
3646 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3647 HasAngles, Angles, LinearVariation,
3648 HasRefPoint, RefPoint, MakeGroups, ElemType)
3650 if isinstance(Base, Mesh): Base = Base.GetMesh()
3651 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3652 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3653 HasAngles, Angles, LinearVariation,
3654 HasRefPoint, RefPoint, MakeGroups, ElemType)
3656 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3659 ## Generates new elements by extrusion of the given elements
3660 # The path of extrusion must be a meshed edge.
3661 # @param IDsOfElements ids of elements
3662 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3663 # @param PathShape shape(edge) defines the sub-mesh for the path
3664 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3665 # @param HasAngles allows the shape to be rotated around the path
3666 # to get the resulting mesh in a helical fashion
3667 # @param Angles list of angles in radians
3668 # @param HasRefPoint allows using the reference point
3669 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3670 # The User can specify any point as the Reference Point.
3671 # @param MakeGroups forces the generation of new groups from existing ones
3672 # @param LinearVariation forces the computation of rotation angles as linear
3673 # variation of the given Angles along path steps
3674 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3675 # only SMESH::Extrusion_Error otherwise
3676 # @ingroup l2_modif_extrurev
3677 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3678 HasAngles, Angles, HasRefPoint, RefPoint,
3679 MakeGroups=False, LinearVariation=False):
3680 if IDsOfElements == []:
3681 IDsOfElements = self.GetElementsId()
3682 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3683 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3685 if ( isinstance( PathMesh, Mesh )):
3686 PathMesh = PathMesh.GetMesh()
3687 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3688 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3689 self.mesh.SetParameters(Parameters)
3690 if HasAngles and Angles and LinearVariation:
3691 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3694 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3695 PathShape, NodeStart, HasAngles,
3696 Angles, HasRefPoint, RefPoint)
3697 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3698 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3700 ## Generates new elements by extrusion of the elements which belong to the object
3701 # The path of extrusion must be a meshed edge.
3702 # @param theObject the object which elements should be processed.
3703 # It can be a mesh, a sub mesh or a group.
3704 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3705 # @param PathShape shape(edge) defines the sub-mesh for the path
3706 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3707 # @param HasAngles allows the shape to be rotated around the path
3708 # to get the resulting mesh in a helical fashion
3709 # @param Angles list of angles
3710 # @param HasRefPoint allows using the reference point
3711 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3712 # The User can specify any point as the Reference Point.
3713 # @param MakeGroups forces the generation of new groups from existing ones
3714 # @param LinearVariation forces the computation of rotation angles as linear
3715 # variation of the given Angles along path steps
3716 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3717 # only SMESH::Extrusion_Error otherwise
3718 # @ingroup l2_modif_extrurev
3719 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3720 HasAngles, Angles, HasRefPoint, RefPoint,
3721 MakeGroups=False, LinearVariation=False):
3722 if ( isinstance( theObject, Mesh )):
3723 theObject = theObject.GetMesh()
3724 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3725 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3726 if ( isinstance( PathMesh, Mesh )):
3727 PathMesh = PathMesh.GetMesh()
3728 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3729 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3730 self.mesh.SetParameters(Parameters)
3731 if HasAngles and Angles and LinearVariation:
3732 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3735 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3736 PathShape, NodeStart, HasAngles,
3737 Angles, HasRefPoint, RefPoint)
3738 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3739 NodeStart, HasAngles, Angles, HasRefPoint,
3742 ## Generates new elements by extrusion of the elements which belong to the object
3743 # The path of extrusion must be a meshed edge.
3744 # @param theObject the object which elements should be processed.
3745 # It can be a mesh, a sub mesh or a group.
3746 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3747 # @param PathShape shape(edge) defines the sub-mesh for the path
3748 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3749 # @param HasAngles allows the shape to be rotated around the path
3750 # to get the resulting mesh in a helical fashion
3751 # @param Angles list of angles
3752 # @param HasRefPoint allows using the reference point
3753 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3754 # The User can specify any point as the Reference Point.
3755 # @param MakeGroups forces the generation of new groups from existing ones
3756 # @param LinearVariation forces the computation of rotation angles as linear
3757 # variation of the given Angles along path steps
3758 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3759 # only SMESH::Extrusion_Error otherwise
3760 # @ingroup l2_modif_extrurev
3761 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3762 HasAngles, Angles, HasRefPoint, RefPoint,
3763 MakeGroups=False, LinearVariation=False):
3764 if ( isinstance( theObject, Mesh )):
3765 theObject = theObject.GetMesh()
3766 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3767 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3768 if ( isinstance( PathMesh, Mesh )):
3769 PathMesh = PathMesh.GetMesh()
3770 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3771 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3772 self.mesh.SetParameters(Parameters)
3773 if HasAngles and Angles and LinearVariation:
3774 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3777 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3778 PathShape, NodeStart, HasAngles,
3779 Angles, HasRefPoint, RefPoint)
3780 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3781 NodeStart, HasAngles, Angles, HasRefPoint,
3784 ## Generates new elements by extrusion of the elements which belong to the object
3785 # The path of extrusion must be a meshed edge.
3786 # @param theObject the object which elements should be processed.
3787 # It can be a mesh, a sub mesh or a group.
3788 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3789 # @param PathShape shape(edge) defines the sub-mesh for the path
3790 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3791 # @param HasAngles allows the shape to be rotated around the path
3792 # to get the resulting mesh in a helical fashion
3793 # @param Angles list of angles
3794 # @param HasRefPoint allows using the reference point
3795 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3796 # The User can specify any point as the Reference Point.
3797 # @param MakeGroups forces the generation of new groups from existing ones
3798 # @param LinearVariation forces the computation of rotation angles as linear
3799 # variation of the given Angles along path steps
3800 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3801 # only SMESH::Extrusion_Error otherwise
3802 # @ingroup l2_modif_extrurev
3803 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3804 HasAngles, Angles, HasRefPoint, RefPoint,
3805 MakeGroups=False, LinearVariation=False):
3806 if ( isinstance( theObject, Mesh )):
3807 theObject = theObject.GetMesh()
3808 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3809 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3810 if ( isinstance( PathMesh, Mesh )):
3811 PathMesh = PathMesh.GetMesh()
3812 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3813 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3814 self.mesh.SetParameters(Parameters)
3815 if HasAngles and Angles and LinearVariation:
3816 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3819 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3820 PathShape, NodeStart, HasAngles,
3821 Angles, HasRefPoint, RefPoint)
3822 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3823 NodeStart, HasAngles, Angles, HasRefPoint,
3826 ## Creates a symmetrical copy of mesh elements
3827 # @param IDsOfElements list of elements ids
3828 # @param Mirror is AxisStruct or geom object(point, line, plane)
3829 # @param theMirrorType is POINT, AXIS or PLANE
3830 # If the Mirror is a geom object this parameter is unnecessary
3831 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3832 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3833 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3834 # @ingroup l2_modif_trsf
3835 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3836 if IDsOfElements == []:
3837 IDsOfElements = self.GetElementsId()
3838 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3839 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3840 self.mesh.SetParameters(Mirror.parameters)
3841 if Copy and MakeGroups:
3842 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3843 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3846 ## Creates a new mesh by a symmetrical copy of mesh elements
3847 # @param IDsOfElements the list of elements ids
3848 # @param Mirror is AxisStruct or geom object (point, line, plane)
3849 # @param theMirrorType is POINT, AXIS or PLANE
3850 # If the Mirror is a geom object this parameter is unnecessary
3851 # @param MakeGroups to generate new groups from existing ones
3852 # @param NewMeshName a name of the new mesh to create
3853 # @return instance of Mesh class
3854 # @ingroup l2_modif_trsf
3855 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3856 if IDsOfElements == []:
3857 IDsOfElements = self.GetElementsId()
3858 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3859 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3860 self.mesh.SetParameters(Mirror.parameters)
3861 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3862 MakeGroups, NewMeshName)
3863 return Mesh(self.smeshpyD,self.geompyD,mesh)
3865 ## Creates a symmetrical copy of the object
3866 # @param theObject mesh, submesh or group
3867 # @param Mirror AxisStruct or geom object (point, line, plane)
3868 # @param theMirrorType is POINT, AXIS or PLANE
3869 # If the Mirror is a geom object this parameter is unnecessary
3870 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3871 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3872 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3873 # @ingroup l2_modif_trsf
3874 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3875 if ( isinstance( theObject, Mesh )):
3876 theObject = theObject.GetMesh()
3877 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3878 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3879 self.mesh.SetParameters(Mirror.parameters)
3880 if Copy and MakeGroups:
3881 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3882 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3885 ## Creates a new mesh by a symmetrical copy of the object
3886 # @param theObject mesh, submesh or group
3887 # @param Mirror AxisStruct or geom object (point, line, plane)
3888 # @param theMirrorType POINT, AXIS or PLANE
3889 # If the Mirror is a geom object this parameter is unnecessary
3890 # @param MakeGroups forces the generation of new groups from existing ones
3891 # @param NewMeshName the name of the new mesh to create
3892 # @return instance of Mesh class
3893 # @ingroup l2_modif_trsf
3894 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3895 if ( isinstance( theObject, Mesh )):
3896 theObject = theObject.GetMesh()
3897 if (isinstance(Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3898 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3899 self.mesh.SetParameters(Mirror.parameters)
3900 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3901 MakeGroups, NewMeshName)
3902 return Mesh( self.smeshpyD,self.geompyD,mesh )
3904 ## Translates the elements
3905 # @param IDsOfElements list of elements ids
3906 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3907 # @param Copy allows copying the translated elements
3908 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3909 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3910 # @ingroup l2_modif_trsf
3911 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3912 if IDsOfElements == []:
3913 IDsOfElements = self.GetElementsId()
3914 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3915 Vector = self.smeshpyD.GetDirStruct(Vector)
3916 if isinstance( Vector, list ):
3917 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3918 self.mesh.SetParameters(Vector.PS.parameters)
3919 if Copy and MakeGroups:
3920 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3921 self.editor.Translate(IDsOfElements, Vector, Copy)
3924 ## Creates a new mesh of translated elements
3925 # @param IDsOfElements list of elements ids
3926 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3927 # @param MakeGroups forces the generation of new groups from existing ones
3928 # @param NewMeshName the name of the newly created mesh
3929 # @return instance of Mesh class
3930 # @ingroup l2_modif_trsf
3931 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3932 if IDsOfElements == []:
3933 IDsOfElements = self.GetElementsId()
3934 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3935 Vector = self.smeshpyD.GetDirStruct(Vector)
3936 if isinstance( Vector, list ):
3937 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3938 self.mesh.SetParameters(Vector.PS.parameters)
3939 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3940 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3942 ## Translates the object
3943 # @param theObject the object to translate (mesh, submesh, or group)
3944 # @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
3945 # @param Copy allows copying the translated elements
3946 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3947 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3948 # @ingroup l2_modif_trsf
3949 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3950 if ( isinstance( theObject, Mesh )):
3951 theObject = theObject.GetMesh()
3952 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3953 Vector = self.smeshpyD.GetDirStruct(Vector)
3954 if isinstance( Vector, list ):
3955 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3956 self.mesh.SetParameters(Vector.PS.parameters)
3957 if Copy and MakeGroups:
3958 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3959 self.editor.TranslateObject(theObject, Vector, Copy)
3962 ## Creates a new mesh from the translated object
3963 # @param theObject the object to translate (mesh, submesh, or group)
3964 # @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
3965 # @param MakeGroups forces the generation of new groups from existing ones
3966 # @param NewMeshName the name of the newly created mesh
3967 # @return instance of Mesh class
3968 # @ingroup l2_modif_trsf
3969 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3970 if isinstance( theObject, Mesh ):
3971 theObject = theObject.GetMesh()
3972 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
3973 Vector = self.smeshpyD.GetDirStruct(Vector)
3974 if isinstance( Vector, list ):
3975 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3976 self.mesh.SetParameters(Vector.PS.parameters)
3977 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3978 return Mesh( self.smeshpyD, self.geompyD, mesh )
3982 ## Scales the object
3983 # @param theObject - the object to translate (mesh, submesh, or group)
3984 # @param thePoint - base point for scale
3985 # @param theScaleFact - list of 1-3 scale factors for axises
3986 # @param Copy - allows copying the translated elements
3987 # @param MakeGroups - forces the generation of new groups from existing
3989 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3990 # empty list otherwise
3991 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3992 unRegister = genObjUnRegister()
3993 if ( isinstance( theObject, Mesh )):
3994 theObject = theObject.GetMesh()
3995 if ( isinstance( theObject, list )):
3996 theObject = self.GetIDSource(theObject, SMESH.ALL)
3997 unRegister.set( theObject )
3998 if ( isinstance( theScaleFact, float )):
3999 theScaleFact = [theScaleFact]
4000 if ( isinstance( theScaleFact, int )):
4001 theScaleFact = [ float(theScaleFact)]
4003 self.mesh.SetParameters(thePoint.parameters)
4005 if Copy and MakeGroups:
4006 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
4007 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
4010 ## Creates a new mesh from the translated object
4011 # @param theObject - the object to translate (mesh, submesh, or group)
4012 # @param thePoint - base point for scale
4013 # @param theScaleFact - list of 1-3 scale factors for axises
4014 # @param MakeGroups - forces the generation of new groups from existing ones
4015 # @param NewMeshName - the name of the newly created mesh
4016 # @return instance of Mesh class
4017 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
4018 unRegister = genObjUnRegister()
4019 if (isinstance(theObject, Mesh)):
4020 theObject = theObject.GetMesh()
4021 if ( isinstance( theObject, list )):
4022 theObject = self.GetIDSource(theObject,SMESH.ALL)
4023 unRegister.set( theObject )
4024 if ( isinstance( theScaleFact, float )):
4025 theScaleFact = [theScaleFact]
4026 if ( isinstance( theScaleFact, int )):
4027 theScaleFact = [ float(theScaleFact)]
4029 self.mesh.SetParameters(thePoint.parameters)
4030 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
4031 MakeGroups, NewMeshName)
4032 return Mesh( self.smeshpyD, self.geompyD, mesh )
4036 ## Rotates the elements
4037 # @param IDsOfElements list of elements ids
4038 # @param Axis the axis of rotation (AxisStruct or geom line)
4039 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4040 # @param Copy allows copying the rotated elements
4041 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4042 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4043 # @ingroup l2_modif_trsf
4044 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
4045 if IDsOfElements == []:
4046 IDsOfElements = self.GetElementsId()
4047 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4048 Axis = self.smeshpyD.GetAxisStruct(Axis)
4049 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4050 Parameters = Axis.parameters + var_separator + Parameters
4051 self.mesh.SetParameters(Parameters)
4052 if Copy and MakeGroups:
4053 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
4054 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
4057 ## Creates a new mesh of rotated elements
4058 # @param IDsOfElements list of element ids
4059 # @param Axis the axis of rotation (AxisStruct or geom line)
4060 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4061 # @param MakeGroups forces the generation of new groups from existing ones
4062 # @param NewMeshName the name of the newly created mesh
4063 # @return instance of Mesh class
4064 # @ingroup l2_modif_trsf
4065 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
4066 if IDsOfElements == []:
4067 IDsOfElements = self.GetElementsId()
4068 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4069 Axis = self.smeshpyD.GetAxisStruct(Axis)
4070 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4071 Parameters = Axis.parameters + var_separator + Parameters
4072 self.mesh.SetParameters(Parameters)
4073 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
4074 MakeGroups, NewMeshName)
4075 return Mesh( self.smeshpyD, self.geompyD, mesh )
4077 ## Rotates the object
4078 # @param theObject the object to rotate( mesh, submesh, or group)
4079 # @param Axis the axis of rotation (AxisStruct or geom line)
4080 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4081 # @param Copy allows copying the rotated elements
4082 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4083 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4084 # @ingroup l2_modif_trsf
4085 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
4086 if (isinstance(theObject, Mesh)):
4087 theObject = theObject.GetMesh()
4088 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4089 Axis = self.smeshpyD.GetAxisStruct(Axis)
4090 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4091 Parameters = Axis.parameters + ":" + Parameters
4092 self.mesh.SetParameters(Parameters)
4093 if Copy and MakeGroups:
4094 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
4095 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
4098 ## Creates a new mesh from the rotated object
4099 # @param theObject the object to rotate (mesh, submesh, or group)
4100 # @param Axis the axis of rotation (AxisStruct or geom line)
4101 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4102 # @param MakeGroups forces the generation of new groups from existing ones
4103 # @param NewMeshName the name of the newly created mesh
4104 # @return instance of Mesh class
4105 # @ingroup l2_modif_trsf
4106 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
4107 if (isinstance( theObject, Mesh )):
4108 theObject = theObject.GetMesh()
4109 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4110 Axis = self.smeshpyD.GetAxisStruct(Axis)
4111 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4112 Parameters = Axis.parameters + ":" + Parameters
4113 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
4114 MakeGroups, NewMeshName)
4115 self.mesh.SetParameters(Parameters)
4116 return Mesh( self.smeshpyD, self.geompyD, mesh )
4118 ## Finds groups of ajacent nodes within Tolerance.
4119 # @param Tolerance the value of tolerance
4120 # @return the list of groups of nodes
4121 # @ingroup l2_modif_trsf
4122 def FindCoincidentNodes (self, Tolerance):
4123 return self.editor.FindCoincidentNodes(Tolerance)
4125 ## Finds groups of ajacent nodes within Tolerance.
4126 # @param Tolerance the value of tolerance
4127 # @param SubMeshOrGroup SubMesh or Group
4128 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
4129 # @return the list of groups of nodes
4130 # @ingroup l2_modif_trsf
4131 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
4132 unRegister = genObjUnRegister()
4133 if (isinstance( SubMeshOrGroup, Mesh )):
4134 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
4135 if not isinstance( exceptNodes, list):
4136 exceptNodes = [ exceptNodes ]
4137 if exceptNodes and isinstance( exceptNodes[0], int):
4138 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
4139 unRegister.set( exceptNodes )
4140 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
4143 # @param GroupsOfNodes the list of groups of nodes
4144 # @ingroup l2_modif_trsf
4145 def MergeNodes (self, GroupsOfNodes):
4146 self.editor.MergeNodes(GroupsOfNodes)
4148 ## Finds the elements built on the same nodes.
4149 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
4150 # @return a list of groups of equal elements
4151 # @ingroup l2_modif_trsf
4152 def FindEqualElements (self, MeshOrSubMeshOrGroup):
4153 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
4154 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4155 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
4157 ## Merges elements in each given group.
4158 # @param GroupsOfElementsID groups of elements for merging
4159 # @ingroup l2_modif_trsf
4160 def MergeElements(self, GroupsOfElementsID):
4161 self.editor.MergeElements(GroupsOfElementsID)
4163 ## Leaves one element and removes all other elements built on the same nodes.
4164 # @ingroup l2_modif_trsf
4165 def MergeEqualElements(self):
4166 self.editor.MergeEqualElements()
4168 ## Sews free borders
4169 # @return SMESH::Sew_Error
4170 # @ingroup l2_modif_trsf
4171 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4172 FirstNodeID2, SecondNodeID2, LastNodeID2,
4173 CreatePolygons, CreatePolyedrs):
4174 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4175 FirstNodeID2, SecondNodeID2, LastNodeID2,
4176 CreatePolygons, CreatePolyedrs)
4178 ## Sews conform free borders
4179 # @return SMESH::Sew_Error
4180 # @ingroup l2_modif_trsf
4181 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4182 FirstNodeID2, SecondNodeID2):
4183 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4184 FirstNodeID2, SecondNodeID2)
4186 ## Sews border to side
4187 # @return SMESH::Sew_Error
4188 # @ingroup l2_modif_trsf
4189 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4190 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4191 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4192 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4194 ## Sews two sides of a mesh. The nodes belonging to Side1 are
4195 # merged with the nodes of elements of Side2.
4196 # The number of elements in theSide1 and in theSide2 must be
4197 # equal and they should have similar nodal connectivity.
4198 # The nodes to merge should belong to side borders and
4199 # the first node should be linked to the second.
4200 # @return SMESH::Sew_Error
4201 # @ingroup l2_modif_trsf
4202 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4203 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4204 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4205 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4206 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4207 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4209 ## Sets new nodes for the given element.
4210 # @param ide the element id
4211 # @param newIDs nodes ids
4212 # @return If the number of nodes does not correspond to the type of element - returns false
4213 # @ingroup l2_modif_edit
4214 def ChangeElemNodes(self, ide, newIDs):
4215 return self.editor.ChangeElemNodes(ide, newIDs)
4217 ## If during the last operation of MeshEditor some nodes were
4218 # created, this method returns the list of their IDs, \n
4219 # if new nodes were not created - returns empty list
4220 # @return the list of integer values (can be empty)
4221 # @ingroup l1_auxiliary
4222 def GetLastCreatedNodes(self):
4223 return self.editor.GetLastCreatedNodes()
4225 ## If during the last operation of MeshEditor some elements were
4226 # created this method returns the list of their IDs, \n
4227 # if new elements were not created - returns empty list
4228 # @return the list of integer values (can be empty)
4229 # @ingroup l1_auxiliary
4230 def GetLastCreatedElems(self):
4231 return self.editor.GetLastCreatedElems()
4233 ## Clears sequences of nodes and elements created by mesh edition oparations
4234 # @ingroup l1_auxiliary
4235 def ClearLastCreated(self):
4236 self.editor.ClearLastCreated()
4238 ## Creates Duplicates given elements, i.e. creates new elements based on the
4239 # same nodes as the given ones.
4240 # @param theElements - container of elements to duplicate. It can be a Mesh,
4241 # sub-mesh, group, filter or a list of element IDs.
4242 # @param theGroupName - a name of group to contain the generated elements.
4243 # If a group with such a name already exists, the new elements
4244 # are added to the existng group, else a new group is created.
4245 # If \a theGroupName is empty, new elements are not added
4247 # @return a group where the new elements are added. None if theGroupName == "".
4248 # @ingroup l2_modif_edit
4249 def DoubleElements(self, theElements, theGroupName=""):
4250 unRegister = genObjUnRegister()
4251 if isinstance( theElements, Mesh ):
4252 theElements = theElements.mesh
4253 elif isinstance( theElements, list ):
4254 theElements = self.GetIDSource( theElements, SMESH.ALL )
4255 unRegister.set( theElements )
4256 return self.editor.DoubleElements(theElements, theGroupName)
4258 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4259 # @param theNodes identifiers of nodes to be doubled
4260 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4261 # nodes. If list of element identifiers is empty then nodes are doubled but
4262 # they not assigned to elements
4263 # @return TRUE if operation has been completed successfully, FALSE otherwise
4264 # @ingroup l2_modif_edit
4265 def DoubleNodes(self, theNodes, theModifiedElems):
4266 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4268 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4269 # This method provided for convenience works as DoubleNodes() described above.
4270 # @param theNodeId identifiers of node to be doubled
4271 # @param theModifiedElems identifiers of elements to be updated
4272 # @return TRUE if operation has been completed successfully, FALSE otherwise
4273 # @ingroup l2_modif_edit
4274 def DoubleNode(self, theNodeId, theModifiedElems):
4275 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4277 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4278 # This method provided for convenience works as DoubleNodes() described above.
4279 # @param theNodes group of nodes to be doubled
4280 # @param theModifiedElems group of elements to be updated.
4281 # @param theMakeGroup forces the generation of a group containing new nodes.
4282 # @return TRUE or a created group if operation has been completed successfully,
4283 # FALSE or None otherwise
4284 # @ingroup l2_modif_edit
4285 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4287 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4288 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4290 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4291 # This method provided for convenience works as DoubleNodes() described above.
4292 # @param theNodes list of groups of nodes to be doubled
4293 # @param theModifiedElems list of groups of elements to be updated.
4294 # @param theMakeGroup forces the generation of a group containing new nodes.
4295 # @return TRUE if operation has been completed successfully, FALSE otherwise
4296 # @ingroup l2_modif_edit
4297 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4299 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4300 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4302 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4303 # @param theElems - the list of elements (edges or faces) to be replicated
4304 # The nodes for duplication could be found from these elements
4305 # @param theNodesNot - list of nodes to NOT replicate
4306 # @param theAffectedElems - the list of elements (cells and edges) to which the
4307 # replicated nodes should be associated to.
4308 # @return TRUE if operation has been completed successfully, FALSE otherwise
4309 # @ingroup l2_modif_edit
4310 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4311 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4313 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4314 # @param theElems - the list of elements (edges or faces) to be replicated
4315 # The nodes for duplication could be found from these elements
4316 # @param theNodesNot - list of nodes to NOT replicate
4317 # @param theShape - shape to detect affected elements (element which geometric center
4318 # located on or inside shape).
4319 # The replicated nodes should be associated to affected elements.
4320 # @return TRUE if operation has been completed successfully, FALSE otherwise
4321 # @ingroup l2_modif_edit
4322 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4323 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4325 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4326 # This method provided for convenience works as DoubleNodes() described above.
4327 # @param theElems - group of of elements (edges or faces) to be replicated
4328 # @param theNodesNot - group of nodes not to replicated
4329 # @param theAffectedElems - group of elements to which the replicated nodes
4330 # should be associated to.
4331 # @param theMakeGroup forces the generation of a group containing new elements.
4332 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4333 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4334 # FALSE or None otherwise
4335 # @ingroup l2_modif_edit
4336 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4337 theMakeGroup=False, theMakeNodeGroup=False):
4338 if theMakeGroup or theMakeNodeGroup:
4339 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4341 theMakeGroup, theMakeNodeGroup)
4342 if theMakeGroup and theMakeNodeGroup:
4345 return twoGroups[ int(theMakeNodeGroup) ]
4346 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4348 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4349 # This method provided for convenience works as DoubleNodes() described above.
4350 # @param theElems - group of of elements (edges or faces) to be replicated
4351 # @param theNodesNot - group of nodes not to replicated
4352 # @param theShape - shape to detect affected elements (element which geometric center
4353 # located on or inside shape).
4354 # The replicated nodes should be associated to affected elements.
4355 # @ingroup l2_modif_edit
4356 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4357 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4359 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4360 # This method provided for convenience works as DoubleNodes() described above.
4361 # @param theElems - list of groups of elements (edges or faces) to be replicated
4362 # @param theNodesNot - list of groups of nodes not to replicated
4363 # @param theAffectedElems - group of elements to which the replicated nodes
4364 # should be associated to.
4365 # @param theMakeGroup forces the generation of a group containing new elements.
4366 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4367 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4368 # FALSE or None otherwise
4369 # @ingroup l2_modif_edit
4370 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4371 theMakeGroup=False, theMakeNodeGroup=False):
4372 if theMakeGroup or theMakeNodeGroup:
4373 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4375 theMakeGroup, theMakeNodeGroup)
4376 if theMakeGroup and theMakeNodeGroup:
4379 return twoGroups[ int(theMakeNodeGroup) ]
4380 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4382 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4383 # This method provided for convenience works as DoubleNodes() described above.
4384 # @param theElems - list of groups of elements (edges or faces) to be replicated
4385 # @param theNodesNot - list of groups of nodes not to replicated
4386 # @param theShape - shape to detect affected elements (element which geometric center
4387 # located on or inside shape).
4388 # The replicated nodes should be associated to affected elements.
4389 # @return TRUE if operation has been completed successfully, FALSE otherwise
4390 # @ingroup l2_modif_edit
4391 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4392 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4394 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4395 # This method is the first step of DoubleNodeElemGroupsInRegion.
4396 # @param theElems - list of groups of elements (edges or faces) to be replicated
4397 # @param theNodesNot - list of groups of nodes not to replicated
4398 # @param theShape - shape to detect affected elements (element which geometric center
4399 # located on or inside shape).
4400 # The replicated nodes should be associated to affected elements.
4401 # @return groups of affected elements
4402 # @ingroup l2_modif_edit
4403 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4404 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4406 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4407 # The list of groups must describe a partition of the mesh volumes.
4408 # The nodes of the internal faces at the boundaries of the groups are doubled.
4409 # In option, the internal faces are replaced by flat elements.
4410 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4411 # @param theDomains - list of groups of volumes
4412 # @param createJointElems - if TRUE, create the elements
4413 # @return TRUE if operation has been completed successfully, FALSE otherwise
4414 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4415 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4417 ## Double nodes on some external faces and create flat elements.
4418 # Flat elements are mainly used by some types of mechanic calculations.
4420 # Each group of the list must be constituted of faces.
4421 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4422 # @param theGroupsOfFaces - list of groups of faces
4423 # @return TRUE if operation has been completed successfully, FALSE otherwise
4424 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4425 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4427 ## identify all the elements around a geom shape, get the faces delimiting the hole
4429 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4430 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4432 def _getFunctor(self, funcType ):
4433 fn = self.functors[ funcType._v ]
4435 fn = self.smeshpyD.GetFunctor(funcType)
4436 fn.SetMesh(self.mesh)
4437 self.functors[ funcType._v ] = fn
4440 def _valueFromFunctor(self, funcType, elemId):
4441 fn = self._getFunctor( funcType )
4442 if fn.GetElementType() == self.GetElementType(elemId, True):
4443 val = fn.GetValue(elemId)
4448 ## Get length of 1D element or sum of lengths of all 1D mesh elements
4449 # @param elemId mesh element ID (if not defined - sum of length of all 1D elements will be calculated)
4450 # @return element's length value if \a elemId is specified or sum of all 1D mesh elements' lengths otherwise
4451 # @ingroup l1_measurements
4452 def GetLength(self, elemId=None):
4455 length = self.smeshpyD.GetLength(self)
4457 length = self._valueFromFunctor(SMESH.FT_Length, elemId)
4460 ## Get area of 2D element or sum of areas of all 2D mesh elements
4461 # @param elemId mesh element ID (if not defined - sum of areas of all 2D elements will be calculated)
4462 # @return element's area value if \a elemId is specified or sum of all 2D mesh elements' areas otherwise
4463 # @ingroup l1_measurements
4464 def GetArea(self, elemId=None):
4467 area = self.smeshpyD.GetArea(self)
4469 area = self._valueFromFunctor(SMESH.FT_Area, elemId)
4472 ## Get volume of 3D element or sum of volumes of all 3D mesh elements
4473 # @param elemId mesh element ID (if not defined - sum of volumes of all 3D elements will be calculated)
4474 # @return element's volume value if \a elemId is specified or sum of all 3D mesh elements' volumes otherwise
4475 # @ingroup l1_measurements
4476 def GetVolume(self, elemId=None):
4479 volume = self.smeshpyD.GetVolume(self)
4481 volume = self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4484 ## Get maximum element length.
4485 # @param elemId mesh element ID
4486 # @return element's maximum length value
4487 # @ingroup l1_measurements
4488 def GetMaxElementLength(self, elemId):
4489 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4490 ftype = SMESH.FT_MaxElementLength3D
4492 ftype = SMESH.FT_MaxElementLength2D
4493 return self._valueFromFunctor(ftype, elemId)
4495 ## Get aspect ratio of 2D or 3D element.
4496 # @param elemId mesh element ID
4497 # @return element's aspect ratio value
4498 # @ingroup l1_measurements
4499 def GetAspectRatio(self, elemId):
4500 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4501 ftype = SMESH.FT_AspectRatio3D
4503 ftype = SMESH.FT_AspectRatio
4504 return self._valueFromFunctor(ftype, elemId)
4506 ## Get warping angle of 2D element.
4507 # @param elemId mesh element ID
4508 # @return element's warping angle value
4509 # @ingroup l1_measurements
4510 def GetWarping(self, elemId):
4511 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4513 ## Get minimum angle of 2D element.
4514 # @param elemId mesh element ID
4515 # @return element's minimum angle value
4516 # @ingroup l1_measurements
4517 def GetMinimumAngle(self, elemId):
4518 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4520 ## Get taper of 2D element.
4521 # @param elemId mesh element ID
4522 # @return element's taper value
4523 # @ingroup l1_measurements
4524 def GetTaper(self, elemId):
4525 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4527 ## Get skew of 2D element.
4528 # @param elemId mesh element ID
4529 # @return element's skew value
4530 # @ingroup l1_measurements
4531 def GetSkew(self, elemId):
4532 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4534 pass # end of Mesh class
4536 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4538 class Pattern(SMESH._objref_SMESH_Pattern):
4540 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4541 decrFun = lambda i: i-1
4542 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4543 theMesh.SetParameters(Parameters)
4544 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4546 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4547 decrFun = lambda i: i-1
4548 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4549 theMesh.SetParameters(Parameters)
4550 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4552 # Registering the new proxy for Pattern
4553 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4555 ## Private class used to bind methods creating algorithms to the class Mesh
4560 self.defaultAlgoType = ""
4561 self.algoTypeToClass = {}
4563 # Stores a python class of algorithm
4564 def add(self, algoClass):
4565 if type( algoClass ).__name__ == 'classobj' and \
4566 hasattr( algoClass, "algoType"):
4567 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4568 if not self.defaultAlgoType and \
4569 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4570 self.defaultAlgoType = algoClass.algoType
4571 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4573 # creates a copy of self and assign mesh to the copy
4574 def copy(self, mesh):
4575 other = algoCreator()
4576 other.defaultAlgoType = self.defaultAlgoType
4577 other.algoTypeToClass = self.algoTypeToClass
4581 # creates an instance of algorithm
4582 def __call__(self,algo="",geom=0,*args):
4583 algoType = self.defaultAlgoType
4584 for arg in args + (algo,geom):
4585 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
4587 if isinstance( arg, str ) and arg:
4589 if not algoType and self.algoTypeToClass:
4590 algoType = self.algoTypeToClass.keys()[0]
4591 if self.algoTypeToClass.has_key( algoType ):
4592 #print "Create algo",algoType
4593 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4594 raise RuntimeError, "No class found for algo type %s" % algoType
4597 # Private class used to substitute and store variable parameters of hypotheses.
4599 class hypMethodWrapper:
4600 def __init__(self, hyp, method):
4602 self.method = method
4603 #print "REBIND:", method.__name__
4606 # call a method of hypothesis with calling SetVarParameter() before
4607 def __call__(self,*args):
4609 return self.method( self.hyp, *args ) # hypothesis method with no args
4611 #print "MethWrapper.__call__",self.method.__name__, args
4613 parsed = ParseParameters(*args) # replace variables with their values
4614 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4615 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4616 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4617 # maybe there is a replaced string arg which is not variable
4618 result = self.method( self.hyp, *args )
4619 except ValueError, detail: # raised by ParseParameters()
4621 result = self.method( self.hyp, *args )
4622 except omniORB.CORBA.BAD_PARAM:
4623 raise ValueError, detail # wrong variable name
4628 # A helper class that call UnRegister() of SALOME.GenericObj'es stored in it
4629 class genObjUnRegister:
4631 def __init__(self, genObj=None):
4632 self.genObjList = []
4636 def set(self, genObj):
4637 "Store one or a list of of SALOME.GenericObj'es"
4638 if isinstance( genObj, list ):
4639 self.genObjList.extend( genObj )
4641 self.genObjList.append( genObj )
4645 for genObj in self.genObjList:
4646 if genObj and hasattr( genObj, "UnRegister" ):
4649 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4651 #print "pluginName: ", pluginName
4652 pluginBuilderName = pluginName + "Builder"
4654 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
4655 except Exception, e:
4656 print "Exception while loading %s: %s" % ( pluginBuilderName, e )
4658 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
4659 plugin = eval( pluginBuilderName )
4660 #print " plugin:" , str(plugin)
4662 # add methods creating algorithms to Mesh
4663 for k in dir( plugin ):
4664 if k[0] == '_': continue
4665 algo = getattr( plugin, k )
4666 #print " algo:", str(algo)
4667 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4668 #print " meshMethod:" , str(algo.meshMethod)
4669 if not hasattr( Mesh, algo.meshMethod ):
4670 setattr( Mesh, algo.meshMethod, algoCreator() )
4672 getattr( Mesh, algo.meshMethod ).add( algo )