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.SetMesh( 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()
1224 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1225 # @return a SMESH_Mesh object
1226 # @ingroup l2_construct
1230 ## Gets the name of the mesh
1231 # @return the name of the mesh as a string
1232 # @ingroup l2_construct
1234 name = GetName(self.GetMesh())
1237 ## Sets a name to the mesh
1238 # @param name a new name of the mesh
1239 # @ingroup l2_construct
1240 def SetName(self, name):
1241 self.smeshpyD.SetName(self.GetMesh(), name)
1243 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1244 # The subMesh object gives access to the IDs of nodes and elements.
1245 # @param geom a geometrical object (shape)
1246 # @param name a name for the submesh
1247 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1248 # @ingroup l2_submeshes
1249 def GetSubMesh(self, geom, name):
1250 AssureGeomPublished( self, geom, name )
1251 submesh = self.mesh.GetSubMesh( geom, name )
1254 ## Returns the shape associated to the mesh
1255 # @return a GEOM_Object
1256 # @ingroup l2_construct
1260 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1261 # @param geom the shape to be meshed (GEOM_Object)
1262 # @ingroup l2_construct
1263 def SetShape(self, geom):
1264 self.mesh = self.smeshpyD.CreateMesh(geom)
1266 ## Loads mesh from the study after opening the study
1270 ## Returns true if the hypotheses are defined well
1271 # @param theSubObject a sub-shape of a mesh shape
1272 # @return True or False
1273 # @ingroup l2_construct
1274 def IsReadyToCompute(self, theSubObject):
1275 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1277 ## Returns errors of hypotheses definition.
1278 # The list of errors is empty if everything is OK.
1279 # @param theSubObject a sub-shape of a mesh shape
1280 # @return a list of errors
1281 # @ingroup l2_construct
1282 def GetAlgoState(self, theSubObject):
1283 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1285 ## Returns a geometrical object on which the given element was built.
1286 # The returned geometrical object, if not nil, is either found in the
1287 # study or published by this method with the given name
1288 # @param theElementID the id of the mesh element
1289 # @param theGeomName the user-defined name of the geometrical object
1290 # @return GEOM::GEOM_Object instance
1291 # @ingroup l2_construct
1292 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1293 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1295 ## Returns the mesh dimension depending on the dimension of the underlying shape
1296 # or, if the mesh is not based on any shape, basing on deimension of elements
1297 # @return mesh dimension as an integer value [0,3]
1298 # @ingroup l1_auxiliary
1299 def MeshDimension(self):
1300 if self.mesh.HasShapeToMesh():
1301 shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
1302 if len( shells ) > 0 :
1304 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1306 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1311 if self.NbVolumes() > 0: return 3
1312 if self.NbFaces() > 0: return 2
1313 if self.NbEdges() > 0: return 1
1316 ## Evaluates size of prospective mesh on a shape
1317 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1318 # To know predicted number of e.g. edges, inquire it this way
1319 # Evaluate()[ EnumToLong( Entity_Edge )]
1320 def Evaluate(self, geom=0):
1321 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1323 geom = self.mesh.GetShapeToMesh()
1326 return self.smeshpyD.Evaluate(self.mesh, geom)
1329 ## Computes the mesh and returns the status of the computation
1330 # @param geom geomtrical shape on which mesh data should be computed
1331 # @param discardModifs if True and the mesh has been edited since
1332 # a last total re-compute and that may prevent successful partial re-compute,
1333 # then the mesh is cleaned before Compute()
1334 # @return True or False
1335 # @ingroup l2_construct
1336 def Compute(self, geom=0, discardModifs=False):
1337 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1339 geom = self.mesh.GetShapeToMesh()
1344 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1346 ok = self.smeshpyD.Compute(self.mesh, geom)
1347 except SALOME.SALOME_Exception, ex:
1348 print "Mesh computation failed, exception caught:"
1349 print " ", ex.details.text
1352 print "Mesh computation failed, exception caught:"
1353 traceback.print_exc()
1357 # Treat compute errors
1358 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1359 for err in computeErrors:
1361 if self.mesh.HasShapeToMesh():
1363 mainIOR = salome.orb.object_to_string(geom)
1364 for sname in salome.myStudyManager.GetOpenStudies():
1365 s = salome.myStudyManager.GetStudyByName(sname)
1367 mainSO = s.FindObjectIOR(mainIOR)
1368 if not mainSO: continue
1369 if err.subShapeID == 1:
1370 shapeText = ' on "%s"' % mainSO.GetName()
1371 subIt = s.NewChildIterator(mainSO)
1373 subSO = subIt.Value()
1375 obj = subSO.GetObject()
1376 if not obj: continue
1377 go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
1379 ids = go.GetSubShapeIndices()
1380 if len(ids) == 1 and ids[0] == err.subShapeID:
1381 shapeText = ' on "%s"' % subSO.GetName()
1384 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1386 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1388 shapeText = " on subshape #%s" % (err.subShapeID)
1390 shapeText = " on subshape #%s" % (err.subShapeID)
1392 stdErrors = ["OK", #COMPERR_OK
1393 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1394 "std::exception", #COMPERR_STD_EXCEPTION
1395 "OCC exception", #COMPERR_OCC_EXCEPTION
1396 "..", #COMPERR_SLM_EXCEPTION
1397 "Unknown exception", #COMPERR_EXCEPTION
1398 "Memory allocation problem", #COMPERR_MEMORY_PB
1399 "Algorithm failed", #COMPERR_ALGO_FAILED
1400 "Unexpected geometry", #COMPERR_BAD_SHAPE
1401 "Warning", #COMPERR_WARNING
1402 "Computation cancelled",#COMPERR_CANCELED
1403 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1405 if err.code < len(stdErrors): errText = stdErrors[err.code]
1407 errText = "code %s" % -err.code
1408 if errText: errText += ". "
1409 errText += err.comment
1410 if allReasons != "":allReasons += "\n"
1412 allReasons += '- "%s"%s - %s' %(err.algoName, shapeText, errText)
1414 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1418 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1420 if err.isGlobalAlgo:
1428 reason = '%s %sD algorithm is missing' % (glob, dim)
1429 elif err.state == HYP_MISSING:
1430 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1431 % (glob, dim, name, dim))
1432 elif err.state == HYP_NOTCONFORM:
1433 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1434 elif err.state == HYP_BAD_PARAMETER:
1435 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1436 % ( glob, dim, name ))
1437 elif err.state == HYP_BAD_GEOMETRY:
1438 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1439 'geometry' % ( glob, dim, name ))
1440 elif err.state == HYP_HIDDEN_ALGO:
1441 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1442 'algorithm of upper dimension generating %sD mesh'
1443 % ( glob, dim, name, glob, dim ))
1445 reason = ("For unknown reason. "
1446 "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1448 if allReasons != "":allReasons += "\n"
1449 allReasons += "- " + reason
1451 if not ok or allReasons != "":
1452 msg = '"' + GetName(self.mesh) + '"'
1453 if ok: msg += " has been computed with warnings"
1454 else: msg += " has not been computed"
1455 if allReasons != "": msg += ":"
1460 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1461 smeshgui = salome.ImportComponentGUI("SMESH")
1462 smeshgui.Init(self.mesh.GetStudyId())
1463 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1464 salome.sg.updateObjBrowser(1)
1468 ## Return submesh objects list in meshing order
1469 # @return list of list of submesh objects
1470 # @ingroup l2_construct
1471 def GetMeshOrder(self):
1472 return self.mesh.GetMeshOrder()
1474 ## Return submesh objects list in meshing order
1475 # @return list of list of submesh objects
1476 # @ingroup l2_construct
1477 def SetMeshOrder(self, submeshes):
1478 return self.mesh.SetMeshOrder(submeshes)
1480 ## Removes all nodes and elements
1481 # @ingroup l2_construct
1484 if ( salome.sg.hasDesktop() and
1485 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1486 smeshgui = salome.ImportComponentGUI("SMESH")
1487 smeshgui.Init(self.mesh.GetStudyId())
1488 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1489 salome.sg.updateObjBrowser(1)
1491 ## Removes all nodes and elements of indicated shape
1492 # @ingroup l2_construct
1493 def ClearSubMesh(self, geomId):
1494 self.mesh.ClearSubMesh(geomId)
1495 if salome.sg.hasDesktop():
1496 smeshgui = salome.ImportComponentGUI("SMESH")
1497 smeshgui.Init(self.mesh.GetStudyId())
1498 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1499 salome.sg.updateObjBrowser(1)
1501 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1502 # @param fineness [0.0,1.0] defines mesh fineness
1503 # @return True or False
1504 # @ingroup l3_algos_basic
1505 def AutomaticTetrahedralization(self, fineness=0):
1506 dim = self.MeshDimension()
1508 self.RemoveGlobalHypotheses()
1509 self.Segment().AutomaticLength(fineness)
1511 self.Triangle().LengthFromEdges()
1514 from salome.NETGENPlugin.NETGENPluginBuilder import NETGEN
1515 self.Tetrahedron(NETGEN)
1517 return self.Compute()
1519 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1520 # @param fineness [0.0, 1.0] defines mesh fineness
1521 # @return True or False
1522 # @ingroup l3_algos_basic
1523 def AutomaticHexahedralization(self, fineness=0):
1524 dim = self.MeshDimension()
1525 # assign the hypotheses
1526 self.RemoveGlobalHypotheses()
1527 self.Segment().AutomaticLength(fineness)
1534 return self.Compute()
1536 ## Assigns a hypothesis
1537 # @param hyp a hypothesis to assign
1538 # @param geom a subhape of mesh geometry
1539 # @return SMESH.Hypothesis_Status
1540 # @ingroup l2_hypotheses
1541 def AddHypothesis(self, hyp, geom=0):
1542 if isinstance( hyp, Mesh_Algorithm ):
1543 hyp = hyp.GetAlgorithm()
1548 geom = self.mesh.GetShapeToMesh()
1550 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1551 status = self.mesh.AddHypothesis(geom, hyp)
1552 isAlgo = hyp._narrow( SMESH_Algo )
1553 hyp_name = GetName( hyp )
1556 geom_name = GetName( geom )
1557 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1560 ## Return True if an algorithm of hypothesis is assigned to a given shape
1561 # @param hyp a hypothesis to check
1562 # @param geom a subhape of mesh geometry
1563 # @return True of False
1564 # @ingroup l2_hypotheses
1565 def IsUsedHypothesis(self, hyp, geom):
1566 if not hyp: # or not geom
1568 if isinstance( hyp, Mesh_Algorithm ):
1569 hyp = hyp.GetAlgorithm()
1571 hyps = self.GetHypothesisList(geom)
1573 if h.GetId() == hyp.GetId():
1577 ## Unassigns a hypothesis
1578 # @param hyp a hypothesis to unassign
1579 # @param geom a sub-shape of mesh geometry
1580 # @return SMESH.Hypothesis_Status
1581 # @ingroup l2_hypotheses
1582 def RemoveHypothesis(self, hyp, geom=0):
1585 if isinstance( hyp, Mesh_Algorithm ):
1586 hyp = hyp.GetAlgorithm()
1592 if self.IsUsedHypothesis( hyp, shape ):
1593 return self.mesh.RemoveHypothesis( shape, hyp )
1594 hypName = GetName( hyp )
1595 geoName = GetName( shape )
1596 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1599 ## Gets the list of hypotheses added on a geometry
1600 # @param geom a sub-shape of mesh geometry
1601 # @return the sequence of SMESH_Hypothesis
1602 # @ingroup l2_hypotheses
1603 def GetHypothesisList(self, geom):
1604 return self.mesh.GetHypothesisList( geom )
1606 ## Removes all global hypotheses
1607 # @ingroup l2_hypotheses
1608 def RemoveGlobalHypotheses(self):
1609 current_hyps = self.mesh.GetHypothesisList( self.geom )
1610 for hyp in current_hyps:
1611 self.mesh.RemoveHypothesis( self.geom, hyp )
1615 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1616 ## allowing to overwrite the file if it exists or add the exported data to its contents
1617 # @param f is the file name
1618 # @param auto_groups boolean parameter for creating/not creating
1619 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1620 # the typical use is auto_groups=false.
1621 # @param version MED format version(MED_V2_1 or MED_V2_2)
1622 # @param overwrite boolean parameter for overwriting/not overwriting the file
1623 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1624 # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1625 # - 1D if all mesh nodes lie on OX coordinate axis, or
1626 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1627 # - 3D in the rest cases.
1629 # If @a autoDimension is @c False, the space dimension is always 3.
1630 # @ingroup l2_impexp
1631 def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
1632 overwrite=1, meshPart=None, autoDimension=True):
1634 unRegister = genObjUnRegister()
1635 if isinstance( meshPart, list ):
1636 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1637 unRegister.set( meshPart )
1638 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension)
1640 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
1642 ## Exports the mesh in a file in SAUV format
1643 # @param f is the file name
1644 # @param auto_groups boolean parameter for creating/not creating
1645 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1646 # the typical use is auto_groups=false.
1647 # @ingroup l2_impexp
1648 def ExportSAUV(self, f, auto_groups=0):
1649 self.mesh.ExportSAUV(f, auto_groups)
1651 ## Exports the mesh in a file in DAT format
1652 # @param f the file name
1653 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1654 # @ingroup l2_impexp
1655 def ExportDAT(self, f, meshPart=None):
1657 unRegister = genObjUnRegister()
1658 if isinstance( meshPart, list ):
1659 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1660 unRegister.set( meshPart )
1661 self.mesh.ExportPartToDAT( meshPart, f )
1663 self.mesh.ExportDAT(f)
1665 ## Exports the mesh in a file in UNV format
1666 # @param f the file name
1667 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1668 # @ingroup l2_impexp
1669 def ExportUNV(self, f, meshPart=None):
1671 unRegister = genObjUnRegister()
1672 if isinstance( meshPart, list ):
1673 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1674 unRegister.set( meshPart )
1675 self.mesh.ExportPartToUNV( meshPart, f )
1677 self.mesh.ExportUNV(f)
1679 ## Export the mesh in a file in STL format
1680 # @param f the file name
1681 # @param ascii defines the file encoding
1682 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1683 # @ingroup l2_impexp
1684 def ExportSTL(self, f, ascii=1, meshPart=None):
1686 unRegister = genObjUnRegister()
1687 if isinstance( meshPart, list ):
1688 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1689 unRegister.set( meshPart )
1690 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1692 self.mesh.ExportSTL(f, ascii)
1694 ## Exports the mesh in a file in CGNS format
1695 # @param f is the file name
1696 # @param overwrite boolean parameter for overwriting/not overwriting the file
1697 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1698 # @ingroup l2_impexp
1699 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1700 unRegister = genObjUnRegister()
1701 if isinstance( meshPart, list ):
1702 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1703 unRegister.set( meshPart )
1704 if isinstance( meshPart, Mesh ):
1705 meshPart = meshPart.mesh
1707 meshPart = self.mesh
1708 self.mesh.ExportCGNS(meshPart, f, overwrite)
1710 ## Exports the mesh in a file in GMF format.
1711 # GMF files must have .mesh extension for the ASCII format and .meshb for
1712 # the bynary format. Other extensions are not allowed.
1713 # @param f is the file name
1714 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1715 # @ingroup l2_impexp
1716 def ExportGMF(self, f, meshPart=None):
1717 unRegister = genObjUnRegister()
1718 if isinstance( meshPart, list ):
1719 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1720 unRegister.set( meshPart )
1721 if isinstance( meshPart, Mesh ):
1722 meshPart = meshPart.mesh
1724 meshPart = self.mesh
1725 self.mesh.ExportGMF(meshPart, f, True)
1727 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1728 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1729 ## allowing to overwrite the file if it exists or add the exported data to its contents
1730 # @param f the file name
1731 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1732 # @param opt boolean parameter for creating/not creating
1733 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1734 # @param overwrite boolean parameter for overwriting/not overwriting the file
1735 # @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1736 # - 1D if all mesh nodes lie on OX coordinate axis, or
1737 # - 2D if all mesh nodes lie on XOY coordinate plane, or
1738 # - 3D in the rest cases.
1740 # If @a autoDimension is @c False, the space dimension is always 3.
1741 # @ingroup l2_impexp
1742 def ExportToMED(self, f, version, opt=0, overwrite=1, autoDimension=True):
1743 self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension)
1745 # Operations with groups:
1746 # ----------------------
1748 ## Creates an empty mesh group
1749 # @param elementType the type of elements in the group
1750 # @param name the name of the mesh group
1751 # @return SMESH_Group
1752 # @ingroup l2_grps_create
1753 def CreateEmptyGroup(self, elementType, name):
1754 return self.mesh.CreateGroup(elementType, name)
1756 ## Creates a mesh group based on the geometric object \a grp
1757 # and gives a \a name, \n if this parameter is not defined
1758 # the name is the same as the geometric group name \n
1759 # Note: Works like GroupOnGeom().
1760 # @param grp a geometric group, a vertex, an edge, a face or a solid
1761 # @param name the name of the mesh group
1762 # @return SMESH_GroupOnGeom
1763 # @ingroup l2_grps_create
1764 def Group(self, grp, name=""):
1765 return self.GroupOnGeom(grp, name)
1767 ## Creates a mesh group based on the geometrical object \a grp
1768 # and gives a \a name, \n if this parameter is not defined
1769 # the name is the same as the geometrical group name
1770 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1771 # @param name the name of the mesh group
1772 # @param typ the type of elements in the group. If not set, it is
1773 # automatically detected by the type of the geometry
1774 # @return SMESH_GroupOnGeom
1775 # @ingroup l2_grps_create
1776 def GroupOnGeom(self, grp, name="", typ=None):
1777 AssureGeomPublished( self, grp, name )
1779 name = grp.GetName()
1781 typ = self._groupTypeFromShape( grp )
1782 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1784 ## Pivate method to get a type of group on geometry
1785 def _groupTypeFromShape( self, shape ):
1786 tgeo = str(shape.GetShapeType())
1787 if tgeo == "VERTEX":
1789 elif tgeo == "EDGE":
1791 elif tgeo == "FACE" or tgeo == "SHELL":
1793 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1795 elif tgeo == "COMPOUND":
1796 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
1798 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1799 return self._groupTypeFromShape( sub[0] )
1802 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1805 ## Creates a mesh group with given \a name based on the \a filter which
1806 ## is a special type of group dynamically updating it's contents during
1807 ## mesh modification
1808 # @param typ the type of elements in the group
1809 # @param name the name of the mesh group
1810 # @param filter the filter defining group contents
1811 # @return SMESH_GroupOnFilter
1812 # @ingroup l2_grps_create
1813 def GroupOnFilter(self, typ, name, filter):
1814 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1816 ## Creates a mesh group by the given ids of elements
1817 # @param groupName the name of the mesh group
1818 # @param elementType the type of elements in the group
1819 # @param elemIDs the list of ids
1820 # @return SMESH_Group
1821 # @ingroup l2_grps_create
1822 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1823 group = self.mesh.CreateGroup(elementType, groupName)
1827 ## Creates a mesh group by the given conditions
1828 # @param groupName the name of the mesh group
1829 # @param elementType the type of elements in the group
1830 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1831 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1832 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1833 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1834 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1835 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1836 # @return SMESH_Group
1837 # @ingroup l2_grps_create
1841 CritType=FT_Undefined,
1844 UnaryOp=FT_Undefined,
1846 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1847 group = self.MakeGroupByCriterion(groupName, aCriterion)
1850 ## Creates a mesh group by the given criterion
1851 # @param groupName the name of the mesh group
1852 # @param Criterion the instance of Criterion class
1853 # @return SMESH_Group
1854 # @ingroup l2_grps_create
1855 def MakeGroupByCriterion(self, groupName, Criterion):
1856 aFilterMgr = self.smeshpyD.CreateFilterManager()
1857 aFilter = aFilterMgr.CreateFilter()
1859 aCriteria.append(Criterion)
1860 aFilter.SetCriteria(aCriteria)
1861 group = self.MakeGroupByFilter(groupName, aFilter)
1862 aFilterMgr.UnRegister()
1865 ## Creates a mesh group by the given criteria (list of criteria)
1866 # @param groupName the name of the mesh group
1867 # @param theCriteria the list of criteria
1868 # @return SMESH_Group
1869 # @ingroup l2_grps_create
1870 def MakeGroupByCriteria(self, groupName, theCriteria):
1871 aFilterMgr = self.smeshpyD.CreateFilterManager()
1872 aFilter = aFilterMgr.CreateFilter()
1873 aFilter.SetCriteria(theCriteria)
1874 group = self.MakeGroupByFilter(groupName, aFilter)
1875 aFilterMgr.UnRegister()
1878 ## Creates a mesh group by the given filter
1879 # @param groupName the name of the mesh group
1880 # @param theFilter the instance of Filter class
1881 # @return SMESH_Group
1882 # @ingroup l2_grps_create
1883 def MakeGroupByFilter(self, groupName, theFilter):
1884 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1885 theFilter.SetMesh( self.mesh )
1886 group.AddFrom( theFilter )
1890 # @ingroup l2_grps_delete
1891 def RemoveGroup(self, group):
1892 self.mesh.RemoveGroup(group)
1894 ## Removes a group with its contents
1895 # @ingroup l2_grps_delete
1896 def RemoveGroupWithContents(self, group):
1897 self.mesh.RemoveGroupWithContents(group)
1899 ## Gets the list of groups existing in the mesh
1900 # @return a sequence of SMESH_GroupBase
1901 # @ingroup l2_grps_create
1902 def GetGroups(self):
1903 return self.mesh.GetGroups()
1905 ## Gets the number of groups existing in the mesh
1906 # @return the quantity of groups as an integer value
1907 # @ingroup l2_grps_create
1909 return self.mesh.NbGroups()
1911 ## Gets the list of names of groups existing in the mesh
1912 # @return list of strings
1913 # @ingroup l2_grps_create
1914 def GetGroupNames(self):
1915 groups = self.GetGroups()
1917 for group in groups:
1918 names.append(group.GetName())
1921 ## Produces a union of two groups
1922 # A new group is created. All mesh elements that are
1923 # present in the initial groups are added to the new one
1924 # @return an instance of SMESH_Group
1925 # @ingroup l2_grps_operon
1926 def UnionGroups(self, group1, group2, name):
1927 return self.mesh.UnionGroups(group1, group2, name)
1929 ## Produces a union list of groups
1930 # New group is created. All mesh elements that are present in
1931 # initial groups are added to the new one
1932 # @return an instance of SMESH_Group
1933 # @ingroup l2_grps_operon
1934 def UnionListOfGroups(self, groups, name):
1935 return self.mesh.UnionListOfGroups(groups, name)
1937 ## Prodices an intersection of two groups
1938 # A new group is created. All mesh elements that are common
1939 # for the two initial groups are added to the new one.
1940 # @return an instance of SMESH_Group
1941 # @ingroup l2_grps_operon
1942 def IntersectGroups(self, group1, group2, name):
1943 return self.mesh.IntersectGroups(group1, group2, name)
1945 ## Produces an intersection of groups
1946 # New group is created. All mesh elements that are present in all
1947 # initial groups simultaneously are added to the new one
1948 # @return an instance of SMESH_Group
1949 # @ingroup l2_grps_operon
1950 def IntersectListOfGroups(self, groups, name):
1951 return self.mesh.IntersectListOfGroups(groups, name)
1953 ## Produces a cut of two groups
1954 # A new group is created. All mesh elements that are present in
1955 # the main group but are not present in the tool group are added to the new one
1956 # @return an instance of SMESH_Group
1957 # @ingroup l2_grps_operon
1958 def CutGroups(self, main_group, tool_group, name):
1959 return self.mesh.CutGroups(main_group, tool_group, name)
1961 ## Produces a cut of groups
1962 # A new group is created. All mesh elements that are present in main groups
1963 # but do not present in tool groups are added to the new one
1964 # @return an instance of SMESH_Group
1965 # @ingroup l2_grps_operon
1966 def CutListOfGroups(self, main_groups, tool_groups, name):
1967 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1969 ## Produces a group of elements of specified type using list of existing groups
1970 # A new group is created. System
1971 # 1) extracts all nodes on which groups elements are built
1972 # 2) combines all elements of specified dimension laying on these nodes
1973 # @return an instance of SMESH_Group
1974 # @ingroup l2_grps_operon
1975 def CreateDimGroup(self, groups, elem_type, name):
1976 return self.mesh.CreateDimGroup(groups, elem_type, name)
1979 ## Convert group on geom into standalone group
1980 # @ingroup l2_grps_delete
1981 def ConvertToStandalone(self, group):
1982 return self.mesh.ConvertToStandalone(group)
1984 # Get some info about mesh:
1985 # ------------------------
1987 ## Returns the log of nodes and elements added or removed
1988 # since the previous clear of the log.
1989 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1990 # @return list of log_block structures:
1995 # @ingroup l1_auxiliary
1996 def GetLog(self, clearAfterGet):
1997 return self.mesh.GetLog(clearAfterGet)
1999 ## Clears the log of nodes and elements added or removed since the previous
2000 # clear. Must be used immediately after GetLog if clearAfterGet is false.
2001 # @ingroup l1_auxiliary
2003 self.mesh.ClearLog()
2005 ## Toggles auto color mode on the object.
2006 # @param theAutoColor the flag which toggles auto color mode.
2007 # @ingroup l1_auxiliary
2008 def SetAutoColor(self, theAutoColor):
2009 self.mesh.SetAutoColor(theAutoColor)
2011 ## Gets flag of object auto color mode.
2012 # @return True or False
2013 # @ingroup l1_auxiliary
2014 def GetAutoColor(self):
2015 return self.mesh.GetAutoColor()
2017 ## Gets the internal ID
2018 # @return integer value, which is the internal Id of the mesh
2019 # @ingroup l1_auxiliary
2021 return self.mesh.GetId()
2024 # @return integer value, which is the study Id of the mesh
2025 # @ingroup l1_auxiliary
2026 def GetStudyId(self):
2027 return self.mesh.GetStudyId()
2029 ## Checks the group names for duplications.
2030 # Consider the maximum group name length stored in MED file.
2031 # @return True or False
2032 # @ingroup l1_auxiliary
2033 def HasDuplicatedGroupNamesMED(self):
2034 return self.mesh.HasDuplicatedGroupNamesMED()
2036 ## Obtains the mesh editor tool
2037 # @return an instance of SMESH_MeshEditor
2038 # @ingroup l1_modifying
2039 def GetMeshEditor(self):
2042 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
2043 # can be passed as argument to a method accepting mesh, group or sub-mesh
2044 # @return an instance of SMESH_IDSource
2045 # @ingroup l1_auxiliary
2046 def GetIDSource(self, ids, elemType):
2047 return self.editor.MakeIDSource(ids, elemType)
2050 # Get informations about mesh contents:
2051 # ------------------------------------
2053 ## Gets the mesh stattistic
2054 # @return dictionary type element - count of elements
2055 # @ingroup l1_meshinfo
2056 def GetMeshInfo(self, obj = None):
2057 if not obj: obj = self.mesh
2058 return self.smeshpyD.GetMeshInfo(obj)
2060 ## Returns the number of nodes in the mesh
2061 # @return an integer value
2062 # @ingroup l1_meshinfo
2064 return self.mesh.NbNodes()
2066 ## Returns the number of elements in the mesh
2067 # @return an integer value
2068 # @ingroup l1_meshinfo
2069 def NbElements(self):
2070 return self.mesh.NbElements()
2072 ## Returns the number of 0d elements in the mesh
2073 # @return an integer value
2074 # @ingroup l1_meshinfo
2075 def Nb0DElements(self):
2076 return self.mesh.Nb0DElements()
2078 ## Returns the number of ball discrete elements in the mesh
2079 # @return an integer value
2080 # @ingroup l1_meshinfo
2082 return self.mesh.NbBalls()
2084 ## Returns the number of edges in the mesh
2085 # @return an integer value
2086 # @ingroup l1_meshinfo
2088 return self.mesh.NbEdges()
2090 ## Returns the number of edges with the given order in the mesh
2091 # @param elementOrder the order of elements:
2092 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2093 # @return an integer value
2094 # @ingroup l1_meshinfo
2095 def NbEdgesOfOrder(self, elementOrder):
2096 return self.mesh.NbEdgesOfOrder(elementOrder)
2098 ## Returns the number of faces in the mesh
2099 # @return an integer value
2100 # @ingroup l1_meshinfo
2102 return self.mesh.NbFaces()
2104 ## Returns the number of faces with the given order in the mesh
2105 # @param elementOrder the order of elements:
2106 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2107 # @return an integer value
2108 # @ingroup l1_meshinfo
2109 def NbFacesOfOrder(self, elementOrder):
2110 return self.mesh.NbFacesOfOrder(elementOrder)
2112 ## Returns the number of triangles in the mesh
2113 # @return an integer value
2114 # @ingroup l1_meshinfo
2115 def NbTriangles(self):
2116 return self.mesh.NbTriangles()
2118 ## Returns the number of triangles with the given order in the mesh
2119 # @param elementOrder is the order of elements:
2120 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2121 # @return an integer value
2122 # @ingroup l1_meshinfo
2123 def NbTrianglesOfOrder(self, elementOrder):
2124 return self.mesh.NbTrianglesOfOrder(elementOrder)
2126 ## Returns the number of biquadratic triangles in the mesh
2127 # @return an integer value
2128 # @ingroup l1_meshinfo
2129 def NbBiQuadTriangles(self):
2130 return self.mesh.NbBiQuadTriangles()
2132 ## Returns the number of quadrangles in the mesh
2133 # @return an integer value
2134 # @ingroup l1_meshinfo
2135 def NbQuadrangles(self):
2136 return self.mesh.NbQuadrangles()
2138 ## Returns the number of quadrangles with the given order in the mesh
2139 # @param elementOrder the order of elements:
2140 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2141 # @return an integer value
2142 # @ingroup l1_meshinfo
2143 def NbQuadranglesOfOrder(self, elementOrder):
2144 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2146 ## Returns the number of biquadratic quadrangles in the mesh
2147 # @return an integer value
2148 # @ingroup l1_meshinfo
2149 def NbBiQuadQuadrangles(self):
2150 return self.mesh.NbBiQuadQuadrangles()
2152 ## Returns the number of polygons in the mesh
2153 # @return an integer value
2154 # @ingroup l1_meshinfo
2155 def NbPolygons(self):
2156 return self.mesh.NbPolygons()
2158 ## Returns the number of volumes in the mesh
2159 # @return an integer value
2160 # @ingroup l1_meshinfo
2161 def NbVolumes(self):
2162 return self.mesh.NbVolumes()
2164 ## Returns the number of volumes with the given order in the mesh
2165 # @param elementOrder the order of elements:
2166 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2167 # @return an integer value
2168 # @ingroup l1_meshinfo
2169 def NbVolumesOfOrder(self, elementOrder):
2170 return self.mesh.NbVolumesOfOrder(elementOrder)
2172 ## Returns the number of tetrahedrons in the mesh
2173 # @return an integer value
2174 # @ingroup l1_meshinfo
2176 return self.mesh.NbTetras()
2178 ## Returns the number of tetrahedrons with the given order in the mesh
2179 # @param elementOrder the order of elements:
2180 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2181 # @return an integer value
2182 # @ingroup l1_meshinfo
2183 def NbTetrasOfOrder(self, elementOrder):
2184 return self.mesh.NbTetrasOfOrder(elementOrder)
2186 ## Returns the number of hexahedrons in the mesh
2187 # @return an integer value
2188 # @ingroup l1_meshinfo
2190 return self.mesh.NbHexas()
2192 ## Returns the number of hexahedrons with the given order in the mesh
2193 # @param elementOrder the order of elements:
2194 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2195 # @return an integer value
2196 # @ingroup l1_meshinfo
2197 def NbHexasOfOrder(self, elementOrder):
2198 return self.mesh.NbHexasOfOrder(elementOrder)
2200 ## Returns the number of triquadratic hexahedrons in the mesh
2201 # @return an integer value
2202 # @ingroup l1_meshinfo
2203 def NbTriQuadraticHexas(self):
2204 return self.mesh.NbTriQuadraticHexas()
2206 ## Returns the number of pyramids in the mesh
2207 # @return an integer value
2208 # @ingroup l1_meshinfo
2209 def NbPyramids(self):
2210 return self.mesh.NbPyramids()
2212 ## Returns the number of pyramids with the given order in the mesh
2213 # @param elementOrder the order of elements:
2214 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2215 # @return an integer value
2216 # @ingroup l1_meshinfo
2217 def NbPyramidsOfOrder(self, elementOrder):
2218 return self.mesh.NbPyramidsOfOrder(elementOrder)
2220 ## Returns the number of prisms in the mesh
2221 # @return an integer value
2222 # @ingroup l1_meshinfo
2224 return self.mesh.NbPrisms()
2226 ## Returns the number of prisms with the given order in the mesh
2227 # @param elementOrder the order of elements:
2228 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2229 # @return an integer value
2230 # @ingroup l1_meshinfo
2231 def NbPrismsOfOrder(self, elementOrder):
2232 return self.mesh.NbPrismsOfOrder(elementOrder)
2234 ## Returns the number of hexagonal prisms in the mesh
2235 # @return an integer value
2236 # @ingroup l1_meshinfo
2237 def NbHexagonalPrisms(self):
2238 return self.mesh.NbHexagonalPrisms()
2240 ## Returns the number of polyhedrons in the mesh
2241 # @return an integer value
2242 # @ingroup l1_meshinfo
2243 def NbPolyhedrons(self):
2244 return self.mesh.NbPolyhedrons()
2246 ## Returns the number of submeshes in the mesh
2247 # @return an integer value
2248 # @ingroup l1_meshinfo
2249 def NbSubMesh(self):
2250 return self.mesh.NbSubMesh()
2252 ## Returns the list of mesh elements IDs
2253 # @return the list of integer values
2254 # @ingroup l1_meshinfo
2255 def GetElementsId(self):
2256 return self.mesh.GetElementsId()
2258 ## Returns the list of IDs of mesh elements with the given type
2259 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2260 # @return list of integer values
2261 # @ingroup l1_meshinfo
2262 def GetElementsByType(self, elementType):
2263 return self.mesh.GetElementsByType(elementType)
2265 ## Returns the list of mesh nodes IDs
2266 # @return the list of integer values
2267 # @ingroup l1_meshinfo
2268 def GetNodesId(self):
2269 return self.mesh.GetNodesId()
2271 # Get the information about mesh elements:
2272 # ------------------------------------
2274 ## Returns the type of mesh element
2275 # @return the value from SMESH::ElementType enumeration
2276 # @ingroup l1_meshinfo
2277 def GetElementType(self, id, iselem):
2278 return self.mesh.GetElementType(id, iselem)
2280 ## Returns the geometric type of mesh element
2281 # @return the value from SMESH::EntityType enumeration
2282 # @ingroup l1_meshinfo
2283 def GetElementGeomType(self, id):
2284 return self.mesh.GetElementGeomType(id)
2286 ## Returns the list of submesh elements IDs
2287 # @param Shape a geom object(sub-shape) IOR
2288 # Shape must be the sub-shape of a ShapeToMesh()
2289 # @return the list of integer values
2290 # @ingroup l1_meshinfo
2291 def GetSubMeshElementsId(self, Shape):
2292 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2293 ShapeID = Shape.GetSubShapeIndices()[0]
2296 return self.mesh.GetSubMeshElementsId(ShapeID)
2298 ## Returns the list of submesh nodes IDs
2299 # @param Shape a geom object(sub-shape) IOR
2300 # Shape must be the sub-shape of a ShapeToMesh()
2301 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2302 # @return the list of integer values
2303 # @ingroup l1_meshinfo
2304 def GetSubMeshNodesId(self, Shape, all):
2305 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2306 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2309 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2311 ## Returns type of elements on given shape
2312 # @param Shape a geom object(sub-shape) IOR
2313 # Shape must be a sub-shape of a ShapeToMesh()
2314 # @return element type
2315 # @ingroup l1_meshinfo
2316 def GetSubMeshElementType(self, Shape):
2317 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2318 ShapeID = Shape.GetSubShapeIndices()[0]
2321 return self.mesh.GetSubMeshElementType(ShapeID)
2323 ## Gets the mesh description
2324 # @return string value
2325 # @ingroup l1_meshinfo
2327 return self.mesh.Dump()
2330 # Get the information about nodes and elements of a mesh by its IDs:
2331 # -----------------------------------------------------------
2333 ## Gets XYZ coordinates of a node
2334 # \n If there is no nodes for the given ID - returns an empty list
2335 # @return a list of double precision values
2336 # @ingroup l1_meshinfo
2337 def GetNodeXYZ(self, id):
2338 return self.mesh.GetNodeXYZ(id)
2340 ## Returns list of IDs of inverse elements for the given node
2341 # \n If there is no node for the given ID - returns an empty list
2342 # @return a list of integer values
2343 # @ingroup l1_meshinfo
2344 def GetNodeInverseElements(self, id):
2345 return self.mesh.GetNodeInverseElements(id)
2347 ## @brief Returns the position of a node on the shape
2348 # @return SMESH::NodePosition
2349 # @ingroup l1_meshinfo
2350 def GetNodePosition(self,NodeID):
2351 return self.mesh.GetNodePosition(NodeID)
2353 ## @brief Returns the position of an element on the shape
2354 # @return SMESH::ElementPosition
2355 # @ingroup l1_meshinfo
2356 def GetElementPosition(self,ElemID):
2357 return self.mesh.GetElementPosition(ElemID)
2359 ## If the given element is a node, returns the ID of shape
2360 # \n If there is no node for the given ID - returns -1
2361 # @return an integer value
2362 # @ingroup l1_meshinfo
2363 def GetShapeID(self, id):
2364 return self.mesh.GetShapeID(id)
2366 ## Returns the ID of the result shape after
2367 # FindShape() from SMESH_MeshEditor for the given element
2368 # \n If there is no element for the given ID - returns -1
2369 # @return an integer value
2370 # @ingroup l1_meshinfo
2371 def GetShapeIDForElem(self,id):
2372 return self.mesh.GetShapeIDForElem(id)
2374 ## Returns the number of nodes for the given element
2375 # \n If there is no element for the given ID - returns -1
2376 # @return an integer value
2377 # @ingroup l1_meshinfo
2378 def GetElemNbNodes(self, id):
2379 return self.mesh.GetElemNbNodes(id)
2381 ## Returns the node ID the given (zero based) index for the given element
2382 # \n If there is no element for the given ID - returns -1
2383 # \n If there is no node for the given index - returns -2
2384 # @return an integer value
2385 # @ingroup l1_meshinfo
2386 def GetElemNode(self, id, index):
2387 return self.mesh.GetElemNode(id, index)
2389 ## Returns the IDs of nodes of the given element
2390 # @return a list of integer values
2391 # @ingroup l1_meshinfo
2392 def GetElemNodes(self, id):
2393 return self.mesh.GetElemNodes(id)
2395 ## Returns true if the given node is the medium node in the given quadratic element
2396 # @ingroup l1_meshinfo
2397 def IsMediumNode(self, elementID, nodeID):
2398 return self.mesh.IsMediumNode(elementID, nodeID)
2400 ## Returns true if the given node is the medium node in one of quadratic elements
2401 # @ingroup l1_meshinfo
2402 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2403 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2405 ## Returns the number of edges for the given element
2406 # @ingroup l1_meshinfo
2407 def ElemNbEdges(self, id):
2408 return self.mesh.ElemNbEdges(id)
2410 ## Returns the number of faces for the given element
2411 # @ingroup l1_meshinfo
2412 def ElemNbFaces(self, id):
2413 return self.mesh.ElemNbFaces(id)
2415 ## Returns nodes of given face (counted from zero) for given volumic element.
2416 # @ingroup l1_meshinfo
2417 def GetElemFaceNodes(self,elemId, faceIndex):
2418 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2420 ## Returns an element based on all given nodes.
2421 # @ingroup l1_meshinfo
2422 def FindElementByNodes(self,nodes):
2423 return self.mesh.FindElementByNodes(nodes)
2425 ## Returns true if the given element is a polygon
2426 # @ingroup l1_meshinfo
2427 def IsPoly(self, id):
2428 return self.mesh.IsPoly(id)
2430 ## Returns true if the given element is quadratic
2431 # @ingroup l1_meshinfo
2432 def IsQuadratic(self, id):
2433 return self.mesh.IsQuadratic(id)
2435 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2436 # @ingroup l1_meshinfo
2437 def GetBallDiameter(self, id):
2438 return self.mesh.GetBallDiameter(id)
2440 ## Returns XYZ coordinates of the barycenter of the given element
2441 # \n If there is no element for the given ID - returns an empty list
2442 # @return a list of three double values
2443 # @ingroup l1_meshinfo
2444 def BaryCenter(self, id):
2445 return self.mesh.BaryCenter(id)
2447 ## Passes mesh elements through the given filter and return IDs of fitting elements
2448 # @param theFilter SMESH_Filter
2449 # @return a list of ids
2450 # @ingroup l1_controls
2451 def GetIdsFromFilter(self, theFilter):
2452 theFilter.SetMesh( self.mesh )
2453 return theFilter.GetIDs()
2455 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2456 # Returns a list of special structures (borders).
2457 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2458 # @ingroup l1_controls
2459 def GetFreeBorders(self):
2460 aFilterMgr = self.smeshpyD.CreateFilterManager()
2461 aPredicate = aFilterMgr.CreateFreeEdges()
2462 aPredicate.SetMesh(self.mesh)
2463 aBorders = aPredicate.GetBorders()
2464 aFilterMgr.UnRegister()
2468 # Get mesh measurements information:
2469 # ------------------------------------
2471 ## Get minimum distance between two nodes, elements or distance to the origin
2472 # @param id1 first node/element id
2473 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2474 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2475 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2476 # @return minimum distance value
2477 # @sa GetMinDistance()
2478 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2479 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2480 return aMeasure.value
2482 ## Get measure structure specifying minimum distance data between two objects
2483 # @param id1 first node/element id
2484 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2485 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2486 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2487 # @return Measure structure
2489 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2491 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2493 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2496 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2498 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2503 aMeasurements = self.smeshpyD.CreateMeasurements()
2504 aMeasure = aMeasurements.MinDistance(id1, id2)
2505 genObjUnRegister([aMeasurements,id1, id2])
2508 ## Get bounding box of the specified object(s)
2509 # @param objects single source object or list of source objects or list of nodes/elements IDs
2510 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2511 # @c False specifies that @a objects are nodes
2512 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2513 # @sa GetBoundingBox()
2514 def BoundingBox(self, objects=None, isElem=False):
2515 result = self.GetBoundingBox(objects, isElem)
2519 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2522 ## Get measure structure specifying bounding box data of the specified object(s)
2523 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2524 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2525 # @c False specifies that @a objects are nodes
2526 # @return Measure structure
2528 def GetBoundingBox(self, IDs=None, isElem=False):
2531 elif isinstance(IDs, tuple):
2533 if not isinstance(IDs, list):
2535 if len(IDs) > 0 and isinstance(IDs[0], int):
2538 unRegister = genObjUnRegister()
2540 if isinstance(o, Mesh):
2541 srclist.append(o.mesh)
2542 elif hasattr(o, "_narrow"):
2543 src = o._narrow(SMESH.SMESH_IDSource)
2544 if src: srclist.append(src)
2546 elif isinstance(o, list):
2548 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2550 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2551 unRegister.set( srclist[-1] )
2554 aMeasurements = self.smeshpyD.CreateMeasurements()
2555 unRegister.set( aMeasurements )
2556 aMeasure = aMeasurements.BoundingBox(srclist)
2559 # Mesh edition (SMESH_MeshEditor functionality):
2560 # ---------------------------------------------
2562 ## Removes the elements from the mesh by ids
2563 # @param IDsOfElements is a list of ids of elements to remove
2564 # @return True or False
2565 # @ingroup l2_modif_del
2566 def RemoveElements(self, IDsOfElements):
2567 return self.editor.RemoveElements(IDsOfElements)
2569 ## Removes nodes from mesh by ids
2570 # @param IDsOfNodes is a list of ids of nodes to remove
2571 # @return True or False
2572 # @ingroup l2_modif_del
2573 def RemoveNodes(self, IDsOfNodes):
2574 return self.editor.RemoveNodes(IDsOfNodes)
2576 ## Removes all orphan (free) nodes from mesh
2577 # @return number of the removed nodes
2578 # @ingroup l2_modif_del
2579 def RemoveOrphanNodes(self):
2580 return self.editor.RemoveOrphanNodes()
2582 ## Add a node to the mesh by coordinates
2583 # @return Id of the new node
2584 # @ingroup l2_modif_add
2585 def AddNode(self, x, y, z):
2586 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2587 if hasVars: self.mesh.SetParameters(Parameters)
2588 return self.editor.AddNode( x, y, z)
2590 ## Creates a 0D element on a node with given number.
2591 # @param IDOfNode the ID of node for creation of the element.
2592 # @return the Id of the new 0D element
2593 # @ingroup l2_modif_add
2594 def Add0DElement(self, IDOfNode):
2595 return self.editor.Add0DElement(IDOfNode)
2597 ## Create 0D elements on all nodes of the given elements except those
2598 # nodes on which a 0D element already exists.
2599 # @param theObject an object on whose nodes 0D elements will be created.
2600 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2601 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2602 # @param theGroupName optional name of a group to add 0D elements created
2603 # and/or found on nodes of \a theObject.
2604 # @return an object (a new group or a temporary SMESH_IDSource) holding
2605 # IDs of new and/or found 0D elements. IDs of 0D elements
2606 # can be retrieved from the returned object by calling GetIDs()
2607 # @ingroup l2_modif_add
2608 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2609 unRegister = genObjUnRegister()
2610 if isinstance( theObject, Mesh ):
2611 theObject = theObject.GetMesh()
2612 if isinstance( theObject, list ):
2613 theObject = self.GetIDSource( theObject, SMESH.ALL )
2614 unRegister.set( theObject )
2615 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2617 ## Creates a ball element on a node with given ID.
2618 # @param IDOfNode the ID of node for creation of the element.
2619 # @param diameter the bal diameter.
2620 # @return the Id of the new ball element
2621 # @ingroup l2_modif_add
2622 def AddBall(self, IDOfNode, diameter):
2623 return self.editor.AddBall( IDOfNode, diameter )
2625 ## Creates a linear or quadratic edge (this is determined
2626 # by the number of given nodes).
2627 # @param IDsOfNodes the list of node IDs for creation of the element.
2628 # The order of nodes in this list should correspond to the description
2629 # of MED. \n This description is located by the following link:
2630 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2631 # @return the Id of the new edge
2632 # @ingroup l2_modif_add
2633 def AddEdge(self, IDsOfNodes):
2634 return self.editor.AddEdge(IDsOfNodes)
2636 ## Creates a linear or quadratic face (this is determined
2637 # by the number of given nodes).
2638 # @param IDsOfNodes the list of node IDs for creation of the element.
2639 # The order of nodes in this list should correspond to the description
2640 # of MED. \n This description is located by the following link:
2641 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2642 # @return the Id of the new face
2643 # @ingroup l2_modif_add
2644 def AddFace(self, IDsOfNodes):
2645 return self.editor.AddFace(IDsOfNodes)
2647 ## Adds a polygonal face to the mesh by the list of node IDs
2648 # @param IdsOfNodes the list of node IDs for creation of the element.
2649 # @return the Id of the new face
2650 # @ingroup l2_modif_add
2651 def AddPolygonalFace(self, IdsOfNodes):
2652 return self.editor.AddPolygonalFace(IdsOfNodes)
2654 ## Creates both simple and quadratic volume (this is determined
2655 # by the number of given nodes).
2656 # @param IDsOfNodes the list of node IDs for creation of the element.
2657 # The order of nodes in this list should correspond to the description
2658 # of MED. \n This description is located by the following link:
2659 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2660 # @return the Id of the new volumic element
2661 # @ingroup l2_modif_add
2662 def AddVolume(self, IDsOfNodes):
2663 return self.editor.AddVolume(IDsOfNodes)
2665 ## Creates a volume of many faces, giving nodes for each face.
2666 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2667 # @param Quantities the list of integer values, Quantities[i]
2668 # gives the quantity of nodes in face number i.
2669 # @return the Id of the new volumic element
2670 # @ingroup l2_modif_add
2671 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2672 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2674 ## Creates a volume of many faces, giving the IDs of the existing faces.
2675 # @param IdsOfFaces the list of face IDs for volume creation.
2677 # Note: The created volume will refer only to the nodes
2678 # of the given faces, not to the faces themselves.
2679 # @return the Id of the new volumic element
2680 # @ingroup l2_modif_add
2681 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2682 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2685 ## @brief Binds a node to a vertex
2686 # @param NodeID a node ID
2687 # @param Vertex a vertex or vertex ID
2688 # @return True if succeed else raises an exception
2689 # @ingroup l2_modif_add
2690 def SetNodeOnVertex(self, NodeID, Vertex):
2691 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
2692 VertexID = Vertex.GetSubShapeIndices()[0]
2696 self.editor.SetNodeOnVertex(NodeID, VertexID)
2697 except SALOME.SALOME_Exception, inst:
2698 raise ValueError, inst.details.text
2702 ## @brief Stores the node position on an edge
2703 # @param NodeID a node ID
2704 # @param Edge an edge or edge ID
2705 # @param paramOnEdge a parameter on the edge where the node is located
2706 # @return True if succeed else raises an exception
2707 # @ingroup l2_modif_add
2708 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2709 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
2710 EdgeID = Edge.GetSubShapeIndices()[0]
2714 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2715 except SALOME.SALOME_Exception, inst:
2716 raise ValueError, inst.details.text
2719 ## @brief Stores node position on a face
2720 # @param NodeID a node ID
2721 # @param Face a face or face ID
2722 # @param u U parameter on the face where the node is located
2723 # @param v V parameter on the face where the node is located
2724 # @return True if succeed else raises an exception
2725 # @ingroup l2_modif_add
2726 def SetNodeOnFace(self, NodeID, Face, u, v):
2727 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
2728 FaceID = Face.GetSubShapeIndices()[0]
2732 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2733 except SALOME.SALOME_Exception, inst:
2734 raise ValueError, inst.details.text
2737 ## @brief Binds a node to a solid
2738 # @param NodeID a node ID
2739 # @param Solid a solid or solid ID
2740 # @return True if succeed else raises an exception
2741 # @ingroup l2_modif_add
2742 def SetNodeInVolume(self, NodeID, Solid):
2743 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
2744 SolidID = Solid.GetSubShapeIndices()[0]
2748 self.editor.SetNodeInVolume(NodeID, SolidID)
2749 except SALOME.SALOME_Exception, inst:
2750 raise ValueError, inst.details.text
2753 ## @brief Bind an element to a shape
2754 # @param ElementID an element ID
2755 # @param Shape a shape or shape ID
2756 # @return True if succeed else raises an exception
2757 # @ingroup l2_modif_add
2758 def SetMeshElementOnShape(self, ElementID, Shape):
2759 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2760 ShapeID = Shape.GetSubShapeIndices()[0]
2764 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2765 except SALOME.SALOME_Exception, inst:
2766 raise ValueError, inst.details.text
2770 ## Moves the node with the given id
2771 # @param NodeID the id of the node
2772 # @param x a new X coordinate
2773 # @param y a new Y coordinate
2774 # @param z a new Z coordinate
2775 # @return True if succeed else False
2776 # @ingroup l2_modif_movenode
2777 def MoveNode(self, NodeID, x, y, z):
2778 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2779 if hasVars: self.mesh.SetParameters(Parameters)
2780 return self.editor.MoveNode(NodeID, x, y, z)
2782 ## Finds the node closest to a point and moves it to a point location
2783 # @param x the X coordinate of a point
2784 # @param y the Y coordinate of a point
2785 # @param z the Z coordinate of a point
2786 # @param NodeID if specified (>0), the node with this ID is moved,
2787 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2788 # @return the ID of a node
2789 # @ingroup l2_modif_throughp
2790 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2791 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2792 if hasVars: self.mesh.SetParameters(Parameters)
2793 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2795 ## Finds the node closest to a point
2796 # @param x the X coordinate of a point
2797 # @param y the Y coordinate of a point
2798 # @param z the Z coordinate of a point
2799 # @return the ID of a node
2800 # @ingroup l2_modif_throughp
2801 def FindNodeClosestTo(self, x, y, z):
2802 #preview = self.mesh.GetMeshEditPreviewer()
2803 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2804 return self.editor.FindNodeClosestTo(x, y, z)
2806 ## Finds the elements where a point lays IN or ON
2807 # @param x the X coordinate of a point
2808 # @param y the Y coordinate of a point
2809 # @param z the Z coordinate of a point
2810 # @param elementType type of elements to find (SMESH.ALL type
2811 # means elements of any type excluding nodes, discrete and 0D elements)
2812 # @param meshPart a part of mesh (group, sub-mesh) to search within
2813 # @return list of IDs of found elements
2814 # @ingroup l2_modif_throughp
2815 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2817 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2819 return self.editor.FindElementsByPoint(x, y, z, elementType)
2821 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2822 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2823 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2825 def GetPointState(self, x, y, z):
2826 return self.editor.GetPointState(x, y, z)
2828 ## Finds the node closest to a point and moves it to a point location
2829 # @param x the X coordinate of a point
2830 # @param y the Y coordinate of a point
2831 # @param z the Z coordinate of a point
2832 # @return the ID of a moved node
2833 # @ingroup l2_modif_throughp
2834 def MeshToPassThroughAPoint(self, x, y, z):
2835 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2837 ## Replaces two neighbour triangles sharing Node1-Node2 link
2838 # with the triangles built on the same 4 nodes but having other common link.
2839 # @param NodeID1 the ID of the first node
2840 # @param NodeID2 the ID of the second node
2841 # @return false if proper faces were not found
2842 # @ingroup l2_modif_invdiag
2843 def InverseDiag(self, NodeID1, NodeID2):
2844 return self.editor.InverseDiag(NodeID1, NodeID2)
2846 ## Replaces two neighbour triangles sharing Node1-Node2 link
2847 # with a quadrangle built on the same 4 nodes.
2848 # @param NodeID1 the ID of the first node
2849 # @param NodeID2 the ID of the second node
2850 # @return false if proper faces were not found
2851 # @ingroup l2_modif_unitetri
2852 def DeleteDiag(self, NodeID1, NodeID2):
2853 return self.editor.DeleteDiag(NodeID1, NodeID2)
2855 ## Reorients elements by ids
2856 # @param IDsOfElements if undefined reorients all mesh elements
2857 # @return True if succeed else False
2858 # @ingroup l2_modif_changori
2859 def Reorient(self, IDsOfElements=None):
2860 if IDsOfElements == None:
2861 IDsOfElements = self.GetElementsId()
2862 return self.editor.Reorient(IDsOfElements)
2864 ## Reorients all elements of the object
2865 # @param theObject mesh, submesh or group
2866 # @return True if succeed else False
2867 # @ingroup l2_modif_changori
2868 def ReorientObject(self, theObject):
2869 if ( isinstance( theObject, Mesh )):
2870 theObject = theObject.GetMesh()
2871 return self.editor.ReorientObject(theObject)
2873 ## Reorient faces contained in \a the2DObject.
2874 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2875 # @param theDirection is a desired direction of normal of \a theFace.
2876 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2877 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2878 # compared with theDirection. It can be either ID of face or a point
2879 # by which the face will be found. The point can be given as either
2880 # a GEOM vertex or a list of point coordinates.
2881 # @return number of reoriented faces
2882 # @ingroup l2_modif_changori
2883 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2884 unRegister = genObjUnRegister()
2886 if isinstance( the2DObject, Mesh ):
2887 the2DObject = the2DObject.GetMesh()
2888 if isinstance( the2DObject, list ):
2889 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2890 unRegister.set( the2DObject )
2891 # check theDirection
2892 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
2893 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2894 if isinstance( theDirection, list ):
2895 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2896 # prepare theFace and thePoint
2897 theFace = theFaceOrPoint
2898 thePoint = PointStruct(0,0,0)
2899 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
2900 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2902 if isinstance( theFaceOrPoint, list ):
2903 thePoint = PointStruct( *theFaceOrPoint )
2905 if isinstance( theFaceOrPoint, PointStruct ):
2906 thePoint = theFaceOrPoint
2908 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2910 ## Fuses the neighbouring triangles into quadrangles.
2911 # @param IDsOfElements The triangles to be fused,
2912 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2913 # choose a neighbour to fuse with.
2914 # @param MaxAngle is the maximum angle between element normals at which the fusion
2915 # is still performed; theMaxAngle is mesured in radians.
2916 # Also it could be a name of variable which defines angle in degrees.
2917 # @return TRUE in case of success, FALSE otherwise.
2918 # @ingroup l2_modif_unitetri
2919 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2920 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2921 self.mesh.SetParameters(Parameters)
2922 if not IDsOfElements:
2923 IDsOfElements = self.GetElementsId()
2924 Functor = self.smeshpyD.GetFunctor(theCriterion)
2925 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2927 ## Fuses the neighbouring triangles of the object into quadrangles
2928 # @param theObject is mesh, submesh or group
2929 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2930 # choose a neighbour to fuse with.
2931 # @param MaxAngle a max angle between element normals at which the fusion
2932 # is still performed; theMaxAngle is mesured in radians.
2933 # @return TRUE in case of success, FALSE otherwise.
2934 # @ingroup l2_modif_unitetri
2935 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2936 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2937 self.mesh.SetParameters(Parameters)
2938 if isinstance( theObject, Mesh ):
2939 theObject = theObject.GetMesh()
2940 Functor = self.smeshpyD.GetFunctor(theCriterion)
2941 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2943 ## Splits quadrangles into triangles.
2944 # @param IDsOfElements the faces to be splitted.
2945 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2946 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2947 # value, then quadrangles will be split by the smallest diagonal.
2948 # @return TRUE in case of success, FALSE otherwise.
2949 # @ingroup l2_modif_cutquadr
2950 def QuadToTri (self, IDsOfElements, theCriterion = None):
2951 if IDsOfElements == []:
2952 IDsOfElements = self.GetElementsId()
2953 if theCriterion is None:
2954 theCriterion = FT_MaxElementLength2D
2955 Functor = self.smeshpyD.GetFunctor(theCriterion)
2956 return self.editor.QuadToTri(IDsOfElements, Functor)
2958 ## Splits quadrangles into triangles.
2959 # @param theObject the object from which the list of elements is taken,
2960 # this is mesh, submesh or group
2961 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2962 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2963 # value, then quadrangles will be split by the smallest diagonal.
2964 # @return TRUE in case of success, FALSE otherwise.
2965 # @ingroup l2_modif_cutquadr
2966 def QuadToTriObject (self, theObject, theCriterion = None):
2967 if ( isinstance( theObject, Mesh )):
2968 theObject = theObject.GetMesh()
2969 if theCriterion is None:
2970 theCriterion = FT_MaxElementLength2D
2971 Functor = self.smeshpyD.GetFunctor(theCriterion)
2972 return self.editor.QuadToTriObject(theObject, Functor)
2974 ## Splits each of given quadrangles into 4 triangles. A node is added at the center of
2976 # @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
2977 # group or a list of face IDs. By default all quadrangles are split
2978 # @ingroup l2_modif_cutquadr
2979 def QuadTo4Tri (self, theElements=[]):
2980 unRegister = genObjUnRegister()
2981 if isinstance( theElements, Mesh ):
2982 theElements = theElements.mesh
2983 elif not theElements:
2984 theElements = self.mesh
2985 elif isinstance( theElements, list ):
2986 theElements = self.GetIDSource( theElements, SMESH.FACE )
2987 unRegister.set( theElements )
2988 return self.editor.QuadTo4Tri( theElements )
2990 ## Splits quadrangles into triangles.
2991 # @param IDsOfElements the faces to be splitted
2992 # @param Diag13 is used to choose a diagonal for splitting.
2993 # @return TRUE in case of success, FALSE otherwise.
2994 # @ingroup l2_modif_cutquadr
2995 def SplitQuad (self, IDsOfElements, Diag13):
2996 if IDsOfElements == []:
2997 IDsOfElements = self.GetElementsId()
2998 return self.editor.SplitQuad(IDsOfElements, Diag13)
3000 ## Splits quadrangles into triangles.
3001 # @param theObject the object from which the list of elements is taken,
3002 # this is mesh, submesh or group
3003 # @param Diag13 is used to choose a diagonal for splitting.
3004 # @return TRUE in case of success, FALSE otherwise.
3005 # @ingroup l2_modif_cutquadr
3006 def SplitQuadObject (self, theObject, Diag13):
3007 if ( isinstance( theObject, Mesh )):
3008 theObject = theObject.GetMesh()
3009 return self.editor.SplitQuadObject(theObject, Diag13)
3011 ## Finds a better splitting of the given quadrangle.
3012 # @param IDOfQuad the ID of the quadrangle to be splitted.
3013 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3014 # choose a diagonal for splitting.
3015 # @return 1 if 1-3 diagonal is better, 2 if 2-4
3016 # diagonal is better, 0 if error occurs.
3017 # @ingroup l2_modif_cutquadr
3018 def BestSplit (self, IDOfQuad, theCriterion):
3019 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
3021 ## Splits volumic elements into tetrahedrons
3022 # @param elemIDs either list of elements or mesh or group or submesh
3023 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
3024 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
3025 # @ingroup l2_modif_cutquadr
3026 def SplitVolumesIntoTetra(self, elemIDs, method=smeshBuilder.Hex_5Tet ):
3027 unRegister = genObjUnRegister()
3028 if isinstance( elemIDs, Mesh ):
3029 elemIDs = elemIDs.GetMesh()
3030 if ( isinstance( elemIDs, list )):
3031 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
3032 unRegister.set( elemIDs )
3033 self.editor.SplitVolumesIntoTetra(elemIDs, method)
3035 ## Splits quadrangle faces near triangular facets of volumes
3037 # @ingroup l1_auxiliary
3038 def SplitQuadsNearTriangularFacets(self):
3039 faces_array = self.GetElementsByType(SMESH.FACE)
3040 for face_id in faces_array:
3041 if self.GetElemNbNodes(face_id) == 4: # quadrangle
3042 quad_nodes = self.mesh.GetElemNodes(face_id)
3043 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
3044 isVolumeFound = False
3045 for node1_elem in node1_elems:
3046 if not isVolumeFound:
3047 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
3048 nb_nodes = self.GetElemNbNodes(node1_elem)
3049 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
3050 volume_elem = node1_elem
3051 volume_nodes = self.mesh.GetElemNodes(volume_elem)
3052 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
3053 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
3054 isVolumeFound = True
3055 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
3056 self.SplitQuad([face_id], False) # diagonal 2-4
3057 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
3058 isVolumeFound = True
3059 self.SplitQuad([face_id], True) # diagonal 1-3
3060 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
3061 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
3062 isVolumeFound = True
3063 self.SplitQuad([face_id], True) # diagonal 1-3
3065 ## @brief Splits hexahedrons into tetrahedrons.
3067 # This operation uses pattern mapping functionality for splitting.
3068 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
3069 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
3070 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
3071 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
3072 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
3073 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
3074 # @return TRUE in case of success, FALSE otherwise.
3075 # @ingroup l1_auxiliary
3076 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
3077 # Pattern: 5.---------.6
3082 # (0,0,1) 4.---------.7 * |
3089 # (0,0,0) 0.---------.3
3090 pattern_tetra = "!!! Nb of points: \n 8 \n\
3100 !!! Indices of points of 6 tetras: \n\
3108 pattern = self.smeshpyD.GetPattern()
3109 isDone = pattern.LoadFromFile(pattern_tetra)
3111 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3114 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3115 isDone = pattern.MakeMesh(self.mesh, False, False)
3116 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3118 # split quafrangle faces near triangular facets of volumes
3119 self.SplitQuadsNearTriangularFacets()
3123 ## @brief Split hexahedrons into prisms.
3125 # Uses the pattern mapping functionality for splitting.
3126 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
3127 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
3128 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
3129 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
3130 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
3131 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
3132 # @return TRUE in case of success, FALSE otherwise.
3133 # @ingroup l1_auxiliary
3134 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3135 # Pattern: 5.---------.6
3140 # (0,0,1) 4.---------.7 |
3147 # (0,0,0) 0.---------.3
3148 pattern_prism = "!!! Nb of points: \n 8 \n\
3158 !!! Indices of points of 2 prisms: \n\
3162 pattern = self.smeshpyD.GetPattern()
3163 isDone = pattern.LoadFromFile(pattern_prism)
3165 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3168 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3169 isDone = pattern.MakeMesh(self.mesh, False, False)
3170 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3172 # Splits quafrangle faces near triangular facets of volumes
3173 self.SplitQuadsNearTriangularFacets()
3177 ## Smoothes elements
3178 # @param IDsOfElements the list if ids of elements to smooth
3179 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3180 # Note that nodes built on edges and boundary nodes are always fixed.
3181 # @param MaxNbOfIterations the maximum number of iterations
3182 # @param MaxAspectRatio varies in range [1.0, inf]
3183 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3184 # @return TRUE in case of success, FALSE otherwise.
3185 # @ingroup l2_modif_smooth
3186 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3187 MaxNbOfIterations, MaxAspectRatio, Method):
3188 if IDsOfElements == []:
3189 IDsOfElements = self.GetElementsId()
3190 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3191 self.mesh.SetParameters(Parameters)
3192 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3193 MaxNbOfIterations, MaxAspectRatio, Method)
3195 ## Smoothes elements which belong to the given object
3196 # @param theObject the object to smooth
3197 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3198 # Note that nodes built on edges and boundary nodes are always fixed.
3199 # @param MaxNbOfIterations the maximum number of iterations
3200 # @param MaxAspectRatio varies in range [1.0, inf]
3201 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3202 # @return TRUE in case of success, FALSE otherwise.
3203 # @ingroup l2_modif_smooth
3204 def SmoothObject(self, theObject, IDsOfFixedNodes,
3205 MaxNbOfIterations, MaxAspectRatio, Method):
3206 if ( isinstance( theObject, Mesh )):
3207 theObject = theObject.GetMesh()
3208 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3209 MaxNbOfIterations, MaxAspectRatio, Method)
3211 ## Parametrically smoothes the given elements
3212 # @param IDsOfElements the list if ids of elements to smooth
3213 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3214 # Note that nodes built on edges and boundary nodes are always fixed.
3215 # @param MaxNbOfIterations the maximum number of iterations
3216 # @param MaxAspectRatio varies in range [1.0, inf]
3217 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3218 # @return TRUE in case of success, FALSE otherwise.
3219 # @ingroup l2_modif_smooth
3220 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3221 MaxNbOfIterations, MaxAspectRatio, Method):
3222 if IDsOfElements == []:
3223 IDsOfElements = self.GetElementsId()
3224 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3225 self.mesh.SetParameters(Parameters)
3226 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3227 MaxNbOfIterations, MaxAspectRatio, Method)
3229 ## Parametrically smoothes the elements which belong to the given object
3230 # @param theObject the object to smooth
3231 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3232 # Note that nodes built on edges and boundary nodes are always fixed.
3233 # @param MaxNbOfIterations the maximum number of iterations
3234 # @param MaxAspectRatio varies in range [1.0, inf]
3235 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3236 # @return TRUE in case of success, FALSE otherwise.
3237 # @ingroup l2_modif_smooth
3238 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3239 MaxNbOfIterations, MaxAspectRatio, Method):
3240 if ( isinstance( theObject, Mesh )):
3241 theObject = theObject.GetMesh()
3242 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3243 MaxNbOfIterations, MaxAspectRatio, Method)
3245 ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3246 # them with quadratic with the same id.
3247 # @param theForce3d new node creation method:
3248 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3249 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3250 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3251 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3252 # @ingroup l2_modif_tofromqu
3253 def ConvertToQuadratic(self, theForce3d, theSubMesh=None, theToBiQuad=False):
3254 if isinstance( theSubMesh, Mesh ):
3255 theSubMesh = theSubMesh.mesh
3257 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3260 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3262 self.editor.ConvertToQuadratic(theForce3d)
3263 error = self.editor.GetLastError()
3264 if error and error.comment:
3267 ## Converts the mesh from quadratic to ordinary,
3268 # deletes old quadratic elements, \n replacing
3269 # them with ordinary mesh elements with the same id.
3270 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3271 # @ingroup l2_modif_tofromqu
3272 def ConvertFromQuadratic(self, theSubMesh=None):
3274 self.editor.ConvertFromQuadraticObject(theSubMesh)
3276 return self.editor.ConvertFromQuadratic()
3278 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3279 # @return TRUE if operation has been completed successfully, FALSE otherwise
3280 # @ingroup l2_modif_edit
3281 def Make2DMeshFrom3D(self):
3282 return self.editor. Make2DMeshFrom3D()
3284 ## Creates missing boundary elements
3285 # @param elements - elements whose boundary is to be checked:
3286 # mesh, group, sub-mesh or list of elements
3287 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3288 # @param dimension - defines type of boundary elements to create:
3289 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3290 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3291 # @param groupName - a name of group to store created boundary elements in,
3292 # "" means not to create the group
3293 # @param meshName - a name of new mesh to store created boundary elements in,
3294 # "" means not to create the new mesh
3295 # @param toCopyElements - if true, the checked elements will be copied into
3296 # the new mesh else only boundary elements will be copied into the new mesh
3297 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3298 # boundary elements will be copied into the new mesh
3299 # @return tuple (mesh, group) where boundary elements were added to
3300 # @ingroup l2_modif_edit
3301 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3302 toCopyElements=False, toCopyExistingBondary=False):
3303 unRegister = genObjUnRegister()
3304 if isinstance( elements, Mesh ):
3305 elements = elements.GetMesh()
3306 if ( isinstance( elements, list )):
3307 elemType = SMESH.ALL
3308 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3309 elements = self.editor.MakeIDSource(elements, elemType)
3310 unRegister.set( elements )
3311 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3312 toCopyElements,toCopyExistingBondary)
3313 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3317 # @brief Creates missing boundary elements around either the whole mesh or
3318 # groups of 2D elements
3319 # @param dimension - defines type of boundary elements to create
3320 # @param groupName - a name of group to store all boundary elements in,
3321 # "" means not to create the group
3322 # @param meshName - a name of a new mesh, which is a copy of the initial
3323 # mesh + created boundary elements; "" means not to create the new mesh
3324 # @param toCopyAll - if true, the whole initial mesh will be copied into
3325 # the new mesh else only boundary elements will be copied into the new mesh
3326 # @param groups - groups of 2D elements to make boundary around
3327 # @retval tuple( long, mesh, groups )
3328 # long - number of added boundary elements
3329 # mesh - the mesh where elements were added to
3330 # group - the group of boundary elements or None
3332 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3333 toCopyAll=False, groups=[]):
3334 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3336 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3337 return nb, mesh, group
3339 ## Renumber mesh nodes
3340 # @ingroup l2_modif_renumber
3341 def RenumberNodes(self):
3342 self.editor.RenumberNodes()
3344 ## Renumber mesh elements
3345 # @ingroup l2_modif_renumber
3346 def RenumberElements(self):
3347 self.editor.RenumberElements()
3349 ## Generates new elements by rotation of the elements around the axis
3350 # @param IDsOfElements the list of ids of elements to sweep
3351 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3352 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3353 # @param NbOfSteps the number of steps
3354 # @param Tolerance tolerance
3355 # @param MakeGroups forces the generation of new groups from existing ones
3356 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3357 # of all steps, else - size of each step
3358 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3359 # @ingroup l2_modif_extrurev
3360 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3361 MakeGroups=False, TotalAngle=False):
3362 if IDsOfElements == []:
3363 IDsOfElements = self.GetElementsId()
3364 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3365 Axis = self.smeshpyD.GetAxisStruct(Axis)
3366 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3367 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3368 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3369 self.mesh.SetParameters(Parameters)
3370 if TotalAngle and NbOfSteps:
3371 AngleInRadians /= NbOfSteps
3373 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3374 AngleInRadians, NbOfSteps, Tolerance)
3375 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3378 ## Generates new elements by rotation of the elements of object around the axis
3379 # @param theObject object which elements should be sweeped.
3380 # It can be a mesh, a sub mesh or a group.
3381 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3382 # @param AngleInRadians the angle of Rotation
3383 # @param NbOfSteps number of steps
3384 # @param Tolerance tolerance
3385 # @param MakeGroups forces the generation of new groups from existing ones
3386 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3387 # of all steps, else - size of each step
3388 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3389 # @ingroup l2_modif_extrurev
3390 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3391 MakeGroups=False, TotalAngle=False):
3392 if ( isinstance( theObject, Mesh )):
3393 theObject = theObject.GetMesh()
3394 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3395 Axis = self.smeshpyD.GetAxisStruct(Axis)
3396 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3397 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3398 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3399 self.mesh.SetParameters(Parameters)
3400 if TotalAngle and NbOfSteps:
3401 AngleInRadians /= NbOfSteps
3403 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3404 NbOfSteps, Tolerance)
3405 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3408 ## Generates new elements by rotation of the elements of object around the axis
3409 # @param theObject object which elements should be sweeped.
3410 # It can be a mesh, a sub mesh or a group.
3411 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3412 # @param AngleInRadians the angle of Rotation
3413 # @param NbOfSteps number of steps
3414 # @param Tolerance tolerance
3415 # @param MakeGroups forces the generation of new groups from existing ones
3416 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3417 # of all steps, else - size of each step
3418 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3419 # @ingroup l2_modif_extrurev
3420 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3421 MakeGroups=False, TotalAngle=False):
3422 if ( isinstance( theObject, Mesh )):
3423 theObject = theObject.GetMesh()
3424 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3425 Axis = self.smeshpyD.GetAxisStruct(Axis)
3426 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3427 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3428 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3429 self.mesh.SetParameters(Parameters)
3430 if TotalAngle and NbOfSteps:
3431 AngleInRadians /= NbOfSteps
3433 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3434 NbOfSteps, Tolerance)
3435 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3438 ## Generates new elements by rotation of the elements of object around the axis
3439 # @param theObject object which elements should be sweeped.
3440 # It can be a mesh, a sub mesh or a group.
3441 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3442 # @param AngleInRadians the angle of Rotation
3443 # @param NbOfSteps number of steps
3444 # @param Tolerance tolerance
3445 # @param MakeGroups forces the generation of new groups from existing ones
3446 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3447 # of all steps, else - size of each step
3448 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3449 # @ingroup l2_modif_extrurev
3450 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3451 MakeGroups=False, TotalAngle=False):
3452 if ( isinstance( theObject, Mesh )):
3453 theObject = theObject.GetMesh()
3454 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3455 Axis = self.smeshpyD.GetAxisStruct(Axis)
3456 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3457 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3458 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3459 self.mesh.SetParameters(Parameters)
3460 if TotalAngle and NbOfSteps:
3461 AngleInRadians /= NbOfSteps
3463 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3464 NbOfSteps, Tolerance)
3465 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3468 ## Generates new elements by extrusion of the elements with given ids
3469 # @param IDsOfElements the list of elements ids for extrusion
3470 # @param StepVector vector or DirStruct or 3 vector components, defining
3471 # the direction and value of extrusion for one step (the total extrusion
3472 # length will be NbOfSteps * ||StepVector||)
3473 # @param NbOfSteps the number of steps
3474 # @param MakeGroups forces the generation of new groups from existing ones
3475 # @param IsNodes is True if elements with given ids are nodes
3476 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3477 # @ingroup l2_modif_extrurev
3478 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3479 if IDsOfElements == []:
3480 IDsOfElements = self.GetElementsId()
3481 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3482 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3483 if isinstance( StepVector, list ):
3484 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3485 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3486 Parameters = StepVector.PS.parameters + var_separator + Parameters
3487 self.mesh.SetParameters(Parameters)
3490 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3492 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3494 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3496 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3499 ## Generates new elements by extrusion of the elements with given ids
3500 # @param IDsOfElements is ids of elements
3501 # @param StepVector vector or DirStruct or 3 vector components, defining
3502 # the direction and value of extrusion for one step (the total extrusion
3503 # length will be NbOfSteps * ||StepVector||)
3504 # @param NbOfSteps the number of steps
3505 # @param ExtrFlags sets flags for extrusion
3506 # @param SewTolerance uses for comparing locations of nodes if flag
3507 # EXTRUSION_FLAG_SEW is set
3508 # @param MakeGroups forces the generation of new groups from existing ones
3509 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3510 # @ingroup l2_modif_extrurev
3511 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3512 ExtrFlags, SewTolerance, MakeGroups=False):
3513 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3514 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3515 if isinstance( StepVector, list ):
3516 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3518 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3519 ExtrFlags, SewTolerance)
3520 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3521 ExtrFlags, SewTolerance)
3524 ## Generates new elements by extrusion of the elements which belong to the object
3525 # @param theObject the object which elements should be processed.
3526 # It can be a mesh, a sub mesh or a group.
3527 # @param StepVector vector or DirStruct or 3 vector components, defining
3528 # the direction and value of extrusion for one step (the total extrusion
3529 # length will be NbOfSteps * ||StepVector||)
3530 # @param NbOfSteps the number of steps
3531 # @param MakeGroups forces the generation of new groups from existing ones
3532 # @param IsNodes is True if elements which belong to the object are nodes
3533 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3534 # @ingroup l2_modif_extrurev
3535 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3536 if ( isinstance( theObject, Mesh )):
3537 theObject = theObject.GetMesh()
3538 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3539 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3540 if isinstance( StepVector, list ):
3541 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3542 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3543 Parameters = StepVector.PS.parameters + var_separator + Parameters
3544 self.mesh.SetParameters(Parameters)
3547 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3549 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3551 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3553 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3556 ## Generates new elements by extrusion of the elements which belong to the object
3557 # @param theObject object which elements should be processed.
3558 # It can be a mesh, a sub mesh or a group.
3559 # @param StepVector vector or DirStruct or 3 vector components, defining
3560 # the direction and value of extrusion for one step (the total extrusion
3561 # length will be NbOfSteps * ||StepVector||)
3562 # @param NbOfSteps the number of steps
3563 # @param MakeGroups to generate new groups from existing ones
3564 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3565 # @ingroup l2_modif_extrurev
3566 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3567 if ( isinstance( theObject, Mesh )):
3568 theObject = theObject.GetMesh()
3569 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3570 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3571 if isinstance( StepVector, list ):
3572 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3573 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3574 Parameters = StepVector.PS.parameters + var_separator + Parameters
3575 self.mesh.SetParameters(Parameters)
3577 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3578 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3581 ## Generates new elements by extrusion of the elements which belong to the object
3582 # @param theObject object which elements should be processed.
3583 # It can be a mesh, a sub mesh or a group.
3584 # @param StepVector vector or DirStruct or 3 vector components, defining
3585 # the direction and value of extrusion for one step (the total extrusion
3586 # length will be NbOfSteps * ||StepVector||)
3587 # @param NbOfSteps the number of steps
3588 # @param MakeGroups forces the generation of new groups from existing ones
3589 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3590 # @ingroup l2_modif_extrurev
3591 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3592 if ( isinstance( theObject, Mesh )):
3593 theObject = theObject.GetMesh()
3594 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3595 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3596 if isinstance( StepVector, list ):
3597 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3598 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3599 Parameters = StepVector.PS.parameters + var_separator + Parameters
3600 self.mesh.SetParameters(Parameters)
3602 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3603 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3608 ## Generates new elements by extrusion of the given elements
3609 # The path of extrusion must be a meshed edge.
3610 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3611 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3612 # @param NodeStart the start node from Path. Defines the direction of extrusion
3613 # @param HasAngles allows the shape to be rotated around the path
3614 # to get the resulting mesh in a helical fashion
3615 # @param Angles list of angles in radians
3616 # @param LinearVariation forces the computation of rotation angles as linear
3617 # variation of the given Angles along path steps
3618 # @param HasRefPoint allows using the reference point
3619 # @param RefPoint the point around which the elements are rotated (the mass
3620 # center of the elements by default).
3621 # The User can specify any point as the Reference Point.
3622 # RefPoint can be either GEOM Vertex, [x,y,z] or SMESH.PointStruct
3623 # @param MakeGroups forces the generation of new groups from existing ones
3624 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3625 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3626 # only SMESH::Extrusion_Error otherwise
3627 # @ingroup l2_modif_extrurev
3628 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3629 HasAngles, Angles, LinearVariation,
3630 HasRefPoint, RefPoint, MakeGroups, ElemType):
3631 if isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object):
3632 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3634 elif isinstance( RefPoint, list ):
3635 RefPoint = PointStruct(*RefPoint)
3637 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3638 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3639 self.mesh.SetParameters(Parameters)
3641 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3643 if isinstance(Base, list):
3645 if Base == []: IDsOfElements = self.GetElementsId()
3646 else: IDsOfElements = Base
3647 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3648 HasAngles, Angles, LinearVariation,
3649 HasRefPoint, RefPoint, MakeGroups, ElemType)
3651 if isinstance(Base, Mesh): Base = Base.GetMesh()
3652 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3653 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3654 HasAngles, Angles, LinearVariation,
3655 HasRefPoint, RefPoint, MakeGroups, ElemType)
3657 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3660 ## Generates new elements by extrusion of the given elements
3661 # The path of extrusion must be a meshed edge.
3662 # @param IDsOfElements ids of elements
3663 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3664 # @param PathShape shape(edge) defines the sub-mesh for the path
3665 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3666 # @param HasAngles allows the shape to be rotated around the path
3667 # to get the resulting mesh in a helical fashion
3668 # @param Angles list of angles in radians
3669 # @param HasRefPoint allows using the reference point
3670 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3671 # The User can specify any point as the Reference Point.
3672 # @param MakeGroups forces the generation of new groups from existing ones
3673 # @param LinearVariation forces the computation of rotation angles as linear
3674 # variation of the given Angles along path steps
3675 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3676 # only SMESH::Extrusion_Error otherwise
3677 # @ingroup l2_modif_extrurev
3678 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3679 HasAngles, Angles, HasRefPoint, RefPoint,
3680 MakeGroups=False, LinearVariation=False):
3681 if IDsOfElements == []:
3682 IDsOfElements = self.GetElementsId()
3683 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3684 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3686 if ( isinstance( PathMesh, Mesh )):
3687 PathMesh = PathMesh.GetMesh()
3688 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3689 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3690 self.mesh.SetParameters(Parameters)
3691 if HasAngles and Angles and LinearVariation:
3692 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3695 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3696 PathShape, NodeStart, HasAngles,
3697 Angles, HasRefPoint, RefPoint)
3698 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3699 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3701 ## Generates new elements by extrusion of the elements which belong to the object
3702 # The path of extrusion must be a meshed edge.
3703 # @param theObject the object which elements should be processed.
3704 # It can be a mesh, a sub mesh or a group.
3705 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3706 # @param PathShape shape(edge) defines the sub-mesh for the path
3707 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3708 # @param HasAngles allows the shape to be rotated around the path
3709 # to get the resulting mesh in a helical fashion
3710 # @param Angles list of angles
3711 # @param HasRefPoint allows using the reference point
3712 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3713 # The User can specify any point as the Reference Point.
3714 # @param MakeGroups forces the generation of new groups from existing ones
3715 # @param LinearVariation forces the computation of rotation angles as linear
3716 # variation of the given Angles along path steps
3717 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3718 # only SMESH::Extrusion_Error otherwise
3719 # @ingroup l2_modif_extrurev
3720 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3721 HasAngles, Angles, HasRefPoint, RefPoint,
3722 MakeGroups=False, LinearVariation=False):
3723 if ( isinstance( theObject, Mesh )):
3724 theObject = theObject.GetMesh()
3725 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3726 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3727 if ( isinstance( PathMesh, Mesh )):
3728 PathMesh = PathMesh.GetMesh()
3729 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3730 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3731 self.mesh.SetParameters(Parameters)
3732 if HasAngles and Angles and LinearVariation:
3733 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3736 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3737 PathShape, NodeStart, HasAngles,
3738 Angles, HasRefPoint, RefPoint)
3739 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3740 NodeStart, HasAngles, Angles, HasRefPoint,
3743 ## Generates new elements by extrusion of the elements which belong to the object
3744 # The path of extrusion must be a meshed edge.
3745 # @param theObject the object which elements should be processed.
3746 # It can be a mesh, a sub mesh or a group.
3747 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3748 # @param PathShape shape(edge) defines the sub-mesh for the path
3749 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3750 # @param HasAngles allows the shape to be rotated around the path
3751 # to get the resulting mesh in a helical fashion
3752 # @param Angles list of angles
3753 # @param HasRefPoint allows using the reference point
3754 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3755 # The User can specify any point as the Reference Point.
3756 # @param MakeGroups forces the generation of new groups from existing ones
3757 # @param LinearVariation forces the computation of rotation angles as linear
3758 # variation of the given Angles along path steps
3759 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3760 # only SMESH::Extrusion_Error otherwise
3761 # @ingroup l2_modif_extrurev
3762 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3763 HasAngles, Angles, HasRefPoint, RefPoint,
3764 MakeGroups=False, LinearVariation=False):
3765 if ( isinstance( theObject, Mesh )):
3766 theObject = theObject.GetMesh()
3767 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3768 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3769 if ( isinstance( PathMesh, Mesh )):
3770 PathMesh = PathMesh.GetMesh()
3771 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3772 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3773 self.mesh.SetParameters(Parameters)
3774 if HasAngles and Angles and LinearVariation:
3775 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3778 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3779 PathShape, NodeStart, HasAngles,
3780 Angles, HasRefPoint, RefPoint)
3781 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3782 NodeStart, HasAngles, Angles, HasRefPoint,
3785 ## Generates new elements by extrusion of the elements which belong to the object
3786 # The path of extrusion must be a meshed edge.
3787 # @param theObject the object which elements should be processed.
3788 # It can be a mesh, a sub mesh or a group.
3789 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3790 # @param PathShape shape(edge) defines the sub-mesh for the path
3791 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3792 # @param HasAngles allows the shape to be rotated around the path
3793 # to get the resulting mesh in a helical fashion
3794 # @param Angles list of angles
3795 # @param HasRefPoint allows using the reference point
3796 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3797 # The User can specify any point as the Reference Point.
3798 # @param MakeGroups forces the generation of new groups from existing ones
3799 # @param LinearVariation forces the computation of rotation angles as linear
3800 # variation of the given Angles along path steps
3801 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3802 # only SMESH::Extrusion_Error otherwise
3803 # @ingroup l2_modif_extrurev
3804 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3805 HasAngles, Angles, HasRefPoint, RefPoint,
3806 MakeGroups=False, LinearVariation=False):
3807 if ( isinstance( theObject, Mesh )):
3808 theObject = theObject.GetMesh()
3809 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3810 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3811 if ( isinstance( PathMesh, Mesh )):
3812 PathMesh = PathMesh.GetMesh()
3813 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3814 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3815 self.mesh.SetParameters(Parameters)
3816 if HasAngles and Angles and LinearVariation:
3817 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3820 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3821 PathShape, NodeStart, HasAngles,
3822 Angles, HasRefPoint, RefPoint)
3823 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3824 NodeStart, HasAngles, Angles, HasRefPoint,
3827 ## Creates a symmetrical copy of mesh elements
3828 # @param IDsOfElements list of elements ids
3829 # @param Mirror is AxisStruct or geom object(point, line, plane)
3830 # @param theMirrorType is POINT, AXIS or PLANE
3831 # If the Mirror is a geom object this parameter is unnecessary
3832 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3833 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3834 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3835 # @ingroup l2_modif_trsf
3836 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3837 if IDsOfElements == []:
3838 IDsOfElements = self.GetElementsId()
3839 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3840 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3841 self.mesh.SetParameters(Mirror.parameters)
3842 if Copy and MakeGroups:
3843 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3844 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3847 ## Creates a new mesh by a symmetrical copy of mesh elements
3848 # @param IDsOfElements the list of elements ids
3849 # @param Mirror is AxisStruct or geom object (point, line, plane)
3850 # @param theMirrorType is POINT, AXIS or PLANE
3851 # If the Mirror is a geom object this parameter is unnecessary
3852 # @param MakeGroups to generate new groups from existing ones
3853 # @param NewMeshName a name of the new mesh to create
3854 # @return instance of Mesh class
3855 # @ingroup l2_modif_trsf
3856 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3857 if IDsOfElements == []:
3858 IDsOfElements = self.GetElementsId()
3859 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3860 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3861 self.mesh.SetParameters(Mirror.parameters)
3862 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3863 MakeGroups, NewMeshName)
3864 return Mesh(self.smeshpyD,self.geompyD,mesh)
3866 ## Creates a symmetrical copy of the object
3867 # @param theObject mesh, submesh or group
3868 # @param Mirror AxisStruct or geom object (point, line, plane)
3869 # @param theMirrorType is POINT, AXIS or PLANE
3870 # If the Mirror is a geom object this parameter is unnecessary
3871 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3872 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3873 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3874 # @ingroup l2_modif_trsf
3875 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3876 if ( isinstance( theObject, Mesh )):
3877 theObject = theObject.GetMesh()
3878 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3879 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3880 self.mesh.SetParameters(Mirror.parameters)
3881 if Copy and MakeGroups:
3882 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3883 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3886 ## Creates a new mesh by a symmetrical copy of the object
3887 # @param theObject mesh, submesh or group
3888 # @param Mirror AxisStruct or geom object (point, line, plane)
3889 # @param theMirrorType POINT, AXIS or PLANE
3890 # If the Mirror is a geom object this parameter is unnecessary
3891 # @param MakeGroups forces the generation of new groups from existing ones
3892 # @param NewMeshName the name of the new mesh to create
3893 # @return instance of Mesh class
3894 # @ingroup l2_modif_trsf
3895 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3896 if ( isinstance( theObject, Mesh )):
3897 theObject = theObject.GetMesh()
3898 if (isinstance(Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3899 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3900 self.mesh.SetParameters(Mirror.parameters)
3901 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3902 MakeGroups, NewMeshName)
3903 return Mesh( self.smeshpyD,self.geompyD,mesh )
3905 ## Translates the elements
3906 # @param IDsOfElements list of elements ids
3907 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3908 # @param Copy allows copying the translated elements
3909 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3910 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3911 # @ingroup l2_modif_trsf
3912 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3913 if IDsOfElements == []:
3914 IDsOfElements = self.GetElementsId()
3915 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3916 Vector = self.smeshpyD.GetDirStruct(Vector)
3917 if isinstance( Vector, list ):
3918 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3919 self.mesh.SetParameters(Vector.PS.parameters)
3920 if Copy and MakeGroups:
3921 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3922 self.editor.Translate(IDsOfElements, Vector, Copy)
3925 ## Creates a new mesh of translated elements
3926 # @param IDsOfElements list of elements ids
3927 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3928 # @param MakeGroups forces the generation of new groups from existing ones
3929 # @param NewMeshName the name of the newly created mesh
3930 # @return instance of Mesh class
3931 # @ingroup l2_modif_trsf
3932 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3933 if IDsOfElements == []:
3934 IDsOfElements = self.GetElementsId()
3935 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3936 Vector = self.smeshpyD.GetDirStruct(Vector)
3937 if isinstance( Vector, list ):
3938 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3939 self.mesh.SetParameters(Vector.PS.parameters)
3940 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3941 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3943 ## Translates the object
3944 # @param theObject the object to translate (mesh, submesh, or group)
3945 # @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
3946 # @param Copy allows copying the translated elements
3947 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3948 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3949 # @ingroup l2_modif_trsf
3950 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3951 if ( isinstance( theObject, Mesh )):
3952 theObject = theObject.GetMesh()
3953 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3954 Vector = self.smeshpyD.GetDirStruct(Vector)
3955 if isinstance( Vector, list ):
3956 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3957 self.mesh.SetParameters(Vector.PS.parameters)
3958 if Copy and MakeGroups:
3959 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3960 self.editor.TranslateObject(theObject, Vector, Copy)
3963 ## Creates a new mesh from the translated object
3964 # @param theObject the object to translate (mesh, submesh, or group)
3965 # @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
3966 # @param MakeGroups forces the generation of new groups from existing ones
3967 # @param NewMeshName the name of the newly created mesh
3968 # @return instance of Mesh class
3969 # @ingroup l2_modif_trsf
3970 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3971 if isinstance( theObject, Mesh ):
3972 theObject = theObject.GetMesh()
3973 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
3974 Vector = self.smeshpyD.GetDirStruct(Vector)
3975 if isinstance( Vector, list ):
3976 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3977 self.mesh.SetParameters(Vector.PS.parameters)
3978 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3979 return Mesh( self.smeshpyD, self.geompyD, mesh )
3983 ## Scales the object
3984 # @param theObject - the object to translate (mesh, submesh, or group)
3985 # @param thePoint - base point for scale
3986 # @param theScaleFact - list of 1-3 scale factors for axises
3987 # @param Copy - allows copying the translated elements
3988 # @param MakeGroups - forces the generation of new groups from existing
3990 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3991 # empty list otherwise
3992 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3993 unRegister = genObjUnRegister()
3994 if ( isinstance( theObject, Mesh )):
3995 theObject = theObject.GetMesh()
3996 if ( isinstance( theObject, list )):
3997 theObject = self.GetIDSource(theObject, SMESH.ALL)
3998 unRegister.set( theObject )
3999 if ( isinstance( theScaleFact, float )):
4000 theScaleFact = [theScaleFact]
4001 if ( isinstance( theScaleFact, int )):
4002 theScaleFact = [ float(theScaleFact)]
4004 self.mesh.SetParameters(thePoint.parameters)
4006 if Copy and MakeGroups:
4007 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
4008 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
4011 ## Creates a new mesh from the translated object
4012 # @param theObject - the object to translate (mesh, submesh, or group)
4013 # @param thePoint - base point for scale
4014 # @param theScaleFact - list of 1-3 scale factors for axises
4015 # @param MakeGroups - forces the generation of new groups from existing ones
4016 # @param NewMeshName - the name of the newly created mesh
4017 # @return instance of Mesh class
4018 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
4019 unRegister = genObjUnRegister()
4020 if (isinstance(theObject, Mesh)):
4021 theObject = theObject.GetMesh()
4022 if ( isinstance( theObject, list )):
4023 theObject = self.GetIDSource(theObject,SMESH.ALL)
4024 unRegister.set( theObject )
4025 if ( isinstance( theScaleFact, float )):
4026 theScaleFact = [theScaleFact]
4027 if ( isinstance( theScaleFact, int )):
4028 theScaleFact = [ float(theScaleFact)]
4030 self.mesh.SetParameters(thePoint.parameters)
4031 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
4032 MakeGroups, NewMeshName)
4033 return Mesh( self.smeshpyD, self.geompyD, mesh )
4037 ## Rotates the elements
4038 # @param IDsOfElements list of elements ids
4039 # @param Axis the axis of rotation (AxisStruct or geom line)
4040 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4041 # @param Copy allows copying the rotated elements
4042 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4043 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4044 # @ingroup l2_modif_trsf
4045 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
4046 if IDsOfElements == []:
4047 IDsOfElements = self.GetElementsId()
4048 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4049 Axis = self.smeshpyD.GetAxisStruct(Axis)
4050 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4051 Parameters = Axis.parameters + var_separator + Parameters
4052 self.mesh.SetParameters(Parameters)
4053 if Copy and MakeGroups:
4054 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
4055 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
4058 ## Creates a new mesh of rotated elements
4059 # @param IDsOfElements list of element ids
4060 # @param Axis the axis of rotation (AxisStruct or geom line)
4061 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4062 # @param MakeGroups forces the generation of new groups from existing ones
4063 # @param NewMeshName the name of the newly created mesh
4064 # @return instance of Mesh class
4065 # @ingroup l2_modif_trsf
4066 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
4067 if IDsOfElements == []:
4068 IDsOfElements = self.GetElementsId()
4069 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4070 Axis = self.smeshpyD.GetAxisStruct(Axis)
4071 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4072 Parameters = Axis.parameters + var_separator + Parameters
4073 self.mesh.SetParameters(Parameters)
4074 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
4075 MakeGroups, NewMeshName)
4076 return Mesh( self.smeshpyD, self.geompyD, mesh )
4078 ## Rotates the object
4079 # @param theObject the object to rotate( mesh, submesh, or group)
4080 # @param Axis the axis of rotation (AxisStruct or geom line)
4081 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4082 # @param Copy allows copying the rotated elements
4083 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4084 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4085 # @ingroup l2_modif_trsf
4086 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
4087 if (isinstance(theObject, Mesh)):
4088 theObject = theObject.GetMesh()
4089 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4090 Axis = self.smeshpyD.GetAxisStruct(Axis)
4091 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4092 Parameters = Axis.parameters + ":" + Parameters
4093 self.mesh.SetParameters(Parameters)
4094 if Copy and MakeGroups:
4095 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
4096 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
4099 ## Creates a new mesh from the rotated object
4100 # @param theObject the object to rotate (mesh, submesh, or group)
4101 # @param Axis the axis of rotation (AxisStruct or geom line)
4102 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4103 # @param MakeGroups forces the generation of new groups from existing ones
4104 # @param NewMeshName the name of the newly created mesh
4105 # @return instance of Mesh class
4106 # @ingroup l2_modif_trsf
4107 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
4108 if (isinstance( theObject, Mesh )):
4109 theObject = theObject.GetMesh()
4110 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4111 Axis = self.smeshpyD.GetAxisStruct(Axis)
4112 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4113 Parameters = Axis.parameters + ":" + Parameters
4114 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
4115 MakeGroups, NewMeshName)
4116 self.mesh.SetParameters(Parameters)
4117 return Mesh( self.smeshpyD, self.geompyD, mesh )
4119 ## Finds groups of ajacent nodes within Tolerance.
4120 # @param Tolerance the value of tolerance
4121 # @return the list of groups of nodes
4122 # @ingroup l2_modif_trsf
4123 def FindCoincidentNodes (self, Tolerance):
4124 return self.editor.FindCoincidentNodes(Tolerance)
4126 ## Finds groups of ajacent nodes within Tolerance.
4127 # @param Tolerance the value of tolerance
4128 # @param SubMeshOrGroup SubMesh or Group
4129 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
4130 # @return the list of groups of nodes
4131 # @ingroup l2_modif_trsf
4132 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
4133 unRegister = genObjUnRegister()
4134 if (isinstance( SubMeshOrGroup, Mesh )):
4135 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
4136 if not isinstance( exceptNodes, list):
4137 exceptNodes = [ exceptNodes ]
4138 if exceptNodes and isinstance( exceptNodes[0], int):
4139 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
4140 unRegister.set( exceptNodes )
4141 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
4144 # @param GroupsOfNodes the list of groups of nodes
4145 # @ingroup l2_modif_trsf
4146 def MergeNodes (self, GroupsOfNodes):
4147 self.editor.MergeNodes(GroupsOfNodes)
4149 ## Finds the elements built on the same nodes.
4150 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
4151 # @return a list of groups of equal elements
4152 # @ingroup l2_modif_trsf
4153 def FindEqualElements (self, MeshOrSubMeshOrGroup):
4154 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
4155 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4156 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
4158 ## Merges elements in each given group.
4159 # @param GroupsOfElementsID groups of elements for merging
4160 # @ingroup l2_modif_trsf
4161 def MergeElements(self, GroupsOfElementsID):
4162 self.editor.MergeElements(GroupsOfElementsID)
4164 ## Leaves one element and removes all other elements built on the same nodes.
4165 # @ingroup l2_modif_trsf
4166 def MergeEqualElements(self):
4167 self.editor.MergeEqualElements()
4169 ## Sews free borders
4170 # @return SMESH::Sew_Error
4171 # @ingroup l2_modif_trsf
4172 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4173 FirstNodeID2, SecondNodeID2, LastNodeID2,
4174 CreatePolygons, CreatePolyedrs):
4175 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4176 FirstNodeID2, SecondNodeID2, LastNodeID2,
4177 CreatePolygons, CreatePolyedrs)
4179 ## Sews conform free borders
4180 # @return SMESH::Sew_Error
4181 # @ingroup l2_modif_trsf
4182 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4183 FirstNodeID2, SecondNodeID2):
4184 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4185 FirstNodeID2, SecondNodeID2)
4187 ## Sews border to side
4188 # @return SMESH::Sew_Error
4189 # @ingroup l2_modif_trsf
4190 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4191 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4192 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4193 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4195 ## Sews two sides of a mesh. The nodes belonging to Side1 are
4196 # merged with the nodes of elements of Side2.
4197 # The number of elements in theSide1 and in theSide2 must be
4198 # equal and they should have similar nodal connectivity.
4199 # The nodes to merge should belong to side borders and
4200 # the first node should be linked to the second.
4201 # @return SMESH::Sew_Error
4202 # @ingroup l2_modif_trsf
4203 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4204 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4205 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4206 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4207 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4208 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4210 ## Sets new nodes for the given element.
4211 # @param ide the element id
4212 # @param newIDs nodes ids
4213 # @return If the number of nodes does not correspond to the type of element - returns false
4214 # @ingroup l2_modif_edit
4215 def ChangeElemNodes(self, ide, newIDs):
4216 return self.editor.ChangeElemNodes(ide, newIDs)
4218 ## If during the last operation of MeshEditor some nodes were
4219 # created, this method returns the list of their IDs, \n
4220 # if new nodes were not created - returns empty list
4221 # @return the list of integer values (can be empty)
4222 # @ingroup l1_auxiliary
4223 def GetLastCreatedNodes(self):
4224 return self.editor.GetLastCreatedNodes()
4226 ## If during the last operation of MeshEditor some elements were
4227 # created this method returns the list of their IDs, \n
4228 # if new elements were not created - returns empty list
4229 # @return the list of integer values (can be empty)
4230 # @ingroup l1_auxiliary
4231 def GetLastCreatedElems(self):
4232 return self.editor.GetLastCreatedElems()
4234 ## Clears sequences of nodes and elements created by mesh edition oparations
4235 # @ingroup l1_auxiliary
4236 def ClearLastCreated(self):
4237 self.editor.ClearLastCreated()
4239 ## Creates Duplicates given elements, i.e. creates new elements based on the
4240 # same nodes as the given ones.
4241 # @param theElements - container of elements to duplicate. It can be a Mesh,
4242 # sub-mesh, group, filter or a list of element IDs.
4243 # @param theGroupName - a name of group to contain the generated elements.
4244 # If a group with such a name already exists, the new elements
4245 # are added to the existng group, else a new group is created.
4246 # If \a theGroupName is empty, new elements are not added
4248 # @return a group where the new elements are added. None if theGroupName == "".
4249 # @ingroup l2_modif_edit
4250 def DoubleElements(self, theElements, theGroupName=""):
4251 unRegister = genObjUnRegister()
4252 if isinstance( theElements, Mesh ):
4253 theElements = theElements.mesh
4254 elif isinstance( theElements, list ):
4255 theElements = self.GetIDSource( theElements, SMESH.ALL )
4256 unRegister.set( theElements )
4257 return self.editor.DoubleElements(theElements, theGroupName)
4259 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4260 # @param theNodes identifiers of nodes to be doubled
4261 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4262 # nodes. If list of element identifiers is empty then nodes are doubled but
4263 # they not assigned to elements
4264 # @return TRUE if operation has been completed successfully, FALSE otherwise
4265 # @ingroup l2_modif_edit
4266 def DoubleNodes(self, theNodes, theModifiedElems):
4267 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4269 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4270 # This method provided for convenience works as DoubleNodes() described above.
4271 # @param theNodeId identifiers of node to be doubled
4272 # @param theModifiedElems identifiers of elements to be updated
4273 # @return TRUE if operation has been completed successfully, FALSE otherwise
4274 # @ingroup l2_modif_edit
4275 def DoubleNode(self, theNodeId, theModifiedElems):
4276 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4278 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4279 # This method provided for convenience works as DoubleNodes() described above.
4280 # @param theNodes group of nodes to be doubled
4281 # @param theModifiedElems group of elements to be updated.
4282 # @param theMakeGroup forces the generation of a group containing new nodes.
4283 # @return TRUE or a created group if operation has been completed successfully,
4284 # FALSE or None otherwise
4285 # @ingroup l2_modif_edit
4286 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4288 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4289 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4291 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4292 # This method provided for convenience works as DoubleNodes() described above.
4293 # @param theNodes list of groups of nodes to be doubled
4294 # @param theModifiedElems list of groups of elements to be updated.
4295 # @param theMakeGroup forces the generation of a group containing new nodes.
4296 # @return TRUE if operation has been completed successfully, FALSE otherwise
4297 # @ingroup l2_modif_edit
4298 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4300 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4301 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4303 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4304 # @param theElems - the list of elements (edges or faces) to be replicated
4305 # The nodes for duplication could be found from these elements
4306 # @param theNodesNot - list of nodes to NOT replicate
4307 # @param theAffectedElems - the list of elements (cells and edges) to which the
4308 # replicated nodes should be associated to.
4309 # @return TRUE if operation has been completed successfully, FALSE otherwise
4310 # @ingroup l2_modif_edit
4311 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4312 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4314 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4315 # @param theElems - the list of elements (edges or faces) to be replicated
4316 # The nodes for duplication could be found from these elements
4317 # @param theNodesNot - list of nodes to NOT replicate
4318 # @param theShape - shape to detect affected elements (element which geometric center
4319 # located on or inside shape).
4320 # The replicated nodes should be associated to affected elements.
4321 # @return TRUE if operation has been completed successfully, FALSE otherwise
4322 # @ingroup l2_modif_edit
4323 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4324 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4326 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4327 # This method provided for convenience works as DoubleNodes() described above.
4328 # @param theElems - group of of elements (edges or faces) to be replicated
4329 # @param theNodesNot - group of nodes not to replicated
4330 # @param theAffectedElems - group of elements to which the replicated nodes
4331 # should be associated to.
4332 # @param theMakeGroup forces the generation of a group containing new elements.
4333 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4334 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4335 # FALSE or None otherwise
4336 # @ingroup l2_modif_edit
4337 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4338 theMakeGroup=False, theMakeNodeGroup=False):
4339 if theMakeGroup or theMakeNodeGroup:
4340 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4342 theMakeGroup, theMakeNodeGroup)
4343 if theMakeGroup and theMakeNodeGroup:
4346 return twoGroups[ int(theMakeNodeGroup) ]
4347 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4349 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4350 # This method provided for convenience works as DoubleNodes() described above.
4351 # @param theElems - group of of elements (edges or faces) to be replicated
4352 # @param theNodesNot - group of nodes not to replicated
4353 # @param theShape - shape to detect affected elements (element which geometric center
4354 # located on or inside shape).
4355 # The replicated nodes should be associated to affected elements.
4356 # @ingroup l2_modif_edit
4357 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4358 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4360 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4361 # This method provided for convenience works as DoubleNodes() described above.
4362 # @param theElems - list of groups of elements (edges or faces) to be replicated
4363 # @param theNodesNot - list of groups of nodes not to replicated
4364 # @param theAffectedElems - group of elements to which the replicated nodes
4365 # should be associated to.
4366 # @param theMakeGroup forces the generation of a group containing new elements.
4367 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4368 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4369 # FALSE or None otherwise
4370 # @ingroup l2_modif_edit
4371 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4372 theMakeGroup=False, theMakeNodeGroup=False):
4373 if theMakeGroup or theMakeNodeGroup:
4374 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4376 theMakeGroup, theMakeNodeGroup)
4377 if theMakeGroup and theMakeNodeGroup:
4380 return twoGroups[ int(theMakeNodeGroup) ]
4381 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4383 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4384 # This method provided for convenience works as DoubleNodes() described above.
4385 # @param theElems - list of groups of elements (edges or faces) to be replicated
4386 # @param theNodesNot - list of groups of nodes not to replicated
4387 # @param theShape - shape to detect affected elements (element which geometric center
4388 # located on or inside shape).
4389 # The replicated nodes should be associated to affected elements.
4390 # @return TRUE if operation has been completed successfully, FALSE otherwise
4391 # @ingroup l2_modif_edit
4392 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4393 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4395 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4396 # This method is the first step of DoubleNodeElemGroupsInRegion.
4397 # @param theElems - list of groups of elements (edges or faces) to be replicated
4398 # @param theNodesNot - list of groups of nodes not to replicated
4399 # @param theShape - shape to detect affected elements (element which geometric center
4400 # located on or inside shape).
4401 # The replicated nodes should be associated to affected elements.
4402 # @return groups of affected elements
4403 # @ingroup l2_modif_edit
4404 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4405 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4407 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4408 # The list of groups must describe a partition of the mesh volumes.
4409 # The nodes of the internal faces at the boundaries of the groups are doubled.
4410 # In option, the internal faces are replaced by flat elements.
4411 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4412 # @param theDomains - list of groups of volumes
4413 # @param createJointElems - if TRUE, create the elements
4414 # @return TRUE if operation has been completed successfully, FALSE otherwise
4415 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4416 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4418 ## Double nodes on some external faces and create flat elements.
4419 # Flat elements are mainly used by some types of mechanic calculations.
4421 # Each group of the list must be constituted of faces.
4422 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4423 # @param theGroupsOfFaces - list of groups of faces
4424 # @return TRUE if operation has been completed successfully, FALSE otherwise
4425 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4426 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4428 ## identify all the elements around a geom shape, get the faces delimiting the hole
4430 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4431 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4433 def _getFunctor(self, funcType ):
4434 fn = self.functors[ funcType._v ]
4436 fn = self.smeshpyD.GetFunctor(funcType)
4437 fn.SetMesh(self.mesh)
4438 self.functors[ funcType._v ] = fn
4441 def _valueFromFunctor(self, funcType, elemId):
4442 fn = self._getFunctor( funcType )
4443 if fn.GetElementType() == self.GetElementType(elemId, True):
4444 val = fn.GetValue(elemId)
4449 ## Get length of 1D element or sum of lengths of all 1D mesh elements
4450 # @param elemId mesh element ID (if not defined - sum of length of all 1D elements will be calculated)
4451 # @return element's length value if \a elemId is specified or sum of all 1D mesh elements' lengths otherwise
4452 # @ingroup l1_measurements
4453 def GetLength(self, elemId=None):
4456 length = self.smeshpyD.GetLength(self)
4458 length = self._valueFromFunctor(SMESH.FT_Length, elemId)
4461 ## Get area of 2D element or sum of areas of all 2D mesh elements
4462 # @param elemId mesh element ID (if not defined - sum of areas of all 2D elements will be calculated)
4463 # @return element's area value if \a elemId is specified or sum of all 2D mesh elements' areas otherwise
4464 # @ingroup l1_measurements
4465 def GetArea(self, elemId=None):
4468 area = self.smeshpyD.GetArea(self)
4470 area = self._valueFromFunctor(SMESH.FT_Area, elemId)
4473 ## Get volume of 3D element or sum of volumes of all 3D mesh elements
4474 # @param elemId mesh element ID (if not defined - sum of volumes of all 3D elements will be calculated)
4475 # @return element's volume value if \a elemId is specified or sum of all 3D mesh elements' volumes otherwise
4476 # @ingroup l1_measurements
4477 def GetVolume(self, elemId=None):
4480 volume = self.smeshpyD.GetVolume(self)
4482 volume = self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4485 ## Get maximum element length.
4486 # @param elemId mesh element ID
4487 # @return element's maximum length value
4488 # @ingroup l1_measurements
4489 def GetMaxElementLength(self, elemId):
4490 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4491 ftype = SMESH.FT_MaxElementLength3D
4493 ftype = SMESH.FT_MaxElementLength2D
4494 return self._valueFromFunctor(ftype, elemId)
4496 ## Get aspect ratio of 2D or 3D element.
4497 # @param elemId mesh element ID
4498 # @return element's aspect ratio value
4499 # @ingroup l1_measurements
4500 def GetAspectRatio(self, elemId):
4501 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4502 ftype = SMESH.FT_AspectRatio3D
4504 ftype = SMESH.FT_AspectRatio
4505 return self._valueFromFunctor(ftype, elemId)
4507 ## Get warping angle of 2D element.
4508 # @param elemId mesh element ID
4509 # @return element's warping angle value
4510 # @ingroup l1_measurements
4511 def GetWarping(self, elemId):
4512 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4514 ## Get minimum angle of 2D element.
4515 # @param elemId mesh element ID
4516 # @return element's minimum angle value
4517 # @ingroup l1_measurements
4518 def GetMinimumAngle(self, elemId):
4519 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4521 ## Get taper of 2D element.
4522 # @param elemId mesh element ID
4523 # @return element's taper value
4524 # @ingroup l1_measurements
4525 def GetTaper(self, elemId):
4526 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4528 ## Get skew of 2D element.
4529 # @param elemId mesh element ID
4530 # @return element's skew value
4531 # @ingroup l1_measurements
4532 def GetSkew(self, elemId):
4533 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4535 pass # end of Mesh class
4537 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4539 class Pattern(SMESH._objref_SMESH_Pattern):
4541 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4542 decrFun = lambda i: i-1
4543 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4544 theMesh.SetParameters(Parameters)
4545 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4547 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4548 decrFun = lambda i: i-1
4549 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4550 theMesh.SetParameters(Parameters)
4551 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4553 # Registering the new proxy for Pattern
4554 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4556 ## Private class used to bind methods creating algorithms to the class Mesh
4561 self.defaultAlgoType = ""
4562 self.algoTypeToClass = {}
4564 # Stores a python class of algorithm
4565 def add(self, algoClass):
4566 if type( algoClass ).__name__ == 'classobj' and \
4567 hasattr( algoClass, "algoType"):
4568 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4569 if not self.defaultAlgoType and \
4570 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4571 self.defaultAlgoType = algoClass.algoType
4572 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4574 # creates a copy of self and assign mesh to the copy
4575 def copy(self, mesh):
4576 other = algoCreator()
4577 other.defaultAlgoType = self.defaultAlgoType
4578 other.algoTypeToClass = self.algoTypeToClass
4582 # creates an instance of algorithm
4583 def __call__(self,algo="",geom=0,*args):
4584 algoType = self.defaultAlgoType
4585 for arg in args + (algo,geom):
4586 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
4588 if isinstance( arg, str ) and arg:
4590 if not algoType and self.algoTypeToClass:
4591 algoType = self.algoTypeToClass.keys()[0]
4592 if self.algoTypeToClass.has_key( algoType ):
4593 #print "Create algo",algoType
4594 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4595 raise RuntimeError, "No class found for algo type %s" % algoType
4598 # Private class used to substitute and store variable parameters of hypotheses.
4600 class hypMethodWrapper:
4601 def __init__(self, hyp, method):
4603 self.method = method
4604 #print "REBIND:", method.__name__
4607 # call a method of hypothesis with calling SetVarParameter() before
4608 def __call__(self,*args):
4610 return self.method( self.hyp, *args ) # hypothesis method with no args
4612 #print "MethWrapper.__call__",self.method.__name__, args
4614 parsed = ParseParameters(*args) # replace variables with their values
4615 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4616 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4617 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4618 # maybe there is a replaced string arg which is not variable
4619 result = self.method( self.hyp, *args )
4620 except ValueError, detail: # raised by ParseParameters()
4622 result = self.method( self.hyp, *args )
4623 except omniORB.CORBA.BAD_PARAM:
4624 raise ValueError, detail # wrong variable name
4629 # A helper class that call UnRegister() of SALOME.GenericObj'es stored in it
4630 class genObjUnRegister:
4632 def __init__(self, genObj=None):
4633 self.genObjList = []
4637 def set(self, genObj):
4638 "Store one or a list of of SALOME.GenericObj'es"
4639 if isinstance( genObj, list ):
4640 self.genObjList.extend( genObj )
4642 self.genObjList.append( genObj )
4646 for genObj in self.genObjList:
4647 if genObj and hasattr( genObj, "UnRegister" ):
4650 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4652 #print "pluginName: ", pluginName
4653 pluginBuilderName = pluginName + "Builder"
4655 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
4656 except Exception, e:
4657 print "Exception while loading %s: %s" % ( pluginBuilderName, e )
4659 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
4660 plugin = eval( pluginBuilderName )
4661 #print " plugin:" , str(plugin)
4663 # add methods creating algorithms to Mesh
4664 for k in dir( plugin ):
4665 if k[0] == '_': continue
4666 algo = getattr( plugin, k )
4667 #print " algo:", str(algo)
4668 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4669 #print " meshMethod:" , str(algo.meshMethod)
4670 if not hasattr( Mesh, algo.meshMethod ):
4671 setattr( Mesh, algo.meshMethod, algoCreator() )
4673 getattr( Mesh, algo.meshMethod ).add( algo )