1 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 # File : smeshBuilder.py
20 # Author : Francis KLOSS, OCC
23 ## @package smeshBuilder
24 # Python API for SALOME %Mesh module
26 ## @defgroup l1_auxiliary Auxiliary methods and structures
27 ## @defgroup l1_creating Creating meshes
29 ## @defgroup l2_impexp Importing and exporting meshes
30 ## @defgroup l2_construct Constructing meshes
31 ## @defgroup l2_algorithms Defining Algorithms
33 ## @defgroup l3_algos_basic Basic meshing algorithms
34 ## @defgroup l3_algos_proj Projection Algorithms
35 ## @defgroup l3_algos_radialp Radial Prism
36 ## @defgroup l3_algos_segmarv Segments around Vertex
37 ## @defgroup l3_algos_3dextr 3D extrusion meshing algorithm
40 ## @defgroup l2_hypotheses Defining hypotheses
42 ## @defgroup l3_hypos_1dhyps 1D Meshing Hypotheses
43 ## @defgroup l3_hypos_2dhyps 2D Meshing Hypotheses
44 ## @defgroup l3_hypos_maxvol Max Element Volume hypothesis
45 ## @defgroup l3_hypos_quad Quadrangle Parameters hypothesis
46 ## @defgroup l3_hypos_additi Additional Hypotheses
49 ## @defgroup l2_submeshes Constructing submeshes
50 ## @defgroup l2_compounds Building Compounds
51 ## @defgroup l2_editing Editing Meshes
54 ## @defgroup l1_meshinfo Mesh Information
55 ## @defgroup l1_controls Quality controls and Filtering
56 ## @defgroup l1_grouping Grouping elements
58 ## @defgroup l2_grps_create Creating groups
59 ## @defgroup l2_grps_edit Editing groups
60 ## @defgroup l2_grps_operon Using operations on groups
61 ## @defgroup l2_grps_delete Deleting Groups
64 ## @defgroup l1_modifying Modifying meshes
66 ## @defgroup l2_modif_add Adding nodes and elements
67 ## @defgroup l2_modif_del Removing nodes and elements
68 ## @defgroup l2_modif_edit Modifying nodes and elements
69 ## @defgroup l2_modif_renumber Renumbering nodes and elements
70 ## @defgroup l2_modif_trsf Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging)
71 ## @defgroup l2_modif_movenode Moving nodes
72 ## @defgroup l2_modif_throughp Mesh through point
73 ## @defgroup l2_modif_invdiag Diagonal inversion of elements
74 ## @defgroup l2_modif_unitetri Uniting triangles
75 ## @defgroup l2_modif_changori Changing orientation of elements
76 ## @defgroup l2_modif_cutquadr Cutting quadrangles
77 ## @defgroup l2_modif_smooth Smoothing
78 ## @defgroup l2_modif_extrurev Extrusion and Revolution
79 ## @defgroup l2_modif_patterns Pattern mapping
80 ## @defgroup l2_modif_tofromqu Convert to/from Quadratic Mesh
83 ## @defgroup l1_measurements Measurements
86 from salome.geom import geomBuilder
88 import SMESH # This is necessary for back compatibility
90 from salome.smesh.smesh_algorithm import Mesh_Algorithm
96 ## @addtogroup l1_auxiliary
99 ## Converts an angle from degrees to radians
100 def DegreesToRadians(AngleInDegrees):
102 return AngleInDegrees * pi / 180.0
104 import salome_notebook
105 notebook = salome_notebook.notebook
106 # Salome notebook variable separator
109 ## Return list of variable values from salome notebook.
110 # The last argument, if is callable, is used to modify values got from notebook
111 def ParseParameters(*args):
116 if args and callable( args[-1] ):
117 args, varModifFun = args[:-1], args[-1]
118 for parameter in args:
120 Parameters += str(parameter) + var_separator
122 if isinstance(parameter,str):
123 # check if there is an inexistent variable name
124 if not notebook.isVariable(parameter):
125 raise ValueError, "Variable with name '" + parameter + "' doesn't exist!!!"
126 parameter = notebook.get(parameter)
129 parameter = varModifFun(parameter)
132 Result.append(parameter)
135 Parameters = Parameters[:-1]
136 Result.append( Parameters )
137 Result.append( hasVariables )
140 # Parse parameters converting variables to radians
141 def ParseAngles(*args):
142 return ParseParameters( *( args + (DegreesToRadians, )))
144 # Substitute PointStruct.__init__() to create SMESH.PointStruct using notebook variables.
145 # Parameters are stored in PointStruct.parameters attribute
146 def __initPointStruct(point,*args):
147 point.x, point.y, point.z, point.parameters,hasVars = ParseParameters(*args)
149 SMESH.PointStruct.__init__ = __initPointStruct
151 # Substitute AxisStruct.__init__() to create SMESH.AxisStruct using notebook variables.
152 # Parameters are stored in AxisStruct.parameters attribute
153 def __initAxisStruct(ax,*args):
154 ax.x, ax.y, ax.z, ax.vx, ax.vy, ax.vz, ax.parameters,hasVars = ParseParameters(*args)
156 SMESH.AxisStruct.__init__ = __initAxisStruct
158 smeshPrecisionConfusion = 1.e-07
159 def IsEqual(val1, val2, tol=smeshPrecisionConfusion):
160 if abs(val1 - val2) < tol:
170 if isinstance(obj, SALOMEDS._objref_SObject):
174 ior = salome.orb.object_to_string(obj)
179 studies = salome.myStudyManager.GetOpenStudies()
180 for sname in studies:
181 s = salome.myStudyManager.GetStudyByName(sname)
183 sobj = s.FindObjectIOR(ior)
184 if not sobj: continue
185 return sobj.GetName()
186 if hasattr(obj, "GetName"):
187 # unknown CORBA object, having GetName() method
190 # unknown CORBA object, no GetName() method
193 if hasattr(obj, "GetName"):
194 # unknown non-CORBA object, having GetName() method
197 raise RuntimeError, "Null or invalid object"
199 ## Prints error message if a hypothesis was not assigned.
200 def TreatHypoStatus(status, hypName, geomName, isAlgo):
202 hypType = "algorithm"
204 hypType = "hypothesis"
206 if status == HYP_UNKNOWN_FATAL :
207 reason = "for unknown reason"
208 elif status == HYP_INCOMPATIBLE :
209 reason = "this hypothesis mismatches the algorithm"
210 elif status == HYP_NOTCONFORM :
211 reason = "a non-conform mesh would be built"
212 elif status == HYP_ALREADY_EXIST :
213 if isAlgo: return # it does not influence anything
214 reason = hypType + " of the same dimension is already assigned to this shape"
215 elif status == HYP_BAD_DIM :
216 reason = hypType + " mismatches the shape"
217 elif status == HYP_CONCURENT :
218 reason = "there are concurrent hypotheses on sub-shapes"
219 elif status == HYP_BAD_SUBSHAPE :
220 reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
221 elif status == HYP_BAD_GEOMETRY:
222 reason = "geometry mismatches the expectation of the algorithm"
223 elif status == HYP_HIDDEN_ALGO:
224 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
225 elif status == HYP_HIDING_ALGO:
226 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
227 elif status == HYP_NEED_SHAPE:
228 reason = "Algorithm can't work without shape"
231 hypName = '"' + hypName + '"'
232 geomName= '"' + geomName+ '"'
233 if status < HYP_UNKNOWN_FATAL and not geomName =='""':
234 print hypName, "was assigned to", geomName,"but", reason
235 elif not geomName == '""':
236 print hypName, "was not assigned to",geomName,":", reason
238 print hypName, "was not assigned:", reason
241 ## Private method. Add geom (sub-shape of the main shape) into the study if not yet there
242 def AssureGeomPublished(mesh, geom, name=''):
243 if not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
245 if not geom.GetStudyEntry() and \
246 mesh.smeshpyD.GetCurrentStudy():
248 studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
249 if studyID != mesh.geompyD.myStudyId:
250 mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
252 if not name and geom.GetShapeType() != geomBuilder.GEOM.COMPOUND:
253 # for all groups SubShapeName() returns "Compound_-1"
254 name = mesh.geompyD.SubShapeName(geom, mesh.geom)
256 name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
258 mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
261 ## Return the first vertex of a geometrical edge by ignoring orientation
262 def FirstVertexOnCurve(mesh, edge):
263 vv = mesh.geompyD.SubShapeAll( edge, geomBuilder.geomBuilder.ShapeType["VERTEX"])
265 raise TypeError, "Given object has no vertices"
266 if len( vv ) == 1: return vv[0]
267 v0 = mesh.geompyD.MakeVertexOnCurve(edge,0.)
268 xyz = mesh.geompyD.PointCoordinates( v0 ) # coords of the first vertex
269 xyz1 = mesh.geompyD.PointCoordinates( vv[0] )
270 xyz2 = mesh.geompyD.PointCoordinates( vv[1] )
273 dist1 += abs( xyz[i] - xyz1[i] )
274 dist2 += abs( xyz[i] - xyz2[i] )
280 # end of l1_auxiliary
284 # Warning: smeshInst is a singleton
290 ## This class allows to create, load or manipulate meshes
291 # It has a set of methods to create load or copy meshes, to combine several meshes.
292 # It also has methods to get infos on meshes.
293 class smeshBuilder(object, SMESH._objref_SMESH_Gen):
295 # MirrorType enumeration
296 POINT = SMESH_MeshEditor.POINT
297 AXIS = SMESH_MeshEditor.AXIS
298 PLANE = SMESH_MeshEditor.PLANE
300 # Smooth_Method enumeration
301 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
302 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
304 PrecisionConfusion = smeshPrecisionConfusion
306 # TopAbs_State enumeration
307 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
309 # Methods of splitting a hexahedron into tetrahedra
310 Hex_5Tet, Hex_6Tet, Hex_24Tet = 1, 2, 3
316 #print "==== __new__", engine, smeshInst, doLcc
318 if smeshInst is None:
319 # smesh engine is either retrieved from engine, or created
321 # Following test avoids a recursive loop
323 if smeshInst is not None:
324 # smesh engine not created: existing engine found
328 # FindOrLoadComponent called:
329 # 1. CORBA resolution of server
330 # 2. the __new__ method is called again
331 #print "==== smeshInst = lcc.FindOrLoadComponent ", engine, smeshInst, doLcc
332 smeshInst = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
334 # FindOrLoadComponent not called
335 if smeshInst is None:
336 # smeshBuilder instance is created from lcc.FindOrLoadComponent
337 #print "==== smeshInst = super(smeshBuilder,cls).__new__(cls) ", engine, smeshInst, doLcc
338 smeshInst = super(smeshBuilder,cls).__new__(cls)
340 # smesh engine not created: existing engine found
341 #print "==== existing ", engine, smeshInst, doLcc
343 #print "====1 ", smeshInst
346 #print "====2 ", smeshInst
351 #print "--------------- smeshbuilder __init__ ---", created
354 SMESH._objref_SMESH_Gen.__init__(self)
356 ## Dump component to the Python script
357 # This method overrides IDL function to allow default values for the parameters.
358 def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
359 return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
361 ## Set mode of DumpPython(), \a historical or \a snapshot.
362 # In the \a historical mode, the Python Dump script includes all commands
363 # performed by SMESH engine. In the \a snapshot mode, commands
364 # relating to objects removed from the Study are excluded from the script
365 # as well as commands not influencing the current state of meshes
366 def SetDumpPythonHistorical(self, isHistorical):
367 if isHistorical: val = "true"
369 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
371 ## Sets the current study and Geometry component
372 # @ingroup l1_auxiliary
373 def init_smesh(self,theStudy,geompyD = None):
375 self.SetCurrentStudy(theStudy,geompyD)
377 ## Creates an empty Mesh. This mesh can have an underlying geometry.
378 # @param obj the Geometrical object on which the mesh is built. If not defined,
379 # the mesh will have no underlying geometry.
380 # @param name the name for the new mesh.
381 # @return an instance of Mesh class.
382 # @ingroup l2_construct
383 def Mesh(self, obj=0, name=0):
384 if isinstance(obj,str):
386 return Mesh(self,self.geompyD,obj,name)
388 ## Returns a long value from enumeration
389 # @ingroup l1_controls
390 def EnumToLong(self,theItem):
393 ## Returns a string representation of the color.
394 # To be used with filters.
395 # @param c color value (SALOMEDS.Color)
396 # @ingroup l1_controls
397 def ColorToString(self,c):
399 if isinstance(c, SALOMEDS.Color):
400 val = "%s;%s;%s" % (c.R, c.G, c.B)
401 elif isinstance(c, str):
404 raise ValueError, "Color value should be of string or SALOMEDS.Color type"
407 ## Gets PointStruct from vertex
408 # @param theVertex a GEOM object(vertex)
409 # @return SMESH.PointStruct
410 # @ingroup l1_auxiliary
411 def GetPointStruct(self,theVertex):
412 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
413 return PointStruct(x,y,z)
415 ## Gets DirStruct from vector
416 # @param theVector a GEOM object(vector)
417 # @return SMESH.DirStruct
418 # @ingroup l1_auxiliary
419 def GetDirStruct(self,theVector):
420 vertices = self.geompyD.SubShapeAll( theVector, geomBuilder.geomBuilder.ShapeType["VERTEX"] )
421 if(len(vertices) != 2):
422 print "Error: vector object is incorrect."
424 p1 = self.geompyD.PointCoordinates(vertices[0])
425 p2 = self.geompyD.PointCoordinates(vertices[1])
426 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
427 dirst = DirStruct(pnt)
430 ## Makes DirStruct from a triplet
431 # @param x,y,z vector components
432 # @return SMESH.DirStruct
433 # @ingroup l1_auxiliary
434 def MakeDirStruct(self,x,y,z):
435 pnt = PointStruct(x,y,z)
436 return DirStruct(pnt)
438 ## Get AxisStruct from object
439 # @param theObj a GEOM object (line or plane)
440 # @return SMESH.AxisStruct
441 # @ingroup l1_auxiliary
442 def GetAxisStruct(self,theObj):
443 edges = self.geompyD.SubShapeAll( theObj, geomBuilder.geomBuilder.ShapeType["EDGE"] )
445 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
446 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
447 vertex1 = self.geompyD.PointCoordinates(vertex1)
448 vertex2 = self.geompyD.PointCoordinates(vertex2)
449 vertex3 = self.geompyD.PointCoordinates(vertex3)
450 vertex4 = self.geompyD.PointCoordinates(vertex4)
451 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
452 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
453 normal = [ v1[1]*v2[2]-v2[1]*v1[2], v1[2]*v2[0]-v2[2]*v1[0], v1[0]*v2[1]-v2[0]*v1[1] ]
454 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
456 elif len(edges) == 1:
457 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
458 p1 = self.geompyD.PointCoordinates( vertex1 )
459 p2 = self.geompyD.PointCoordinates( vertex2 )
460 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
464 # From SMESH_Gen interface:
465 # ------------------------
467 ## Sets the given name to the object
468 # @param obj the object to rename
469 # @param name a new object name
470 # @ingroup l1_auxiliary
471 def SetName(self, obj, name):
472 if isinstance( obj, Mesh ):
474 elif isinstance( obj, Mesh_Algorithm ):
475 obj = obj.GetAlgorithm()
476 ior = salome.orb.object_to_string(obj)
477 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
479 ## Sets the current mode
480 # @ingroup l1_auxiliary
481 def SetEmbeddedMode( self,theMode ):
482 #self.SetEmbeddedMode(theMode)
483 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
485 ## Gets the current mode
486 # @ingroup l1_auxiliary
487 def IsEmbeddedMode(self):
488 #return self.IsEmbeddedMode()
489 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
491 ## Sets the current study
492 # @ingroup l1_auxiliary
493 def SetCurrentStudy( self, theStudy, geompyD = None ):
494 #self.SetCurrentStudy(theStudy)
496 from salome.geom import geomBuilder
497 geompyD = geomBuilder.geom
500 self.SetGeomEngine(geompyD)
501 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
504 notebook = salome_notebook.NoteBook( theStudy )
506 notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
508 ## Gets the current study
509 # @ingroup l1_auxiliary
510 def GetCurrentStudy(self):
511 #return self.GetCurrentStudy()
512 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
514 ## Creates a Mesh object importing data from the given UNV file
515 # @return an instance of Mesh class
517 def CreateMeshesFromUNV( self,theFileName ):
518 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
519 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
522 ## Creates a Mesh object(s) importing data from the given MED file
523 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
525 def CreateMeshesFromMED( self,theFileName ):
526 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
527 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
528 return aMeshes, aStatus
530 ## Creates a Mesh object(s) importing data from the given SAUV file
531 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
533 def CreateMeshesFromSAUV( self,theFileName ):
534 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
535 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
536 return aMeshes, aStatus
538 ## Creates a Mesh object importing data from the given STL file
539 # @return an instance of Mesh class
541 def CreateMeshesFromSTL( self, theFileName ):
542 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
543 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
546 ## Creates Mesh objects importing data from the given CGNS file
547 # @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
549 def CreateMeshesFromCGNS( self, theFileName ):
550 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
551 aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
552 return aMeshes, aStatus
554 ## Creates a Mesh object importing data from the given GMF file
555 # @return [ an instance of Mesh class, SMESH.ComputeError ]
557 def CreateMeshesFromGMF( self, theFileName ):
558 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
561 if error.comment: print "*** CreateMeshesFromGMF() errors:\n", error.comment
562 return Mesh(self, self.geompyD, aSmeshMesh), error
564 ## Concatenate the given meshes into one mesh.
565 # @return an instance of Mesh class
566 # @param meshes the meshes to combine into one mesh
567 # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
568 # @param mergeNodesAndElements if true, equal nodes and elements aremerged
569 # @param mergeTolerance tolerance for merging nodes
570 # @param allGroups forces creation of groups of all elements
571 # @param name name of a new mesh
572 def Concatenate( self, meshes, uniteIdenticalGroups,
573 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
575 if not meshes: return None
576 for i,m in enumerate(meshes):
577 if isinstance(m, Mesh):
578 meshes[i] = m.GetMesh()
579 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
580 meshes[0].SetParameters(Parameters)
582 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
583 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
585 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
586 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
587 aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
590 ## Create a mesh by copying a part of another mesh.
591 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
592 # to copy nodes or elements not contained in any mesh object,
593 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
594 # @param meshName a name of the new mesh
595 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
596 # @param toKeepIDs to preserve IDs of the copied elements or not
597 # @return an instance of Mesh class
598 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
599 if (isinstance( meshPart, Mesh )):
600 meshPart = meshPart.GetMesh()
601 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
602 return Mesh(self, self.geompyD, mesh)
604 ## From SMESH_Gen interface
605 # @return the list of integer values
606 # @ingroup l1_auxiliary
607 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
608 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
610 ## From SMESH_Gen interface. Creates a pattern
611 # @return an instance of SMESH_Pattern
613 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
614 # @ingroup l2_modif_patterns
615 def GetPattern(self):
616 return SMESH._objref_SMESH_Gen.GetPattern(self)
618 ## Sets number of segments per diagonal of boundary box of geometry by which
619 # default segment length of appropriate 1D hypotheses is defined.
620 # Default value is 10
621 # @ingroup l1_auxiliary
622 def SetBoundaryBoxSegmentation(self, nbSegments):
623 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
625 # Filtering. Auxiliary functions:
626 # ------------------------------
628 ## Creates an empty criterion
629 # @return SMESH.Filter.Criterion
630 # @ingroup l1_controls
631 def GetEmptyCriterion(self):
632 Type = self.EnumToLong(FT_Undefined)
633 Compare = self.EnumToLong(FT_Undefined)
637 UnaryOp = self.EnumToLong(FT_Undefined)
638 BinaryOp = self.EnumToLong(FT_Undefined)
641 Precision = -1 ##@1e-07
642 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
643 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
645 ## Creates a criterion by the given parameters
646 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
647 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
648 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
649 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
650 # @param Threshold the threshold value (range of ids as string, shape, numeric)
651 # @param UnaryOp FT_LogicalNOT or FT_Undefined
652 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
653 # FT_Undefined (must be for the last criterion of all criteria)
654 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
655 # FT_LyingOnGeom, FT_CoplanarFaces criteria
656 # @return SMESH.Filter.Criterion
658 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
659 # @ingroup l1_controls
660 def GetCriterion(self,elementType,
662 Compare = FT_EqualTo,
664 UnaryOp=FT_Undefined,
665 BinaryOp=FT_Undefined,
667 if not CritType in SMESH.FunctorType._items:
668 raise TypeError, "CritType should be of SMESH.FunctorType"
669 aCriterion = self.GetEmptyCriterion()
670 aCriterion.TypeOfElement = elementType
671 aCriterion.Type = self.EnumToLong(CritType)
672 aCriterion.Tolerance = Tolerance
674 aThreshold = Threshold
676 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
677 aCriterion.Compare = self.EnumToLong(Compare)
678 elif Compare == "=" or Compare == "==":
679 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
681 aCriterion.Compare = self.EnumToLong(FT_LessThan)
683 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
684 elif Compare != FT_Undefined:
685 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
688 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
689 FT_BelongToCylinder, FT_LyingOnGeom]:
690 # Checks that Threshold is GEOM object
691 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object):
692 aCriterion.ThresholdStr = GetName(aThreshold)
693 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
694 if not aCriterion.ThresholdID:
695 name = aCriterion.ThresholdStr
697 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
698 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
699 #raise RuntimeError, "Threshold shape must be published"
701 print "Error: The Threshold should be a shape."
703 if isinstance(UnaryOp,float):
704 aCriterion.Tolerance = UnaryOp
705 UnaryOp = FT_Undefined
707 elif CritType == FT_RangeOfIds:
708 # Checks that Threshold is string
709 if isinstance(aThreshold, str):
710 aCriterion.ThresholdStr = aThreshold
712 print "Error: The Threshold should be a string."
714 elif CritType == FT_CoplanarFaces:
715 # Checks the Threshold
716 if isinstance(aThreshold, int):
717 aCriterion.ThresholdID = str(aThreshold)
718 elif isinstance(aThreshold, str):
721 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
722 aCriterion.ThresholdID = aThreshold
725 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
726 elif CritType == FT_ConnectedElements:
727 # Checks the Threshold
728 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object): # shape
729 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
730 if not aCriterion.ThresholdID:
731 name = aThreshold.GetName()
733 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
734 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
735 elif isinstance(aThreshold, int): # node id
736 aCriterion.Threshold = aThreshold
737 elif isinstance(aThreshold, list): # 3 point coordinates
738 if len( aThreshold ) < 3:
739 raise ValueError, "too few point coordinates, must be 3"
740 aCriterion.ThresholdStr = " ".join( [str(c) for c in aThreshold[:3]] )
741 elif isinstance(aThreshold, str):
742 if aThreshold.isdigit():
743 aCriterion.Threshold = aThreshold # node id
745 aCriterion.ThresholdStr = aThreshold # hope that it's point coordinates
748 "The Threshold should either a VERTEX, or a node ID, "\
749 "or a list of point coordinates and not '%s'"%aThreshold
750 elif CritType == FT_ElemGeomType:
751 # Checks the Threshold
753 aCriterion.Threshold = self.EnumToLong(aThreshold)
754 assert( aThreshold in SMESH.GeometryType._items )
756 if isinstance(aThreshold, int):
757 aCriterion.Threshold = aThreshold
759 print "Error: The Threshold should be an integer or SMESH.GeometryType."
763 elif CritType == FT_EntityType:
764 # Checks the Threshold
766 aCriterion.Threshold = self.EnumToLong(aThreshold)
767 assert( aThreshold in SMESH.EntityType._items )
769 if isinstance(aThreshold, int):
770 aCriterion.Threshold = aThreshold
772 print "Error: The Threshold should be an integer or SMESH.EntityType."
777 elif CritType == FT_GroupColor:
778 # Checks the Threshold
780 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
782 print "Error: The threshold value should be of SALOMEDS.Color type"
785 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
786 FT_LinearOrQuadratic, FT_BadOrientedVolume,
787 FT_BareBorderFace, FT_BareBorderVolume,
788 FT_OverConstrainedFace, FT_OverConstrainedVolume,
789 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
790 # At this point the Threshold is unnecessary
791 if aThreshold == FT_LogicalNOT:
792 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
793 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
794 aCriterion.BinaryOp = aThreshold
798 aThreshold = float(aThreshold)
799 aCriterion.Threshold = aThreshold
801 print "Error: The Threshold should be a number."
804 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
805 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
807 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
808 aCriterion.BinaryOp = self.EnumToLong(Threshold)
810 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
811 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
813 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
814 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
818 ## Creates a filter with the given parameters
819 # @param elementType the type of elements in the group
820 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
821 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
822 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
823 # @param UnaryOp FT_LogicalNOT or FT_Undefined
824 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
825 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
826 # @return SMESH_Filter
828 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
829 # @ingroup l1_controls
830 def GetFilter(self,elementType,
831 CritType=FT_Undefined,
834 UnaryOp=FT_Undefined,
837 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
838 aFilterMgr = self.CreateFilterManager()
839 aFilter = aFilterMgr.CreateFilter()
841 aCriteria.append(aCriterion)
842 aFilter.SetCriteria(aCriteria)
844 if isinstance( mesh, Mesh ): aFilter.SetMesh( mesh.GetMesh() )
845 else : aFilter.SetMesh( mesh )
846 aFilterMgr.UnRegister()
849 ## Creates a filter from criteria
850 # @param criteria a list of criteria
851 # @return SMESH_Filter
853 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
854 # @ingroup l1_controls
855 def GetFilterFromCriteria(self,criteria):
856 aFilterMgr = self.CreateFilterManager()
857 aFilter = aFilterMgr.CreateFilter()
858 aFilter.SetCriteria(criteria)
859 aFilterMgr.UnRegister()
862 ## Creates a numerical functor by its type
863 # @param theCriterion FT_...; functor type
864 # @return SMESH_NumericalFunctor
865 # @ingroup l1_controls
866 def GetFunctor(self,theCriterion):
867 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
869 aFilterMgr = self.CreateFilterManager()
871 if theCriterion == FT_AspectRatio:
872 functor = aFilterMgr.CreateAspectRatio()
873 elif theCriterion == FT_AspectRatio3D:
874 functor = aFilterMgr.CreateAspectRatio3D()
875 elif theCriterion == FT_Warping:
876 functor = aFilterMgr.CreateWarping()
877 elif theCriterion == FT_MinimumAngle:
878 functor = aFilterMgr.CreateMinimumAngle()
879 elif theCriterion == FT_Taper:
880 functor = aFilterMgr.CreateTaper()
881 elif theCriterion == FT_Skew:
882 functor = aFilterMgr.CreateSkew()
883 elif theCriterion == FT_Area:
884 functor = aFilterMgr.CreateArea()
885 elif theCriterion == FT_Volume3D:
886 functor = aFilterMgr.CreateVolume3D()
887 elif theCriterion == FT_MaxElementLength2D:
888 functor = aFilterMgr.CreateMaxElementLength2D()
889 elif theCriterion == FT_MaxElementLength3D:
890 functor = aFilterMgr.CreateMaxElementLength3D()
891 elif theCriterion == FT_MultiConnection:
892 functor = aFilterMgr.CreateMultiConnection()
893 elif theCriterion == FT_MultiConnection2D:
894 functor = aFilterMgr.CreateMultiConnection2D()
895 elif theCriterion == FT_Length:
896 functor = aFilterMgr.CreateLength()
897 elif theCriterion == FT_Length2D:
898 functor = aFilterMgr.CreateLength2D()
900 print "Error: given parameter is not numerical functor type."
901 aFilterMgr.UnRegister()
904 ## Creates hypothesis
905 # @param theHType mesh hypothesis type (string)
906 # @param theLibName mesh plug-in library name
907 # @return created hypothesis instance
908 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
909 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
911 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
914 # wrap hypothesis methods
915 #print "HYPOTHESIS", theHType
916 for meth_name in dir( hyp.__class__ ):
917 if not meth_name.startswith("Get") and \
918 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
919 method = getattr ( hyp.__class__, meth_name )
921 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
925 ## Gets the mesh statistic
926 # @return dictionary "element type" - "count of elements"
927 # @ingroup l1_meshinfo
928 def GetMeshInfo(self, obj):
929 if isinstance( obj, Mesh ):
932 if hasattr(obj, "GetMeshInfo"):
933 values = obj.GetMeshInfo()
934 for i in range(SMESH.Entity_Last._v):
935 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
939 ## Get minimum distance between two objects
941 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
942 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
944 # @param src1 first source object
945 # @param src2 second source object
946 # @param id1 node/element id from the first source
947 # @param id2 node/element id from the second (or first) source
948 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
949 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
950 # @return minimum distance value
951 # @sa GetMinDistance()
952 # @ingroup l1_measurements
953 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
954 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
958 result = result.value
961 ## Get measure structure specifying minimum distance data between two objects
963 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
964 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
966 # @param src1 first source object
967 # @param src2 second source object
968 # @param id1 node/element id from the first source
969 # @param id2 node/element id from the second (or first) source
970 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
971 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
972 # @return Measure structure or None if input data is invalid
974 # @ingroup l1_measurements
975 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
976 if isinstance(src1, Mesh): src1 = src1.mesh
977 if isinstance(src2, Mesh): src2 = src2.mesh
978 if src2 is None and id2 != 0: src2 = src1
979 if not hasattr(src1, "_narrow"): return None
980 src1 = src1._narrow(SMESH.SMESH_IDSource)
981 if not src1: return None
984 e = m.GetMeshEditor()
986 src1 = e.MakeIDSource([id1], SMESH.FACE)
988 src1 = e.MakeIDSource([id1], SMESH.NODE)
990 if hasattr(src2, "_narrow"):
991 src2 = src2._narrow(SMESH.SMESH_IDSource)
992 if src2 and id2 != 0:
994 e = m.GetMeshEditor()
996 src2 = e.MakeIDSource([id2], SMESH.FACE)
998 src2 = e.MakeIDSource([id2], SMESH.NODE)
1001 aMeasurements = self.CreateMeasurements()
1002 result = aMeasurements.MinDistance(src1, src2)
1003 aMeasurements.UnRegister()
1006 ## Get bounding box of the specified object(s)
1007 # @param objects single source object or list of source objects
1008 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
1009 # @sa GetBoundingBox()
1010 # @ingroup l1_measurements
1011 def BoundingBox(self, objects):
1012 result = self.GetBoundingBox(objects)
1016 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
1019 ## Get measure structure specifying bounding box data of the specified object(s)
1020 # @param objects single source object or list of source objects
1021 # @return Measure structure
1023 # @ingroup l1_measurements
1024 def GetBoundingBox(self, objects):
1025 if isinstance(objects, tuple):
1026 objects = list(objects)
1027 if not isinstance(objects, list):
1031 if isinstance(o, Mesh):
1032 srclist.append(o.mesh)
1033 elif hasattr(o, "_narrow"):
1034 src = o._narrow(SMESH.SMESH_IDSource)
1035 if src: srclist.append(src)
1038 aMeasurements = self.CreateMeasurements()
1039 result = aMeasurements.BoundingBox(srclist)
1040 aMeasurements.UnRegister()
1044 #Registering the new proxy for SMESH_Gen
1045 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
1047 ## Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1048 # interface to create or load meshes.
1053 # salome.salome_init()
1054 # from salome.smesh import smeshBuilder
1055 # smesh = smeshBuilder.New(theStudy)
1057 # @param study SALOME study, generally obtained by salome.myStudy.
1058 # @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1059 # @return smeshBuilder instance
1061 def New( study, instance=None):
1063 Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1064 interface to create or load meshes.
1068 salome.salome_init()
1069 from salome.smesh import smeshBuilder
1070 smesh = smeshBuilder.New(theStudy)
1073 study SALOME study, generally obtained by salome.myStudy.
1074 instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1076 smeshBuilder instance
1084 smeshInst = smeshBuilder()
1085 assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__
1086 smeshInst.init_smesh(study)
1090 # Public class: Mesh
1091 # ==================
1093 ## This class allows defining and managing a mesh.
1094 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1095 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1096 # new nodes and elements and by changing the existing entities), to get information
1097 # about a mesh and to export a mesh into different formats.
1106 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1107 # sets the GUI name of this mesh to \a name.
1108 # @param smeshpyD an instance of smeshBuilder class
1109 # @param geompyD an instance of geomBuilder class
1110 # @param obj Shape to be meshed or SMESH_Mesh object
1111 # @param name Study name of the mesh
1112 # @ingroup l2_construct
1113 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1114 self.smeshpyD=smeshpyD
1115 self.geompyD=geompyD
1120 if isinstance(obj, geomBuilder.GEOM._objref_GEOM_Object):
1123 # publish geom of mesh (issue 0021122)
1124 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
1126 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
1127 if studyID != geompyD.myStudyId:
1128 geompyD.init_geom( smeshpyD.GetCurrentStudy())
1131 geo_name = name + " shape"
1133 geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1134 geompyD.addToStudy( self.geom, geo_name )
1135 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1137 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1140 self.mesh = self.smeshpyD.CreateEmptyMesh()
1142 self.smeshpyD.SetName(self.mesh, name)
1144 self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1147 self.geom = self.mesh.GetShapeToMesh()
1149 self.editor = self.mesh.GetMeshEditor()
1150 self.functors = [None] * SMESH.FT_Undefined._v
1152 # set self to algoCreator's
1153 for attrName in dir(self):
1154 attr = getattr( self, attrName )
1155 if isinstance( attr, algoCreator ):
1156 #print "algoCreator ", attrName
1157 setattr( self, attrName, attr.copy( self ))
1159 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1160 # @param theMesh a SMESH_Mesh object
1161 # @ingroup l2_construct
1162 def SetMesh(self, theMesh):
1163 if self.mesh: self.mesh.UnRegister()
1166 self.mesh.Register()
1167 self.geom = self.mesh.GetShapeToMesh()
1169 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1170 # @return a SMESH_Mesh object
1171 # @ingroup l2_construct
1175 ## Gets the name of the mesh
1176 # @return the name of the mesh as a string
1177 # @ingroup l2_construct
1179 name = GetName(self.GetMesh())
1182 ## Sets a name to the mesh
1183 # @param name a new name of the mesh
1184 # @ingroup l2_construct
1185 def SetName(self, name):
1186 self.smeshpyD.SetName(self.GetMesh(), name)
1188 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1189 # The subMesh object gives access to the IDs of nodes and elements.
1190 # @param geom a geometrical object (shape)
1191 # @param name a name for the submesh
1192 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1193 # @ingroup l2_submeshes
1194 def GetSubMesh(self, geom, name):
1195 AssureGeomPublished( self, geom, name )
1196 submesh = self.mesh.GetSubMesh( geom, name )
1199 ## Returns the shape associated to the mesh
1200 # @return a GEOM_Object
1201 # @ingroup l2_construct
1205 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1206 # @param geom the shape to be meshed (GEOM_Object)
1207 # @ingroup l2_construct
1208 def SetShape(self, geom):
1209 self.mesh = self.smeshpyD.CreateMesh(geom)
1211 ## Loads mesh from the study after opening the study
1215 ## Returns true if the hypotheses are defined well
1216 # @param theSubObject a sub-shape of a mesh shape
1217 # @return True or False
1218 # @ingroup l2_construct
1219 def IsReadyToCompute(self, theSubObject):
1220 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1222 ## Returns errors of hypotheses definition.
1223 # The list of errors is empty if everything is OK.
1224 # @param theSubObject a sub-shape of a mesh shape
1225 # @return a list of errors
1226 # @ingroup l2_construct
1227 def GetAlgoState(self, theSubObject):
1228 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1230 ## Returns a geometrical object on which the given element was built.
1231 # The returned geometrical object, if not nil, is either found in the
1232 # study or published by this method with the given name
1233 # @param theElementID the id of the mesh element
1234 # @param theGeomName the user-defined name of the geometrical object
1235 # @return GEOM::GEOM_Object instance
1236 # @ingroup l2_construct
1237 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1238 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1240 ## Returns the mesh dimension depending on the dimension of the underlying shape
1241 # or, if the mesh is not based on any shape, basing on deimension of elements
1242 # @return mesh dimension as an integer value [0,3]
1243 # @ingroup l1_auxiliary
1244 def MeshDimension(self):
1245 if self.mesh.HasShapeToMesh():
1246 shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
1247 if len( shells ) > 0 :
1249 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1251 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1256 if self.NbVolumes() > 0: return 3
1257 if self.NbFaces() > 0: return 2
1258 if self.NbEdges() > 0: return 1
1261 ## Evaluates size of prospective mesh on a shape
1262 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1263 # To know predicted number of e.g. edges, inquire it this way
1264 # Evaluate()[ EnumToLong( Entity_Edge )]
1265 def Evaluate(self, geom=0):
1266 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1268 geom = self.mesh.GetShapeToMesh()
1271 return self.smeshpyD.Evaluate(self.mesh, geom)
1274 ## Computes the mesh and returns the status of the computation
1275 # @param geom geomtrical shape on which mesh data should be computed
1276 # @param discardModifs if True and the mesh has been edited since
1277 # a last total re-compute and that may prevent successful partial re-compute,
1278 # then the mesh is cleaned before Compute()
1279 # @return True or False
1280 # @ingroup l2_construct
1281 def Compute(self, geom=0, discardModifs=False):
1282 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1284 geom = self.mesh.GetShapeToMesh()
1289 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1291 ok = self.smeshpyD.Compute(self.mesh, geom)
1292 except SALOME.SALOME_Exception, ex:
1293 print "Mesh computation failed, exception caught:"
1294 print " ", ex.details.text
1297 print "Mesh computation failed, exception caught:"
1298 traceback.print_exc()
1302 # Treat compute errors
1303 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1304 for err in computeErrors:
1306 if self.mesh.HasShapeToMesh():
1308 mainIOR = salome.orb.object_to_string(geom)
1309 for sname in salome.myStudyManager.GetOpenStudies():
1310 s = salome.myStudyManager.GetStudyByName(sname)
1312 mainSO = s.FindObjectIOR(mainIOR)
1313 if not mainSO: continue
1314 if err.subShapeID == 1:
1315 shapeText = ' on "%s"' % mainSO.GetName()
1316 subIt = s.NewChildIterator(mainSO)
1318 subSO = subIt.Value()
1320 obj = subSO.GetObject()
1321 if not obj: continue
1322 go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
1324 ids = go.GetSubShapeIndices()
1325 if len(ids) == 1 and ids[0] == err.subShapeID:
1326 shapeText = ' on "%s"' % subSO.GetName()
1329 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1331 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1333 shapeText = " on subshape #%s" % (err.subShapeID)
1335 shapeText = " on subshape #%s" % (err.subShapeID)
1337 stdErrors = ["OK", #COMPERR_OK
1338 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1339 "std::exception", #COMPERR_STD_EXCEPTION
1340 "OCC exception", #COMPERR_OCC_EXCEPTION
1341 "..", #COMPERR_SLM_EXCEPTION
1342 "Unknown exception", #COMPERR_EXCEPTION
1343 "Memory allocation problem", #COMPERR_MEMORY_PB
1344 "Algorithm failed", #COMPERR_ALGO_FAILED
1345 "Unexpected geometry", #COMPERR_BAD_SHAPE
1346 "Warning", #COMPERR_WARNING
1347 "Computation cancelled",#COMPERR_CANCELED
1348 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1350 if err.code < len(stdErrors): errText = stdErrors[err.code]
1352 errText = "code %s" % -err.code
1353 if errText: errText += ". "
1354 errText += err.comment
1355 if allReasons != "":allReasons += "\n"
1356 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1360 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1362 if err.isGlobalAlgo:
1370 reason = '%s %sD algorithm is missing' % (glob, dim)
1371 elif err.state == HYP_MISSING:
1372 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1373 % (glob, dim, name, dim))
1374 elif err.state == HYP_NOTCONFORM:
1375 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1376 elif err.state == HYP_BAD_PARAMETER:
1377 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1378 % ( glob, dim, name ))
1379 elif err.state == HYP_BAD_GEOMETRY:
1380 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1381 'geometry' % ( glob, dim, name ))
1382 elif err.state == HYP_HIDDEN_ALGO:
1383 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1384 'algorithm of upper dimension generating %sD mesh'
1385 % ( glob, dim, name, glob, dim ))
1387 reason = ("For unknown reason. "
1388 "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1390 if allReasons != "":allReasons += "\n"
1391 allReasons += "- " + reason
1393 if not ok or allReasons != "":
1394 msg = '"' + GetName(self.mesh) + '"'
1395 if ok: msg += " has been computed with warnings"
1396 else: msg += " has not been computed"
1397 if allReasons != "": msg += ":"
1402 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1403 smeshgui = salome.ImportComponentGUI("SMESH")
1404 smeshgui.Init(self.mesh.GetStudyId())
1405 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1406 salome.sg.updateObjBrowser(1)
1410 ## Return submesh objects list in meshing order
1411 # @return list of list of submesh objects
1412 # @ingroup l2_construct
1413 def GetMeshOrder(self):
1414 return self.mesh.GetMeshOrder()
1416 ## Return submesh objects list in meshing order
1417 # @return list of list of submesh objects
1418 # @ingroup l2_construct
1419 def SetMeshOrder(self, submeshes):
1420 return self.mesh.SetMeshOrder(submeshes)
1422 ## Removes all nodes and elements
1423 # @ingroup l2_construct
1426 if ( salome.sg.hasDesktop() and
1427 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1428 smeshgui = salome.ImportComponentGUI("SMESH")
1429 smeshgui.Init(self.mesh.GetStudyId())
1430 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1431 salome.sg.updateObjBrowser(1)
1433 ## Removes all nodes and elements of indicated shape
1434 # @ingroup l2_construct
1435 def ClearSubMesh(self, geomId):
1436 self.mesh.ClearSubMesh(geomId)
1437 if salome.sg.hasDesktop():
1438 smeshgui = salome.ImportComponentGUI("SMESH")
1439 smeshgui.Init(self.mesh.GetStudyId())
1440 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1441 salome.sg.updateObjBrowser(1)
1443 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1444 # @param fineness [0.0,1.0] defines mesh fineness
1445 # @return True or False
1446 # @ingroup l3_algos_basic
1447 def AutomaticTetrahedralization(self, fineness=0):
1448 dim = self.MeshDimension()
1450 self.RemoveGlobalHypotheses()
1451 self.Segment().AutomaticLength(fineness)
1453 self.Triangle().LengthFromEdges()
1456 from salome.NETGENPlugin.NETGENPluginBuilder import NETGEN
1457 self.Tetrahedron(NETGEN)
1459 return self.Compute()
1461 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1462 # @param fineness [0.0, 1.0] defines mesh fineness
1463 # @return True or False
1464 # @ingroup l3_algos_basic
1465 def AutomaticHexahedralization(self, fineness=0):
1466 dim = self.MeshDimension()
1467 # assign the hypotheses
1468 self.RemoveGlobalHypotheses()
1469 self.Segment().AutomaticLength(fineness)
1476 return self.Compute()
1478 ## Assigns a hypothesis
1479 # @param hyp a hypothesis to assign
1480 # @param geom a subhape of mesh geometry
1481 # @return SMESH.Hypothesis_Status
1482 # @ingroup l2_hypotheses
1483 def AddHypothesis(self, hyp, geom=0):
1484 if isinstance( hyp, Mesh_Algorithm ):
1485 hyp = hyp.GetAlgorithm()
1490 geom = self.mesh.GetShapeToMesh()
1492 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1493 status = self.mesh.AddHypothesis(geom, hyp)
1494 isAlgo = hyp._narrow( SMESH_Algo )
1495 hyp_name = GetName( hyp )
1498 geom_name = GetName( geom )
1499 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1502 ## Return True if an algorithm of hypothesis is assigned to a given shape
1503 # @param hyp a hypothesis to check
1504 # @param geom a subhape of mesh geometry
1505 # @return True of False
1506 # @ingroup l2_hypotheses
1507 def IsUsedHypothesis(self, hyp, geom):
1508 if not hyp: # or not geom
1510 if isinstance( hyp, Mesh_Algorithm ):
1511 hyp = hyp.GetAlgorithm()
1513 hyps = self.GetHypothesisList(geom)
1515 if h.GetId() == hyp.GetId():
1519 ## Unassigns a hypothesis
1520 # @param hyp a hypothesis to unassign
1521 # @param geom a sub-shape of mesh geometry
1522 # @return SMESH.Hypothesis_Status
1523 # @ingroup l2_hypotheses
1524 def RemoveHypothesis(self, hyp, geom=0):
1527 if isinstance( hyp, Mesh_Algorithm ):
1528 hyp = hyp.GetAlgorithm()
1534 if self.IsUsedHypothesis( hyp, shape ):
1535 return self.mesh.RemoveHypothesis( shape, hyp )
1536 hypName = GetName( hyp )
1537 geoName = GetName( shape )
1538 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1541 ## Gets the list of hypotheses added on a geometry
1542 # @param geom a sub-shape of mesh geometry
1543 # @return the sequence of SMESH_Hypothesis
1544 # @ingroup l2_hypotheses
1545 def GetHypothesisList(self, geom):
1546 return self.mesh.GetHypothesisList( geom )
1548 ## Removes all global hypotheses
1549 # @ingroup l2_hypotheses
1550 def RemoveGlobalHypotheses(self):
1551 current_hyps = self.mesh.GetHypothesisList( self.geom )
1552 for hyp in current_hyps:
1553 self.mesh.RemoveHypothesis( self.geom, hyp )
1557 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1558 ## allowing to overwrite the file if it exists or add the exported data to its contents
1559 # @param f is the file name
1560 # @param auto_groups boolean parameter for creating/not creating
1561 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1562 # the typical use is auto_groups=false.
1563 # @param version MED format version(MED_V2_1 or MED_V2_2)
1564 # @param overwrite boolean parameter for overwriting/not overwriting the file
1565 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1566 # @ingroup l2_impexp
1567 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1569 if isinstance( meshPart, list ):
1570 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1571 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1573 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1575 ## Exports the mesh in a file in SAUV format
1576 # @param f is the file name
1577 # @param auto_groups boolean parameter for creating/not creating
1578 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1579 # the typical use is auto_groups=false.
1580 # @ingroup l2_impexp
1581 def ExportSAUV(self, f, auto_groups=0):
1582 self.mesh.ExportSAUV(f, auto_groups)
1584 ## Exports the mesh in a file in DAT format
1585 # @param f the file name
1586 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1587 # @ingroup l2_impexp
1588 def ExportDAT(self, f, meshPart=None):
1590 if isinstance( meshPart, list ):
1591 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1592 self.mesh.ExportPartToDAT( meshPart, f )
1594 self.mesh.ExportDAT(f)
1596 ## Exports the mesh in a file in UNV format
1597 # @param f the file name
1598 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1599 # @ingroup l2_impexp
1600 def ExportUNV(self, f, meshPart=None):
1602 if isinstance( meshPart, list ):
1603 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1604 self.mesh.ExportPartToUNV( meshPart, f )
1606 self.mesh.ExportUNV(f)
1608 ## Export the mesh in a file in STL format
1609 # @param f the file name
1610 # @param ascii defines the file encoding
1611 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1612 # @ingroup l2_impexp
1613 def ExportSTL(self, f, ascii=1, meshPart=None):
1615 if isinstance( meshPart, list ):
1616 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1617 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1619 self.mesh.ExportSTL(f, ascii)
1621 ## Exports the mesh in a file in CGNS format
1622 # @param f is the file name
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 # @ingroup l2_impexp
1626 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1627 if isinstance( meshPart, list ):
1628 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1629 if isinstance( meshPart, Mesh ):
1630 meshPart = meshPart.mesh
1632 meshPart = self.mesh
1633 self.mesh.ExportCGNS(meshPart, f, overwrite)
1635 ## Exports the mesh in a file in GMF format
1636 # @param f is the file name
1637 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1638 # @ingroup l2_impexp
1639 def ExportGMF(self, f, meshPart=None):
1640 if isinstance( meshPart, list ):
1641 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1642 if isinstance( meshPart, Mesh ):
1643 meshPart = meshPart.mesh
1645 meshPart = self.mesh
1646 self.mesh.ExportGMF(meshPart, f, True)
1648 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1649 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1650 ## allowing to overwrite the file if it exists or add the exported data to its contents
1651 # @param f the file name
1652 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1653 # @param opt boolean parameter for creating/not creating
1654 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1655 # @param overwrite boolean parameter for overwriting/not overwriting the file
1656 # @ingroup l2_impexp
1657 def ExportToMED(self, f, version, opt=0, overwrite=1):
1658 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1660 # Operations with groups:
1661 # ----------------------
1663 ## Creates an empty mesh group
1664 # @param elementType the type of elements in the group
1665 # @param name the name of the mesh group
1666 # @return SMESH_Group
1667 # @ingroup l2_grps_create
1668 def CreateEmptyGroup(self, elementType, name):
1669 return self.mesh.CreateGroup(elementType, name)
1671 ## Creates a mesh group based on the geometric object \a grp
1672 # and gives a \a name, \n if this parameter is not defined
1673 # the name is the same as the geometric group name \n
1674 # Note: Works like GroupOnGeom().
1675 # @param grp a geometric group, a vertex, an edge, a face or a solid
1676 # @param name the name of the mesh group
1677 # @return SMESH_GroupOnGeom
1678 # @ingroup l2_grps_create
1679 def Group(self, grp, name=""):
1680 return self.GroupOnGeom(grp, name)
1682 ## Creates a mesh group based on the geometrical object \a grp
1683 # and gives a \a name, \n if this parameter is not defined
1684 # the name is the same as the geometrical group name
1685 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1686 # @param name the name of the mesh group
1687 # @param typ the type of elements in the group. If not set, it is
1688 # automatically detected by the type of the geometry
1689 # @return SMESH_GroupOnGeom
1690 # @ingroup l2_grps_create
1691 def GroupOnGeom(self, grp, name="", typ=None):
1692 AssureGeomPublished( self, grp, name )
1694 name = grp.GetName()
1696 typ = self._groupTypeFromShape( grp )
1697 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1699 ## Pivate method to get a type of group on geometry
1700 def _groupTypeFromShape( self, shape ):
1701 tgeo = str(shape.GetShapeType())
1702 if tgeo == "VERTEX":
1704 elif tgeo == "EDGE":
1706 elif tgeo == "FACE" or tgeo == "SHELL":
1708 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1710 elif tgeo == "COMPOUND":
1711 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
1713 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1714 return self._groupTypeFromShape( sub[0] )
1717 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1720 ## Creates a mesh group with given \a name based on the \a filter which
1721 ## is a special type of group dynamically updating it's contents during
1722 ## mesh modification
1723 # @param typ the type of elements in the group
1724 # @param name the name of the mesh group
1725 # @param filter the filter defining group contents
1726 # @return SMESH_GroupOnFilter
1727 # @ingroup l2_grps_create
1728 def GroupOnFilter(self, typ, name, filter):
1729 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1731 ## Creates a mesh group by the given ids of elements
1732 # @param groupName the name of the mesh group
1733 # @param elementType the type of elements in the group
1734 # @param elemIDs the list of ids
1735 # @return SMESH_Group
1736 # @ingroup l2_grps_create
1737 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1738 group = self.mesh.CreateGroup(elementType, groupName)
1742 ## Creates a mesh group by the given conditions
1743 # @param groupName the name of the mesh group
1744 # @param elementType the type of elements in the group
1745 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1746 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1747 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1748 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1749 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1750 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1751 # @return SMESH_Group
1752 # @ingroup l2_grps_create
1756 CritType=FT_Undefined,
1759 UnaryOp=FT_Undefined,
1761 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1762 group = self.MakeGroupByCriterion(groupName, aCriterion)
1765 ## Creates a mesh group by the given criterion
1766 # @param groupName the name of the mesh group
1767 # @param Criterion the instance of Criterion class
1768 # @return SMESH_Group
1769 # @ingroup l2_grps_create
1770 def MakeGroupByCriterion(self, groupName, Criterion):
1771 aFilterMgr = self.smeshpyD.CreateFilterManager()
1772 aFilter = aFilterMgr.CreateFilter()
1774 aCriteria.append(Criterion)
1775 aFilter.SetCriteria(aCriteria)
1776 group = self.MakeGroupByFilter(groupName, aFilter)
1777 aFilterMgr.UnRegister()
1780 ## Creates a mesh group by the given criteria (list of criteria)
1781 # @param groupName the name of the mesh group
1782 # @param theCriteria the list of criteria
1783 # @return SMESH_Group
1784 # @ingroup l2_grps_create
1785 def MakeGroupByCriteria(self, groupName, theCriteria):
1786 aFilterMgr = self.smeshpyD.CreateFilterManager()
1787 aFilter = aFilterMgr.CreateFilter()
1788 aFilter.SetCriteria(theCriteria)
1789 group = self.MakeGroupByFilter(groupName, aFilter)
1790 aFilterMgr.UnRegister()
1793 ## Creates a mesh group by the given filter
1794 # @param groupName the name of the mesh group
1795 # @param theFilter the instance of Filter class
1796 # @return SMESH_Group
1797 # @ingroup l2_grps_create
1798 def MakeGroupByFilter(self, groupName, theFilter):
1799 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1800 theFilter.SetMesh( self.mesh )
1801 group.AddFrom( theFilter )
1805 # @ingroup l2_grps_delete
1806 def RemoveGroup(self, group):
1807 self.mesh.RemoveGroup(group)
1809 ## Removes a group with its contents
1810 # @ingroup l2_grps_delete
1811 def RemoveGroupWithContents(self, group):
1812 self.mesh.RemoveGroupWithContents(group)
1814 ## Gets the list of groups existing in the mesh
1815 # @return a sequence of SMESH_GroupBase
1816 # @ingroup l2_grps_create
1817 def GetGroups(self):
1818 return self.mesh.GetGroups()
1820 ## Gets the number of groups existing in the mesh
1821 # @return the quantity of groups as an integer value
1822 # @ingroup l2_grps_create
1824 return self.mesh.NbGroups()
1826 ## Gets the list of names of groups existing in the mesh
1827 # @return list of strings
1828 # @ingroup l2_grps_create
1829 def GetGroupNames(self):
1830 groups = self.GetGroups()
1832 for group in groups:
1833 names.append(group.GetName())
1836 ## Produces a union of two groups
1837 # A new group is created. All mesh elements that are
1838 # present in the initial groups are added to the new one
1839 # @return an instance of SMESH_Group
1840 # @ingroup l2_grps_operon
1841 def UnionGroups(self, group1, group2, name):
1842 return self.mesh.UnionGroups(group1, group2, name)
1844 ## Produces a union list of groups
1845 # New group is created. All mesh elements that are present in
1846 # initial groups are added to the new one
1847 # @return an instance of SMESH_Group
1848 # @ingroup l2_grps_operon
1849 def UnionListOfGroups(self, groups, name):
1850 return self.mesh.UnionListOfGroups(groups, name)
1852 ## Prodices an intersection of two groups
1853 # A new group is created. All mesh elements that are common
1854 # for the two initial groups are added to the new one.
1855 # @return an instance of SMESH_Group
1856 # @ingroup l2_grps_operon
1857 def IntersectGroups(self, group1, group2, name):
1858 return self.mesh.IntersectGroups(group1, group2, name)
1860 ## Produces an intersection of groups
1861 # New group is created. All mesh elements that are present in all
1862 # initial groups simultaneously are added to the new one
1863 # @return an instance of SMESH_Group
1864 # @ingroup l2_grps_operon
1865 def IntersectListOfGroups(self, groups, name):
1866 return self.mesh.IntersectListOfGroups(groups, name)
1868 ## Produces a cut of two groups
1869 # A new group is created. All mesh elements that are present in
1870 # the main group but are not present in the tool group are added to the new one
1871 # @return an instance of SMESH_Group
1872 # @ingroup l2_grps_operon
1873 def CutGroups(self, main_group, tool_group, name):
1874 return self.mesh.CutGroups(main_group, tool_group, name)
1876 ## Produces a cut of groups
1877 # A new group is created. All mesh elements that are present in main groups
1878 # but do not present in tool groups are added to the new one
1879 # @return an instance of SMESH_Group
1880 # @ingroup l2_grps_operon
1881 def CutListOfGroups(self, main_groups, tool_groups, name):
1882 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1884 ## Produces a group of elements of specified type using list of existing groups
1885 # A new group is created. System
1886 # 1) extracts all nodes on which groups elements are built
1887 # 2) combines all elements of specified dimension laying on these nodes
1888 # @return an instance of SMESH_Group
1889 # @ingroup l2_grps_operon
1890 def CreateDimGroup(self, groups, elem_type, name):
1891 return self.mesh.CreateDimGroup(groups, elem_type, name)
1894 ## Convert group on geom into standalone group
1895 # @ingroup l2_grps_delete
1896 def ConvertToStandalone(self, group):
1897 return self.mesh.ConvertToStandalone(group)
1899 # Get some info about mesh:
1900 # ------------------------
1902 ## Returns the log of nodes and elements added or removed
1903 # since the previous clear of the log.
1904 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1905 # @return list of log_block structures:
1910 # @ingroup l1_auxiliary
1911 def GetLog(self, clearAfterGet):
1912 return self.mesh.GetLog(clearAfterGet)
1914 ## Clears the log of nodes and elements added or removed since the previous
1915 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1916 # @ingroup l1_auxiliary
1918 self.mesh.ClearLog()
1920 ## Toggles auto color mode on the object.
1921 # @param theAutoColor the flag which toggles auto color mode.
1922 # @ingroup l1_auxiliary
1923 def SetAutoColor(self, theAutoColor):
1924 self.mesh.SetAutoColor(theAutoColor)
1926 ## Gets flag of object auto color mode.
1927 # @return True or False
1928 # @ingroup l1_auxiliary
1929 def GetAutoColor(self):
1930 return self.mesh.GetAutoColor()
1932 ## Gets the internal ID
1933 # @return integer value, which is the internal Id of the mesh
1934 # @ingroup l1_auxiliary
1936 return self.mesh.GetId()
1939 # @return integer value, which is the study Id of the mesh
1940 # @ingroup l1_auxiliary
1941 def GetStudyId(self):
1942 return self.mesh.GetStudyId()
1944 ## Checks the group names for duplications.
1945 # Consider the maximum group name length stored in MED file.
1946 # @return True or False
1947 # @ingroup l1_auxiliary
1948 def HasDuplicatedGroupNamesMED(self):
1949 return self.mesh.HasDuplicatedGroupNamesMED()
1951 ## Obtains the mesh editor tool
1952 # @return an instance of SMESH_MeshEditor
1953 # @ingroup l1_modifying
1954 def GetMeshEditor(self):
1957 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1958 # can be passed as argument to a method accepting mesh, group or sub-mesh
1959 # @return an instance of SMESH_IDSource
1960 # @ingroup l1_auxiliary
1961 def GetIDSource(self, ids, elemType):
1962 return self.editor.MakeIDSource(ids, elemType)
1965 # @return an instance of SALOME_MED::MESH
1966 # @ingroup l1_auxiliary
1967 def GetMEDMesh(self):
1968 return self.mesh.GetMEDMesh()
1971 # Get informations about mesh contents:
1972 # ------------------------------------
1974 ## Gets the mesh stattistic
1975 # @return dictionary type element - count of elements
1976 # @ingroup l1_meshinfo
1977 def GetMeshInfo(self, obj = None):
1978 if not obj: obj = self.mesh
1979 return self.smeshpyD.GetMeshInfo(obj)
1981 ## Returns the number of nodes in the mesh
1982 # @return an integer value
1983 # @ingroup l1_meshinfo
1985 return self.mesh.NbNodes()
1987 ## Returns the number of elements in the mesh
1988 # @return an integer value
1989 # @ingroup l1_meshinfo
1990 def NbElements(self):
1991 return self.mesh.NbElements()
1993 ## Returns the number of 0d elements in the mesh
1994 # @return an integer value
1995 # @ingroup l1_meshinfo
1996 def Nb0DElements(self):
1997 return self.mesh.Nb0DElements()
1999 ## Returns the number of ball discrete elements in the mesh
2000 # @return an integer value
2001 # @ingroup l1_meshinfo
2003 return self.mesh.NbBalls()
2005 ## Returns the number of edges in the mesh
2006 # @return an integer value
2007 # @ingroup l1_meshinfo
2009 return self.mesh.NbEdges()
2011 ## Returns the number of edges with the given order in the mesh
2012 # @param elementOrder the order of elements:
2013 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2014 # @return an integer value
2015 # @ingroup l1_meshinfo
2016 def NbEdgesOfOrder(self, elementOrder):
2017 return self.mesh.NbEdgesOfOrder(elementOrder)
2019 ## Returns the number of faces in the mesh
2020 # @return an integer value
2021 # @ingroup l1_meshinfo
2023 return self.mesh.NbFaces()
2025 ## Returns the number of faces with the given order in the mesh
2026 # @param elementOrder the order of elements:
2027 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2028 # @return an integer value
2029 # @ingroup l1_meshinfo
2030 def NbFacesOfOrder(self, elementOrder):
2031 return self.mesh.NbFacesOfOrder(elementOrder)
2033 ## Returns the number of triangles in the mesh
2034 # @return an integer value
2035 # @ingroup l1_meshinfo
2036 def NbTriangles(self):
2037 return self.mesh.NbTriangles()
2039 ## Returns the number of triangles with the given order in the mesh
2040 # @param elementOrder is the order of elements:
2041 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2042 # @return an integer value
2043 # @ingroup l1_meshinfo
2044 def NbTrianglesOfOrder(self, elementOrder):
2045 return self.mesh.NbTrianglesOfOrder(elementOrder)
2047 ## Returns the number of biquadratic triangles in the mesh
2048 # @return an integer value
2049 # @ingroup l1_meshinfo
2050 def NbBiQuadTriangles(self):
2051 return self.mesh.NbBiQuadTriangles()
2053 ## Returns the number of quadrangles in the mesh
2054 # @return an integer value
2055 # @ingroup l1_meshinfo
2056 def NbQuadrangles(self):
2057 return self.mesh.NbQuadrangles()
2059 ## Returns the number of quadrangles with the given order in the mesh
2060 # @param elementOrder the order of elements:
2061 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2062 # @return an integer value
2063 # @ingroup l1_meshinfo
2064 def NbQuadranglesOfOrder(self, elementOrder):
2065 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2067 ## Returns the number of biquadratic quadrangles in the mesh
2068 # @return an integer value
2069 # @ingroup l1_meshinfo
2070 def NbBiQuadQuadrangles(self):
2071 return self.mesh.NbBiQuadQuadrangles()
2073 ## Returns the number of polygons in the mesh
2074 # @return an integer value
2075 # @ingroup l1_meshinfo
2076 def NbPolygons(self):
2077 return self.mesh.NbPolygons()
2079 ## Returns the number of volumes in the mesh
2080 # @return an integer value
2081 # @ingroup l1_meshinfo
2082 def NbVolumes(self):
2083 return self.mesh.NbVolumes()
2085 ## Returns the number of volumes with the given order in the mesh
2086 # @param elementOrder the order of elements:
2087 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2088 # @return an integer value
2089 # @ingroup l1_meshinfo
2090 def NbVolumesOfOrder(self, elementOrder):
2091 return self.mesh.NbVolumesOfOrder(elementOrder)
2093 ## Returns the number of tetrahedrons in the mesh
2094 # @return an integer value
2095 # @ingroup l1_meshinfo
2097 return self.mesh.NbTetras()
2099 ## Returns the number of tetrahedrons with the given order in the mesh
2100 # @param elementOrder the order of elements:
2101 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2102 # @return an integer value
2103 # @ingroup l1_meshinfo
2104 def NbTetrasOfOrder(self, elementOrder):
2105 return self.mesh.NbTetrasOfOrder(elementOrder)
2107 ## Returns the number of hexahedrons in the mesh
2108 # @return an integer value
2109 # @ingroup l1_meshinfo
2111 return self.mesh.NbHexas()
2113 ## Returns the number of hexahedrons with the given order in the mesh
2114 # @param elementOrder the order of elements:
2115 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2116 # @return an integer value
2117 # @ingroup l1_meshinfo
2118 def NbHexasOfOrder(self, elementOrder):
2119 return self.mesh.NbHexasOfOrder(elementOrder)
2121 ## Returns the number of triquadratic hexahedrons in the mesh
2122 # @return an integer value
2123 # @ingroup l1_meshinfo
2124 def NbTriQuadraticHexas(self):
2125 return self.mesh.NbTriQuadraticHexas()
2127 ## Returns the number of pyramids in the mesh
2128 # @return an integer value
2129 # @ingroup l1_meshinfo
2130 def NbPyramids(self):
2131 return self.mesh.NbPyramids()
2133 ## Returns the number of pyramids with the given order in the mesh
2134 # @param elementOrder the order of elements:
2135 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2136 # @return an integer value
2137 # @ingroup l1_meshinfo
2138 def NbPyramidsOfOrder(self, elementOrder):
2139 return self.mesh.NbPyramidsOfOrder(elementOrder)
2141 ## Returns the number of prisms in the mesh
2142 # @return an integer value
2143 # @ingroup l1_meshinfo
2145 return self.mesh.NbPrisms()
2147 ## Returns the number of prisms with the given order in the mesh
2148 # @param elementOrder the order of elements:
2149 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2150 # @return an integer value
2151 # @ingroup l1_meshinfo
2152 def NbPrismsOfOrder(self, elementOrder):
2153 return self.mesh.NbPrismsOfOrder(elementOrder)
2155 ## Returns the number of hexagonal prisms in the mesh
2156 # @return an integer value
2157 # @ingroup l1_meshinfo
2158 def NbHexagonalPrisms(self):
2159 return self.mesh.NbHexagonalPrisms()
2161 ## Returns the number of polyhedrons in the mesh
2162 # @return an integer value
2163 # @ingroup l1_meshinfo
2164 def NbPolyhedrons(self):
2165 return self.mesh.NbPolyhedrons()
2167 ## Returns the number of submeshes in the mesh
2168 # @return an integer value
2169 # @ingroup l1_meshinfo
2170 def NbSubMesh(self):
2171 return self.mesh.NbSubMesh()
2173 ## Returns the list of mesh elements IDs
2174 # @return the list of integer values
2175 # @ingroup l1_meshinfo
2176 def GetElementsId(self):
2177 return self.mesh.GetElementsId()
2179 ## Returns the list of IDs of mesh elements with the given type
2180 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2181 # @return list of integer values
2182 # @ingroup l1_meshinfo
2183 def GetElementsByType(self, elementType):
2184 return self.mesh.GetElementsByType(elementType)
2186 ## Returns the list of mesh nodes IDs
2187 # @return the list of integer values
2188 # @ingroup l1_meshinfo
2189 def GetNodesId(self):
2190 return self.mesh.GetNodesId()
2192 # Get the information about mesh elements:
2193 # ------------------------------------
2195 ## Returns the type of mesh element
2196 # @return the value from SMESH::ElementType enumeration
2197 # @ingroup l1_meshinfo
2198 def GetElementType(self, id, iselem):
2199 return self.mesh.GetElementType(id, iselem)
2201 ## Returns the geometric type of mesh element
2202 # @return the value from SMESH::EntityType enumeration
2203 # @ingroup l1_meshinfo
2204 def GetElementGeomType(self, id):
2205 return self.mesh.GetElementGeomType(id)
2207 ## Returns the list of submesh elements IDs
2208 # @param Shape a geom object(sub-shape) IOR
2209 # Shape must be the sub-shape of a ShapeToMesh()
2210 # @return the list of integer values
2211 # @ingroup l1_meshinfo
2212 def GetSubMeshElementsId(self, Shape):
2213 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2214 ShapeID = Shape.GetSubShapeIndices()[0]
2217 return self.mesh.GetSubMeshElementsId(ShapeID)
2219 ## Returns the list of submesh nodes IDs
2220 # @param Shape a geom object(sub-shape) IOR
2221 # Shape must be the sub-shape of a ShapeToMesh()
2222 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2223 # @return the list of integer values
2224 # @ingroup l1_meshinfo
2225 def GetSubMeshNodesId(self, Shape, all):
2226 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2227 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2230 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2232 ## Returns type of elements on given shape
2233 # @param Shape a geom object(sub-shape) IOR
2234 # Shape must be a sub-shape of a ShapeToMesh()
2235 # @return element type
2236 # @ingroup l1_meshinfo
2237 def GetSubMeshElementType(self, Shape):
2238 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2239 ShapeID = Shape.GetSubShapeIndices()[0]
2242 return self.mesh.GetSubMeshElementType(ShapeID)
2244 ## Gets the mesh description
2245 # @return string value
2246 # @ingroup l1_meshinfo
2248 return self.mesh.Dump()
2251 # Get the information about nodes and elements of a mesh by its IDs:
2252 # -----------------------------------------------------------
2254 ## Gets XYZ coordinates of a node
2255 # \n If there is no nodes for the given ID - returns an empty list
2256 # @return a list of double precision values
2257 # @ingroup l1_meshinfo
2258 def GetNodeXYZ(self, id):
2259 return self.mesh.GetNodeXYZ(id)
2261 ## Returns list of IDs of inverse elements for the given node
2262 # \n If there is no node for the given ID - returns an empty list
2263 # @return a list of integer values
2264 # @ingroup l1_meshinfo
2265 def GetNodeInverseElements(self, id):
2266 return self.mesh.GetNodeInverseElements(id)
2268 ## @brief Returns the position of a node on the shape
2269 # @return SMESH::NodePosition
2270 # @ingroup l1_meshinfo
2271 def GetNodePosition(self,NodeID):
2272 return self.mesh.GetNodePosition(NodeID)
2274 ## @brief Returns the position of an element on the shape
2275 # @return SMESH::ElementPosition
2276 # @ingroup l1_meshinfo
2277 def GetElementPosition(self,ElemID):
2278 return self.mesh.GetElementPosition(ElemID)
2280 ## If the given element is a node, returns the ID of shape
2281 # \n If there is no node for the given ID - returns -1
2282 # @return an integer value
2283 # @ingroup l1_meshinfo
2284 def GetShapeID(self, id):
2285 return self.mesh.GetShapeID(id)
2287 ## Returns the ID of the result shape after
2288 # FindShape() from SMESH_MeshEditor for the given element
2289 # \n If there is no element for the given ID - returns -1
2290 # @return an integer value
2291 # @ingroup l1_meshinfo
2292 def GetShapeIDForElem(self,id):
2293 return self.mesh.GetShapeIDForElem(id)
2295 ## Returns the number of nodes for the given element
2296 # \n If there is no element for the given ID - returns -1
2297 # @return an integer value
2298 # @ingroup l1_meshinfo
2299 def GetElemNbNodes(self, id):
2300 return self.mesh.GetElemNbNodes(id)
2302 ## Returns the node ID the given (zero based) index for the given element
2303 # \n If there is no element for the given ID - returns -1
2304 # \n If there is no node for the given index - returns -2
2305 # @return an integer value
2306 # @ingroup l1_meshinfo
2307 def GetElemNode(self, id, index):
2308 return self.mesh.GetElemNode(id, index)
2310 ## Returns the IDs of nodes of the given element
2311 # @return a list of integer values
2312 # @ingroup l1_meshinfo
2313 def GetElemNodes(self, id):
2314 return self.mesh.GetElemNodes(id)
2316 ## Returns true if the given node is the medium node in the given quadratic element
2317 # @ingroup l1_meshinfo
2318 def IsMediumNode(self, elementID, nodeID):
2319 return self.mesh.IsMediumNode(elementID, nodeID)
2321 ## Returns true if the given node is the medium node in one of quadratic elements
2322 # @ingroup l1_meshinfo
2323 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2324 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2326 ## Returns the number of edges for the given element
2327 # @ingroup l1_meshinfo
2328 def ElemNbEdges(self, id):
2329 return self.mesh.ElemNbEdges(id)
2331 ## Returns the number of faces for the given element
2332 # @ingroup l1_meshinfo
2333 def ElemNbFaces(self, id):
2334 return self.mesh.ElemNbFaces(id)
2336 ## Returns nodes of given face (counted from zero) for given volumic element.
2337 # @ingroup l1_meshinfo
2338 def GetElemFaceNodes(self,elemId, faceIndex):
2339 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2341 ## Returns an element based on all given nodes.
2342 # @ingroup l1_meshinfo
2343 def FindElementByNodes(self,nodes):
2344 return self.mesh.FindElementByNodes(nodes)
2346 ## Returns true if the given element is a polygon
2347 # @ingroup l1_meshinfo
2348 def IsPoly(self, id):
2349 return self.mesh.IsPoly(id)
2351 ## Returns true if the given element is quadratic
2352 # @ingroup l1_meshinfo
2353 def IsQuadratic(self, id):
2354 return self.mesh.IsQuadratic(id)
2356 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2357 # @ingroup l1_meshinfo
2358 def GetBallDiameter(self, id):
2359 return self.mesh.GetBallDiameter(id)
2361 ## Returns XYZ coordinates of the barycenter of the given element
2362 # \n If there is no element for the given ID - returns an empty list
2363 # @return a list of three double values
2364 # @ingroup l1_meshinfo
2365 def BaryCenter(self, id):
2366 return self.mesh.BaryCenter(id)
2368 ## Passes mesh elements through the given filter and return IDs of fitting elements
2369 # @param theFilter SMESH_Filter
2370 # @return a list of ids
2371 # @ingroup l1_controls
2372 def GetIdsFromFilter(self, theFilter):
2373 theFilter.SetMesh( self.mesh )
2374 return theFilter.GetIDs()
2376 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2377 # Returns a list of special structures (borders).
2378 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2379 # @ingroup l1_controls
2380 def GetFreeBorders(self):
2381 aFilterMgr = self.smeshpyD.CreateFilterManager()
2382 aPredicate = aFilterMgr.CreateFreeEdges()
2383 aPredicate.SetMesh(self.mesh)
2384 aBorders = aPredicate.GetBorders()
2385 aFilterMgr.UnRegister()
2389 # Get mesh measurements information:
2390 # ------------------------------------
2392 ## Get minimum distance between two nodes, elements or distance to the origin
2393 # @param id1 first node/element id
2394 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2395 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2396 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2397 # @return minimum distance value
2398 # @sa GetMinDistance()
2399 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2400 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2401 return aMeasure.value
2403 ## Get measure structure specifying minimum distance data between two objects
2404 # @param id1 first node/element id
2405 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2406 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2407 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2408 # @return Measure structure
2410 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2412 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2414 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2417 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2419 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2424 aMeasurements = self.smeshpyD.CreateMeasurements()
2425 aMeasure = aMeasurements.MinDistance(id1, id2)
2426 aMeasurements.UnRegister()
2429 ## Get bounding box of the specified object(s)
2430 # @param objects single source object or list of source objects or list of nodes/elements IDs
2431 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2432 # @c False specifies that @a objects are nodes
2433 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2434 # @sa GetBoundingBox()
2435 def BoundingBox(self, objects=None, isElem=False):
2436 result = self.GetBoundingBox(objects, isElem)
2440 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2443 ## Get measure structure specifying bounding box data of the specified object(s)
2444 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2445 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2446 # @c False specifies that @a objects are nodes
2447 # @return Measure structure
2449 def GetBoundingBox(self, IDs=None, isElem=False):
2452 elif isinstance(IDs, tuple):
2454 if not isinstance(IDs, list):
2456 if len(IDs) > 0 and isinstance(IDs[0], int):
2460 if isinstance(o, Mesh):
2461 srclist.append(o.mesh)
2462 elif hasattr(o, "_narrow"):
2463 src = o._narrow(SMESH.SMESH_IDSource)
2464 if src: srclist.append(src)
2466 elif isinstance(o, list):
2468 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2470 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2473 aMeasurements = self.smeshpyD.CreateMeasurements()
2474 aMeasure = aMeasurements.BoundingBox(srclist)
2475 aMeasurements.UnRegister()
2478 # Mesh edition (SMESH_MeshEditor functionality):
2479 # ---------------------------------------------
2481 ## Removes the elements from the mesh by ids
2482 # @param IDsOfElements is a list of ids of elements to remove
2483 # @return True or False
2484 # @ingroup l2_modif_del
2485 def RemoveElements(self, IDsOfElements):
2486 return self.editor.RemoveElements(IDsOfElements)
2488 ## Removes nodes from mesh by ids
2489 # @param IDsOfNodes is a list of ids of nodes to remove
2490 # @return True or False
2491 # @ingroup l2_modif_del
2492 def RemoveNodes(self, IDsOfNodes):
2493 return self.editor.RemoveNodes(IDsOfNodes)
2495 ## Removes all orphan (free) nodes from mesh
2496 # @return number of the removed nodes
2497 # @ingroup l2_modif_del
2498 def RemoveOrphanNodes(self):
2499 return self.editor.RemoveOrphanNodes()
2501 ## Add a node to the mesh by coordinates
2502 # @return Id of the new node
2503 # @ingroup l2_modif_add
2504 def AddNode(self, x, y, z):
2505 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2506 if hasVars: self.mesh.SetParameters(Parameters)
2507 return self.editor.AddNode( x, y, z)
2509 ## Creates a 0D element on a node with given number.
2510 # @param IDOfNode the ID of node for creation of the element.
2511 # @return the Id of the new 0D element
2512 # @ingroup l2_modif_add
2513 def Add0DElement(self, IDOfNode):
2514 return self.editor.Add0DElement(IDOfNode)
2516 ## Create 0D elements on all nodes of the given elements except those
2517 # nodes on which a 0D element already exists.
2518 # @param theObject an object on whose nodes 0D elements will be created.
2519 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2520 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2521 # @param theGroupName optional name of a group to add 0D elements created
2522 # and/or found on nodes of \a theObject.
2523 # @return an object (a new group or a temporary SMESH_IDSource) holding
2524 # IDs of new and/or found 0D elements. IDs of 0D elements
2525 # can be retrieved from the returned object by calling GetIDs()
2526 # @ingroup l2_modif_add
2527 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2528 if isinstance( theObject, Mesh ):
2529 theObject = theObject.GetMesh()
2530 if isinstance( theObject, list ):
2531 theObject = self.GetIDSource( theObject, SMESH.ALL )
2532 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2534 ## Creates a ball element on a node with given ID.
2535 # @param IDOfNode the ID of node for creation of the element.
2536 # @param diameter the bal diameter.
2537 # @return the Id of the new ball element
2538 # @ingroup l2_modif_add
2539 def AddBall(self, IDOfNode, diameter):
2540 return self.editor.AddBall( IDOfNode, diameter )
2542 ## Creates a linear or quadratic edge (this is determined
2543 # by the number of given nodes).
2544 # @param IDsOfNodes the list of node IDs for creation of the element.
2545 # The order of nodes in this list should correspond to the description
2546 # of MED. \n This description is located by the following link:
2547 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2548 # @return the Id of the new edge
2549 # @ingroup l2_modif_add
2550 def AddEdge(self, IDsOfNodes):
2551 return self.editor.AddEdge(IDsOfNodes)
2553 ## Creates a linear or quadratic face (this is determined
2554 # by the number of given nodes).
2555 # @param IDsOfNodes the list of node IDs for creation of the element.
2556 # The order of nodes in this list should correspond to the description
2557 # of MED. \n This description is located by the following link:
2558 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2559 # @return the Id of the new face
2560 # @ingroup l2_modif_add
2561 def AddFace(self, IDsOfNodes):
2562 return self.editor.AddFace(IDsOfNodes)
2564 ## Adds a polygonal face to the mesh by the list of node IDs
2565 # @param IdsOfNodes the list of node IDs for creation of the element.
2566 # @return the Id of the new face
2567 # @ingroup l2_modif_add
2568 def AddPolygonalFace(self, IdsOfNodes):
2569 return self.editor.AddPolygonalFace(IdsOfNodes)
2571 ## Creates both simple and quadratic volume (this is determined
2572 # by the number of given nodes).
2573 # @param IDsOfNodes the list of node IDs for creation of the element.
2574 # The order of nodes in this list should correspond to the description
2575 # of MED. \n This description is located by the following link:
2576 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2577 # @return the Id of the new volumic element
2578 # @ingroup l2_modif_add
2579 def AddVolume(self, IDsOfNodes):
2580 return self.editor.AddVolume(IDsOfNodes)
2582 ## Creates a volume of many faces, giving nodes for each face.
2583 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2584 # @param Quantities the list of integer values, Quantities[i]
2585 # gives the quantity of nodes in face number i.
2586 # @return the Id of the new volumic element
2587 # @ingroup l2_modif_add
2588 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2589 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2591 ## Creates a volume of many faces, giving the IDs of the existing faces.
2592 # @param IdsOfFaces the list of face IDs for volume creation.
2594 # Note: The created volume will refer only to the nodes
2595 # of the given faces, not to the faces themselves.
2596 # @return the Id of the new volumic element
2597 # @ingroup l2_modif_add
2598 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2599 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2602 ## @brief Binds a node to a vertex
2603 # @param NodeID a node ID
2604 # @param Vertex a vertex or vertex ID
2605 # @return True if succeed else raises an exception
2606 # @ingroup l2_modif_add
2607 def SetNodeOnVertex(self, NodeID, Vertex):
2608 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
2609 VertexID = Vertex.GetSubShapeIndices()[0]
2613 self.editor.SetNodeOnVertex(NodeID, VertexID)
2614 except SALOME.SALOME_Exception, inst:
2615 raise ValueError, inst.details.text
2619 ## @brief Stores the node position on an edge
2620 # @param NodeID a node ID
2621 # @param Edge an edge or edge ID
2622 # @param paramOnEdge a parameter on the edge where the node is located
2623 # @return True if succeed else raises an exception
2624 # @ingroup l2_modif_add
2625 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2626 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
2627 EdgeID = Edge.GetSubShapeIndices()[0]
2631 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2632 except SALOME.SALOME_Exception, inst:
2633 raise ValueError, inst.details.text
2636 ## @brief Stores node position on a face
2637 # @param NodeID a node ID
2638 # @param Face a face or face ID
2639 # @param u U parameter on the face where the node is located
2640 # @param v V parameter on the face where the node is located
2641 # @return True if succeed else raises an exception
2642 # @ingroup l2_modif_add
2643 def SetNodeOnFace(self, NodeID, Face, u, v):
2644 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
2645 FaceID = Face.GetSubShapeIndices()[0]
2649 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2650 except SALOME.SALOME_Exception, inst:
2651 raise ValueError, inst.details.text
2654 ## @brief Binds a node to a solid
2655 # @param NodeID a node ID
2656 # @param Solid a solid or solid ID
2657 # @return True if succeed else raises an exception
2658 # @ingroup l2_modif_add
2659 def SetNodeInVolume(self, NodeID, Solid):
2660 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
2661 SolidID = Solid.GetSubShapeIndices()[0]
2665 self.editor.SetNodeInVolume(NodeID, SolidID)
2666 except SALOME.SALOME_Exception, inst:
2667 raise ValueError, inst.details.text
2670 ## @brief Bind an element to a shape
2671 # @param ElementID an element ID
2672 # @param Shape a shape or shape ID
2673 # @return True if succeed else raises an exception
2674 # @ingroup l2_modif_add
2675 def SetMeshElementOnShape(self, ElementID, Shape):
2676 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2677 ShapeID = Shape.GetSubShapeIndices()[0]
2681 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2682 except SALOME.SALOME_Exception, inst:
2683 raise ValueError, inst.details.text
2687 ## Moves the node with the given id
2688 # @param NodeID the id of the node
2689 # @param x a new X coordinate
2690 # @param y a new Y coordinate
2691 # @param z a new Z coordinate
2692 # @return True if succeed else False
2693 # @ingroup l2_modif_movenode
2694 def MoveNode(self, NodeID, x, y, z):
2695 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2696 if hasVars: self.mesh.SetParameters(Parameters)
2697 return self.editor.MoveNode(NodeID, x, y, z)
2699 ## Finds the node closest to a point and moves it to a point location
2700 # @param x the X coordinate of a point
2701 # @param y the Y coordinate of a point
2702 # @param z the Z coordinate of a point
2703 # @param NodeID if specified (>0), the node with this ID is moved,
2704 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2705 # @return the ID of a node
2706 # @ingroup l2_modif_throughp
2707 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2708 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2709 if hasVars: self.mesh.SetParameters(Parameters)
2710 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2712 ## Finds the node closest to a point
2713 # @param x the X coordinate of a point
2714 # @param y the Y coordinate of a point
2715 # @param z the Z coordinate of a point
2716 # @return the ID of a node
2717 # @ingroup l2_modif_throughp
2718 def FindNodeClosestTo(self, x, y, z):
2719 #preview = self.mesh.GetMeshEditPreviewer()
2720 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2721 return self.editor.FindNodeClosestTo(x, y, z)
2723 ## Finds the elements where a point lays IN or ON
2724 # @param x the X coordinate of a point
2725 # @param y the Y coordinate of a point
2726 # @param z the Z coordinate of a point
2727 # @param elementType type of elements to find (SMESH.ALL type
2728 # means elements of any type excluding nodes, discrete and 0D elements)
2729 # @param meshPart a part of mesh (group, sub-mesh) to search within
2730 # @return list of IDs of found elements
2731 # @ingroup l2_modif_throughp
2732 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2734 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2736 return self.editor.FindElementsByPoint(x, y, z, elementType)
2738 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2739 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2740 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2742 def GetPointState(self, x, y, z):
2743 return self.editor.GetPointState(x, y, z)
2745 ## Finds the node closest to a point and moves it to a point location
2746 # @param x the X coordinate of a point
2747 # @param y the Y coordinate of a point
2748 # @param z the Z coordinate of a point
2749 # @return the ID of a moved node
2750 # @ingroup l2_modif_throughp
2751 def MeshToPassThroughAPoint(self, x, y, z):
2752 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2754 ## Replaces two neighbour triangles sharing Node1-Node2 link
2755 # with the triangles built on the same 4 nodes but having other common link.
2756 # @param NodeID1 the ID of the first node
2757 # @param NodeID2 the ID of the second node
2758 # @return false if proper faces were not found
2759 # @ingroup l2_modif_invdiag
2760 def InverseDiag(self, NodeID1, NodeID2):
2761 return self.editor.InverseDiag(NodeID1, NodeID2)
2763 ## Replaces two neighbour triangles sharing Node1-Node2 link
2764 # with a quadrangle built on the same 4 nodes.
2765 # @param NodeID1 the ID of the first node
2766 # @param NodeID2 the ID of the second node
2767 # @return false if proper faces were not found
2768 # @ingroup l2_modif_unitetri
2769 def DeleteDiag(self, NodeID1, NodeID2):
2770 return self.editor.DeleteDiag(NodeID1, NodeID2)
2772 ## Reorients elements by ids
2773 # @param IDsOfElements if undefined reorients all mesh elements
2774 # @return True if succeed else False
2775 # @ingroup l2_modif_changori
2776 def Reorient(self, IDsOfElements=None):
2777 if IDsOfElements == None:
2778 IDsOfElements = self.GetElementsId()
2779 return self.editor.Reorient(IDsOfElements)
2781 ## Reorients all elements of the object
2782 # @param theObject mesh, submesh or group
2783 # @return True if succeed else False
2784 # @ingroup l2_modif_changori
2785 def ReorientObject(self, theObject):
2786 if ( isinstance( theObject, Mesh )):
2787 theObject = theObject.GetMesh()
2788 return self.editor.ReorientObject(theObject)
2790 ## Reorient faces contained in \a the2DObject.
2791 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2792 # @param theDirection is a desired direction of normal of \a theFace.
2793 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2794 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2795 # compared with theDirection. It can be either ID of face or a point
2796 # by which the face will be found. The point can be given as either
2797 # a GEOM vertex or a list of point coordinates.
2798 # @return number of reoriented faces
2799 # @ingroup l2_modif_changori
2800 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2802 if isinstance( the2DObject, Mesh ):
2803 the2DObject = the2DObject.GetMesh()
2804 if isinstance( the2DObject, list ):
2805 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2806 # check theDirection
2807 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
2808 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2809 if isinstance( theDirection, list ):
2810 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2811 # prepare theFace and thePoint
2812 theFace = theFaceOrPoint
2813 thePoint = PointStruct(0,0,0)
2814 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
2815 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2817 if isinstance( theFaceOrPoint, list ):
2818 thePoint = PointStruct( *theFaceOrPoint )
2820 if isinstance( theFaceOrPoint, PointStruct ):
2821 thePoint = theFaceOrPoint
2823 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2825 ## Fuses the neighbouring triangles into quadrangles.
2826 # @param IDsOfElements The triangles to be fused,
2827 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2828 # choose a neighbour to fuse with.
2829 # @param MaxAngle is the maximum angle between element normals at which the fusion
2830 # is still performed; theMaxAngle is mesured in radians.
2831 # Also it could be a name of variable which defines angle in degrees.
2832 # @return TRUE in case of success, FALSE otherwise.
2833 # @ingroup l2_modif_unitetri
2834 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2835 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2836 self.mesh.SetParameters(Parameters)
2837 if not IDsOfElements:
2838 IDsOfElements = self.GetElementsId()
2839 Functor = self.smeshpyD.GetFunctor(theCriterion)
2840 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2842 ## Fuses the neighbouring triangles of the object into quadrangles
2843 # @param theObject is mesh, submesh or group
2844 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2845 # choose a neighbour to fuse with.
2846 # @param MaxAngle a max angle between element normals at which the fusion
2847 # is still performed; theMaxAngle is mesured in radians.
2848 # @return TRUE in case of success, FALSE otherwise.
2849 # @ingroup l2_modif_unitetri
2850 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2851 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2852 self.mesh.SetParameters(Parameters)
2853 if isinstance( theObject, Mesh ):
2854 theObject = theObject.GetMesh()
2855 Functor = self.smeshpyD.GetFunctor(theCriterion)
2856 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2858 ## Splits quadrangles into triangles.
2860 # @param IDsOfElements the faces to be splitted.
2861 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2862 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2863 # value, then quadrangles will be split by the smallest diagonal.
2864 # @return TRUE in case of success, FALSE otherwise.
2865 # @ingroup l2_modif_cutquadr
2866 def QuadToTri (self, IDsOfElements, theCriterion = None):
2867 if IDsOfElements == []:
2868 IDsOfElements = self.GetElementsId()
2869 if theCriterion is None:
2870 theCriterion = FT_MaxElementLength2D
2871 Functor = self.smeshpyD.GetFunctor(theCriterion)
2872 return self.editor.QuadToTri(IDsOfElements, Functor)
2874 ## Splits quadrangles into triangles.
2875 # @param theObject the object from which the list of elements is taken,
2876 # this is mesh, submesh or group
2877 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2878 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2879 # value, then quadrangles will be split by the smallest diagonal.
2880 # @return TRUE in case of success, FALSE otherwise.
2881 # @ingroup l2_modif_cutquadr
2882 def QuadToTriObject (self, theObject, theCriterion = None):
2883 if ( isinstance( theObject, Mesh )):
2884 theObject = theObject.GetMesh()
2885 if theCriterion is None:
2886 theCriterion = FT_MaxElementLength2D
2887 Functor = self.smeshpyD.GetFunctor(theCriterion)
2888 return self.editor.QuadToTriObject(theObject, Functor)
2890 ## Splits quadrangles into triangles.
2891 # @param IDsOfElements the faces to be splitted
2892 # @param Diag13 is used to choose a diagonal for splitting.
2893 # @return TRUE in case of success, FALSE otherwise.
2894 # @ingroup l2_modif_cutquadr
2895 def SplitQuad (self, IDsOfElements, Diag13):
2896 if IDsOfElements == []:
2897 IDsOfElements = self.GetElementsId()
2898 return self.editor.SplitQuad(IDsOfElements, Diag13)
2900 ## Splits quadrangles into triangles.
2901 # @param theObject the object from which the list of elements is taken,
2902 # this is mesh, submesh or group
2903 # @param Diag13 is used to choose a diagonal for splitting.
2904 # @return TRUE in case of success, FALSE otherwise.
2905 # @ingroup l2_modif_cutquadr
2906 def SplitQuadObject (self, theObject, Diag13):
2907 if ( isinstance( theObject, Mesh )):
2908 theObject = theObject.GetMesh()
2909 return self.editor.SplitQuadObject(theObject, Diag13)
2911 ## Finds a better splitting of the given quadrangle.
2912 # @param IDOfQuad the ID of the quadrangle to be splitted.
2913 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2914 # choose a diagonal for splitting.
2915 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2916 # diagonal is better, 0 if error occurs.
2917 # @ingroup l2_modif_cutquadr
2918 def BestSplit (self, IDOfQuad, theCriterion):
2919 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2921 ## Splits volumic elements into tetrahedrons
2922 # @param elemIDs either list of elements or mesh or group or submesh
2923 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2924 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2925 # @ingroup l2_modif_cutquadr
2926 def SplitVolumesIntoTetra(self, elemIDs, method=smeshBuilder.Hex_5Tet ):
2927 if isinstance( elemIDs, Mesh ):
2928 elemIDs = elemIDs.GetMesh()
2929 if ( isinstance( elemIDs, list )):
2930 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2931 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2933 ## Splits quadrangle faces near triangular facets of volumes
2935 # @ingroup l1_auxiliary
2936 def SplitQuadsNearTriangularFacets(self):
2937 faces_array = self.GetElementsByType(SMESH.FACE)
2938 for face_id in faces_array:
2939 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2940 quad_nodes = self.mesh.GetElemNodes(face_id)
2941 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2942 isVolumeFound = False
2943 for node1_elem in node1_elems:
2944 if not isVolumeFound:
2945 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2946 nb_nodes = self.GetElemNbNodes(node1_elem)
2947 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2948 volume_elem = node1_elem
2949 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2950 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2951 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2952 isVolumeFound = True
2953 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2954 self.SplitQuad([face_id], False) # diagonal 2-4
2955 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2956 isVolumeFound = True
2957 self.SplitQuad([face_id], True) # diagonal 1-3
2958 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2959 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2960 isVolumeFound = True
2961 self.SplitQuad([face_id], True) # diagonal 1-3
2963 ## @brief Splits hexahedrons into tetrahedrons.
2965 # This operation uses pattern mapping functionality for splitting.
2966 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2967 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2968 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2969 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2970 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2971 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2972 # @return TRUE in case of success, FALSE otherwise.
2973 # @ingroup l1_auxiliary
2974 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2975 # Pattern: 5.---------.6
2980 # (0,0,1) 4.---------.7 * |
2987 # (0,0,0) 0.---------.3
2988 pattern_tetra = "!!! Nb of points: \n 8 \n\
2998 !!! Indices of points of 6 tetras: \n\
3006 pattern = self.smeshpyD.GetPattern()
3007 isDone = pattern.LoadFromFile(pattern_tetra)
3009 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3012 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3013 isDone = pattern.MakeMesh(self.mesh, False, False)
3014 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3016 # split quafrangle faces near triangular facets of volumes
3017 self.SplitQuadsNearTriangularFacets()
3021 ## @brief Split hexahedrons into prisms.
3023 # Uses the pattern mapping functionality for splitting.
3024 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
3025 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
3026 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
3027 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
3028 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
3029 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
3030 # @return TRUE in case of success, FALSE otherwise.
3031 # @ingroup l1_auxiliary
3032 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3033 # Pattern: 5.---------.6
3038 # (0,0,1) 4.---------.7 |
3045 # (0,0,0) 0.---------.3
3046 pattern_prism = "!!! Nb of points: \n 8 \n\
3056 !!! Indices of points of 2 prisms: \n\
3060 pattern = self.smeshpyD.GetPattern()
3061 isDone = pattern.LoadFromFile(pattern_prism)
3063 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3066 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3067 isDone = pattern.MakeMesh(self.mesh, False, False)
3068 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3070 # Splits quafrangle faces near triangular facets of volumes
3071 self.SplitQuadsNearTriangularFacets()
3075 ## Smoothes elements
3076 # @param IDsOfElements the list if ids of elements to smooth
3077 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3078 # Note that nodes built on edges and boundary nodes are always fixed.
3079 # @param MaxNbOfIterations the maximum number of iterations
3080 # @param MaxAspectRatio varies in range [1.0, inf]
3081 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3082 # @return TRUE in case of success, FALSE otherwise.
3083 # @ingroup l2_modif_smooth
3084 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3085 MaxNbOfIterations, MaxAspectRatio, Method):
3086 if IDsOfElements == []:
3087 IDsOfElements = self.GetElementsId()
3088 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3089 self.mesh.SetParameters(Parameters)
3090 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3091 MaxNbOfIterations, MaxAspectRatio, Method)
3093 ## Smoothes elements which belong to the given object
3094 # @param theObject the object to smooth
3095 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3096 # Note that nodes built on edges and boundary nodes are always fixed.
3097 # @param MaxNbOfIterations the maximum number of iterations
3098 # @param MaxAspectRatio varies in range [1.0, inf]
3099 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3100 # @return TRUE in case of success, FALSE otherwise.
3101 # @ingroup l2_modif_smooth
3102 def SmoothObject(self, theObject, IDsOfFixedNodes,
3103 MaxNbOfIterations, MaxAspectRatio, Method):
3104 if ( isinstance( theObject, Mesh )):
3105 theObject = theObject.GetMesh()
3106 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3107 MaxNbOfIterations, MaxAspectRatio, Method)
3109 ## Parametrically smoothes the given elements
3110 # @param IDsOfElements the list if ids of elements to smooth
3111 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3112 # Note that nodes built on edges and boundary nodes are always fixed.
3113 # @param MaxNbOfIterations the maximum number of iterations
3114 # @param MaxAspectRatio varies in range [1.0, inf]
3115 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3116 # @return TRUE in case of success, FALSE otherwise.
3117 # @ingroup l2_modif_smooth
3118 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3119 MaxNbOfIterations, MaxAspectRatio, Method):
3120 if IDsOfElements == []:
3121 IDsOfElements = self.GetElementsId()
3122 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3123 self.mesh.SetParameters(Parameters)
3124 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3125 MaxNbOfIterations, MaxAspectRatio, Method)
3127 ## Parametrically smoothes the elements which belong to the given object
3128 # @param theObject the object to smooth
3129 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3130 # Note that nodes built on edges and boundary nodes are always fixed.
3131 # @param MaxNbOfIterations the maximum number of iterations
3132 # @param MaxAspectRatio varies in range [1.0, inf]
3133 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3134 # @return TRUE in case of success, FALSE otherwise.
3135 # @ingroup l2_modif_smooth
3136 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3137 MaxNbOfIterations, MaxAspectRatio, Method):
3138 if ( isinstance( theObject, Mesh )):
3139 theObject = theObject.GetMesh()
3140 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3141 MaxNbOfIterations, MaxAspectRatio, Method)
3143 ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3144 # them with quadratic with the same id.
3145 # @param theForce3d new node creation method:
3146 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3147 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3148 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3149 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3150 # @ingroup l2_modif_tofromqu
3151 def ConvertToQuadratic(self, theForce3d, theSubMesh=None, theToBiQuad=False):
3153 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3156 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3158 self.editor.ConvertToQuadratic(theForce3d)
3160 ## Converts the mesh from quadratic to ordinary,
3161 # deletes old quadratic elements, \n replacing
3162 # them with ordinary mesh elements with the same id.
3163 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3164 # @ingroup l2_modif_tofromqu
3165 def ConvertFromQuadratic(self, theSubMesh=None):
3167 self.editor.ConvertFromQuadraticObject(theSubMesh)
3169 return self.editor.ConvertFromQuadratic()
3171 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3172 # @return TRUE if operation has been completed successfully, FALSE otherwise
3173 # @ingroup l2_modif_edit
3174 def Make2DMeshFrom3D(self):
3175 return self.editor. Make2DMeshFrom3D()
3177 ## Creates missing boundary elements
3178 # @param elements - elements whose boundary is to be checked:
3179 # mesh, group, sub-mesh or list of elements
3180 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3181 # @param dimension - defines type of boundary elements to create:
3182 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3183 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3184 # @param groupName - a name of group to store created boundary elements in,
3185 # "" means not to create the group
3186 # @param meshName - a name of new mesh to store created boundary elements in,
3187 # "" means not to create the new mesh
3188 # @param toCopyElements - if true, the checked elements will be copied into
3189 # the new mesh else only boundary elements will be copied into the new mesh
3190 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3191 # boundary elements will be copied into the new mesh
3192 # @return tuple (mesh, group) where bondary elements were added to
3193 # @ingroup l2_modif_edit
3194 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3195 toCopyElements=False, toCopyExistingBondary=False):
3196 if isinstance( elements, Mesh ):
3197 elements = elements.GetMesh()
3198 if ( isinstance( elements, list )):
3199 elemType = SMESH.ALL
3200 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3201 elements = self.editor.MakeIDSource(elements, elemType)
3202 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3203 toCopyElements,toCopyExistingBondary)
3204 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3208 # @brief Creates missing boundary elements around either the whole mesh or
3209 # groups of 2D elements
3210 # @param dimension - defines type of boundary elements to create
3211 # @param groupName - a name of group to store all boundary elements in,
3212 # "" means not to create the group
3213 # @param meshName - a name of a new mesh, which is a copy of the initial
3214 # mesh + created boundary elements; "" means not to create the new mesh
3215 # @param toCopyAll - if true, the whole initial mesh will be copied into
3216 # the new mesh else only boundary elements will be copied into the new mesh
3217 # @param groups - groups of 2D elements to make boundary around
3218 # @retval tuple( long, mesh, groups )
3219 # long - number of added boundary elements
3220 # mesh - the mesh where elements were added to
3221 # group - the group of boundary elements or None
3223 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3224 toCopyAll=False, groups=[]):
3225 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3227 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3228 return nb, mesh, group
3230 ## Renumber mesh nodes
3231 # @ingroup l2_modif_renumber
3232 def RenumberNodes(self):
3233 self.editor.RenumberNodes()
3235 ## Renumber mesh elements
3236 # @ingroup l2_modif_renumber
3237 def RenumberElements(self):
3238 self.editor.RenumberElements()
3240 ## Generates new elements by rotation of the elements around the axis
3241 # @param IDsOfElements the list of ids of elements to sweep
3242 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3243 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3244 # @param NbOfSteps the number of steps
3245 # @param Tolerance tolerance
3246 # @param MakeGroups forces the generation of new groups from existing ones
3247 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3248 # of all steps, else - size of each step
3249 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3250 # @ingroup l2_modif_extrurev
3251 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3252 MakeGroups=False, TotalAngle=False):
3253 if IDsOfElements == []:
3254 IDsOfElements = self.GetElementsId()
3255 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3256 Axis = self.smeshpyD.GetAxisStruct(Axis)
3257 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3258 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3259 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3260 self.mesh.SetParameters(Parameters)
3261 if TotalAngle and NbOfSteps:
3262 AngleInRadians /= NbOfSteps
3264 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3265 AngleInRadians, NbOfSteps, Tolerance)
3266 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3269 ## Generates new elements by rotation of the elements of object around the axis
3270 # @param theObject object which elements should be sweeped.
3271 # It can be a mesh, a sub mesh or a group.
3272 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3273 # @param AngleInRadians the angle of Rotation
3274 # @param NbOfSteps number of steps
3275 # @param Tolerance tolerance
3276 # @param MakeGroups forces the generation of new groups from existing ones
3277 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3278 # of all steps, else - size of each step
3279 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3280 # @ingroup l2_modif_extrurev
3281 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3282 MakeGroups=False, TotalAngle=False):
3283 if ( isinstance( theObject, Mesh )):
3284 theObject = theObject.GetMesh()
3285 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3286 Axis = self.smeshpyD.GetAxisStruct(Axis)
3287 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3288 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3289 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3290 self.mesh.SetParameters(Parameters)
3291 if TotalAngle and NbOfSteps:
3292 AngleInRadians /= NbOfSteps
3294 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3295 NbOfSteps, Tolerance)
3296 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3299 ## Generates new elements by rotation of the elements of object around the axis
3300 # @param theObject object which elements should be sweeped.
3301 # It can be a mesh, a sub mesh or a group.
3302 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3303 # @param AngleInRadians the angle of Rotation
3304 # @param NbOfSteps number of steps
3305 # @param Tolerance tolerance
3306 # @param MakeGroups forces the generation of new groups from existing ones
3307 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3308 # of all steps, else - size of each step
3309 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3310 # @ingroup l2_modif_extrurev
3311 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3312 MakeGroups=False, TotalAngle=False):
3313 if ( isinstance( theObject, Mesh )):
3314 theObject = theObject.GetMesh()
3315 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3316 Axis = self.smeshpyD.GetAxisStruct(Axis)
3317 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3318 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3319 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3320 self.mesh.SetParameters(Parameters)
3321 if TotalAngle and NbOfSteps:
3322 AngleInRadians /= NbOfSteps
3324 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3325 NbOfSteps, Tolerance)
3326 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3329 ## Generates new elements by rotation of the elements of object around the axis
3330 # @param theObject object which elements should be sweeped.
3331 # It can be a mesh, a sub mesh or a group.
3332 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3333 # @param AngleInRadians the angle of Rotation
3334 # @param NbOfSteps number of steps
3335 # @param Tolerance tolerance
3336 # @param MakeGroups forces the generation of new groups from existing ones
3337 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3338 # of all steps, else - size of each step
3339 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3340 # @ingroup l2_modif_extrurev
3341 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3342 MakeGroups=False, TotalAngle=False):
3343 if ( isinstance( theObject, Mesh )):
3344 theObject = theObject.GetMesh()
3345 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3346 Axis = self.smeshpyD.GetAxisStruct(Axis)
3347 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3348 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3349 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3350 self.mesh.SetParameters(Parameters)
3351 if TotalAngle and NbOfSteps:
3352 AngleInRadians /= NbOfSteps
3354 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3355 NbOfSteps, Tolerance)
3356 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3359 ## Generates new elements by extrusion of the elements with given ids
3360 # @param IDsOfElements the list of elements ids for extrusion
3361 # @param StepVector vector or DirStruct or 3 vector components, defining
3362 # the direction and value of extrusion for one step (the total extrusion
3363 # length will be NbOfSteps * ||StepVector||)
3364 # @param NbOfSteps the number of steps
3365 # @param MakeGroups forces the generation of new groups from existing ones
3366 # @param IsNodes is True if elements with given ids are nodes
3367 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3368 # @ingroup l2_modif_extrurev
3369 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3370 if IDsOfElements == []:
3371 IDsOfElements = self.GetElementsId()
3372 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3373 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3374 if isinstance( StepVector, list ):
3375 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3376 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3377 Parameters = StepVector.PS.parameters + var_separator + Parameters
3378 self.mesh.SetParameters(Parameters)
3381 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3383 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3385 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3387 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3390 ## Generates new elements by extrusion of the elements with given ids
3391 # @param IDsOfElements is ids of elements
3392 # @param StepVector vector or DirStruct or 3 vector components, defining
3393 # the direction and value of extrusion for one step (the total extrusion
3394 # length will be NbOfSteps * ||StepVector||)
3395 # @param NbOfSteps the number of steps
3396 # @param ExtrFlags sets flags for extrusion
3397 # @param SewTolerance uses for comparing locations of nodes if flag
3398 # EXTRUSION_FLAG_SEW is set
3399 # @param MakeGroups forces the generation of new groups from existing ones
3400 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3401 # @ingroup l2_modif_extrurev
3402 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3403 ExtrFlags, SewTolerance, MakeGroups=False):
3404 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3405 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3406 if isinstance( StepVector, list ):
3407 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3409 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3410 ExtrFlags, SewTolerance)
3411 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3412 ExtrFlags, SewTolerance)
3415 ## Generates new elements by extrusion of the elements which belong to the object
3416 # @param theObject the object which elements should be processed.
3417 # It can be a mesh, a sub mesh or a group.
3418 # @param StepVector vector or DirStruct or 3 vector components, defining
3419 # the direction and value of extrusion for one step (the total extrusion
3420 # length will be NbOfSteps * ||StepVector||)
3421 # @param NbOfSteps the number of steps
3422 # @param MakeGroups forces the generation of new groups from existing ones
3423 # @param IsNodes is True if elements which belong to the object are nodes
3424 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3425 # @ingroup l2_modif_extrurev
3426 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3427 if ( isinstance( theObject, Mesh )):
3428 theObject = theObject.GetMesh()
3429 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3430 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3431 if isinstance( StepVector, list ):
3432 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3433 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3434 Parameters = StepVector.PS.parameters + var_separator + Parameters
3435 self.mesh.SetParameters(Parameters)
3438 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3440 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3442 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3444 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3447 ## Generates new elements by extrusion of the elements which belong to the object
3448 # @param theObject object which elements should be processed.
3449 # It can be a mesh, a sub mesh or a group.
3450 # @param StepVector vector or DirStruct or 3 vector components, defining
3451 # the direction and value of extrusion for one step (the total extrusion
3452 # length will be NbOfSteps * ||StepVector||)
3453 # @param NbOfSteps the number of steps
3454 # @param MakeGroups to generate new groups from existing ones
3455 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3456 # @ingroup l2_modif_extrurev
3457 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3458 if ( isinstance( theObject, Mesh )):
3459 theObject = theObject.GetMesh()
3460 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3461 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3462 if isinstance( StepVector, list ):
3463 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3464 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3465 Parameters = StepVector.PS.parameters + var_separator + Parameters
3466 self.mesh.SetParameters(Parameters)
3468 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3469 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3472 ## Generates new elements by extrusion of the elements which belong to the object
3473 # @param theObject object which elements should be processed.
3474 # It can be a mesh, a sub mesh or a group.
3475 # @param StepVector vector or DirStruct or 3 vector components, defining
3476 # the direction and value of extrusion for one step (the total extrusion
3477 # length will be NbOfSteps * ||StepVector||)
3478 # @param NbOfSteps the number of steps
3479 # @param MakeGroups forces the generation of new groups from existing ones
3480 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3481 # @ingroup l2_modif_extrurev
3482 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3483 if ( isinstance( theObject, Mesh )):
3484 theObject = theObject.GetMesh()
3485 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3486 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3487 if isinstance( StepVector, list ):
3488 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3489 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3490 Parameters = StepVector.PS.parameters + var_separator + Parameters
3491 self.mesh.SetParameters(Parameters)
3493 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3494 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3499 ## Generates new elements by extrusion of the given elements
3500 # The path of extrusion must be a meshed edge.
3501 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3502 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3503 # @param NodeStart the start node from Path. Defines the direction of extrusion
3504 # @param HasAngles allows the shape to be rotated around the path
3505 # to get the resulting mesh in a helical fashion
3506 # @param Angles list of angles in radians
3507 # @param LinearVariation forces the computation of rotation angles as linear
3508 # variation of the given Angles along path steps
3509 # @param HasRefPoint allows using the reference point
3510 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3511 # The User can specify any point as the Reference Point.
3512 # @param MakeGroups forces the generation of new groups from existing ones
3513 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3514 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3515 # only SMESH::Extrusion_Error otherwise
3516 # @ingroup l2_modif_extrurev
3517 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3518 HasAngles, Angles, LinearVariation,
3519 HasRefPoint, RefPoint, MakeGroups, ElemType):
3520 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3521 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3523 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3524 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3525 self.mesh.SetParameters(Parameters)
3527 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3529 if isinstance(Base, list):
3531 if Base == []: IDsOfElements = self.GetElementsId()
3532 else: IDsOfElements = Base
3533 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3534 HasAngles, Angles, LinearVariation,
3535 HasRefPoint, RefPoint, MakeGroups, ElemType)
3537 if isinstance(Base, Mesh): Base = Base.GetMesh()
3538 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3539 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3540 HasAngles, Angles, LinearVariation,
3541 HasRefPoint, RefPoint, MakeGroups, ElemType)
3543 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3546 ## Generates new elements by extrusion of the given elements
3547 # The path of extrusion must be a meshed edge.
3548 # @param IDsOfElements ids of elements
3549 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3550 # @param PathShape shape(edge) defines the sub-mesh for the path
3551 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3552 # @param HasAngles allows the shape to be rotated around the path
3553 # to get the resulting mesh in a helical fashion
3554 # @param Angles list of angles in radians
3555 # @param HasRefPoint allows using the reference point
3556 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3557 # The User can specify any point as the Reference Point.
3558 # @param MakeGroups forces the generation of new groups from existing ones
3559 # @param LinearVariation forces the computation of rotation angles as linear
3560 # variation of the given Angles along path steps
3561 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3562 # only SMESH::Extrusion_Error otherwise
3563 # @ingroup l2_modif_extrurev
3564 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3565 HasAngles, Angles, HasRefPoint, RefPoint,
3566 MakeGroups=False, LinearVariation=False):
3567 if IDsOfElements == []:
3568 IDsOfElements = self.GetElementsId()
3569 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3570 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3572 if ( isinstance( PathMesh, Mesh )):
3573 PathMesh = PathMesh.GetMesh()
3574 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3575 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3576 self.mesh.SetParameters(Parameters)
3577 if HasAngles and Angles and LinearVariation:
3578 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3581 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3582 PathShape, NodeStart, HasAngles,
3583 Angles, HasRefPoint, RefPoint)
3584 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3585 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3587 ## Generates new elements by extrusion of the elements which belong to the object
3588 # The path of extrusion must be a meshed edge.
3589 # @param theObject the object which elements should be processed.
3590 # It can be a mesh, a sub mesh or a group.
3591 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3592 # @param PathShape shape(edge) defines the sub-mesh for the path
3593 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3594 # @param HasAngles allows the shape to be rotated around the path
3595 # to get the resulting mesh in a helical fashion
3596 # @param Angles list of angles
3597 # @param HasRefPoint allows using the reference point
3598 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3599 # The User can specify any point as the Reference Point.
3600 # @param MakeGroups forces the generation of new groups from existing ones
3601 # @param LinearVariation forces the computation of rotation angles as linear
3602 # variation of the given Angles along path steps
3603 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3604 # only SMESH::Extrusion_Error otherwise
3605 # @ingroup l2_modif_extrurev
3606 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3607 HasAngles, Angles, HasRefPoint, RefPoint,
3608 MakeGroups=False, LinearVariation=False):
3609 if ( isinstance( theObject, Mesh )):
3610 theObject = theObject.GetMesh()
3611 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3612 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3613 if ( isinstance( PathMesh, Mesh )):
3614 PathMesh = PathMesh.GetMesh()
3615 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3616 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3617 self.mesh.SetParameters(Parameters)
3618 if HasAngles and Angles and LinearVariation:
3619 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3622 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3623 PathShape, NodeStart, HasAngles,
3624 Angles, HasRefPoint, RefPoint)
3625 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3626 NodeStart, HasAngles, Angles, HasRefPoint,
3629 ## Generates new elements by extrusion of the elements which belong to the object
3630 # The path of extrusion must be a meshed edge.
3631 # @param theObject the object which elements should be processed.
3632 # It can be a mesh, a sub mesh or a group.
3633 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3634 # @param PathShape shape(edge) defines the sub-mesh for the path
3635 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3636 # @param HasAngles allows the shape to be rotated around the path
3637 # to get the resulting mesh in a helical fashion
3638 # @param Angles list of angles
3639 # @param HasRefPoint allows using the reference point
3640 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3641 # The User can specify any point as the Reference Point.
3642 # @param MakeGroups forces the generation of new groups from existing ones
3643 # @param LinearVariation forces the computation of rotation angles as linear
3644 # variation of the given Angles along path steps
3645 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3646 # only SMESH::Extrusion_Error otherwise
3647 # @ingroup l2_modif_extrurev
3648 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3649 HasAngles, Angles, HasRefPoint, RefPoint,
3650 MakeGroups=False, LinearVariation=False):
3651 if ( isinstance( theObject, Mesh )):
3652 theObject = theObject.GetMesh()
3653 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3654 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3655 if ( isinstance( PathMesh, Mesh )):
3656 PathMesh = PathMesh.GetMesh()
3657 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3658 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3659 self.mesh.SetParameters(Parameters)
3660 if HasAngles and Angles and LinearVariation:
3661 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3664 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3665 PathShape, NodeStart, HasAngles,
3666 Angles, HasRefPoint, RefPoint)
3667 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3668 NodeStart, HasAngles, Angles, HasRefPoint,
3671 ## Generates new elements by extrusion of the elements which belong to the object
3672 # The path of extrusion must be a meshed edge.
3673 # @param theObject the object which elements should be processed.
3674 # It can be a mesh, a sub mesh or a group.
3675 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3676 # @param PathShape shape(edge) defines the sub-mesh for the path
3677 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3678 # @param HasAngles allows the shape to be rotated around the path
3679 # to get the resulting mesh in a helical fashion
3680 # @param Angles list of angles
3681 # @param HasRefPoint allows using the reference point
3682 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3683 # The User can specify any point as the Reference Point.
3684 # @param MakeGroups forces the generation of new groups from existing ones
3685 # @param LinearVariation forces the computation of rotation angles as linear
3686 # variation of the given Angles along path steps
3687 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3688 # only SMESH::Extrusion_Error otherwise
3689 # @ingroup l2_modif_extrurev
3690 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3691 HasAngles, Angles, HasRefPoint, RefPoint,
3692 MakeGroups=False, LinearVariation=False):
3693 if ( isinstance( theObject, Mesh )):
3694 theObject = theObject.GetMesh()
3695 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3696 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3697 if ( isinstance( PathMesh, Mesh )):
3698 PathMesh = PathMesh.GetMesh()
3699 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3700 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3701 self.mesh.SetParameters(Parameters)
3702 if HasAngles and Angles and LinearVariation:
3703 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3706 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3707 PathShape, NodeStart, HasAngles,
3708 Angles, HasRefPoint, RefPoint)
3709 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3710 NodeStart, HasAngles, Angles, HasRefPoint,
3713 ## Creates a symmetrical copy of mesh elements
3714 # @param IDsOfElements list of elements ids
3715 # @param Mirror is AxisStruct or geom object(point, line, plane)
3716 # @param theMirrorType is POINT, AXIS or PLANE
3717 # If the Mirror is a geom object this parameter is unnecessary
3718 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3719 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3720 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3721 # @ingroup l2_modif_trsf
3722 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3723 if IDsOfElements == []:
3724 IDsOfElements = self.GetElementsId()
3725 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3726 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3727 self.mesh.SetParameters(Mirror.parameters)
3728 if Copy and MakeGroups:
3729 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3730 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3733 ## Creates a new mesh by a symmetrical copy of mesh elements
3734 # @param IDsOfElements the list of elements ids
3735 # @param Mirror is AxisStruct or geom object (point, line, plane)
3736 # @param theMirrorType is POINT, AXIS or PLANE
3737 # If the Mirror is a geom object this parameter is unnecessary
3738 # @param MakeGroups to generate new groups from existing ones
3739 # @param NewMeshName a name of the new mesh to create
3740 # @return instance of Mesh class
3741 # @ingroup l2_modif_trsf
3742 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3743 if IDsOfElements == []:
3744 IDsOfElements = self.GetElementsId()
3745 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3746 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3747 self.mesh.SetParameters(Mirror.parameters)
3748 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3749 MakeGroups, NewMeshName)
3750 return Mesh(self.smeshpyD,self.geompyD,mesh)
3752 ## Creates a symmetrical copy of the object
3753 # @param theObject mesh, submesh or group
3754 # @param Mirror AxisStruct or geom object (point, line, plane)
3755 # @param theMirrorType is POINT, AXIS or PLANE
3756 # If the Mirror is a geom object this parameter is unnecessary
3757 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3758 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3759 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3760 # @ingroup l2_modif_trsf
3761 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3762 if ( isinstance( theObject, Mesh )):
3763 theObject = theObject.GetMesh()
3764 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3765 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3766 self.mesh.SetParameters(Mirror.parameters)
3767 if Copy and MakeGroups:
3768 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3769 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3772 ## Creates a new mesh by a symmetrical copy of the object
3773 # @param theObject mesh, submesh or group
3774 # @param Mirror AxisStruct or geom object (point, line, plane)
3775 # @param theMirrorType POINT, AXIS or PLANE
3776 # If the Mirror is a geom object this parameter is unnecessary
3777 # @param MakeGroups forces the generation of new groups from existing ones
3778 # @param NewMeshName the name of the new mesh to create
3779 # @return instance of Mesh class
3780 # @ingroup l2_modif_trsf
3781 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3782 if ( isinstance( theObject, Mesh )):
3783 theObject = theObject.GetMesh()
3784 if (isinstance(Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3785 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3786 self.mesh.SetParameters(Mirror.parameters)
3787 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3788 MakeGroups, NewMeshName)
3789 return Mesh( self.smeshpyD,self.geompyD,mesh )
3791 ## Translates the elements
3792 # @param IDsOfElements list of elements ids
3793 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3794 # @param Copy allows copying the translated elements
3795 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3796 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3797 # @ingroup l2_modif_trsf
3798 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3799 if IDsOfElements == []:
3800 IDsOfElements = self.GetElementsId()
3801 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3802 Vector = self.smeshpyD.GetDirStruct(Vector)
3803 if isinstance( Vector, list ):
3804 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3805 self.mesh.SetParameters(Vector.PS.parameters)
3806 if Copy and MakeGroups:
3807 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3808 self.editor.Translate(IDsOfElements, Vector, Copy)
3811 ## Creates a new mesh of translated elements
3812 # @param IDsOfElements list of elements ids
3813 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3814 # @param MakeGroups forces the generation of new groups from existing ones
3815 # @param NewMeshName the name of the newly created mesh
3816 # @return instance of Mesh class
3817 # @ingroup l2_modif_trsf
3818 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3819 if IDsOfElements == []:
3820 IDsOfElements = self.GetElementsId()
3821 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3822 Vector = self.smeshpyD.GetDirStruct(Vector)
3823 if isinstance( Vector, list ):
3824 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3825 self.mesh.SetParameters(Vector.PS.parameters)
3826 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3827 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3829 ## Translates the object
3830 # @param theObject the object to translate (mesh, submesh, or group)
3831 # @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
3832 # @param Copy allows copying the translated elements
3833 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3834 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3835 # @ingroup l2_modif_trsf
3836 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3837 if ( isinstance( theObject, Mesh )):
3838 theObject = theObject.GetMesh()
3839 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3840 Vector = self.smeshpyD.GetDirStruct(Vector)
3841 if isinstance( Vector, list ):
3842 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3843 self.mesh.SetParameters(Vector.PS.parameters)
3844 if Copy and MakeGroups:
3845 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3846 self.editor.TranslateObject(theObject, Vector, Copy)
3849 ## Creates a new mesh from the translated object
3850 # @param theObject the object to translate (mesh, submesh, or group)
3851 # @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
3852 # @param MakeGroups forces the generation of new groups from existing ones
3853 # @param NewMeshName the name of the newly created mesh
3854 # @return instance of Mesh class
3855 # @ingroup l2_modif_trsf
3856 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3857 if isinstance( theObject, Mesh ):
3858 theObject = theObject.GetMesh()
3859 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
3860 Vector = self.smeshpyD.GetDirStruct(Vector)
3861 if isinstance( Vector, list ):
3862 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3863 self.mesh.SetParameters(Vector.PS.parameters)
3864 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3865 return Mesh( self.smeshpyD, self.geompyD, mesh )
3869 ## Scales the object
3870 # @param theObject - the object to translate (mesh, submesh, or group)
3871 # @param thePoint - base point for scale
3872 # @param theScaleFact - list of 1-3 scale factors for axises
3873 # @param Copy - allows copying the translated elements
3874 # @param MakeGroups - forces the generation of new groups from existing
3876 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3877 # empty list otherwise
3878 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3879 if ( isinstance( theObject, Mesh )):
3880 theObject = theObject.GetMesh()
3881 if ( isinstance( theObject, list )):
3882 theObject = self.GetIDSource(theObject, SMESH.ALL)
3883 if ( isinstance( theScaleFact, float )):
3884 theScaleFact = [theScaleFact]
3885 if ( isinstance( theScaleFact, int )):
3886 theScaleFact = [ float(theScaleFact)]
3888 self.mesh.SetParameters(thePoint.parameters)
3890 if Copy and MakeGroups:
3891 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3892 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3895 ## Creates a new mesh from the translated object
3896 # @param theObject - the object to translate (mesh, submesh, or group)
3897 # @param thePoint - base point for scale
3898 # @param theScaleFact - list of 1-3 scale factors for axises
3899 # @param MakeGroups - forces the generation of new groups from existing ones
3900 # @param NewMeshName - the name of the newly created mesh
3901 # @return instance of Mesh class
3902 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3903 if (isinstance(theObject, Mesh)):
3904 theObject = theObject.GetMesh()
3905 if ( isinstance( theObject, list )):
3906 theObject = self.GetIDSource(theObject,SMESH.ALL)
3907 if ( isinstance( theScaleFact, float )):
3908 theScaleFact = [theScaleFact]
3909 if ( isinstance( theScaleFact, int )):
3910 theScaleFact = [ float(theScaleFact)]
3912 self.mesh.SetParameters(thePoint.parameters)
3913 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3914 MakeGroups, NewMeshName)
3915 return Mesh( self.smeshpyD, self.geompyD, mesh )
3919 ## Rotates the elements
3920 # @param IDsOfElements list of elements ids
3921 # @param Axis the axis of rotation (AxisStruct or geom line)
3922 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3923 # @param Copy allows copying the rotated elements
3924 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3925 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3926 # @ingroup l2_modif_trsf
3927 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3928 if IDsOfElements == []:
3929 IDsOfElements = self.GetElementsId()
3930 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3931 Axis = self.smeshpyD.GetAxisStruct(Axis)
3932 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3933 Parameters = Axis.parameters + var_separator + Parameters
3934 self.mesh.SetParameters(Parameters)
3935 if Copy and MakeGroups:
3936 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3937 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3940 ## Creates a new mesh of rotated elements
3941 # @param IDsOfElements list of element ids
3942 # @param Axis the axis of rotation (AxisStruct or geom line)
3943 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3944 # @param MakeGroups forces the generation of new groups from existing ones
3945 # @param NewMeshName the name of the newly created mesh
3946 # @return instance of Mesh class
3947 # @ingroup l2_modif_trsf
3948 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3949 if IDsOfElements == []:
3950 IDsOfElements = self.GetElementsId()
3951 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3952 Axis = self.smeshpyD.GetAxisStruct(Axis)
3953 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3954 Parameters = Axis.parameters + var_separator + Parameters
3955 self.mesh.SetParameters(Parameters)
3956 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3957 MakeGroups, NewMeshName)
3958 return Mesh( self.smeshpyD, self.geompyD, mesh )
3960 ## Rotates the object
3961 # @param theObject the object to rotate( mesh, submesh, or group)
3962 # @param Axis the axis of rotation (AxisStruct or geom line)
3963 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3964 # @param Copy allows copying the rotated elements
3965 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3966 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3967 # @ingroup l2_modif_trsf
3968 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3969 if (isinstance(theObject, Mesh)):
3970 theObject = theObject.GetMesh()
3971 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3972 Axis = self.smeshpyD.GetAxisStruct(Axis)
3973 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3974 Parameters = Axis.parameters + ":" + Parameters
3975 self.mesh.SetParameters(Parameters)
3976 if Copy and MakeGroups:
3977 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3978 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3981 ## Creates a new mesh from the rotated object
3982 # @param theObject the object to rotate (mesh, submesh, or group)
3983 # @param Axis the axis of rotation (AxisStruct or geom line)
3984 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3985 # @param MakeGroups forces the generation of new groups from existing ones
3986 # @param NewMeshName the name of the newly created mesh
3987 # @return instance of Mesh class
3988 # @ingroup l2_modif_trsf
3989 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3990 if (isinstance( theObject, Mesh )):
3991 theObject = theObject.GetMesh()
3992 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3993 Axis = self.smeshpyD.GetAxisStruct(Axis)
3994 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3995 Parameters = Axis.parameters + ":" + Parameters
3996 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3997 MakeGroups, NewMeshName)
3998 self.mesh.SetParameters(Parameters)
3999 return Mesh( self.smeshpyD, self.geompyD, mesh )
4001 ## Finds groups of ajacent nodes within Tolerance.
4002 # @param Tolerance the value of tolerance
4003 # @return the list of groups of nodes
4004 # @ingroup l2_modif_trsf
4005 def FindCoincidentNodes (self, Tolerance):
4006 return self.editor.FindCoincidentNodes(Tolerance)
4008 ## Finds groups of ajacent nodes within Tolerance.
4009 # @param Tolerance the value of tolerance
4010 # @param SubMeshOrGroup SubMesh or Group
4011 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
4012 # @return the list of groups of nodes
4013 # @ingroup l2_modif_trsf
4014 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
4015 if (isinstance( SubMeshOrGroup, Mesh )):
4016 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
4017 if not isinstance( exceptNodes, list):
4018 exceptNodes = [ exceptNodes ]
4019 if exceptNodes and isinstance( exceptNodes[0], int):
4020 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
4021 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
4024 # @param GroupsOfNodes the list of groups of nodes
4025 # @ingroup l2_modif_trsf
4026 def MergeNodes (self, GroupsOfNodes):
4027 self.editor.MergeNodes(GroupsOfNodes)
4029 ## Finds the elements built on the same nodes.
4030 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
4031 # @return a list of groups of equal elements
4032 # @ingroup l2_modif_trsf
4033 def FindEqualElements (self, MeshOrSubMeshOrGroup):
4034 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
4035 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4036 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
4038 ## Merges elements in each given group.
4039 # @param GroupsOfElementsID groups of elements for merging
4040 # @ingroup l2_modif_trsf
4041 def MergeElements(self, GroupsOfElementsID):
4042 self.editor.MergeElements(GroupsOfElementsID)
4044 ## Leaves one element and removes all other elements built on the same nodes.
4045 # @ingroup l2_modif_trsf
4046 def MergeEqualElements(self):
4047 self.editor.MergeEqualElements()
4049 ## Sews free borders
4050 # @return SMESH::Sew_Error
4051 # @ingroup l2_modif_trsf
4052 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4053 FirstNodeID2, SecondNodeID2, LastNodeID2,
4054 CreatePolygons, CreatePolyedrs):
4055 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4056 FirstNodeID2, SecondNodeID2, LastNodeID2,
4057 CreatePolygons, CreatePolyedrs)
4059 ## Sews conform free borders
4060 # @return SMESH::Sew_Error
4061 # @ingroup l2_modif_trsf
4062 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4063 FirstNodeID2, SecondNodeID2):
4064 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4065 FirstNodeID2, SecondNodeID2)
4067 ## Sews border to side
4068 # @return SMESH::Sew_Error
4069 # @ingroup l2_modif_trsf
4070 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4071 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4072 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4073 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4075 ## Sews two sides of a mesh. The nodes belonging to Side1 are
4076 # merged with the nodes of elements of Side2.
4077 # The number of elements in theSide1 and in theSide2 must be
4078 # equal and they should have similar nodal connectivity.
4079 # The nodes to merge should belong to side borders and
4080 # the first node should be linked to the second.
4081 # @return SMESH::Sew_Error
4082 # @ingroup l2_modif_trsf
4083 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4084 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4085 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4086 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4087 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4088 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4090 ## Sets new nodes for the given element.
4091 # @param ide the element id
4092 # @param newIDs nodes ids
4093 # @return If the number of nodes does not correspond to the type of element - returns false
4094 # @ingroup l2_modif_edit
4095 def ChangeElemNodes(self, ide, newIDs):
4096 return self.editor.ChangeElemNodes(ide, newIDs)
4098 ## If during the last operation of MeshEditor some nodes were
4099 # created, this method returns the list of their IDs, \n
4100 # if new nodes were not created - returns empty list
4101 # @return the list of integer values (can be empty)
4102 # @ingroup l1_auxiliary
4103 def GetLastCreatedNodes(self):
4104 return self.editor.GetLastCreatedNodes()
4106 ## If during the last operation of MeshEditor some elements were
4107 # created this method returns the list of their IDs, \n
4108 # if new elements were not created - returns empty list
4109 # @return the list of integer values (can be empty)
4110 # @ingroup l1_auxiliary
4111 def GetLastCreatedElems(self):
4112 return self.editor.GetLastCreatedElems()
4114 ## Clear sequences of nodes and elements created by mesh edition oparations
4115 # @ingroup l1_auxiliary
4116 def ClearLastCreated(self):
4117 self.editor.ClearLastCreated()
4119 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4120 # @param theNodes identifiers of nodes to be doubled
4121 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4122 # nodes. If list of element identifiers is empty then nodes are doubled but
4123 # they not assigned to elements
4124 # @return TRUE if operation has been completed successfully, FALSE otherwise
4125 # @ingroup l2_modif_edit
4126 def DoubleNodes(self, theNodes, theModifiedElems):
4127 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4129 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4130 # This method provided for convenience works as DoubleNodes() described above.
4131 # @param theNodeId identifiers of node to be doubled
4132 # @param theModifiedElems identifiers of elements to be updated
4133 # @return TRUE if operation has been completed successfully, FALSE otherwise
4134 # @ingroup l2_modif_edit
4135 def DoubleNode(self, theNodeId, theModifiedElems):
4136 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4138 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4139 # This method provided for convenience works as DoubleNodes() described above.
4140 # @param theNodes group of nodes to be doubled
4141 # @param theModifiedElems group of elements to be updated.
4142 # @param theMakeGroup forces the generation of a group containing new nodes.
4143 # @return TRUE or a created group if operation has been completed successfully,
4144 # FALSE or None otherwise
4145 # @ingroup l2_modif_edit
4146 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4148 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4149 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4151 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4152 # This method provided for convenience works as DoubleNodes() described above.
4153 # @param theNodes list of groups of nodes to be doubled
4154 # @param theModifiedElems list of groups of elements to be updated.
4155 # @param theMakeGroup forces the generation of a group containing new nodes.
4156 # @return TRUE if operation has been completed successfully, FALSE otherwise
4157 # @ingroup l2_modif_edit
4158 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4160 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4161 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4163 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4164 # @param theElems - the list of elements (edges or faces) to be replicated
4165 # The nodes for duplication could be found from these elements
4166 # @param theNodesNot - list of nodes to NOT replicate
4167 # @param theAffectedElems - the list of elements (cells and edges) to which the
4168 # replicated nodes should be associated to.
4169 # @return TRUE if operation has been completed successfully, FALSE otherwise
4170 # @ingroup l2_modif_edit
4171 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4172 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4174 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4175 # @param theElems - the list of elements (edges or faces) to be replicated
4176 # The nodes for duplication could be found from these elements
4177 # @param theNodesNot - list of nodes to NOT replicate
4178 # @param theShape - shape to detect affected elements (element which geometric center
4179 # located on or inside shape).
4180 # The replicated nodes should be associated to affected elements.
4181 # @return TRUE if operation has been completed successfully, FALSE otherwise
4182 # @ingroup l2_modif_edit
4183 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4184 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4186 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4187 # This method provided for convenience works as DoubleNodes() described above.
4188 # @param theElems - group of of elements (edges or faces) to be replicated
4189 # @param theNodesNot - group of nodes not to replicated
4190 # @param theAffectedElems - group of elements to which the replicated nodes
4191 # should be associated to.
4192 # @param theMakeGroup forces the generation of a group containing new elements.
4193 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4194 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4195 # FALSE or None otherwise
4196 # @ingroup l2_modif_edit
4197 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4198 theMakeGroup=False, theMakeNodeGroup=False):
4199 if theMakeGroup or theMakeNodeGroup:
4200 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4202 theMakeGroup, theMakeNodeGroup)
4203 if theMakeGroup and theMakeNodeGroup:
4206 return twoGroups[ int(theMakeNodeGroup) ]
4207 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4209 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4210 # This method provided for convenience works as DoubleNodes() described above.
4211 # @param theElems - group of of elements (edges or faces) to be replicated
4212 # @param theNodesNot - group of nodes not to replicated
4213 # @param theShape - shape to detect affected elements (element which geometric center
4214 # located on or inside shape).
4215 # The replicated nodes should be associated to affected elements.
4216 # @ingroup l2_modif_edit
4217 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4218 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4220 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4221 # This method provided for convenience works as DoubleNodes() described above.
4222 # @param theElems - list of groups of elements (edges or faces) to be replicated
4223 # @param theNodesNot - list of groups of nodes not to replicated
4224 # @param theAffectedElems - group of elements to which the replicated nodes
4225 # should be associated to.
4226 # @param theMakeGroup forces the generation of a group containing new elements.
4227 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4228 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4229 # FALSE or None otherwise
4230 # @ingroup l2_modif_edit
4231 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4232 theMakeGroup=False, theMakeNodeGroup=False):
4233 if theMakeGroup or theMakeNodeGroup:
4234 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4236 theMakeGroup, theMakeNodeGroup)
4237 if theMakeGroup and theMakeNodeGroup:
4240 return twoGroups[ int(theMakeNodeGroup) ]
4241 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4243 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4244 # This method provided for convenience works as DoubleNodes() described above.
4245 # @param theElems - list of groups of elements (edges or faces) to be replicated
4246 # @param theNodesNot - list of groups of nodes not to replicated
4247 # @param theShape - shape to detect affected elements (element which geometric center
4248 # located on or inside shape).
4249 # The replicated nodes should be associated to affected elements.
4250 # @return TRUE if operation has been completed successfully, FALSE otherwise
4251 # @ingroup l2_modif_edit
4252 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4253 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4255 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4256 # This method is the first step of DoubleNodeElemGroupsInRegion.
4257 # @param theElems - list of groups of elements (edges or faces) to be replicated
4258 # @param theNodesNot - list of groups of nodes not to replicated
4259 # @param theShape - shape to detect affected elements (element which geometric center
4260 # located on or inside shape).
4261 # The replicated nodes should be associated to affected elements.
4262 # @return groups of affected elements
4263 # @ingroup l2_modif_edit
4264 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4265 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4267 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4268 # The list of groups must describe a partition of the mesh volumes.
4269 # The nodes of the internal faces at the boundaries of the groups are doubled.
4270 # In option, the internal faces are replaced by flat elements.
4271 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4272 # @param theDomains - list of groups of volumes
4273 # @param createJointElems - if TRUE, create the elements
4274 # @return TRUE if operation has been completed successfully, FALSE otherwise
4275 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4276 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4278 ## Double nodes on some external faces and create flat elements.
4279 # Flat elements are mainly used by some types of mechanic calculations.
4281 # Each group of the list must be constituted of faces.
4282 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4283 # @param theGroupsOfFaces - list of groups of faces
4284 # @return TRUE if operation has been completed successfully, FALSE otherwise
4285 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4286 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4288 ## identify all the elements around a geom shape, get the faces delimiting the hole
4290 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4291 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4293 def _getFunctor(self, funcType ):
4294 fn = self.functors[ funcType._v ]
4296 fn = self.smeshpyD.GetFunctor(funcType)
4297 fn.SetMesh(self.mesh)
4298 self.functors[ funcType._v ] = fn
4301 def _valueFromFunctor(self, funcType, elemId):
4302 fn = self._getFunctor( funcType )
4303 if fn.GetElementType() == self.GetElementType(elemId, True):
4304 val = fn.GetValue(elemId)
4309 ## Get length of 1D element.
4310 # @param elemId mesh element ID
4311 # @return element's length value
4312 # @ingroup l1_measurements
4313 def GetLength(self, elemId):
4314 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4316 ## Get area of 2D element.
4317 # @param elemId mesh element ID
4318 # @return element's area value
4319 # @ingroup l1_measurements
4320 def GetArea(self, elemId):
4321 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4323 ## Get volume of 3D element.
4324 # @param elemId mesh element ID
4325 # @return element's volume value
4326 # @ingroup l1_measurements
4327 def GetVolume(self, elemId):
4328 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4330 ## Get maximum element length.
4331 # @param elemId mesh element ID
4332 # @return element's maximum length value
4333 # @ingroup l1_measurements
4334 def GetMaxElementLength(self, elemId):
4335 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4336 ftype = SMESH.FT_MaxElementLength3D
4338 ftype = SMESH.FT_MaxElementLength2D
4339 return self._valueFromFunctor(ftype, elemId)
4341 ## Get aspect ratio of 2D or 3D element.
4342 # @param elemId mesh element ID
4343 # @return element's aspect ratio value
4344 # @ingroup l1_measurements
4345 def GetAspectRatio(self, elemId):
4346 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4347 ftype = SMESH.FT_AspectRatio3D
4349 ftype = SMESH.FT_AspectRatio
4350 return self._valueFromFunctor(ftype, elemId)
4352 ## Get warping angle of 2D element.
4353 # @param elemId mesh element ID
4354 # @return element's warping angle value
4355 # @ingroup l1_measurements
4356 def GetWarping(self, elemId):
4357 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4359 ## Get minimum angle of 2D element.
4360 # @param elemId mesh element ID
4361 # @return element's minimum angle value
4362 # @ingroup l1_measurements
4363 def GetMinimumAngle(self, elemId):
4364 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4366 ## Get taper of 2D element.
4367 # @param elemId mesh element ID
4368 # @return element's taper value
4369 # @ingroup l1_measurements
4370 def GetTaper(self, elemId):
4371 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4373 ## Get skew of 2D element.
4374 # @param elemId mesh element ID
4375 # @return element's skew value
4376 # @ingroup l1_measurements
4377 def GetSkew(self, elemId):
4378 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4380 pass # end of Mesh class
4382 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4384 class Pattern(SMESH._objref_SMESH_Pattern):
4386 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4387 decrFun = lambda i: i-1
4388 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4389 theMesh.SetParameters(Parameters)
4390 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4392 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4393 decrFun = lambda i: i-1
4394 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4395 theMesh.SetParameters(Parameters)
4396 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4398 # Registering the new proxy for Pattern
4399 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4401 ## Private class used to bind methods creating algorithms to the class Mesh
4406 self.defaultAlgoType = ""
4407 self.algoTypeToClass = {}
4409 # Stores a python class of algorithm
4410 def add(self, algoClass):
4411 if type( algoClass ).__name__ == 'classobj' and \
4412 hasattr( algoClass, "algoType"):
4413 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4414 if not self.defaultAlgoType and \
4415 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4416 self.defaultAlgoType = algoClass.algoType
4417 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4419 # creates a copy of self and assign mesh to the copy
4420 def copy(self, mesh):
4421 other = algoCreator()
4422 other.defaultAlgoType = self.defaultAlgoType
4423 other.algoTypeToClass = self.algoTypeToClass
4427 # creates an instance of algorithm
4428 def __call__(self,algo="",geom=0,*args):
4429 algoType = self.defaultAlgoType
4430 for arg in args + (algo,geom):
4431 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
4433 if isinstance( arg, str ) and arg:
4435 if not algoType and self.algoTypeToClass:
4436 algoType = self.algoTypeToClass.keys()[0]
4437 if self.algoTypeToClass.has_key( algoType ):
4438 #print "Create algo",algoType
4439 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4440 raise RuntimeError, "No class found for algo type %s" % algoType
4443 # Private class used to substitute and store variable parameters of hypotheses.
4445 class hypMethodWrapper:
4446 def __init__(self, hyp, method):
4448 self.method = method
4449 #print "REBIND:", method.__name__
4452 # call a method of hypothesis with calling SetVarParameter() before
4453 def __call__(self,*args):
4455 return self.method( self.hyp, *args ) # hypothesis method with no args
4457 #print "MethWrapper.__call__",self.method.__name__, args
4459 parsed = ParseParameters(*args) # replace variables with their values
4460 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4461 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4462 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4463 # maybe there is a replaced string arg which is not variable
4464 result = self.method( self.hyp, *args )
4465 except ValueError, detail: # raised by ParseParameters()
4467 result = self.method( self.hyp, *args )
4468 except omniORB.CORBA.BAD_PARAM:
4469 raise ValueError, detail # wrong variable name
4473 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4475 #print "pluginName: ", pluginName
4476 pluginBuilderName = pluginName + "Builder"
4478 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
4479 except Exception, e:
4480 print "Exception while loading %s: %s" % ( pluginBuilderName, e )
4482 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
4483 plugin = eval( pluginBuilderName )
4484 #print " plugin:" , str(plugin)
4486 # add methods creating algorithms to Mesh
4487 for k in dir( plugin ):
4488 if k[0] == '_': continue
4489 algo = getattr( plugin, k )
4490 #print " algo:", str(algo)
4491 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4492 #print " meshMethod:" , str(algo.meshMethod)
4493 if not hasattr( Mesh, algo.meshMethod ):
4494 setattr( Mesh, algo.meshMethod, algoCreator() )
4496 getattr( Mesh, algo.meshMethod ).add( algo )