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"
1357 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1361 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1363 if err.isGlobalAlgo:
1371 reason = '%s %sD algorithm is missing' % (glob, dim)
1372 elif err.state == HYP_MISSING:
1373 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1374 % (glob, dim, name, dim))
1375 elif err.state == HYP_NOTCONFORM:
1376 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1377 elif err.state == HYP_BAD_PARAMETER:
1378 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1379 % ( glob, dim, name ))
1380 elif err.state == HYP_BAD_GEOMETRY:
1381 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1382 'geometry' % ( glob, dim, name ))
1383 elif err.state == HYP_HIDDEN_ALGO:
1384 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1385 'algorithm of upper dimension generating %sD mesh'
1386 % ( glob, dim, name, glob, dim ))
1388 reason = ("For unknown reason. "
1389 "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1391 if allReasons != "":allReasons += "\n"
1392 allReasons += "- " + reason
1394 if not ok or allReasons != "":
1395 msg = '"' + GetName(self.mesh) + '"'
1396 if ok: msg += " has been computed with warnings"
1397 else: msg += " has not been computed"
1398 if allReasons != "": msg += ":"
1403 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1404 smeshgui = salome.ImportComponentGUI("SMESH")
1405 smeshgui.Init(self.mesh.GetStudyId())
1406 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1407 salome.sg.updateObjBrowser(1)
1411 ## Return submesh objects list in meshing order
1412 # @return list of list of submesh objects
1413 # @ingroup l2_construct
1414 def GetMeshOrder(self):
1415 return self.mesh.GetMeshOrder()
1417 ## Return submesh objects list in meshing order
1418 # @return list of list of submesh objects
1419 # @ingroup l2_construct
1420 def SetMeshOrder(self, submeshes):
1421 return self.mesh.SetMeshOrder(submeshes)
1423 ## Removes all nodes and elements
1424 # @ingroup l2_construct
1427 if ( salome.sg.hasDesktop() and
1428 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1429 smeshgui = salome.ImportComponentGUI("SMESH")
1430 smeshgui.Init(self.mesh.GetStudyId())
1431 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1432 salome.sg.updateObjBrowser(1)
1434 ## Removes all nodes and elements of indicated shape
1435 # @ingroup l2_construct
1436 def ClearSubMesh(self, geomId):
1437 self.mesh.ClearSubMesh(geomId)
1438 if salome.sg.hasDesktop():
1439 smeshgui = salome.ImportComponentGUI("SMESH")
1440 smeshgui.Init(self.mesh.GetStudyId())
1441 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1442 salome.sg.updateObjBrowser(1)
1444 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1445 # @param fineness [0.0,1.0] defines mesh fineness
1446 # @return True or False
1447 # @ingroup l3_algos_basic
1448 def AutomaticTetrahedralization(self, fineness=0):
1449 dim = self.MeshDimension()
1451 self.RemoveGlobalHypotheses()
1452 self.Segment().AutomaticLength(fineness)
1454 self.Triangle().LengthFromEdges()
1457 from salome.NETGENPlugin.NETGENPluginBuilder import NETGEN
1458 self.Tetrahedron(NETGEN)
1460 return self.Compute()
1462 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1463 # @param fineness [0.0, 1.0] defines mesh fineness
1464 # @return True or False
1465 # @ingroup l3_algos_basic
1466 def AutomaticHexahedralization(self, fineness=0):
1467 dim = self.MeshDimension()
1468 # assign the hypotheses
1469 self.RemoveGlobalHypotheses()
1470 self.Segment().AutomaticLength(fineness)
1477 return self.Compute()
1479 ## Assigns a hypothesis
1480 # @param hyp a hypothesis to assign
1481 # @param geom a subhape of mesh geometry
1482 # @return SMESH.Hypothesis_Status
1483 # @ingroup l2_hypotheses
1484 def AddHypothesis(self, hyp, geom=0):
1485 if isinstance( hyp, Mesh_Algorithm ):
1486 hyp = hyp.GetAlgorithm()
1491 geom = self.mesh.GetShapeToMesh()
1493 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1494 status = self.mesh.AddHypothesis(geom, hyp)
1495 isAlgo = hyp._narrow( SMESH_Algo )
1496 hyp_name = GetName( hyp )
1499 geom_name = GetName( geom )
1500 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1503 ## Return True if an algorithm of hypothesis is assigned to a given shape
1504 # @param hyp a hypothesis to check
1505 # @param geom a subhape of mesh geometry
1506 # @return True of False
1507 # @ingroup l2_hypotheses
1508 def IsUsedHypothesis(self, hyp, geom):
1509 if not hyp: # or not geom
1511 if isinstance( hyp, Mesh_Algorithm ):
1512 hyp = hyp.GetAlgorithm()
1514 hyps = self.GetHypothesisList(geom)
1516 if h.GetId() == hyp.GetId():
1520 ## Unassigns a hypothesis
1521 # @param hyp a hypothesis to unassign
1522 # @param geom a sub-shape of mesh geometry
1523 # @return SMESH.Hypothesis_Status
1524 # @ingroup l2_hypotheses
1525 def RemoveHypothesis(self, hyp, geom=0):
1528 if isinstance( hyp, Mesh_Algorithm ):
1529 hyp = hyp.GetAlgorithm()
1535 if self.IsUsedHypothesis( hyp, shape ):
1536 return self.mesh.RemoveHypothesis( shape, hyp )
1537 hypName = GetName( hyp )
1538 geoName = GetName( shape )
1539 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1542 ## Gets the list of hypotheses added on a geometry
1543 # @param geom a sub-shape of mesh geometry
1544 # @return the sequence of SMESH_Hypothesis
1545 # @ingroup l2_hypotheses
1546 def GetHypothesisList(self, geom):
1547 return self.mesh.GetHypothesisList( geom )
1549 ## Removes all global hypotheses
1550 # @ingroup l2_hypotheses
1551 def RemoveGlobalHypotheses(self):
1552 current_hyps = self.mesh.GetHypothesisList( self.geom )
1553 for hyp in current_hyps:
1554 self.mesh.RemoveHypothesis( self.geom, hyp )
1558 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1559 ## allowing to overwrite the file if it exists or add the exported data to its contents
1560 # @param f is the file name
1561 # @param auto_groups boolean parameter for creating/not creating
1562 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1563 # the typical use is auto_groups=false.
1564 # @param version MED format version(MED_V2_1 or MED_V2_2)
1565 # @param overwrite boolean parameter for overwriting/not overwriting the file
1566 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1567 # @ingroup l2_impexp
1568 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1570 if isinstance( meshPart, list ):
1571 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1572 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1574 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1576 ## Exports the mesh in a file in SAUV format
1577 # @param f is the file name
1578 # @param auto_groups boolean parameter for creating/not creating
1579 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1580 # the typical use is auto_groups=false.
1581 # @ingroup l2_impexp
1582 def ExportSAUV(self, f, auto_groups=0):
1583 self.mesh.ExportSAUV(f, auto_groups)
1585 ## Exports the mesh in a file in DAT format
1586 # @param f the file name
1587 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1588 # @ingroup l2_impexp
1589 def ExportDAT(self, f, meshPart=None):
1591 if isinstance( meshPart, list ):
1592 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1593 self.mesh.ExportPartToDAT( meshPart, f )
1595 self.mesh.ExportDAT(f)
1597 ## Exports the mesh in a file in UNV format
1598 # @param f the file name
1599 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1600 # @ingroup l2_impexp
1601 def ExportUNV(self, f, meshPart=None):
1603 if isinstance( meshPart, list ):
1604 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1605 self.mesh.ExportPartToUNV( meshPart, f )
1607 self.mesh.ExportUNV(f)
1609 ## Export the mesh in a file in STL format
1610 # @param f the file name
1611 # @param ascii defines the file encoding
1612 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1613 # @ingroup l2_impexp
1614 def ExportSTL(self, f, ascii=1, meshPart=None):
1616 if isinstance( meshPart, list ):
1617 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1618 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1620 self.mesh.ExportSTL(f, ascii)
1622 ## Exports the mesh in a file in CGNS format
1623 # @param f is the file name
1624 # @param overwrite boolean parameter for overwriting/not overwriting the file
1625 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1626 # @ingroup l2_impexp
1627 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1628 if isinstance( meshPart, list ):
1629 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1630 if isinstance( meshPart, Mesh ):
1631 meshPart = meshPart.mesh
1633 meshPart = self.mesh
1634 self.mesh.ExportCGNS(meshPart, f, overwrite)
1636 ## Exports the mesh in a file in GMF format
1637 # @param f is the file name
1638 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1639 # @ingroup l2_impexp
1640 def ExportGMF(self, f, meshPart=None):
1641 if isinstance( meshPart, list ):
1642 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1643 if isinstance( meshPart, Mesh ):
1644 meshPart = meshPart.mesh
1646 meshPart = self.mesh
1647 self.mesh.ExportGMF(meshPart, f, True)
1649 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1650 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1651 ## allowing to overwrite the file if it exists or add the exported data to its contents
1652 # @param f the file name
1653 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1654 # @param opt boolean parameter for creating/not creating
1655 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1656 # @param overwrite boolean parameter for overwriting/not overwriting the file
1657 # @ingroup l2_impexp
1658 def ExportToMED(self, f, version, opt=0, overwrite=1):
1659 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1661 # Operations with groups:
1662 # ----------------------
1664 ## Creates an empty mesh group
1665 # @param elementType the type of elements in the group
1666 # @param name the name of the mesh group
1667 # @return SMESH_Group
1668 # @ingroup l2_grps_create
1669 def CreateEmptyGroup(self, elementType, name):
1670 return self.mesh.CreateGroup(elementType, name)
1672 ## Creates a mesh group based on the geometric object \a grp
1673 # and gives a \a name, \n if this parameter is not defined
1674 # the name is the same as the geometric group name \n
1675 # Note: Works like GroupOnGeom().
1676 # @param grp a geometric group, a vertex, an edge, a face or a solid
1677 # @param name the name of the mesh group
1678 # @return SMESH_GroupOnGeom
1679 # @ingroup l2_grps_create
1680 def Group(self, grp, name=""):
1681 return self.GroupOnGeom(grp, name)
1683 ## Creates a mesh group based on the geometrical object \a grp
1684 # and gives a \a name, \n if this parameter is not defined
1685 # the name is the same as the geometrical group name
1686 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1687 # @param name the name of the mesh group
1688 # @param typ the type of elements in the group. If not set, it is
1689 # automatically detected by the type of the geometry
1690 # @return SMESH_GroupOnGeom
1691 # @ingroup l2_grps_create
1692 def GroupOnGeom(self, grp, name="", typ=None):
1693 AssureGeomPublished( self, grp, name )
1695 name = grp.GetName()
1697 typ = self._groupTypeFromShape( grp )
1698 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1700 ## Pivate method to get a type of group on geometry
1701 def _groupTypeFromShape( self, shape ):
1702 tgeo = str(shape.GetShapeType())
1703 if tgeo == "VERTEX":
1705 elif tgeo == "EDGE":
1707 elif tgeo == "FACE" or tgeo == "SHELL":
1709 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1711 elif tgeo == "COMPOUND":
1712 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
1714 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1715 return self._groupTypeFromShape( sub[0] )
1718 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1721 ## Creates a mesh group with given \a name based on the \a filter which
1722 ## is a special type of group dynamically updating it's contents during
1723 ## mesh modification
1724 # @param typ the type of elements in the group
1725 # @param name the name of the mesh group
1726 # @param filter the filter defining group contents
1727 # @return SMESH_GroupOnFilter
1728 # @ingroup l2_grps_create
1729 def GroupOnFilter(self, typ, name, filter):
1730 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1732 ## Creates a mesh group by the given ids of elements
1733 # @param groupName the name of the mesh group
1734 # @param elementType the type of elements in the group
1735 # @param elemIDs the list of ids
1736 # @return SMESH_Group
1737 # @ingroup l2_grps_create
1738 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1739 group = self.mesh.CreateGroup(elementType, groupName)
1743 ## Creates a mesh group by the given conditions
1744 # @param groupName the name of the mesh group
1745 # @param elementType the type of elements in the group
1746 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1747 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1748 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1749 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1750 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1751 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1752 # @return SMESH_Group
1753 # @ingroup l2_grps_create
1757 CritType=FT_Undefined,
1760 UnaryOp=FT_Undefined,
1762 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1763 group = self.MakeGroupByCriterion(groupName, aCriterion)
1766 ## Creates a mesh group by the given criterion
1767 # @param groupName the name of the mesh group
1768 # @param Criterion the instance of Criterion class
1769 # @return SMESH_Group
1770 # @ingroup l2_grps_create
1771 def MakeGroupByCriterion(self, groupName, Criterion):
1772 aFilterMgr = self.smeshpyD.CreateFilterManager()
1773 aFilter = aFilterMgr.CreateFilter()
1775 aCriteria.append(Criterion)
1776 aFilter.SetCriteria(aCriteria)
1777 group = self.MakeGroupByFilter(groupName, aFilter)
1778 aFilterMgr.UnRegister()
1781 ## Creates a mesh group by the given criteria (list of criteria)
1782 # @param groupName the name of the mesh group
1783 # @param theCriteria the list of criteria
1784 # @return SMESH_Group
1785 # @ingroup l2_grps_create
1786 def MakeGroupByCriteria(self, groupName, theCriteria):
1787 aFilterMgr = self.smeshpyD.CreateFilterManager()
1788 aFilter = aFilterMgr.CreateFilter()
1789 aFilter.SetCriteria(theCriteria)
1790 group = self.MakeGroupByFilter(groupName, aFilter)
1791 aFilterMgr.UnRegister()
1794 ## Creates a mesh group by the given filter
1795 # @param groupName the name of the mesh group
1796 # @param theFilter the instance of Filter class
1797 # @return SMESH_Group
1798 # @ingroup l2_grps_create
1799 def MakeGroupByFilter(self, groupName, theFilter):
1800 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1801 theFilter.SetMesh( self.mesh )
1802 group.AddFrom( theFilter )
1806 # @ingroup l2_grps_delete
1807 def RemoveGroup(self, group):
1808 self.mesh.RemoveGroup(group)
1810 ## Removes a group with its contents
1811 # @ingroup l2_grps_delete
1812 def RemoveGroupWithContents(self, group):
1813 self.mesh.RemoveGroupWithContents(group)
1815 ## Gets the list of groups existing in the mesh
1816 # @return a sequence of SMESH_GroupBase
1817 # @ingroup l2_grps_create
1818 def GetGroups(self):
1819 return self.mesh.GetGroups()
1821 ## Gets the number of groups existing in the mesh
1822 # @return the quantity of groups as an integer value
1823 # @ingroup l2_grps_create
1825 return self.mesh.NbGroups()
1827 ## Gets the list of names of groups existing in the mesh
1828 # @return list of strings
1829 # @ingroup l2_grps_create
1830 def GetGroupNames(self):
1831 groups = self.GetGroups()
1833 for group in groups:
1834 names.append(group.GetName())
1837 ## Produces a union of two groups
1838 # A new group is created. All mesh elements that are
1839 # present in the initial groups are added to the new one
1840 # @return an instance of SMESH_Group
1841 # @ingroup l2_grps_operon
1842 def UnionGroups(self, group1, group2, name):
1843 return self.mesh.UnionGroups(group1, group2, name)
1845 ## Produces a union list of groups
1846 # New group is created. All mesh elements that are present in
1847 # initial groups are added to the new one
1848 # @return an instance of SMESH_Group
1849 # @ingroup l2_grps_operon
1850 def UnionListOfGroups(self, groups, name):
1851 return self.mesh.UnionListOfGroups(groups, name)
1853 ## Prodices an intersection of two groups
1854 # A new group is created. All mesh elements that are common
1855 # for the two initial groups are added to the new one.
1856 # @return an instance of SMESH_Group
1857 # @ingroup l2_grps_operon
1858 def IntersectGroups(self, group1, group2, name):
1859 return self.mesh.IntersectGroups(group1, group2, name)
1861 ## Produces an intersection of groups
1862 # New group is created. All mesh elements that are present in all
1863 # initial groups simultaneously are added to the new one
1864 # @return an instance of SMESH_Group
1865 # @ingroup l2_grps_operon
1866 def IntersectListOfGroups(self, groups, name):
1867 return self.mesh.IntersectListOfGroups(groups, name)
1869 ## Produces a cut of two groups
1870 # A new group is created. All mesh elements that are present in
1871 # the main group but are not present in the tool group are added to the new one
1872 # @return an instance of SMESH_Group
1873 # @ingroup l2_grps_operon
1874 def CutGroups(self, main_group, tool_group, name):
1875 return self.mesh.CutGroups(main_group, tool_group, name)
1877 ## Produces a cut of groups
1878 # A new group is created. All mesh elements that are present in main groups
1879 # but do not present in tool groups are added to the new one
1880 # @return an instance of SMESH_Group
1881 # @ingroup l2_grps_operon
1882 def CutListOfGroups(self, main_groups, tool_groups, name):
1883 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1885 ## Produces a group of elements of specified type using list of existing groups
1886 # A new group is created. System
1887 # 1) extracts all nodes on which groups elements are built
1888 # 2) combines all elements of specified dimension laying on these nodes
1889 # @return an instance of SMESH_Group
1890 # @ingroup l2_grps_operon
1891 def CreateDimGroup(self, groups, elem_type, name):
1892 return self.mesh.CreateDimGroup(groups, elem_type, name)
1895 ## Convert group on geom into standalone group
1896 # @ingroup l2_grps_delete
1897 def ConvertToStandalone(self, group):
1898 return self.mesh.ConvertToStandalone(group)
1900 # Get some info about mesh:
1901 # ------------------------
1903 ## Returns the log of nodes and elements added or removed
1904 # since the previous clear of the log.
1905 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1906 # @return list of log_block structures:
1911 # @ingroup l1_auxiliary
1912 def GetLog(self, clearAfterGet):
1913 return self.mesh.GetLog(clearAfterGet)
1915 ## Clears the log of nodes and elements added or removed since the previous
1916 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1917 # @ingroup l1_auxiliary
1919 self.mesh.ClearLog()
1921 ## Toggles auto color mode on the object.
1922 # @param theAutoColor the flag which toggles auto color mode.
1923 # @ingroup l1_auxiliary
1924 def SetAutoColor(self, theAutoColor):
1925 self.mesh.SetAutoColor(theAutoColor)
1927 ## Gets flag of object auto color mode.
1928 # @return True or False
1929 # @ingroup l1_auxiliary
1930 def GetAutoColor(self):
1931 return self.mesh.GetAutoColor()
1933 ## Gets the internal ID
1934 # @return integer value, which is the internal Id of the mesh
1935 # @ingroup l1_auxiliary
1937 return self.mesh.GetId()
1940 # @return integer value, which is the study Id of the mesh
1941 # @ingroup l1_auxiliary
1942 def GetStudyId(self):
1943 return self.mesh.GetStudyId()
1945 ## Checks the group names for duplications.
1946 # Consider the maximum group name length stored in MED file.
1947 # @return True or False
1948 # @ingroup l1_auxiliary
1949 def HasDuplicatedGroupNamesMED(self):
1950 return self.mesh.HasDuplicatedGroupNamesMED()
1952 ## Obtains the mesh editor tool
1953 # @return an instance of SMESH_MeshEditor
1954 # @ingroup l1_modifying
1955 def GetMeshEditor(self):
1958 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1959 # can be passed as argument to a method accepting mesh, group or sub-mesh
1960 # @return an instance of SMESH_IDSource
1961 # @ingroup l1_auxiliary
1962 def GetIDSource(self, ids, elemType):
1963 return self.editor.MakeIDSource(ids, elemType)
1966 # @return an instance of SALOME_MED::MESH
1967 # @ingroup l1_auxiliary
1968 def GetMEDMesh(self):
1969 return self.mesh.GetMEDMesh()
1972 # Get informations about mesh contents:
1973 # ------------------------------------
1975 ## Gets the mesh stattistic
1976 # @return dictionary type element - count of elements
1977 # @ingroup l1_meshinfo
1978 def GetMeshInfo(self, obj = None):
1979 if not obj: obj = self.mesh
1980 return self.smeshpyD.GetMeshInfo(obj)
1982 ## Returns the number of nodes in the mesh
1983 # @return an integer value
1984 # @ingroup l1_meshinfo
1986 return self.mesh.NbNodes()
1988 ## Returns the number of elements in the mesh
1989 # @return an integer value
1990 # @ingroup l1_meshinfo
1991 def NbElements(self):
1992 return self.mesh.NbElements()
1994 ## Returns the number of 0d elements in the mesh
1995 # @return an integer value
1996 # @ingroup l1_meshinfo
1997 def Nb0DElements(self):
1998 return self.mesh.Nb0DElements()
2000 ## Returns the number of ball discrete elements in the mesh
2001 # @return an integer value
2002 # @ingroup l1_meshinfo
2004 return self.mesh.NbBalls()
2006 ## Returns the number of edges in the mesh
2007 # @return an integer value
2008 # @ingroup l1_meshinfo
2010 return self.mesh.NbEdges()
2012 ## Returns the number of edges with the given order in the mesh
2013 # @param elementOrder the order of elements:
2014 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2015 # @return an integer value
2016 # @ingroup l1_meshinfo
2017 def NbEdgesOfOrder(self, elementOrder):
2018 return self.mesh.NbEdgesOfOrder(elementOrder)
2020 ## Returns the number of faces in the mesh
2021 # @return an integer value
2022 # @ingroup l1_meshinfo
2024 return self.mesh.NbFaces()
2026 ## Returns the number of faces with the given order in the mesh
2027 # @param elementOrder the order of elements:
2028 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2029 # @return an integer value
2030 # @ingroup l1_meshinfo
2031 def NbFacesOfOrder(self, elementOrder):
2032 return self.mesh.NbFacesOfOrder(elementOrder)
2034 ## Returns the number of triangles in the mesh
2035 # @return an integer value
2036 # @ingroup l1_meshinfo
2037 def NbTriangles(self):
2038 return self.mesh.NbTriangles()
2040 ## Returns the number of triangles with the given order in the mesh
2041 # @param elementOrder is the order of elements:
2042 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2043 # @return an integer value
2044 # @ingroup l1_meshinfo
2045 def NbTrianglesOfOrder(self, elementOrder):
2046 return self.mesh.NbTrianglesOfOrder(elementOrder)
2048 ## Returns the number of biquadratic triangles in the mesh
2049 # @return an integer value
2050 # @ingroup l1_meshinfo
2051 def NbBiQuadTriangles(self):
2052 return self.mesh.NbBiQuadTriangles()
2054 ## Returns the number of quadrangles in the mesh
2055 # @return an integer value
2056 # @ingroup l1_meshinfo
2057 def NbQuadrangles(self):
2058 return self.mesh.NbQuadrangles()
2060 ## Returns the number of quadrangles with the given order in the mesh
2061 # @param elementOrder the order of elements:
2062 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2063 # @return an integer value
2064 # @ingroup l1_meshinfo
2065 def NbQuadranglesOfOrder(self, elementOrder):
2066 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2068 ## Returns the number of biquadratic quadrangles in the mesh
2069 # @return an integer value
2070 # @ingroup l1_meshinfo
2071 def NbBiQuadQuadrangles(self):
2072 return self.mesh.NbBiQuadQuadrangles()
2074 ## Returns the number of polygons in the mesh
2075 # @return an integer value
2076 # @ingroup l1_meshinfo
2077 def NbPolygons(self):
2078 return self.mesh.NbPolygons()
2080 ## Returns the number of volumes in the mesh
2081 # @return an integer value
2082 # @ingroup l1_meshinfo
2083 def NbVolumes(self):
2084 return self.mesh.NbVolumes()
2086 ## Returns the number of volumes with the given order in the mesh
2087 # @param elementOrder the order of elements:
2088 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2089 # @return an integer value
2090 # @ingroup l1_meshinfo
2091 def NbVolumesOfOrder(self, elementOrder):
2092 return self.mesh.NbVolumesOfOrder(elementOrder)
2094 ## Returns the number of tetrahedrons in the mesh
2095 # @return an integer value
2096 # @ingroup l1_meshinfo
2098 return self.mesh.NbTetras()
2100 ## Returns the number of tetrahedrons with the given order in the mesh
2101 # @param elementOrder the order of elements:
2102 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2103 # @return an integer value
2104 # @ingroup l1_meshinfo
2105 def NbTetrasOfOrder(self, elementOrder):
2106 return self.mesh.NbTetrasOfOrder(elementOrder)
2108 ## Returns the number of hexahedrons in the mesh
2109 # @return an integer value
2110 # @ingroup l1_meshinfo
2112 return self.mesh.NbHexas()
2114 ## Returns the number of hexahedrons with the given order in the mesh
2115 # @param elementOrder the order of elements:
2116 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2117 # @return an integer value
2118 # @ingroup l1_meshinfo
2119 def NbHexasOfOrder(self, elementOrder):
2120 return self.mesh.NbHexasOfOrder(elementOrder)
2122 ## Returns the number of triquadratic hexahedrons in the mesh
2123 # @return an integer value
2124 # @ingroup l1_meshinfo
2125 def NbTriQuadraticHexas(self):
2126 return self.mesh.NbTriQuadraticHexas()
2128 ## Returns the number of pyramids in the mesh
2129 # @return an integer value
2130 # @ingroup l1_meshinfo
2131 def NbPyramids(self):
2132 return self.mesh.NbPyramids()
2134 ## Returns the number of pyramids with the given order in the mesh
2135 # @param elementOrder the order of elements:
2136 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2137 # @return an integer value
2138 # @ingroup l1_meshinfo
2139 def NbPyramidsOfOrder(self, elementOrder):
2140 return self.mesh.NbPyramidsOfOrder(elementOrder)
2142 ## Returns the number of prisms in the mesh
2143 # @return an integer value
2144 # @ingroup l1_meshinfo
2146 return self.mesh.NbPrisms()
2148 ## Returns the number of prisms with the given order in the mesh
2149 # @param elementOrder the order of elements:
2150 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2151 # @return an integer value
2152 # @ingroup l1_meshinfo
2153 def NbPrismsOfOrder(self, elementOrder):
2154 return self.mesh.NbPrismsOfOrder(elementOrder)
2156 ## Returns the number of hexagonal prisms in the mesh
2157 # @return an integer value
2158 # @ingroup l1_meshinfo
2159 def NbHexagonalPrisms(self):
2160 return self.mesh.NbHexagonalPrisms()
2162 ## Returns the number of polyhedrons in the mesh
2163 # @return an integer value
2164 # @ingroup l1_meshinfo
2165 def NbPolyhedrons(self):
2166 return self.mesh.NbPolyhedrons()
2168 ## Returns the number of submeshes in the mesh
2169 # @return an integer value
2170 # @ingroup l1_meshinfo
2171 def NbSubMesh(self):
2172 return self.mesh.NbSubMesh()
2174 ## Returns the list of mesh elements IDs
2175 # @return the list of integer values
2176 # @ingroup l1_meshinfo
2177 def GetElementsId(self):
2178 return self.mesh.GetElementsId()
2180 ## Returns the list of IDs of mesh elements with the given type
2181 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2182 # @return list of integer values
2183 # @ingroup l1_meshinfo
2184 def GetElementsByType(self, elementType):
2185 return self.mesh.GetElementsByType(elementType)
2187 ## Returns the list of mesh nodes IDs
2188 # @return the list of integer values
2189 # @ingroup l1_meshinfo
2190 def GetNodesId(self):
2191 return self.mesh.GetNodesId()
2193 # Get the information about mesh elements:
2194 # ------------------------------------
2196 ## Returns the type of mesh element
2197 # @return the value from SMESH::ElementType enumeration
2198 # @ingroup l1_meshinfo
2199 def GetElementType(self, id, iselem):
2200 return self.mesh.GetElementType(id, iselem)
2202 ## Returns the geometric type of mesh element
2203 # @return the value from SMESH::EntityType enumeration
2204 # @ingroup l1_meshinfo
2205 def GetElementGeomType(self, id):
2206 return self.mesh.GetElementGeomType(id)
2208 ## Returns the list of submesh elements IDs
2209 # @param Shape a geom object(sub-shape) IOR
2210 # Shape must be the sub-shape of a ShapeToMesh()
2211 # @return the list of integer values
2212 # @ingroup l1_meshinfo
2213 def GetSubMeshElementsId(self, Shape):
2214 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2215 ShapeID = Shape.GetSubShapeIndices()[0]
2218 return self.mesh.GetSubMeshElementsId(ShapeID)
2220 ## Returns the list of submesh nodes IDs
2221 # @param Shape a geom object(sub-shape) IOR
2222 # Shape must be the sub-shape of a ShapeToMesh()
2223 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2224 # @return the list of integer values
2225 # @ingroup l1_meshinfo
2226 def GetSubMeshNodesId(self, Shape, all):
2227 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2228 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2231 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2233 ## Returns type of elements on given shape
2234 # @param Shape a geom object(sub-shape) IOR
2235 # Shape must be a sub-shape of a ShapeToMesh()
2236 # @return element type
2237 # @ingroup l1_meshinfo
2238 def GetSubMeshElementType(self, Shape):
2239 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2240 ShapeID = Shape.GetSubShapeIndices()[0]
2243 return self.mesh.GetSubMeshElementType(ShapeID)
2245 ## Gets the mesh description
2246 # @return string value
2247 # @ingroup l1_meshinfo
2249 return self.mesh.Dump()
2252 # Get the information about nodes and elements of a mesh by its IDs:
2253 # -----------------------------------------------------------
2255 ## Gets XYZ coordinates of a node
2256 # \n If there is no nodes for the given ID - returns an empty list
2257 # @return a list of double precision values
2258 # @ingroup l1_meshinfo
2259 def GetNodeXYZ(self, id):
2260 return self.mesh.GetNodeXYZ(id)
2262 ## Returns list of IDs of inverse elements for the given node
2263 # \n If there is no node for the given ID - returns an empty list
2264 # @return a list of integer values
2265 # @ingroup l1_meshinfo
2266 def GetNodeInverseElements(self, id):
2267 return self.mesh.GetNodeInverseElements(id)
2269 ## @brief Returns the position of a node on the shape
2270 # @return SMESH::NodePosition
2271 # @ingroup l1_meshinfo
2272 def GetNodePosition(self,NodeID):
2273 return self.mesh.GetNodePosition(NodeID)
2275 ## @brief Returns the position of an element on the shape
2276 # @return SMESH::ElementPosition
2277 # @ingroup l1_meshinfo
2278 def GetElementPosition(self,ElemID):
2279 return self.mesh.GetElementPosition(ElemID)
2281 ## If the given element is a node, returns the ID of shape
2282 # \n If there is no node for the given ID - returns -1
2283 # @return an integer value
2284 # @ingroup l1_meshinfo
2285 def GetShapeID(self, id):
2286 return self.mesh.GetShapeID(id)
2288 ## Returns the ID of the result shape after
2289 # FindShape() from SMESH_MeshEditor for the given element
2290 # \n If there is no element for the given ID - returns -1
2291 # @return an integer value
2292 # @ingroup l1_meshinfo
2293 def GetShapeIDForElem(self,id):
2294 return self.mesh.GetShapeIDForElem(id)
2296 ## Returns the number of nodes for the given element
2297 # \n If there is no element for the given ID - returns -1
2298 # @return an integer value
2299 # @ingroup l1_meshinfo
2300 def GetElemNbNodes(self, id):
2301 return self.mesh.GetElemNbNodes(id)
2303 ## Returns the node ID the given (zero based) index for the given element
2304 # \n If there is no element for the given ID - returns -1
2305 # \n If there is no node for the given index - returns -2
2306 # @return an integer value
2307 # @ingroup l1_meshinfo
2308 def GetElemNode(self, id, index):
2309 return self.mesh.GetElemNode(id, index)
2311 ## Returns the IDs of nodes of the given element
2312 # @return a list of integer values
2313 # @ingroup l1_meshinfo
2314 def GetElemNodes(self, id):
2315 return self.mesh.GetElemNodes(id)
2317 ## Returns true if the given node is the medium node in the given quadratic element
2318 # @ingroup l1_meshinfo
2319 def IsMediumNode(self, elementID, nodeID):
2320 return self.mesh.IsMediumNode(elementID, nodeID)
2322 ## Returns true if the given node is the medium node in one of quadratic elements
2323 # @ingroup l1_meshinfo
2324 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2325 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2327 ## Returns the number of edges for the given element
2328 # @ingroup l1_meshinfo
2329 def ElemNbEdges(self, id):
2330 return self.mesh.ElemNbEdges(id)
2332 ## Returns the number of faces for the given element
2333 # @ingroup l1_meshinfo
2334 def ElemNbFaces(self, id):
2335 return self.mesh.ElemNbFaces(id)
2337 ## Returns nodes of given face (counted from zero) for given volumic element.
2338 # @ingroup l1_meshinfo
2339 def GetElemFaceNodes(self,elemId, faceIndex):
2340 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2342 ## Returns an element based on all given nodes.
2343 # @ingroup l1_meshinfo
2344 def FindElementByNodes(self,nodes):
2345 return self.mesh.FindElementByNodes(nodes)
2347 ## Returns true if the given element is a polygon
2348 # @ingroup l1_meshinfo
2349 def IsPoly(self, id):
2350 return self.mesh.IsPoly(id)
2352 ## Returns true if the given element is quadratic
2353 # @ingroup l1_meshinfo
2354 def IsQuadratic(self, id):
2355 return self.mesh.IsQuadratic(id)
2357 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2358 # @ingroup l1_meshinfo
2359 def GetBallDiameter(self, id):
2360 return self.mesh.GetBallDiameter(id)
2362 ## Returns XYZ coordinates of the barycenter of the given element
2363 # \n If there is no element for the given ID - returns an empty list
2364 # @return a list of three double values
2365 # @ingroup l1_meshinfo
2366 def BaryCenter(self, id):
2367 return self.mesh.BaryCenter(id)
2369 ## Passes mesh elements through the given filter and return IDs of fitting elements
2370 # @param theFilter SMESH_Filter
2371 # @return a list of ids
2372 # @ingroup l1_controls
2373 def GetIdsFromFilter(self, theFilter):
2374 theFilter.SetMesh( self.mesh )
2375 return theFilter.GetIDs()
2377 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2378 # Returns a list of special structures (borders).
2379 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2380 # @ingroup l1_controls
2381 def GetFreeBorders(self):
2382 aFilterMgr = self.smeshpyD.CreateFilterManager()
2383 aPredicate = aFilterMgr.CreateFreeEdges()
2384 aPredicate.SetMesh(self.mesh)
2385 aBorders = aPredicate.GetBorders()
2386 aFilterMgr.UnRegister()
2390 # Get mesh measurements information:
2391 # ------------------------------------
2393 ## Get minimum distance between two nodes, elements or distance to the origin
2394 # @param id1 first node/element id
2395 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2396 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2397 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2398 # @return minimum distance value
2399 # @sa GetMinDistance()
2400 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2401 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2402 return aMeasure.value
2404 ## Get measure structure specifying minimum distance data between two objects
2405 # @param id1 first node/element id
2406 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2407 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2408 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2409 # @return Measure structure
2411 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2413 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2415 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2418 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2420 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2425 aMeasurements = self.smeshpyD.CreateMeasurements()
2426 aMeasure = aMeasurements.MinDistance(id1, id2)
2427 aMeasurements.UnRegister()
2430 ## Get bounding box of the specified object(s)
2431 # @param objects single source object or list of source objects or list of nodes/elements IDs
2432 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2433 # @c False specifies that @a objects are nodes
2434 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2435 # @sa GetBoundingBox()
2436 def BoundingBox(self, objects=None, isElem=False):
2437 result = self.GetBoundingBox(objects, isElem)
2441 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2444 ## Get measure structure specifying bounding box data of the specified object(s)
2445 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2446 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2447 # @c False specifies that @a objects are nodes
2448 # @return Measure structure
2450 def GetBoundingBox(self, IDs=None, isElem=False):
2453 elif isinstance(IDs, tuple):
2455 if not isinstance(IDs, list):
2457 if len(IDs) > 0 and isinstance(IDs[0], int):
2461 if isinstance(o, Mesh):
2462 srclist.append(o.mesh)
2463 elif hasattr(o, "_narrow"):
2464 src = o._narrow(SMESH.SMESH_IDSource)
2465 if src: srclist.append(src)
2467 elif isinstance(o, list):
2469 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2471 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2474 aMeasurements = self.smeshpyD.CreateMeasurements()
2475 aMeasure = aMeasurements.BoundingBox(srclist)
2476 aMeasurements.UnRegister()
2479 # Mesh edition (SMESH_MeshEditor functionality):
2480 # ---------------------------------------------
2482 ## Removes the elements from the mesh by ids
2483 # @param IDsOfElements is a list of ids of elements to remove
2484 # @return True or False
2485 # @ingroup l2_modif_del
2486 def RemoveElements(self, IDsOfElements):
2487 return self.editor.RemoveElements(IDsOfElements)
2489 ## Removes nodes from mesh by ids
2490 # @param IDsOfNodes is a list of ids of nodes to remove
2491 # @return True or False
2492 # @ingroup l2_modif_del
2493 def RemoveNodes(self, IDsOfNodes):
2494 return self.editor.RemoveNodes(IDsOfNodes)
2496 ## Removes all orphan (free) nodes from mesh
2497 # @return number of the removed nodes
2498 # @ingroup l2_modif_del
2499 def RemoveOrphanNodes(self):
2500 return self.editor.RemoveOrphanNodes()
2502 ## Add a node to the mesh by coordinates
2503 # @return Id of the new node
2504 # @ingroup l2_modif_add
2505 def AddNode(self, x, y, z):
2506 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2507 if hasVars: self.mesh.SetParameters(Parameters)
2508 return self.editor.AddNode( x, y, z)
2510 ## Creates a 0D element on a node with given number.
2511 # @param IDOfNode the ID of node for creation of the element.
2512 # @return the Id of the new 0D element
2513 # @ingroup l2_modif_add
2514 def Add0DElement(self, IDOfNode):
2515 return self.editor.Add0DElement(IDOfNode)
2517 ## Create 0D elements on all nodes of the given elements except those
2518 # nodes on which a 0D element already exists.
2519 # @param theObject an object on whose nodes 0D elements will be created.
2520 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2521 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2522 # @param theGroupName optional name of a group to add 0D elements created
2523 # and/or found on nodes of \a theObject.
2524 # @return an object (a new group or a temporary SMESH_IDSource) holding
2525 # IDs of new and/or found 0D elements. IDs of 0D elements
2526 # can be retrieved from the returned object by calling GetIDs()
2527 # @ingroup l2_modif_add
2528 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2529 if isinstance( theObject, Mesh ):
2530 theObject = theObject.GetMesh()
2531 if isinstance( theObject, list ):
2532 theObject = self.GetIDSource( theObject, SMESH.ALL )
2533 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2535 ## Creates a ball element on a node with given ID.
2536 # @param IDOfNode the ID of node for creation of the element.
2537 # @param diameter the bal diameter.
2538 # @return the Id of the new ball element
2539 # @ingroup l2_modif_add
2540 def AddBall(self, IDOfNode, diameter):
2541 return self.editor.AddBall( IDOfNode, diameter )
2543 ## Creates a linear or quadratic edge (this is determined
2544 # by the number of given nodes).
2545 # @param IDsOfNodes the list of node IDs for creation of the element.
2546 # The order of nodes in this list should correspond to the description
2547 # of MED. \n This description is located by the following link:
2548 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2549 # @return the Id of the new edge
2550 # @ingroup l2_modif_add
2551 def AddEdge(self, IDsOfNodes):
2552 return self.editor.AddEdge(IDsOfNodes)
2554 ## Creates a linear or quadratic face (this is determined
2555 # by the number of given nodes).
2556 # @param IDsOfNodes the list of node IDs for creation of the element.
2557 # The order of nodes in this list should correspond to the description
2558 # of MED. \n This description is located by the following link:
2559 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2560 # @return the Id of the new face
2561 # @ingroup l2_modif_add
2562 def AddFace(self, IDsOfNodes):
2563 return self.editor.AddFace(IDsOfNodes)
2565 ## Adds a polygonal face to the mesh by the list of node IDs
2566 # @param IdsOfNodes the list of node IDs for creation of the element.
2567 # @return the Id of the new face
2568 # @ingroup l2_modif_add
2569 def AddPolygonalFace(self, IdsOfNodes):
2570 return self.editor.AddPolygonalFace(IdsOfNodes)
2572 ## Creates both simple and quadratic volume (this is determined
2573 # by the number of given nodes).
2574 # @param IDsOfNodes the list of node IDs for creation of the element.
2575 # The order of nodes in this list should correspond to the description
2576 # of MED. \n This description is located by the following link:
2577 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2578 # @return the Id of the new volumic element
2579 # @ingroup l2_modif_add
2580 def AddVolume(self, IDsOfNodes):
2581 return self.editor.AddVolume(IDsOfNodes)
2583 ## Creates a volume of many faces, giving nodes for each face.
2584 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2585 # @param Quantities the list of integer values, Quantities[i]
2586 # gives the quantity of nodes in face number i.
2587 # @return the Id of the new volumic element
2588 # @ingroup l2_modif_add
2589 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2590 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2592 ## Creates a volume of many faces, giving the IDs of the existing faces.
2593 # @param IdsOfFaces the list of face IDs for volume creation.
2595 # Note: The created volume will refer only to the nodes
2596 # of the given faces, not to the faces themselves.
2597 # @return the Id of the new volumic element
2598 # @ingroup l2_modif_add
2599 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2600 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2603 ## @brief Binds a node to a vertex
2604 # @param NodeID a node ID
2605 # @param Vertex a vertex or vertex ID
2606 # @return True if succeed else raises an exception
2607 # @ingroup l2_modif_add
2608 def SetNodeOnVertex(self, NodeID, Vertex):
2609 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
2610 VertexID = Vertex.GetSubShapeIndices()[0]
2614 self.editor.SetNodeOnVertex(NodeID, VertexID)
2615 except SALOME.SALOME_Exception, inst:
2616 raise ValueError, inst.details.text
2620 ## @brief Stores the node position on an edge
2621 # @param NodeID a node ID
2622 # @param Edge an edge or edge ID
2623 # @param paramOnEdge a parameter on the edge where the node is located
2624 # @return True if succeed else raises an exception
2625 # @ingroup l2_modif_add
2626 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2627 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
2628 EdgeID = Edge.GetSubShapeIndices()[0]
2632 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2633 except SALOME.SALOME_Exception, inst:
2634 raise ValueError, inst.details.text
2637 ## @brief Stores node position on a face
2638 # @param NodeID a node ID
2639 # @param Face a face or face ID
2640 # @param u U parameter on the face where the node is located
2641 # @param v V parameter on the face where the node is located
2642 # @return True if succeed else raises an exception
2643 # @ingroup l2_modif_add
2644 def SetNodeOnFace(self, NodeID, Face, u, v):
2645 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
2646 FaceID = Face.GetSubShapeIndices()[0]
2650 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2651 except SALOME.SALOME_Exception, inst:
2652 raise ValueError, inst.details.text
2655 ## @brief Binds a node to a solid
2656 # @param NodeID a node ID
2657 # @param Solid a solid or solid ID
2658 # @return True if succeed else raises an exception
2659 # @ingroup l2_modif_add
2660 def SetNodeInVolume(self, NodeID, Solid):
2661 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
2662 SolidID = Solid.GetSubShapeIndices()[0]
2666 self.editor.SetNodeInVolume(NodeID, SolidID)
2667 except SALOME.SALOME_Exception, inst:
2668 raise ValueError, inst.details.text
2671 ## @brief Bind an element to a shape
2672 # @param ElementID an element ID
2673 # @param Shape a shape or shape ID
2674 # @return True if succeed else raises an exception
2675 # @ingroup l2_modif_add
2676 def SetMeshElementOnShape(self, ElementID, Shape):
2677 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2678 ShapeID = Shape.GetSubShapeIndices()[0]
2682 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2683 except SALOME.SALOME_Exception, inst:
2684 raise ValueError, inst.details.text
2688 ## Moves the node with the given id
2689 # @param NodeID the id of the node
2690 # @param x a new X coordinate
2691 # @param y a new Y coordinate
2692 # @param z a new Z coordinate
2693 # @return True if succeed else False
2694 # @ingroup l2_modif_movenode
2695 def MoveNode(self, NodeID, x, y, z):
2696 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2697 if hasVars: self.mesh.SetParameters(Parameters)
2698 return self.editor.MoveNode(NodeID, x, y, z)
2700 ## Finds the node closest to a point and moves it to a point location
2701 # @param x the X coordinate of a point
2702 # @param y the Y coordinate of a point
2703 # @param z the Z coordinate of a point
2704 # @param NodeID if specified (>0), the node with this ID is moved,
2705 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2706 # @return the ID of a node
2707 # @ingroup l2_modif_throughp
2708 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2709 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2710 if hasVars: self.mesh.SetParameters(Parameters)
2711 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2713 ## Finds the node closest to a point
2714 # @param x the X coordinate of a point
2715 # @param y the Y coordinate of a point
2716 # @param z the Z coordinate of a point
2717 # @return the ID of a node
2718 # @ingroup l2_modif_throughp
2719 def FindNodeClosestTo(self, x, y, z):
2720 #preview = self.mesh.GetMeshEditPreviewer()
2721 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2722 return self.editor.FindNodeClosestTo(x, y, z)
2724 ## Finds the elements where a point lays IN or ON
2725 # @param x the X coordinate of a point
2726 # @param y the Y coordinate of a point
2727 # @param z the Z coordinate of a point
2728 # @param elementType type of elements to find (SMESH.ALL type
2729 # means elements of any type excluding nodes, discrete and 0D elements)
2730 # @param meshPart a part of mesh (group, sub-mesh) to search within
2731 # @return list of IDs of found elements
2732 # @ingroup l2_modif_throughp
2733 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2735 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2737 return self.editor.FindElementsByPoint(x, y, z, elementType)
2739 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2740 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2741 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2743 def GetPointState(self, x, y, z):
2744 return self.editor.GetPointState(x, y, z)
2746 ## Finds the node closest to a point and moves it to a point location
2747 # @param x the X coordinate of a point
2748 # @param y the Y coordinate of a point
2749 # @param z the Z coordinate of a point
2750 # @return the ID of a moved node
2751 # @ingroup l2_modif_throughp
2752 def MeshToPassThroughAPoint(self, x, y, z):
2753 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2755 ## Replaces two neighbour triangles sharing Node1-Node2 link
2756 # with the triangles built on the same 4 nodes but having other common link.
2757 # @param NodeID1 the ID of the first node
2758 # @param NodeID2 the ID of the second node
2759 # @return false if proper faces were not found
2760 # @ingroup l2_modif_invdiag
2761 def InverseDiag(self, NodeID1, NodeID2):
2762 return self.editor.InverseDiag(NodeID1, NodeID2)
2764 ## Replaces two neighbour triangles sharing Node1-Node2 link
2765 # with a quadrangle built on the same 4 nodes.
2766 # @param NodeID1 the ID of the first node
2767 # @param NodeID2 the ID of the second node
2768 # @return false if proper faces were not found
2769 # @ingroup l2_modif_unitetri
2770 def DeleteDiag(self, NodeID1, NodeID2):
2771 return self.editor.DeleteDiag(NodeID1, NodeID2)
2773 ## Reorients elements by ids
2774 # @param IDsOfElements if undefined reorients all mesh elements
2775 # @return True if succeed else False
2776 # @ingroup l2_modif_changori
2777 def Reorient(self, IDsOfElements=None):
2778 if IDsOfElements == None:
2779 IDsOfElements = self.GetElementsId()
2780 return self.editor.Reorient(IDsOfElements)
2782 ## Reorients all elements of the object
2783 # @param theObject mesh, submesh or group
2784 # @return True if succeed else False
2785 # @ingroup l2_modif_changori
2786 def ReorientObject(self, theObject):
2787 if ( isinstance( theObject, Mesh )):
2788 theObject = theObject.GetMesh()
2789 return self.editor.ReorientObject(theObject)
2791 ## Reorient faces contained in \a the2DObject.
2792 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2793 # @param theDirection is a desired direction of normal of \a theFace.
2794 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2795 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2796 # compared with theDirection. It can be either ID of face or a point
2797 # by which the face will be found. The point can be given as either
2798 # a GEOM vertex or a list of point coordinates.
2799 # @return number of reoriented faces
2800 # @ingroup l2_modif_changori
2801 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2803 if isinstance( the2DObject, Mesh ):
2804 the2DObject = the2DObject.GetMesh()
2805 if isinstance( the2DObject, list ):
2806 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2807 # check theDirection
2808 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
2809 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2810 if isinstance( theDirection, list ):
2811 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2812 # prepare theFace and thePoint
2813 theFace = theFaceOrPoint
2814 thePoint = PointStruct(0,0,0)
2815 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
2816 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2818 if isinstance( theFaceOrPoint, list ):
2819 thePoint = PointStruct( *theFaceOrPoint )
2821 if isinstance( theFaceOrPoint, PointStruct ):
2822 thePoint = theFaceOrPoint
2824 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2826 ## Fuses the neighbouring triangles into quadrangles.
2827 # @param IDsOfElements The triangles to be fused,
2828 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2829 # choose a neighbour to fuse with.
2830 # @param MaxAngle is the maximum angle between element normals at which the fusion
2831 # is still performed; theMaxAngle is mesured in radians.
2832 # Also it could be a name of variable which defines angle in degrees.
2833 # @return TRUE in case of success, FALSE otherwise.
2834 # @ingroup l2_modif_unitetri
2835 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2836 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2837 self.mesh.SetParameters(Parameters)
2838 if not IDsOfElements:
2839 IDsOfElements = self.GetElementsId()
2840 Functor = self.smeshpyD.GetFunctor(theCriterion)
2841 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2843 ## Fuses the neighbouring triangles of the object into quadrangles
2844 # @param theObject is mesh, submesh or group
2845 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2846 # choose a neighbour to fuse with.
2847 # @param MaxAngle a max angle between element normals at which the fusion
2848 # is still performed; theMaxAngle is mesured in radians.
2849 # @return TRUE in case of success, FALSE otherwise.
2850 # @ingroup l2_modif_unitetri
2851 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2852 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2853 self.mesh.SetParameters(Parameters)
2854 if isinstance( theObject, Mesh ):
2855 theObject = theObject.GetMesh()
2856 Functor = self.smeshpyD.GetFunctor(theCriterion)
2857 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2859 ## Splits quadrangles into triangles.
2860 # @param IDsOfElements the faces to be splitted.
2861 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2862 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2863 # value, then quadrangles will be split by the smallest diagonal.
2864 # @return TRUE in case of success, FALSE otherwise.
2865 # @ingroup l2_modif_cutquadr
2866 def QuadToTri (self, IDsOfElements, theCriterion = None):
2867 if IDsOfElements == []:
2868 IDsOfElements = self.GetElementsId()
2869 if theCriterion is None:
2870 theCriterion = FT_MaxElementLength2D
2871 Functor = self.smeshpyD.GetFunctor(theCriterion)
2872 return self.editor.QuadToTri(IDsOfElements, Functor)
2874 ## Splits quadrangles into triangles.
2875 # @param theObject the object from which the list of elements is taken,
2876 # this is mesh, submesh or group
2877 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2878 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2879 # value, then quadrangles will be split by the smallest diagonal.
2880 # @return TRUE in case of success, FALSE otherwise.
2881 # @ingroup l2_modif_cutquadr
2882 def QuadToTriObject (self, theObject, theCriterion = None):
2883 if ( isinstance( theObject, Mesh )):
2884 theObject = theObject.GetMesh()
2885 if theCriterion is None:
2886 theCriterion = FT_MaxElementLength2D
2887 Functor = self.smeshpyD.GetFunctor(theCriterion)
2888 return self.editor.QuadToTriObject(theObject, Functor)
2890 ## Splits each of given quadrangles into 4 triangles. A node is added at the center of
2892 # @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
2893 # group or a list of face IDs. By default all quadrangles are split
2894 # @ingroup l2_modif_cutquadr
2895 def QuadTo4Tri (self, theElements=[]):
2896 if isinstance( theElements, Mesh ):
2897 theElements = theElements.mesh
2898 elif not theElements:
2899 theElements = self.mesh
2900 elif isinstance( theElements, list ):
2901 theElements = self.GetIDSource( theElements, SMESH.FACE )
2902 return self.editor.QuadTo4Tri( theElements )
2904 ## Splits quadrangles into triangles.
2905 # @param IDsOfElements the faces to be splitted
2906 # @param Diag13 is used to choose a diagonal for splitting.
2907 # @return TRUE in case of success, FALSE otherwise.
2908 # @ingroup l2_modif_cutquadr
2909 def SplitQuad (self, IDsOfElements, Diag13):
2910 if IDsOfElements == []:
2911 IDsOfElements = self.GetElementsId()
2912 return self.editor.SplitQuad(IDsOfElements, Diag13)
2914 ## Splits quadrangles into triangles.
2915 # @param theObject the object from which the list of elements is taken,
2916 # this is mesh, submesh or group
2917 # @param Diag13 is used to choose a diagonal for splitting.
2918 # @return TRUE in case of success, FALSE otherwise.
2919 # @ingroup l2_modif_cutquadr
2920 def SplitQuadObject (self, theObject, Diag13):
2921 if ( isinstance( theObject, Mesh )):
2922 theObject = theObject.GetMesh()
2923 return self.editor.SplitQuadObject(theObject, Diag13)
2925 ## Finds a better splitting of the given quadrangle.
2926 # @param IDOfQuad the ID of the quadrangle to be splitted.
2927 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2928 # choose a diagonal for splitting.
2929 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2930 # diagonal is better, 0 if error occurs.
2931 # @ingroup l2_modif_cutquadr
2932 def BestSplit (self, IDOfQuad, theCriterion):
2933 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2935 ## Splits volumic elements into tetrahedrons
2936 # @param elemIDs either list of elements or mesh or group or submesh
2937 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2938 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2939 # @ingroup l2_modif_cutquadr
2940 def SplitVolumesIntoTetra(self, elemIDs, method=smeshBuilder.Hex_5Tet ):
2941 if isinstance( elemIDs, Mesh ):
2942 elemIDs = elemIDs.GetMesh()
2943 if ( isinstance( elemIDs, list )):
2944 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2945 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2947 ## Splits quadrangle faces near triangular facets of volumes
2949 # @ingroup l1_auxiliary
2950 def SplitQuadsNearTriangularFacets(self):
2951 faces_array = self.GetElementsByType(SMESH.FACE)
2952 for face_id in faces_array:
2953 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2954 quad_nodes = self.mesh.GetElemNodes(face_id)
2955 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2956 isVolumeFound = False
2957 for node1_elem in node1_elems:
2958 if not isVolumeFound:
2959 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2960 nb_nodes = self.GetElemNbNodes(node1_elem)
2961 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2962 volume_elem = node1_elem
2963 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2964 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2965 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2966 isVolumeFound = True
2967 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2968 self.SplitQuad([face_id], False) # diagonal 2-4
2969 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2970 isVolumeFound = True
2971 self.SplitQuad([face_id], True) # diagonal 1-3
2972 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2973 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2974 isVolumeFound = True
2975 self.SplitQuad([face_id], True) # diagonal 1-3
2977 ## @brief Splits hexahedrons into tetrahedrons.
2979 # This operation uses pattern mapping functionality for splitting.
2980 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2981 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2982 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2983 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2984 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2985 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2986 # @return TRUE in case of success, FALSE otherwise.
2987 # @ingroup l1_auxiliary
2988 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2989 # Pattern: 5.---------.6
2994 # (0,0,1) 4.---------.7 * |
3001 # (0,0,0) 0.---------.3
3002 pattern_tetra = "!!! Nb of points: \n 8 \n\
3012 !!! Indices of points of 6 tetras: \n\
3020 pattern = self.smeshpyD.GetPattern()
3021 isDone = pattern.LoadFromFile(pattern_tetra)
3023 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3026 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3027 isDone = pattern.MakeMesh(self.mesh, False, False)
3028 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3030 # split quafrangle faces near triangular facets of volumes
3031 self.SplitQuadsNearTriangularFacets()
3035 ## @brief Split hexahedrons into prisms.
3037 # Uses the pattern mapping functionality for splitting.
3038 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
3039 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
3040 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
3041 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
3042 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
3043 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
3044 # @return TRUE in case of success, FALSE otherwise.
3045 # @ingroup l1_auxiliary
3046 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3047 # Pattern: 5.---------.6
3052 # (0,0,1) 4.---------.7 |
3059 # (0,0,0) 0.---------.3
3060 pattern_prism = "!!! Nb of points: \n 8 \n\
3070 !!! Indices of points of 2 prisms: \n\
3074 pattern = self.smeshpyD.GetPattern()
3075 isDone = pattern.LoadFromFile(pattern_prism)
3077 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3080 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3081 isDone = pattern.MakeMesh(self.mesh, False, False)
3082 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3084 # Splits quafrangle faces near triangular facets of volumes
3085 self.SplitQuadsNearTriangularFacets()
3089 ## Smoothes elements
3090 # @param IDsOfElements the list if ids of elements to smooth
3091 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3092 # Note that nodes built on edges and boundary nodes are always fixed.
3093 # @param MaxNbOfIterations the maximum number of iterations
3094 # @param MaxAspectRatio varies in range [1.0, inf]
3095 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3096 # @return TRUE in case of success, FALSE otherwise.
3097 # @ingroup l2_modif_smooth
3098 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3099 MaxNbOfIterations, MaxAspectRatio, Method):
3100 if IDsOfElements == []:
3101 IDsOfElements = self.GetElementsId()
3102 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3103 self.mesh.SetParameters(Parameters)
3104 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3105 MaxNbOfIterations, MaxAspectRatio, Method)
3107 ## Smoothes elements which belong to the given object
3108 # @param theObject the object to smooth
3109 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3110 # Note that nodes built on edges and boundary nodes are always fixed.
3111 # @param MaxNbOfIterations the maximum number of iterations
3112 # @param MaxAspectRatio varies in range [1.0, inf]
3113 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3114 # @return TRUE in case of success, FALSE otherwise.
3115 # @ingroup l2_modif_smooth
3116 def SmoothObject(self, theObject, IDsOfFixedNodes,
3117 MaxNbOfIterations, MaxAspectRatio, Method):
3118 if ( isinstance( theObject, Mesh )):
3119 theObject = theObject.GetMesh()
3120 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3121 MaxNbOfIterations, MaxAspectRatio, Method)
3123 ## Parametrically smoothes the given elements
3124 # @param IDsOfElements the list if ids of elements to smooth
3125 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3126 # Note that nodes built on edges and boundary nodes are always fixed.
3127 # @param MaxNbOfIterations the maximum number of iterations
3128 # @param MaxAspectRatio varies in range [1.0, inf]
3129 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3130 # @return TRUE in case of success, FALSE otherwise.
3131 # @ingroup l2_modif_smooth
3132 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3133 MaxNbOfIterations, MaxAspectRatio, Method):
3134 if IDsOfElements == []:
3135 IDsOfElements = self.GetElementsId()
3136 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3137 self.mesh.SetParameters(Parameters)
3138 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3139 MaxNbOfIterations, MaxAspectRatio, Method)
3141 ## Parametrically smoothes the elements which belong to the given object
3142 # @param theObject the object to smooth
3143 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3144 # Note that nodes built on edges and boundary nodes are always fixed.
3145 # @param MaxNbOfIterations the maximum number of iterations
3146 # @param MaxAspectRatio varies in range [1.0, inf]
3147 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3148 # @return TRUE in case of success, FALSE otherwise.
3149 # @ingroup l2_modif_smooth
3150 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3151 MaxNbOfIterations, MaxAspectRatio, Method):
3152 if ( isinstance( theObject, Mesh )):
3153 theObject = theObject.GetMesh()
3154 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3155 MaxNbOfIterations, MaxAspectRatio, Method)
3157 ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3158 # them with quadratic with the same id.
3159 # @param theForce3d new node creation method:
3160 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3161 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3162 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3163 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3164 # @ingroup l2_modif_tofromqu
3165 def ConvertToQuadratic(self, theForce3d, theSubMesh=None, theToBiQuad=False):
3166 if isinstance( theSubMesh, Mesh ):
3167 theSubMesh = theSubMesh.mesh
3169 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3172 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3174 self.editor.ConvertToQuadratic(theForce3d)
3175 error = self.editor.GetLastError()
3176 if error and error.comment:
3179 ## Converts the mesh from quadratic to ordinary,
3180 # deletes old quadratic elements, \n replacing
3181 # them with ordinary mesh elements with the same id.
3182 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3183 # @ingroup l2_modif_tofromqu
3184 def ConvertFromQuadratic(self, theSubMesh=None):
3186 self.editor.ConvertFromQuadraticObject(theSubMesh)
3188 return self.editor.ConvertFromQuadratic()
3190 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3191 # @return TRUE if operation has been completed successfully, FALSE otherwise
3192 # @ingroup l2_modif_edit
3193 def Make2DMeshFrom3D(self):
3194 return self.editor. Make2DMeshFrom3D()
3196 ## Creates missing boundary elements
3197 # @param elements - elements whose boundary is to be checked:
3198 # mesh, group, sub-mesh or list of elements
3199 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3200 # @param dimension - defines type of boundary elements to create:
3201 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3202 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3203 # @param groupName - a name of group to store created boundary elements in,
3204 # "" means not to create the group
3205 # @param meshName - a name of new mesh to store created boundary elements in,
3206 # "" means not to create the new mesh
3207 # @param toCopyElements - if true, the checked elements will be copied into
3208 # the new mesh else only boundary elements will be copied into the new mesh
3209 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3210 # boundary elements will be copied into the new mesh
3211 # @return tuple (mesh, group) where bondary elements were added to
3212 # @ingroup l2_modif_edit
3213 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3214 toCopyElements=False, toCopyExistingBondary=False):
3215 if isinstance( elements, Mesh ):
3216 elements = elements.GetMesh()
3217 if ( isinstance( elements, list )):
3218 elemType = SMESH.ALL
3219 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3220 elements = self.editor.MakeIDSource(elements, elemType)
3221 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3222 toCopyElements,toCopyExistingBondary)
3223 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3227 # @brief Creates missing boundary elements around either the whole mesh or
3228 # groups of 2D elements
3229 # @param dimension - defines type of boundary elements to create
3230 # @param groupName - a name of group to store all boundary elements in,
3231 # "" means not to create the group
3232 # @param meshName - a name of a new mesh, which is a copy of the initial
3233 # mesh + created boundary elements; "" means not to create the new mesh
3234 # @param toCopyAll - if true, the whole initial mesh will be copied into
3235 # the new mesh else only boundary elements will be copied into the new mesh
3236 # @param groups - groups of 2D elements to make boundary around
3237 # @retval tuple( long, mesh, groups )
3238 # long - number of added boundary elements
3239 # mesh - the mesh where elements were added to
3240 # group - the group of boundary elements or None
3242 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3243 toCopyAll=False, groups=[]):
3244 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3246 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3247 return nb, mesh, group
3249 ## Renumber mesh nodes
3250 # @ingroup l2_modif_renumber
3251 def RenumberNodes(self):
3252 self.editor.RenumberNodes()
3254 ## Renumber mesh elements
3255 # @ingroup l2_modif_renumber
3256 def RenumberElements(self):
3257 self.editor.RenumberElements()
3259 ## Generates new elements by rotation of the elements around the axis
3260 # @param IDsOfElements the list of ids of elements to sweep
3261 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3262 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3263 # @param NbOfSteps the number of steps
3264 # @param Tolerance tolerance
3265 # @param MakeGroups forces the generation of new groups from existing ones
3266 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3267 # of all steps, else - size of each step
3268 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3269 # @ingroup l2_modif_extrurev
3270 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3271 MakeGroups=False, TotalAngle=False):
3272 if IDsOfElements == []:
3273 IDsOfElements = self.GetElementsId()
3274 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3275 Axis = self.smeshpyD.GetAxisStruct(Axis)
3276 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3277 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3278 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3279 self.mesh.SetParameters(Parameters)
3280 if TotalAngle and NbOfSteps:
3281 AngleInRadians /= NbOfSteps
3283 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3284 AngleInRadians, NbOfSteps, Tolerance)
3285 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3288 ## Generates new elements by rotation of the elements of object around the axis
3289 # @param theObject object which elements should be sweeped.
3290 # It can be a mesh, a sub mesh or a group.
3291 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3292 # @param AngleInRadians the angle of Rotation
3293 # @param NbOfSteps number of steps
3294 # @param Tolerance tolerance
3295 # @param MakeGroups forces the generation of new groups from existing ones
3296 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3297 # of all steps, else - size of each step
3298 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3299 # @ingroup l2_modif_extrurev
3300 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3301 MakeGroups=False, TotalAngle=False):
3302 if ( isinstance( theObject, Mesh )):
3303 theObject = theObject.GetMesh()
3304 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3305 Axis = self.smeshpyD.GetAxisStruct(Axis)
3306 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3307 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3308 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3309 self.mesh.SetParameters(Parameters)
3310 if TotalAngle and NbOfSteps:
3311 AngleInRadians /= NbOfSteps
3313 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3314 NbOfSteps, Tolerance)
3315 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3318 ## Generates new elements by rotation of the elements of object around the axis
3319 # @param theObject object which elements should be sweeped.
3320 # It can be a mesh, a sub mesh or a group.
3321 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3322 # @param AngleInRadians the angle of Rotation
3323 # @param NbOfSteps number of steps
3324 # @param Tolerance tolerance
3325 # @param MakeGroups forces the generation of new groups from existing ones
3326 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3327 # of all steps, else - size of each step
3328 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3329 # @ingroup l2_modif_extrurev
3330 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3331 MakeGroups=False, TotalAngle=False):
3332 if ( isinstance( theObject, Mesh )):
3333 theObject = theObject.GetMesh()
3334 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3335 Axis = self.smeshpyD.GetAxisStruct(Axis)
3336 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3337 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3338 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3339 self.mesh.SetParameters(Parameters)
3340 if TotalAngle and NbOfSteps:
3341 AngleInRadians /= NbOfSteps
3343 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3344 NbOfSteps, Tolerance)
3345 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3348 ## Generates new elements by rotation of the elements of object around the axis
3349 # @param theObject object which elements should be sweeped.
3350 # It can be a mesh, a sub mesh or a group.
3351 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3352 # @param AngleInRadians the angle of Rotation
3353 # @param NbOfSteps number of steps
3354 # @param Tolerance tolerance
3355 # @param MakeGroups forces the generation of new groups from existing ones
3356 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3357 # of all steps, else - size of each step
3358 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3359 # @ingroup l2_modif_extrurev
3360 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3361 MakeGroups=False, TotalAngle=False):
3362 if ( isinstance( theObject, Mesh )):
3363 theObject = theObject.GetMesh()
3364 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3365 Axis = self.smeshpyD.GetAxisStruct(Axis)
3366 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3367 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3368 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3369 self.mesh.SetParameters(Parameters)
3370 if TotalAngle and NbOfSteps:
3371 AngleInRadians /= NbOfSteps
3373 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3374 NbOfSteps, Tolerance)
3375 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3378 ## Generates new elements by extrusion of the elements with given ids
3379 # @param IDsOfElements the list of elements ids for extrusion
3380 # @param StepVector vector or DirStruct or 3 vector components, defining
3381 # the direction and value of extrusion for one step (the total extrusion
3382 # length will be NbOfSteps * ||StepVector||)
3383 # @param NbOfSteps the number of steps
3384 # @param MakeGroups forces the generation of new groups from existing ones
3385 # @param IsNodes is True if elements with given ids are nodes
3386 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3387 # @ingroup l2_modif_extrurev
3388 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3389 if IDsOfElements == []:
3390 IDsOfElements = self.GetElementsId()
3391 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3392 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3393 if isinstance( StepVector, list ):
3394 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3395 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3396 Parameters = StepVector.PS.parameters + var_separator + Parameters
3397 self.mesh.SetParameters(Parameters)
3400 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3402 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3404 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3406 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3409 ## Generates new elements by extrusion of the elements with given ids
3410 # @param IDsOfElements is ids of elements
3411 # @param StepVector vector or DirStruct or 3 vector components, defining
3412 # the direction and value of extrusion for one step (the total extrusion
3413 # length will be NbOfSteps * ||StepVector||)
3414 # @param NbOfSteps the number of steps
3415 # @param ExtrFlags sets flags for extrusion
3416 # @param SewTolerance uses for comparing locations of nodes if flag
3417 # EXTRUSION_FLAG_SEW is set
3418 # @param MakeGroups forces the generation of new groups from existing ones
3419 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3420 # @ingroup l2_modif_extrurev
3421 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3422 ExtrFlags, SewTolerance, MakeGroups=False):
3423 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3424 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3425 if isinstance( StepVector, list ):
3426 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3428 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3429 ExtrFlags, SewTolerance)
3430 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3431 ExtrFlags, SewTolerance)
3434 ## Generates new elements by extrusion of the elements which belong to the object
3435 # @param theObject the object which elements should be processed.
3436 # It can be a mesh, a sub mesh or a group.
3437 # @param StepVector vector or DirStruct or 3 vector components, defining
3438 # the direction and value of extrusion for one step (the total extrusion
3439 # length will be NbOfSteps * ||StepVector||)
3440 # @param NbOfSteps the number of steps
3441 # @param MakeGroups forces the generation of new groups from existing ones
3442 # @param IsNodes is True if elements which belong to the object are nodes
3443 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3444 # @ingroup l2_modif_extrurev
3445 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3446 if ( isinstance( theObject, Mesh )):
3447 theObject = theObject.GetMesh()
3448 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3449 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3450 if isinstance( StepVector, list ):
3451 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3452 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3453 Parameters = StepVector.PS.parameters + var_separator + Parameters
3454 self.mesh.SetParameters(Parameters)
3457 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3459 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3461 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3463 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3466 ## Generates new elements by extrusion of the elements which belong to the object
3467 # @param theObject object which elements should be processed.
3468 # It can be a mesh, a sub mesh or a group.
3469 # @param StepVector vector or DirStruct or 3 vector components, defining
3470 # the direction and value of extrusion for one step (the total extrusion
3471 # length will be NbOfSteps * ||StepVector||)
3472 # @param NbOfSteps the number of steps
3473 # @param MakeGroups to generate new groups from existing ones
3474 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3475 # @ingroup l2_modif_extrurev
3476 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3477 if ( isinstance( theObject, Mesh )):
3478 theObject = theObject.GetMesh()
3479 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3480 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3481 if isinstance( StepVector, list ):
3482 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3483 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3484 Parameters = StepVector.PS.parameters + var_separator + Parameters
3485 self.mesh.SetParameters(Parameters)
3487 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3488 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3491 ## Generates new elements by extrusion of the elements which belong to the object
3492 # @param theObject object which elements should be processed.
3493 # It can be a mesh, a sub mesh or a group.
3494 # @param StepVector vector or DirStruct or 3 vector components, defining
3495 # the direction and value of extrusion for one step (the total extrusion
3496 # length will be NbOfSteps * ||StepVector||)
3497 # @param NbOfSteps the number of steps
3498 # @param MakeGroups forces the generation of new groups from existing ones
3499 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3500 # @ingroup l2_modif_extrurev
3501 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3502 if ( isinstance( theObject, Mesh )):
3503 theObject = theObject.GetMesh()
3504 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3505 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3506 if isinstance( StepVector, list ):
3507 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3508 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3509 Parameters = StepVector.PS.parameters + var_separator + Parameters
3510 self.mesh.SetParameters(Parameters)
3512 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3513 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3518 ## Generates new elements by extrusion of the given elements
3519 # The path of extrusion must be a meshed edge.
3520 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3521 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3522 # @param NodeStart the start node from Path. Defines the direction of extrusion
3523 # @param HasAngles allows the shape to be rotated around the path
3524 # to get the resulting mesh in a helical fashion
3525 # @param Angles list of angles in radians
3526 # @param LinearVariation forces the computation of rotation angles as linear
3527 # variation of the given Angles along path steps
3528 # @param HasRefPoint allows using the reference point
3529 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3530 # The User can specify any point as the Reference Point.
3531 # @param MakeGroups forces the generation of new groups from existing ones
3532 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3533 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3534 # only SMESH::Extrusion_Error otherwise
3535 # @ingroup l2_modif_extrurev
3536 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3537 HasAngles, Angles, LinearVariation,
3538 HasRefPoint, RefPoint, MakeGroups, ElemType):
3539 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3540 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3542 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3543 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3544 self.mesh.SetParameters(Parameters)
3546 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3548 if isinstance(Base, list):
3550 if Base == []: IDsOfElements = self.GetElementsId()
3551 else: IDsOfElements = Base
3552 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3553 HasAngles, Angles, LinearVariation,
3554 HasRefPoint, RefPoint, MakeGroups, ElemType)
3556 if isinstance(Base, Mesh): Base = Base.GetMesh()
3557 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3558 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3559 HasAngles, Angles, LinearVariation,
3560 HasRefPoint, RefPoint, MakeGroups, ElemType)
3562 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3565 ## Generates new elements by extrusion of the given elements
3566 # The path of extrusion must be a meshed edge.
3567 # @param IDsOfElements ids of elements
3568 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3569 # @param PathShape shape(edge) defines the sub-mesh for the path
3570 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3571 # @param HasAngles allows the shape to be rotated around the path
3572 # to get the resulting mesh in a helical fashion
3573 # @param Angles list of angles in radians
3574 # @param HasRefPoint allows using the reference point
3575 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3576 # The User can specify any point as the Reference Point.
3577 # @param MakeGroups forces the generation of new groups from existing ones
3578 # @param LinearVariation forces the computation of rotation angles as linear
3579 # variation of the given Angles along path steps
3580 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3581 # only SMESH::Extrusion_Error otherwise
3582 # @ingroup l2_modif_extrurev
3583 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3584 HasAngles, Angles, HasRefPoint, RefPoint,
3585 MakeGroups=False, LinearVariation=False):
3586 if IDsOfElements == []:
3587 IDsOfElements = self.GetElementsId()
3588 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3589 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3591 if ( isinstance( PathMesh, Mesh )):
3592 PathMesh = PathMesh.GetMesh()
3593 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3594 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3595 self.mesh.SetParameters(Parameters)
3596 if HasAngles and Angles and LinearVariation:
3597 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3600 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3601 PathShape, NodeStart, HasAngles,
3602 Angles, HasRefPoint, RefPoint)
3603 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3604 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3606 ## Generates new elements by extrusion of the elements which belong to the object
3607 # The path of extrusion must be a meshed edge.
3608 # @param theObject the object which elements should be processed.
3609 # It can be a mesh, a sub mesh or a group.
3610 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3611 # @param PathShape shape(edge) defines the sub-mesh for the path
3612 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3613 # @param HasAngles allows the shape to be rotated around the path
3614 # to get the resulting mesh in a helical fashion
3615 # @param Angles list of angles
3616 # @param HasRefPoint allows using the reference point
3617 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3618 # The User can specify any point as the Reference Point.
3619 # @param MakeGroups forces the generation of new groups from existing ones
3620 # @param LinearVariation forces the computation of rotation angles as linear
3621 # variation of the given Angles along path steps
3622 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3623 # only SMESH::Extrusion_Error otherwise
3624 # @ingroup l2_modif_extrurev
3625 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3626 HasAngles, Angles, HasRefPoint, RefPoint,
3627 MakeGroups=False, LinearVariation=False):
3628 if ( isinstance( theObject, Mesh )):
3629 theObject = theObject.GetMesh()
3630 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3631 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3632 if ( isinstance( PathMesh, Mesh )):
3633 PathMesh = PathMesh.GetMesh()
3634 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3635 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3636 self.mesh.SetParameters(Parameters)
3637 if HasAngles and Angles and LinearVariation:
3638 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3641 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3642 PathShape, NodeStart, HasAngles,
3643 Angles, HasRefPoint, RefPoint)
3644 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3645 NodeStart, HasAngles, Angles, HasRefPoint,
3648 ## Generates new elements by extrusion of the elements which belong to the object
3649 # The path of extrusion must be a meshed edge.
3650 # @param theObject the object which elements should be processed.
3651 # It can be a mesh, a sub mesh or a group.
3652 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3653 # @param PathShape shape(edge) defines the sub-mesh for the path
3654 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3655 # @param HasAngles allows the shape to be rotated around the path
3656 # to get the resulting mesh in a helical fashion
3657 # @param Angles list of angles
3658 # @param HasRefPoint allows using the reference point
3659 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3660 # The User can specify any point as the Reference Point.
3661 # @param MakeGroups forces the generation of new groups from existing ones
3662 # @param LinearVariation forces the computation of rotation angles as linear
3663 # variation of the given Angles along path steps
3664 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3665 # only SMESH::Extrusion_Error otherwise
3666 # @ingroup l2_modif_extrurev
3667 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3668 HasAngles, Angles, HasRefPoint, RefPoint,
3669 MakeGroups=False, LinearVariation=False):
3670 if ( isinstance( theObject, Mesh )):
3671 theObject = theObject.GetMesh()
3672 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3673 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3674 if ( isinstance( PathMesh, Mesh )):
3675 PathMesh = PathMesh.GetMesh()
3676 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3677 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3678 self.mesh.SetParameters(Parameters)
3679 if HasAngles and Angles and LinearVariation:
3680 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3683 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3684 PathShape, NodeStart, HasAngles,
3685 Angles, HasRefPoint, RefPoint)
3686 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3687 NodeStart, HasAngles, Angles, HasRefPoint,
3690 ## Generates new elements by extrusion of the elements which belong to the object
3691 # The path of extrusion must be a meshed edge.
3692 # @param theObject the object which elements should be processed.
3693 # It can be a mesh, a sub mesh or a group.
3694 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3695 # @param PathShape shape(edge) defines the sub-mesh for the path
3696 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3697 # @param HasAngles allows the shape to be rotated around the path
3698 # to get the resulting mesh in a helical fashion
3699 # @param Angles list of angles
3700 # @param HasRefPoint allows using the reference point
3701 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3702 # The User can specify any point as the Reference Point.
3703 # @param MakeGroups forces the generation of new groups from existing ones
3704 # @param LinearVariation forces the computation of rotation angles as linear
3705 # variation of the given Angles along path steps
3706 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3707 # only SMESH::Extrusion_Error otherwise
3708 # @ingroup l2_modif_extrurev
3709 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3710 HasAngles, Angles, HasRefPoint, RefPoint,
3711 MakeGroups=False, LinearVariation=False):
3712 if ( isinstance( theObject, Mesh )):
3713 theObject = theObject.GetMesh()
3714 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3715 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3716 if ( isinstance( PathMesh, Mesh )):
3717 PathMesh = PathMesh.GetMesh()
3718 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3719 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3720 self.mesh.SetParameters(Parameters)
3721 if HasAngles and Angles and LinearVariation:
3722 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3725 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3726 PathShape, NodeStart, HasAngles,
3727 Angles, HasRefPoint, RefPoint)
3728 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3729 NodeStart, HasAngles, Angles, HasRefPoint,
3732 ## Creates a symmetrical copy of mesh elements
3733 # @param IDsOfElements list of elements ids
3734 # @param Mirror is AxisStruct or geom object(point, line, plane)
3735 # @param theMirrorType is POINT, AXIS or PLANE
3736 # If the Mirror is a geom object this parameter is unnecessary
3737 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3738 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3739 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3740 # @ingroup l2_modif_trsf
3741 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3742 if IDsOfElements == []:
3743 IDsOfElements = self.GetElementsId()
3744 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3745 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3746 self.mesh.SetParameters(Mirror.parameters)
3747 if Copy and MakeGroups:
3748 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3749 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3752 ## Creates a new mesh by a symmetrical copy of mesh elements
3753 # @param IDsOfElements the list of elements ids
3754 # @param Mirror is AxisStruct or geom object (point, line, plane)
3755 # @param theMirrorType is POINT, AXIS or PLANE
3756 # If the Mirror is a geom object this parameter is unnecessary
3757 # @param MakeGroups to generate new groups from existing ones
3758 # @param NewMeshName a name of the new mesh to create
3759 # @return instance of Mesh class
3760 # @ingroup l2_modif_trsf
3761 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3762 if IDsOfElements == []:
3763 IDsOfElements = self.GetElementsId()
3764 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3765 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3766 self.mesh.SetParameters(Mirror.parameters)
3767 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3768 MakeGroups, NewMeshName)
3769 return Mesh(self.smeshpyD,self.geompyD,mesh)
3771 ## Creates a symmetrical copy of the object
3772 # @param theObject mesh, submesh or group
3773 # @param Mirror AxisStruct or geom object (point, line, plane)
3774 # @param theMirrorType is POINT, AXIS or PLANE
3775 # If the Mirror is a geom object this parameter is unnecessary
3776 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3777 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3778 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3779 # @ingroup l2_modif_trsf
3780 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3781 if ( isinstance( theObject, Mesh )):
3782 theObject = theObject.GetMesh()
3783 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3784 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3785 self.mesh.SetParameters(Mirror.parameters)
3786 if Copy and MakeGroups:
3787 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3788 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3791 ## Creates a new mesh by a symmetrical copy of the object
3792 # @param theObject mesh, submesh or group
3793 # @param Mirror AxisStruct or geom object (point, line, plane)
3794 # @param theMirrorType POINT, AXIS or PLANE
3795 # If the Mirror is a geom object this parameter is unnecessary
3796 # @param MakeGroups forces the generation of new groups from existing ones
3797 # @param NewMeshName the name of the new mesh to create
3798 # @return instance of Mesh class
3799 # @ingroup l2_modif_trsf
3800 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3801 if ( isinstance( theObject, Mesh )):
3802 theObject = theObject.GetMesh()
3803 if (isinstance(Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3804 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3805 self.mesh.SetParameters(Mirror.parameters)
3806 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3807 MakeGroups, NewMeshName)
3808 return Mesh( self.smeshpyD,self.geompyD,mesh )
3810 ## Translates the elements
3811 # @param IDsOfElements list of elements ids
3812 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3813 # @param Copy allows copying the translated elements
3814 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3815 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3816 # @ingroup l2_modif_trsf
3817 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3818 if IDsOfElements == []:
3819 IDsOfElements = self.GetElementsId()
3820 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3821 Vector = self.smeshpyD.GetDirStruct(Vector)
3822 if isinstance( Vector, list ):
3823 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3824 self.mesh.SetParameters(Vector.PS.parameters)
3825 if Copy and MakeGroups:
3826 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3827 self.editor.Translate(IDsOfElements, Vector, Copy)
3830 ## Creates a new mesh of translated elements
3831 # @param IDsOfElements list of elements ids
3832 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3833 # @param MakeGroups forces the generation of new groups from existing ones
3834 # @param NewMeshName the name of the newly created mesh
3835 # @return instance of Mesh class
3836 # @ingroup l2_modif_trsf
3837 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3838 if IDsOfElements == []:
3839 IDsOfElements = self.GetElementsId()
3840 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3841 Vector = self.smeshpyD.GetDirStruct(Vector)
3842 if isinstance( Vector, list ):
3843 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3844 self.mesh.SetParameters(Vector.PS.parameters)
3845 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3846 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3848 ## Translates the object
3849 # @param theObject the object to translate (mesh, submesh, or group)
3850 # @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
3851 # @param Copy allows copying the translated elements
3852 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3853 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3854 # @ingroup l2_modif_trsf
3855 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3856 if ( isinstance( theObject, Mesh )):
3857 theObject = theObject.GetMesh()
3858 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3859 Vector = self.smeshpyD.GetDirStruct(Vector)
3860 if isinstance( Vector, list ):
3861 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3862 self.mesh.SetParameters(Vector.PS.parameters)
3863 if Copy and MakeGroups:
3864 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3865 self.editor.TranslateObject(theObject, Vector, Copy)
3868 ## Creates a new mesh from the translated object
3869 # @param theObject the object to translate (mesh, submesh, or group)
3870 # @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
3871 # @param MakeGroups forces the generation of new groups from existing ones
3872 # @param NewMeshName the name of the newly created mesh
3873 # @return instance of Mesh class
3874 # @ingroup l2_modif_trsf
3875 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3876 if isinstance( theObject, Mesh ):
3877 theObject = theObject.GetMesh()
3878 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
3879 Vector = self.smeshpyD.GetDirStruct(Vector)
3880 if isinstance( Vector, list ):
3881 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3882 self.mesh.SetParameters(Vector.PS.parameters)
3883 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3884 return Mesh( self.smeshpyD, self.geompyD, mesh )
3888 ## Scales the object
3889 # @param theObject - the object to translate (mesh, submesh, or group)
3890 # @param thePoint - base point for scale
3891 # @param theScaleFact - list of 1-3 scale factors for axises
3892 # @param Copy - allows copying the translated elements
3893 # @param MakeGroups - forces the generation of new groups from existing
3895 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3896 # empty list otherwise
3897 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3898 if ( isinstance( theObject, Mesh )):
3899 theObject = theObject.GetMesh()
3900 if ( isinstance( theObject, list )):
3901 theObject = self.GetIDSource(theObject, SMESH.ALL)
3902 if ( isinstance( theScaleFact, float )):
3903 theScaleFact = [theScaleFact]
3904 if ( isinstance( theScaleFact, int )):
3905 theScaleFact = [ float(theScaleFact)]
3907 self.mesh.SetParameters(thePoint.parameters)
3909 if Copy and MakeGroups:
3910 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3911 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3914 ## Creates a new mesh from the translated object
3915 # @param theObject - the object to translate (mesh, submesh, or group)
3916 # @param thePoint - base point for scale
3917 # @param theScaleFact - list of 1-3 scale factors for axises
3918 # @param MakeGroups - forces the generation of new groups from existing ones
3919 # @param NewMeshName - the name of the newly created mesh
3920 # @return instance of Mesh class
3921 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3922 if (isinstance(theObject, Mesh)):
3923 theObject = theObject.GetMesh()
3924 if ( isinstance( theObject, list )):
3925 theObject = self.GetIDSource(theObject,SMESH.ALL)
3926 if ( isinstance( theScaleFact, float )):
3927 theScaleFact = [theScaleFact]
3928 if ( isinstance( theScaleFact, int )):
3929 theScaleFact = [ float(theScaleFact)]
3931 self.mesh.SetParameters(thePoint.parameters)
3932 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3933 MakeGroups, NewMeshName)
3934 return Mesh( self.smeshpyD, self.geompyD, mesh )
3938 ## Rotates the elements
3939 # @param IDsOfElements list of elements ids
3940 # @param Axis the axis of rotation (AxisStruct or geom line)
3941 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3942 # @param Copy allows copying the rotated elements
3943 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3944 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3945 # @ingroup l2_modif_trsf
3946 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3947 if IDsOfElements == []:
3948 IDsOfElements = self.GetElementsId()
3949 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3950 Axis = self.smeshpyD.GetAxisStruct(Axis)
3951 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3952 Parameters = Axis.parameters + var_separator + Parameters
3953 self.mesh.SetParameters(Parameters)
3954 if Copy and MakeGroups:
3955 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3956 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3959 ## Creates a new mesh of rotated elements
3960 # @param IDsOfElements list of element ids
3961 # @param Axis the axis of rotation (AxisStruct or geom line)
3962 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3963 # @param MakeGroups forces the generation of new groups from existing ones
3964 # @param NewMeshName the name of the newly created mesh
3965 # @return instance of Mesh class
3966 # @ingroup l2_modif_trsf
3967 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3968 if IDsOfElements == []:
3969 IDsOfElements = self.GetElementsId()
3970 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3971 Axis = self.smeshpyD.GetAxisStruct(Axis)
3972 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3973 Parameters = Axis.parameters + var_separator + Parameters
3974 self.mesh.SetParameters(Parameters)
3975 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3976 MakeGroups, NewMeshName)
3977 return Mesh( self.smeshpyD, self.geompyD, mesh )
3979 ## Rotates the object
3980 # @param theObject the object to rotate( mesh, submesh, or group)
3981 # @param Axis the axis of rotation (AxisStruct or geom line)
3982 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3983 # @param Copy allows copying the rotated elements
3984 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3985 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3986 # @ingroup l2_modif_trsf
3987 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3988 if (isinstance(theObject, Mesh)):
3989 theObject = theObject.GetMesh()
3990 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3991 Axis = self.smeshpyD.GetAxisStruct(Axis)
3992 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3993 Parameters = Axis.parameters + ":" + Parameters
3994 self.mesh.SetParameters(Parameters)
3995 if Copy and MakeGroups:
3996 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3997 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
4000 ## Creates a new mesh from the rotated object
4001 # @param theObject the object to rotate (mesh, submesh, or group)
4002 # @param Axis the axis of rotation (AxisStruct or geom line)
4003 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4004 # @param MakeGroups forces the generation of new groups from existing ones
4005 # @param NewMeshName the name of the newly created mesh
4006 # @return instance of Mesh class
4007 # @ingroup l2_modif_trsf
4008 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
4009 if (isinstance( theObject, Mesh )):
4010 theObject = theObject.GetMesh()
4011 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4012 Axis = self.smeshpyD.GetAxisStruct(Axis)
4013 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4014 Parameters = Axis.parameters + ":" + Parameters
4015 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
4016 MakeGroups, NewMeshName)
4017 self.mesh.SetParameters(Parameters)
4018 return Mesh( self.smeshpyD, self.geompyD, mesh )
4020 ## Finds groups of ajacent nodes within Tolerance.
4021 # @param Tolerance the value of tolerance
4022 # @return the list of groups of nodes
4023 # @ingroup l2_modif_trsf
4024 def FindCoincidentNodes (self, Tolerance):
4025 return self.editor.FindCoincidentNodes(Tolerance)
4027 ## Finds groups of ajacent nodes within Tolerance.
4028 # @param Tolerance the value of tolerance
4029 # @param SubMeshOrGroup SubMesh or Group
4030 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
4031 # @return the list of groups of nodes
4032 # @ingroup l2_modif_trsf
4033 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
4034 if (isinstance( SubMeshOrGroup, Mesh )):
4035 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
4036 if not isinstance( exceptNodes, list):
4037 exceptNodes = [ exceptNodes ]
4038 if exceptNodes and isinstance( exceptNodes[0], int):
4039 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
4040 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
4043 # @param GroupsOfNodes the list of groups of nodes
4044 # @ingroup l2_modif_trsf
4045 def MergeNodes (self, GroupsOfNodes):
4046 self.editor.MergeNodes(GroupsOfNodes)
4048 ## Finds the elements built on the same nodes.
4049 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
4050 # @return a list of groups of equal elements
4051 # @ingroup l2_modif_trsf
4052 def FindEqualElements (self, MeshOrSubMeshOrGroup):
4053 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
4054 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4055 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
4057 ## Merges elements in each given group.
4058 # @param GroupsOfElementsID groups of elements for merging
4059 # @ingroup l2_modif_trsf
4060 def MergeElements(self, GroupsOfElementsID):
4061 self.editor.MergeElements(GroupsOfElementsID)
4063 ## Leaves one element and removes all other elements built on the same nodes.
4064 # @ingroup l2_modif_trsf
4065 def MergeEqualElements(self):
4066 self.editor.MergeEqualElements()
4068 ## Sews free borders
4069 # @return SMESH::Sew_Error
4070 # @ingroup l2_modif_trsf
4071 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4072 FirstNodeID2, SecondNodeID2, LastNodeID2,
4073 CreatePolygons, CreatePolyedrs):
4074 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4075 FirstNodeID2, SecondNodeID2, LastNodeID2,
4076 CreatePolygons, CreatePolyedrs)
4078 ## Sews conform free borders
4079 # @return SMESH::Sew_Error
4080 # @ingroup l2_modif_trsf
4081 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4082 FirstNodeID2, SecondNodeID2):
4083 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4084 FirstNodeID2, SecondNodeID2)
4086 ## Sews border to side
4087 # @return SMESH::Sew_Error
4088 # @ingroup l2_modif_trsf
4089 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4090 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4091 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4092 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4094 ## Sews two sides of a mesh. The nodes belonging to Side1 are
4095 # merged with the nodes of elements of Side2.
4096 # The number of elements in theSide1 and in theSide2 must be
4097 # equal and they should have similar nodal connectivity.
4098 # The nodes to merge should belong to side borders and
4099 # the first node should be linked to the second.
4100 # @return SMESH::Sew_Error
4101 # @ingroup l2_modif_trsf
4102 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4103 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4104 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4105 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4106 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4107 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4109 ## Sets new nodes for the given element.
4110 # @param ide the element id
4111 # @param newIDs nodes ids
4112 # @return If the number of nodes does not correspond to the type of element - returns false
4113 # @ingroup l2_modif_edit
4114 def ChangeElemNodes(self, ide, newIDs):
4115 return self.editor.ChangeElemNodes(ide, newIDs)
4117 ## If during the last operation of MeshEditor some nodes were
4118 # created, this method returns the list of their IDs, \n
4119 # if new nodes were not created - returns empty list
4120 # @return the list of integer values (can be empty)
4121 # @ingroup l1_auxiliary
4122 def GetLastCreatedNodes(self):
4123 return self.editor.GetLastCreatedNodes()
4125 ## If during the last operation of MeshEditor some elements were
4126 # created this method returns the list of their IDs, \n
4127 # if new elements were not created - returns empty list
4128 # @return the list of integer values (can be empty)
4129 # @ingroup l1_auxiliary
4130 def GetLastCreatedElems(self):
4131 return self.editor.GetLastCreatedElems()
4133 ## Clear sequences of nodes and elements created by mesh edition oparations
4134 # @ingroup l1_auxiliary
4135 def ClearLastCreated(self):
4136 self.editor.ClearLastCreated()
4138 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4139 # @param theNodes identifiers of nodes to be doubled
4140 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4141 # nodes. If list of element identifiers is empty then nodes are doubled but
4142 # they not assigned to elements
4143 # @return TRUE if operation has been completed successfully, FALSE otherwise
4144 # @ingroup l2_modif_edit
4145 def DoubleNodes(self, theNodes, theModifiedElems):
4146 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4148 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4149 # This method provided for convenience works as DoubleNodes() described above.
4150 # @param theNodeId identifiers of node to be doubled
4151 # @param theModifiedElems identifiers of elements to be updated
4152 # @return TRUE if operation has been completed successfully, FALSE otherwise
4153 # @ingroup l2_modif_edit
4154 def DoubleNode(self, theNodeId, theModifiedElems):
4155 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4157 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4158 # This method provided for convenience works as DoubleNodes() described above.
4159 # @param theNodes group of nodes to be doubled
4160 # @param theModifiedElems group of elements to be updated.
4161 # @param theMakeGroup forces the generation of a group containing new nodes.
4162 # @return TRUE or a created group if operation has been completed successfully,
4163 # FALSE or None otherwise
4164 # @ingroup l2_modif_edit
4165 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4167 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4168 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4170 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4171 # This method provided for convenience works as DoubleNodes() described above.
4172 # @param theNodes list of groups of nodes to be doubled
4173 # @param theModifiedElems list of groups of elements to be updated.
4174 # @param theMakeGroup forces the generation of a group containing new nodes.
4175 # @return TRUE if operation has been completed successfully, FALSE otherwise
4176 # @ingroup l2_modif_edit
4177 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4179 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4180 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4182 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4183 # @param theElems - the list of elements (edges or faces) to be replicated
4184 # The nodes for duplication could be found from these elements
4185 # @param theNodesNot - list of nodes to NOT replicate
4186 # @param theAffectedElems - the list of elements (cells and edges) to which the
4187 # replicated nodes should be associated to.
4188 # @return TRUE if operation has been completed successfully, FALSE otherwise
4189 # @ingroup l2_modif_edit
4190 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4191 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4193 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4194 # @param theElems - the list of elements (edges or faces) to be replicated
4195 # The nodes for duplication could be found from these elements
4196 # @param theNodesNot - list of nodes to NOT replicate
4197 # @param theShape - shape to detect affected elements (element which geometric center
4198 # located on or inside shape).
4199 # The replicated nodes should be associated to affected elements.
4200 # @return TRUE if operation has been completed successfully, FALSE otherwise
4201 # @ingroup l2_modif_edit
4202 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4203 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4205 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4206 # This method provided for convenience works as DoubleNodes() described above.
4207 # @param theElems - group of of elements (edges or faces) to be replicated
4208 # @param theNodesNot - group of nodes not to replicated
4209 # @param theAffectedElems - group of elements to which the replicated nodes
4210 # should be associated to.
4211 # @param theMakeGroup forces the generation of a group containing new elements.
4212 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4213 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4214 # FALSE or None otherwise
4215 # @ingroup l2_modif_edit
4216 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4217 theMakeGroup=False, theMakeNodeGroup=False):
4218 if theMakeGroup or theMakeNodeGroup:
4219 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4221 theMakeGroup, theMakeNodeGroup)
4222 if theMakeGroup and theMakeNodeGroup:
4225 return twoGroups[ int(theMakeNodeGroup) ]
4226 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4228 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4229 # This method provided for convenience works as DoubleNodes() described above.
4230 # @param theElems - group of of elements (edges or faces) to be replicated
4231 # @param theNodesNot - group of nodes not to replicated
4232 # @param theShape - shape to detect affected elements (element which geometric center
4233 # located on or inside shape).
4234 # The replicated nodes should be associated to affected elements.
4235 # @ingroup l2_modif_edit
4236 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4237 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4239 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4240 # This method provided for convenience works as DoubleNodes() described above.
4241 # @param theElems - list of groups of elements (edges or faces) to be replicated
4242 # @param theNodesNot - list of groups of nodes not to replicated
4243 # @param theAffectedElems - group of elements to which the replicated nodes
4244 # should be associated to.
4245 # @param theMakeGroup forces the generation of a group containing new elements.
4246 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4247 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4248 # FALSE or None otherwise
4249 # @ingroup l2_modif_edit
4250 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4251 theMakeGroup=False, theMakeNodeGroup=False):
4252 if theMakeGroup or theMakeNodeGroup:
4253 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4255 theMakeGroup, theMakeNodeGroup)
4256 if theMakeGroup and theMakeNodeGroup:
4259 return twoGroups[ int(theMakeNodeGroup) ]
4260 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4262 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4263 # This method provided for convenience works as DoubleNodes() described above.
4264 # @param theElems - list of groups of elements (edges or faces) to be replicated
4265 # @param theNodesNot - list of groups of nodes not to replicated
4266 # @param theShape - shape to detect affected elements (element which geometric center
4267 # located on or inside shape).
4268 # The replicated nodes should be associated to affected elements.
4269 # @return TRUE if operation has been completed successfully, FALSE otherwise
4270 # @ingroup l2_modif_edit
4271 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4272 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4274 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4275 # This method is the first step of DoubleNodeElemGroupsInRegion.
4276 # @param theElems - list of groups of elements (edges or faces) to be replicated
4277 # @param theNodesNot - list of groups of nodes not to replicated
4278 # @param theShape - shape to detect affected elements (element which geometric center
4279 # located on or inside shape).
4280 # The replicated nodes should be associated to affected elements.
4281 # @return groups of affected elements
4282 # @ingroup l2_modif_edit
4283 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4284 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4286 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4287 # The list of groups must describe a partition of the mesh volumes.
4288 # The nodes of the internal faces at the boundaries of the groups are doubled.
4289 # In option, the internal faces are replaced by flat elements.
4290 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4291 # @param theDomains - list of groups of volumes
4292 # @param createJointElems - if TRUE, create the elements
4293 # @return TRUE if operation has been completed successfully, FALSE otherwise
4294 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4295 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4297 ## Double nodes on some external faces and create flat elements.
4298 # Flat elements are mainly used by some types of mechanic calculations.
4300 # Each group of the list must be constituted of faces.
4301 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4302 # @param theGroupsOfFaces - list of groups of faces
4303 # @return TRUE if operation has been completed successfully, FALSE otherwise
4304 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4305 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4307 ## identify all the elements around a geom shape, get the faces delimiting the hole
4309 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4310 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4312 def _getFunctor(self, funcType ):
4313 fn = self.functors[ funcType._v ]
4315 fn = self.smeshpyD.GetFunctor(funcType)
4316 fn.SetMesh(self.mesh)
4317 self.functors[ funcType._v ] = fn
4320 def _valueFromFunctor(self, funcType, elemId):
4321 fn = self._getFunctor( funcType )
4322 if fn.GetElementType() == self.GetElementType(elemId, True):
4323 val = fn.GetValue(elemId)
4328 ## Get length of 1D element.
4329 # @param elemId mesh element ID
4330 # @return element's length value
4331 # @ingroup l1_measurements
4332 def GetLength(self, elemId):
4333 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4335 ## Get area of 2D element.
4336 # @param elemId mesh element ID
4337 # @return element's area value
4338 # @ingroup l1_measurements
4339 def GetArea(self, elemId):
4340 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4342 ## Get volume of 3D element.
4343 # @param elemId mesh element ID
4344 # @return element's volume value
4345 # @ingroup l1_measurements
4346 def GetVolume(self, elemId):
4347 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4349 ## Get maximum element length.
4350 # @param elemId mesh element ID
4351 # @return element's maximum length value
4352 # @ingroup l1_measurements
4353 def GetMaxElementLength(self, elemId):
4354 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4355 ftype = SMESH.FT_MaxElementLength3D
4357 ftype = SMESH.FT_MaxElementLength2D
4358 return self._valueFromFunctor(ftype, elemId)
4360 ## Get aspect ratio of 2D or 3D element.
4361 # @param elemId mesh element ID
4362 # @return element's aspect ratio value
4363 # @ingroup l1_measurements
4364 def GetAspectRatio(self, elemId):
4365 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4366 ftype = SMESH.FT_AspectRatio3D
4368 ftype = SMESH.FT_AspectRatio
4369 return self._valueFromFunctor(ftype, elemId)
4371 ## Get warping angle of 2D element.
4372 # @param elemId mesh element ID
4373 # @return element's warping angle value
4374 # @ingroup l1_measurements
4375 def GetWarping(self, elemId):
4376 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4378 ## Get minimum angle of 2D element.
4379 # @param elemId mesh element ID
4380 # @return element's minimum angle value
4381 # @ingroup l1_measurements
4382 def GetMinimumAngle(self, elemId):
4383 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4385 ## Get taper of 2D element.
4386 # @param elemId mesh element ID
4387 # @return element's taper value
4388 # @ingroup l1_measurements
4389 def GetTaper(self, elemId):
4390 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4392 ## Get skew of 2D element.
4393 # @param elemId mesh element ID
4394 # @return element's skew value
4395 # @ingroup l1_measurements
4396 def GetSkew(self, elemId):
4397 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4399 pass # end of Mesh class
4401 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4403 class Pattern(SMESH._objref_SMESH_Pattern):
4405 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4406 decrFun = lambda i: i-1
4407 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4408 theMesh.SetParameters(Parameters)
4409 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4411 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4412 decrFun = lambda i: i-1
4413 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4414 theMesh.SetParameters(Parameters)
4415 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4417 # Registering the new proxy for Pattern
4418 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4420 ## Private class used to bind methods creating algorithms to the class Mesh
4425 self.defaultAlgoType = ""
4426 self.algoTypeToClass = {}
4428 # Stores a python class of algorithm
4429 def add(self, algoClass):
4430 if type( algoClass ).__name__ == 'classobj' and \
4431 hasattr( algoClass, "algoType"):
4432 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4433 if not self.defaultAlgoType and \
4434 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4435 self.defaultAlgoType = algoClass.algoType
4436 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4438 # creates a copy of self and assign mesh to the copy
4439 def copy(self, mesh):
4440 other = algoCreator()
4441 other.defaultAlgoType = self.defaultAlgoType
4442 other.algoTypeToClass = self.algoTypeToClass
4446 # creates an instance of algorithm
4447 def __call__(self,algo="",geom=0,*args):
4448 algoType = self.defaultAlgoType
4449 for arg in args + (algo,geom):
4450 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
4452 if isinstance( arg, str ) and arg:
4454 if not algoType and self.algoTypeToClass:
4455 algoType = self.algoTypeToClass.keys()[0]
4456 if self.algoTypeToClass.has_key( algoType ):
4457 #print "Create algo",algoType
4458 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4459 raise RuntimeError, "No class found for algo type %s" % algoType
4462 # Private class used to substitute and store variable parameters of hypotheses.
4464 class hypMethodWrapper:
4465 def __init__(self, hyp, method):
4467 self.method = method
4468 #print "REBIND:", method.__name__
4471 # call a method of hypothesis with calling SetVarParameter() before
4472 def __call__(self,*args):
4474 return self.method( self.hyp, *args ) # hypothesis method with no args
4476 #print "MethWrapper.__call__",self.method.__name__, args
4478 parsed = ParseParameters(*args) # replace variables with their values
4479 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4480 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4481 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4482 # maybe there is a replaced string arg which is not variable
4483 result = self.method( self.hyp, *args )
4484 except ValueError, detail: # raised by ParseParameters()
4486 result = self.method( self.hyp, *args )
4487 except omniORB.CORBA.BAD_PARAM:
4488 raise ValueError, detail # wrong variable name
4492 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4494 #print "pluginName: ", pluginName
4495 pluginBuilderName = pluginName + "Builder"
4497 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
4498 except Exception, e:
4499 print "Exception while loading %s: %s" % ( pluginBuilderName, e )
4501 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
4502 plugin = eval( pluginBuilderName )
4503 #print " plugin:" , str(plugin)
4505 # add methods creating algorithms to Mesh
4506 for k in dir( plugin ):
4507 if k[0] == '_': continue
4508 algo = getattr( plugin, k )
4509 #print " algo:", str(algo)
4510 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4511 #print " meshMethod:" , str(algo.meshMethod)
4512 if not hasattr( Mesh, algo.meshMethod ):
4513 setattr( Mesh, algo.meshMethod, algoCreator() )
4515 getattr( Mesh, algo.meshMethod ).add( algo )