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