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