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(edge):
263 vv = geomBuilder.SubShapeAll( edge, geomBuilder.geomBuilder.ShapeType["VERTEX"])
265 raise TypeError, "Given object has no vertices"
266 if len( vv ) == 1: return vv[0]
267 v0 = geomBuilder.MakeVertexOnCurve(edge,0.)
268 xyz = geomBuilder.PointCoordinates( v0 ) # coords of the first vertex
269 xyz1 = geomBuilder.PointCoordinates( vv[0] )
270 xyz2 = geomBuilder.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
289 ## This class allows to create, load or manipulate meshes
290 # It has a set of methods to create load or copy meshes, to combine several meshes.
291 # It also has methods to get infos on meshes.
292 class smeshBuilder(object, SMESH._objref_SMESH_Gen):
294 # MirrorType enumeration
295 POINT = SMESH_MeshEditor.POINT
296 AXIS = SMESH_MeshEditor.AXIS
297 PLANE = SMESH_MeshEditor.PLANE
299 # Smooth_Method enumeration
300 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
301 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
303 PrecisionConfusion = smeshPrecisionConfusion
305 # TopAbs_State enumeration
306 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
308 # Methods of splitting a hexahedron into tetrahedra
309 Hex_5Tet, Hex_6Tet, Hex_24Tet = 1, 2, 3
315 #print "__new__", engine, smeshInst, doLcc
317 if smeshInst is None:
318 # smesh engine is either retrieved from engine, or created
320 # Following test avoids a recursive loop
322 if smeshInst is not None:
323 # smesh engine not created: existing engine found
327 # FindOrLoadComponent called:
328 # 1. CORBA resolution of server
329 # 2. the __new__ method is called again
330 #print "smeshInst = lcc.FindOrLoadComponent ", engine, smeshInst, doLcc
331 smeshInst = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
333 # FindOrLoadComponent not called
334 if smeshInst is None:
335 # smeshBuilder instance is created from lcc.FindOrLoadComponent
336 #print "smeshInst = super(smeshBuilder,cls).__new__(cls) ", engine, smeshInst, doLcc
337 smeshInst = super(smeshBuilder,cls).__new__(cls)
339 # smesh engine not created: existing engine found
340 #print "existing ", engine, smeshInst, doLcc
349 SMESH._objref_SMESH_Gen.__init__(self)
351 ## Dump component to the Python script
352 # This method overrides IDL function to allow default values for the parameters.
353 def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
354 return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
356 ## Set mode of DumpPython(), \a historical or \a snapshot.
357 # In the \a historical mode, the Python Dump script includes all commands
358 # performed by SMESH engine. In the \a snapshot mode, commands
359 # relating to objects removed from the Study are excluded from the script
360 # as well as commands not influencing the current state of meshes
361 def SetDumpPythonHistorical(self, isHistorical):
362 if isHistorical: val = "true"
364 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
366 ## Sets the current study and Geometry component
367 # @ingroup l1_auxiliary
368 def init_smesh(self,theStudy,geompyD = None):
370 self.SetCurrentStudy(theStudy,geompyD)
372 ## Creates an empty Mesh. This mesh can have an underlying geometry.
373 # @param obj the Geometrical object on which the mesh is built. If not defined,
374 # the mesh will have no underlying geometry.
375 # @param name the name for the new mesh.
376 # @return an instance of Mesh class.
377 # @ingroup l2_construct
378 def Mesh(self, obj=0, name=0):
379 if isinstance(obj,str):
381 return Mesh(self,self.geompyD,obj,name)
383 ## Returns a long value from enumeration
384 # @ingroup l1_controls
385 def EnumToLong(self,theItem):
388 ## Returns a string representation of the color.
389 # To be used with filters.
390 # @param c color value (SALOMEDS.Color)
391 # @ingroup l1_controls
392 def ColorToString(self,c):
394 if isinstance(c, SALOMEDS.Color):
395 val = "%s;%s;%s" % (c.R, c.G, c.B)
396 elif isinstance(c, str):
399 raise ValueError, "Color value should be of string or SALOMEDS.Color type"
402 ## Gets PointStruct from vertex
403 # @param theVertex a GEOM object(vertex)
404 # @return SMESH.PointStruct
405 # @ingroup l1_auxiliary
406 def GetPointStruct(self,theVertex):
407 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
408 return PointStruct(x,y,z)
410 ## Gets DirStruct from vector
411 # @param theVector a GEOM object(vector)
412 # @return SMESH.DirStruct
413 # @ingroup l1_auxiliary
414 def GetDirStruct(self,theVector):
415 vertices = self.geompyD.SubShapeAll( theVector, geomBuilder.geomBuilder.ShapeType["VERTEX"] )
416 if(len(vertices) != 2):
417 print "Error: vector object is incorrect."
419 p1 = self.geompyD.PointCoordinates(vertices[0])
420 p2 = self.geompyD.PointCoordinates(vertices[1])
421 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
422 dirst = DirStruct(pnt)
425 ## Makes DirStruct from a triplet
426 # @param x,y,z vector components
427 # @return SMESH.DirStruct
428 # @ingroup l1_auxiliary
429 def MakeDirStruct(self,x,y,z):
430 pnt = PointStruct(x,y,z)
431 return DirStruct(pnt)
433 ## Get AxisStruct from object
434 # @param theObj a GEOM object (line or plane)
435 # @return SMESH.AxisStruct
436 # @ingroup l1_auxiliary
437 def GetAxisStruct(self,theObj):
438 edges = self.geompyD.SubShapeAll( theObj, geomBuilder.geomBuilder.ShapeType["EDGE"] )
440 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
441 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
442 vertex1 = self.geompyD.PointCoordinates(vertex1)
443 vertex2 = self.geompyD.PointCoordinates(vertex2)
444 vertex3 = self.geompyD.PointCoordinates(vertex3)
445 vertex4 = self.geompyD.PointCoordinates(vertex4)
446 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
447 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
448 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] ]
449 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
451 elif len(edges) == 1:
452 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
453 p1 = self.geompyD.PointCoordinates( vertex1 )
454 p2 = self.geompyD.PointCoordinates( vertex2 )
455 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
459 # From SMESH_Gen interface:
460 # ------------------------
462 ## Sets the given name to the object
463 # @param obj the object to rename
464 # @param name a new object name
465 # @ingroup l1_auxiliary
466 def SetName(self, obj, name):
467 if isinstance( obj, Mesh ):
469 elif isinstance( obj, Mesh_Algorithm ):
470 obj = obj.GetAlgorithm()
471 ior = salome.orb.object_to_string(obj)
472 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
474 ## Sets the current mode
475 # @ingroup l1_auxiliary
476 def SetEmbeddedMode( self,theMode ):
477 #self.SetEmbeddedMode(theMode)
478 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
480 ## Gets the current mode
481 # @ingroup l1_auxiliary
482 def IsEmbeddedMode(self):
483 #return self.IsEmbeddedMode()
484 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
486 ## Sets the current study
487 # @ingroup l1_auxiliary
488 def SetCurrentStudy( self, theStudy, geompyD = None ):
489 #self.SetCurrentStudy(theStudy)
491 from salome.geom import geomBuilder
492 geompyD = geomBuilder.geom
495 self.SetGeomEngine(geompyD)
496 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
499 notebook = salome_notebook.NoteBook( theStudy )
501 notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
503 ## Gets the current study
504 # @ingroup l1_auxiliary
505 def GetCurrentStudy(self):
506 #return self.GetCurrentStudy()
507 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
509 ## Creates a Mesh object importing data from the given UNV file
510 # @return an instance of Mesh class
512 def CreateMeshesFromUNV( self,theFileName ):
513 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
514 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
517 ## Creates a Mesh object(s) importing data from the given MED file
518 # @return a list of Mesh class instances
520 def CreateMeshesFromMED( self,theFileName ):
521 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
523 for iMesh in range(len(aSmeshMeshes)) :
524 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
525 aMeshes.append(aMesh)
526 return aMeshes, aStatus
528 ## Creates a Mesh object(s) importing data from the given SAUV file
529 # @return a list of Mesh class instances
531 def CreateMeshesFromSAUV( self,theFileName ):
532 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
534 for iMesh in range(len(aSmeshMeshes)) :
535 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
536 aMeshes.append(aMesh)
537 return aMeshes, aStatus
539 ## Creates a Mesh object importing data from the given STL file
540 # @return an instance of Mesh class
542 def CreateMeshesFromSTL( self, theFileName ):
543 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
544 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
547 ## Creates Mesh objects importing data from the given CGNS file
548 # @return an instance of Mesh class
550 def CreateMeshesFromCGNS( self, theFileName ):
551 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
553 for iMesh in range(len(aSmeshMeshes)) :
554 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
555 aMeshes.append(aMesh)
556 return aMeshes, aStatus
558 ## Creates a Mesh object importing data from the given GMF file
559 # @return [ an instance of Mesh class, SMESH::ComputeError ]
561 def CreateMeshesFromGMF( self, theFileName ):
562 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
565 if error.comment: print "*** CreateMeshesFromGMF() errors:\n", error.comment
566 return Mesh(self, self.geompyD, aSmeshMesh), error
568 ## Concatenate the given meshes into one mesh.
569 # @return an instance of Mesh class
570 # @param meshes the meshes to combine into one mesh
571 # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
572 # @param mergeNodesAndElements if true, equal nodes and elements aremerged
573 # @param mergeTolerance tolerance for merging nodes
574 # @param allGroups forces creation of groups of all elements
575 # @param name name of a new mesh
576 def Concatenate( self, meshes, uniteIdenticalGroups,
577 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
579 if not meshes: return None
580 for i,m in enumerate(meshes):
581 if isinstance(m, Mesh):
582 meshes[i] = m.GetMesh()
583 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
584 meshes[0].SetParameters(Parameters)
586 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
587 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
589 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
590 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
591 aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
594 ## Create a mesh by copying a part of another mesh.
595 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
596 # to copy nodes or elements not contained in any mesh object,
597 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
598 # @param meshName a name of the new mesh
599 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
600 # @param toKeepIDs to preserve IDs of the copied elements or not
601 # @return an instance of Mesh class
602 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
603 if (isinstance( meshPart, Mesh )):
604 meshPart = meshPart.GetMesh()
605 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
606 return Mesh(self, self.geompyD, mesh)
608 ## From SMESH_Gen interface
609 # @return the list of integer values
610 # @ingroup l1_auxiliary
611 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
612 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
614 ## From SMESH_Gen interface. Creates a pattern
615 # @return an instance of SMESH_Pattern
617 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
618 # @ingroup l2_modif_patterns
619 def GetPattern(self):
620 return SMESH._objref_SMESH_Gen.GetPattern(self)
622 ## Sets number of segments per diagonal of boundary box of geometry by which
623 # default segment length of appropriate 1D hypotheses is defined.
624 # Default value is 10
625 # @ingroup l1_auxiliary
626 def SetBoundaryBoxSegmentation(self, nbSegments):
627 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
629 # Filtering. Auxiliary functions:
630 # ------------------------------
632 ## Creates an empty criterion
633 # @return SMESH.Filter.Criterion
634 # @ingroup l1_controls
635 def GetEmptyCriterion(self):
636 Type = self.EnumToLong(FT_Undefined)
637 Compare = self.EnumToLong(FT_Undefined)
641 UnaryOp = self.EnumToLong(FT_Undefined)
642 BinaryOp = self.EnumToLong(FT_Undefined)
645 Precision = -1 ##@1e-07
646 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
647 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
649 ## Creates a criterion by the given parameters
650 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
651 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
652 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
653 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
654 # @param Threshold the threshold value (range of ids as string, shape, numeric)
655 # @param UnaryOp FT_LogicalNOT or FT_Undefined
656 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
657 # FT_Undefined (must be for the last criterion of all criteria)
658 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
659 # FT_LyingOnGeom, FT_CoplanarFaces criteria
660 # @return SMESH.Filter.Criterion
662 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
663 # @ingroup l1_controls
664 def GetCriterion(self,elementType,
666 Compare = FT_EqualTo,
668 UnaryOp=FT_Undefined,
669 BinaryOp=FT_Undefined,
671 if not CritType in SMESH.FunctorType._items:
672 raise TypeError, "CritType should be of SMESH.FunctorType"
673 aCriterion = self.GetEmptyCriterion()
674 aCriterion.TypeOfElement = elementType
675 aCriterion.Type = self.EnumToLong(CritType)
676 aCriterion.Tolerance = Tolerance
678 aThreshold = Threshold
680 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
681 aCriterion.Compare = self.EnumToLong(Compare)
682 elif Compare == "=" or Compare == "==":
683 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
685 aCriterion.Compare = self.EnumToLong(FT_LessThan)
687 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
688 elif Compare != FT_Undefined:
689 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
692 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
693 FT_BelongToCylinder, FT_LyingOnGeom]:
694 # Checks that Threshold is GEOM object
695 if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object):
696 aCriterion.ThresholdStr = GetName(aThreshold)
697 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
698 if not aCriterion.ThresholdID:
699 name = aCriterion.ThresholdStr
701 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
702 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
703 #raise RuntimeError, "Threshold shape must be published"
705 print "Error: The Threshold should be a shape."
707 if isinstance(UnaryOp,float):
708 aCriterion.Tolerance = UnaryOp
709 UnaryOp = FT_Undefined
711 elif CritType == FT_RangeOfIds:
712 # Checks that Threshold is string
713 if isinstance(aThreshold, str):
714 aCriterion.ThresholdStr = aThreshold
716 print "Error: The Threshold should be a string."
718 elif CritType == FT_CoplanarFaces:
719 # Checks the Threshold
720 if isinstance(aThreshold, int):
721 aCriterion.ThresholdID = str(aThreshold)
722 elif isinstance(aThreshold, str):
725 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
726 aCriterion.ThresholdID = aThreshold
729 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
730 elif CritType == FT_ElemGeomType:
731 # Checks the Threshold
733 aCriterion.Threshold = self.EnumToLong(aThreshold)
734 assert( aThreshold in SMESH.GeometryType._items )
736 if isinstance(aThreshold, int):
737 aCriterion.Threshold = aThreshold
739 print "Error: The Threshold should be an integer or SMESH.GeometryType."
743 elif CritType == FT_EntityType:
744 # Checks the Threshold
746 aCriterion.Threshold = self.EnumToLong(aThreshold)
747 assert( aThreshold in SMESH.EntityType._items )
749 if isinstance(aThreshold, int):
750 aCriterion.Threshold = aThreshold
752 print "Error: The Threshold should be an integer or SMESH.EntityType."
757 elif CritType == FT_GroupColor:
758 # Checks the Threshold
760 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
762 print "Error: The threshold value should be of SALOMEDS.Color type"
765 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
766 FT_LinearOrQuadratic, FT_BadOrientedVolume,
767 FT_BareBorderFace, FT_BareBorderVolume,
768 FT_OverConstrainedFace, FT_OverConstrainedVolume,
769 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
770 # At this point the Threshold is unnecessary
771 if aThreshold == FT_LogicalNOT:
772 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
773 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
774 aCriterion.BinaryOp = aThreshold
778 aThreshold = float(aThreshold)
779 aCriterion.Threshold = aThreshold
781 print "Error: The Threshold should be a number."
784 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
785 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
787 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
788 aCriterion.BinaryOp = self.EnumToLong(Threshold)
790 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
791 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
793 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
794 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
798 ## Creates a filter with the given parameters
799 # @param elementType the type of elements in the group
800 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
801 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
802 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
803 # @param UnaryOp FT_LogicalNOT or FT_Undefined
804 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
805 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
806 # @return SMESH_Filter
808 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
809 # @ingroup l1_controls
810 def GetFilter(self,elementType,
811 CritType=FT_Undefined,
814 UnaryOp=FT_Undefined,
816 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
817 aFilterMgr = self.CreateFilterManager()
818 aFilter = aFilterMgr.CreateFilter()
820 aCriteria.append(aCriterion)
821 aFilter.SetCriteria(aCriteria)
822 aFilterMgr.UnRegister()
825 ## Creates a filter from criteria
826 # @param criteria a list of criteria
827 # @return SMESH_Filter
829 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
830 # @ingroup l1_controls
831 def GetFilterFromCriteria(self,criteria):
832 aFilterMgr = self.CreateFilterManager()
833 aFilter = aFilterMgr.CreateFilter()
834 aFilter.SetCriteria(criteria)
835 aFilterMgr.UnRegister()
838 ## Creates a numerical functor by its type
839 # @param theCriterion FT_...; functor type
840 # @return SMESH_NumericalFunctor
841 # @ingroup l1_controls
842 def GetFunctor(self,theCriterion):
843 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
845 aFilterMgr = self.CreateFilterManager()
847 if theCriterion == FT_AspectRatio:
848 functor = aFilterMgr.CreateAspectRatio()
849 elif theCriterion == FT_AspectRatio3D:
850 functor = aFilterMgr.CreateAspectRatio3D()
851 elif theCriterion == FT_Warping:
852 functor = aFilterMgr.CreateWarping()
853 elif theCriterion == FT_MinimumAngle:
854 functor = aFilterMgr.CreateMinimumAngle()
855 elif theCriterion == FT_Taper:
856 functor = aFilterMgr.CreateTaper()
857 elif theCriterion == FT_Skew:
858 functor = aFilterMgr.CreateSkew()
859 elif theCriterion == FT_Area:
860 functor = aFilterMgr.CreateArea()
861 elif theCriterion == FT_Volume3D:
862 functor = aFilterMgr.CreateVolume3D()
863 elif theCriterion == FT_MaxElementLength2D:
864 functor = aFilterMgr.CreateMaxElementLength2D()
865 elif theCriterion == FT_MaxElementLength3D:
866 functor = aFilterMgr.CreateMaxElementLength3D()
867 elif theCriterion == FT_MultiConnection:
868 functor = aFilterMgr.CreateMultiConnection()
869 elif theCriterion == FT_MultiConnection2D:
870 functor = aFilterMgr.CreateMultiConnection2D()
871 elif theCriterion == FT_Length:
872 functor = aFilterMgr.CreateLength()
873 elif theCriterion == FT_Length2D:
874 functor = aFilterMgr.CreateLength2D()
876 print "Error: given parameter is not numerical functor type."
877 aFilterMgr.UnRegister()
880 ## Creates hypothesis
881 # @param theHType mesh hypothesis type (string)
882 # @param theLibName mesh plug-in library name
883 # @return created hypothesis instance
884 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
885 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
887 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
890 # wrap hypothesis methods
891 #print "HYPOTHESIS", theHType
892 for meth_name in dir( hyp.__class__ ):
893 if not meth_name.startswith("Get") and \
894 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
895 method = getattr ( hyp.__class__, meth_name )
897 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
901 ## Gets the mesh statistic
902 # @return dictionary "element type" - "count of elements"
903 # @ingroup l1_meshinfo
904 def GetMeshInfo(self, obj):
905 if isinstance( obj, Mesh ):
908 if hasattr(obj, "GetMeshInfo"):
909 values = obj.GetMeshInfo()
910 for i in range(SMESH.Entity_Last._v):
911 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
915 ## Get minimum distance between two objects
917 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
918 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
920 # @param src1 first source object
921 # @param src2 second source object
922 # @param id1 node/element id from the first source
923 # @param id2 node/element id from the second (or first) source
924 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
925 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
926 # @return minimum distance value
927 # @sa GetMinDistance()
928 # @ingroup l1_measurements
929 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
930 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
934 result = result.value
937 ## Get measure structure specifying minimum distance data between two objects
939 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
940 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
942 # @param src1 first source object
943 # @param src2 second source object
944 # @param id1 node/element id from the first source
945 # @param id2 node/element id from the second (or first) source
946 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
947 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
948 # @return Measure structure or None if input data is invalid
950 # @ingroup l1_measurements
951 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
952 if isinstance(src1, Mesh): src1 = src1.mesh
953 if isinstance(src2, Mesh): src2 = src2.mesh
954 if src2 is None and id2 != 0: src2 = src1
955 if not hasattr(src1, "_narrow"): return None
956 src1 = src1._narrow(SMESH.SMESH_IDSource)
957 if not src1: return None
960 e = m.GetMeshEditor()
962 src1 = e.MakeIDSource([id1], SMESH.FACE)
964 src1 = e.MakeIDSource([id1], SMESH.NODE)
966 if hasattr(src2, "_narrow"):
967 src2 = src2._narrow(SMESH.SMESH_IDSource)
968 if src2 and id2 != 0:
970 e = m.GetMeshEditor()
972 src2 = e.MakeIDSource([id2], SMESH.FACE)
974 src2 = e.MakeIDSource([id2], SMESH.NODE)
977 aMeasurements = self.CreateMeasurements()
978 result = aMeasurements.MinDistance(src1, src2)
979 aMeasurements.UnRegister()
982 ## Get bounding box of the specified object(s)
983 # @param objects single source object or list of source objects
984 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
985 # @sa GetBoundingBox()
986 # @ingroup l1_measurements
987 def BoundingBox(self, objects):
988 result = self.GetBoundingBox(objects)
992 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
995 ## Get measure structure specifying bounding box data of the specified object(s)
996 # @param objects single source object or list of source objects
997 # @return Measure structure
999 # @ingroup l1_measurements
1000 def GetBoundingBox(self, objects):
1001 if isinstance(objects, tuple):
1002 objects = list(objects)
1003 if not isinstance(objects, list):
1007 if isinstance(o, Mesh):
1008 srclist.append(o.mesh)
1009 elif hasattr(o, "_narrow"):
1010 src = o._narrow(SMESH.SMESH_IDSource)
1011 if src: srclist.append(src)
1014 aMeasurements = self.CreateMeasurements()
1015 result = aMeasurements.BoundingBox(srclist)
1016 aMeasurements.UnRegister()
1020 #Registering the new proxy for SMESH_Gen
1021 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
1023 ## Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1024 # interface to create or load meshes.
1029 # salome.salome_init()
1030 # from salome.smesh import smeshBuilder
1031 # smesh = smeshBuilder.New(theStudy)
1033 # @param study SALOME study, generally obtained by salome.myStudy.
1034 # @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1035 # @return smeshBuilder instance
1037 def New( study, instance=None):
1039 Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1040 interface to create or load meshes.
1044 salome.salome_init()
1045 from salome.smesh import smeshBuilder
1046 smesh = smeshBuilder.New(theStudy)
1049 study SALOME study, generally obtained by salome.myStudy.
1050 instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
1052 smeshBuilder instance
1060 smeshInst = smeshBuilder()
1061 assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__
1062 smeshInst.init_smesh(study)
1066 # Public class: Mesh
1067 # ==================
1069 ## This class allows defining and managing a mesh.
1070 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1071 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1072 # new nodes and elements and by changing the existing entities), to get information
1073 # about a mesh and to export a mesh into different formats.
1082 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1083 # sets the GUI name of this mesh to \a name.
1084 # @param smeshpyD an instance of smeshBuilder class
1085 # @param geompyD an instance of geomBuilder class
1086 # @param obj Shape to be meshed or SMESH_Mesh object
1087 # @param name Study name of the mesh
1088 # @ingroup l2_construct
1089 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1090 self.smeshpyD=smeshpyD
1091 self.geompyD=geompyD
1096 if isinstance(obj, geomBuilder.GEOM._objref_GEOM_Object):
1099 # publish geom of mesh (issue 0021122)
1100 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
1102 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
1103 if studyID != geompyD.myStudyId:
1104 geompyD.init_geom( smeshpyD.GetCurrentStudy())
1107 geo_name = name + " shape"
1109 geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1110 geompyD.addToStudy( self.geom, geo_name )
1111 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1113 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1116 self.mesh = self.smeshpyD.CreateEmptyMesh()
1118 self.smeshpyD.SetName(self.mesh, name)
1120 self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1123 self.geom = self.mesh.GetShapeToMesh()
1125 self.editor = self.mesh.GetMeshEditor()
1126 self.functors = [None] * SMESH.FT_Undefined._v
1128 # set self to algoCreator's
1129 for attrName in dir(self):
1130 attr = getattr( self, attrName )
1131 if isinstance( attr, algoCreator ):
1132 #print "algoCreator ", attrName
1133 setattr( self, attrName, attr.copy( self ))
1135 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1136 # @param theMesh a SMESH_Mesh object
1137 # @ingroup l2_construct
1138 def SetMesh(self, theMesh):
1139 if self.mesh: self.mesh.UnRegister()
1142 self.mesh.Register()
1143 self.geom = self.mesh.GetShapeToMesh()
1145 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1146 # @return a SMESH_Mesh object
1147 # @ingroup l2_construct
1151 ## Gets the name of the mesh
1152 # @return the name of the mesh as a string
1153 # @ingroup l2_construct
1155 name = GetName(self.GetMesh())
1158 ## Sets a name to the mesh
1159 # @param name a new name of the mesh
1160 # @ingroup l2_construct
1161 def SetName(self, name):
1162 self.smeshpyD.SetName(self.GetMesh(), name)
1164 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1165 # The subMesh object gives access to the IDs of nodes and elements.
1166 # @param geom a geometrical object (shape)
1167 # @param name a name for the submesh
1168 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1169 # @ingroup l2_submeshes
1170 def GetSubMesh(self, geom, name):
1171 AssureGeomPublished( self, geom, name )
1172 submesh = self.mesh.GetSubMesh( geom, name )
1175 ## Returns the shape associated to the mesh
1176 # @return a GEOM_Object
1177 # @ingroup l2_construct
1181 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1182 # @param geom the shape to be meshed (GEOM_Object)
1183 # @ingroup l2_construct
1184 def SetShape(self, geom):
1185 self.mesh = self.smeshpyD.CreateMesh(geom)
1187 ## Loads mesh from the study after opening the study
1191 ## Returns true if the hypotheses are defined well
1192 # @param theSubObject a sub-shape of a mesh shape
1193 # @return True or False
1194 # @ingroup l2_construct
1195 def IsReadyToCompute(self, theSubObject):
1196 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1198 ## Returns errors of hypotheses definition.
1199 # The list of errors is empty if everything is OK.
1200 # @param theSubObject a sub-shape of a mesh shape
1201 # @return a list of errors
1202 # @ingroup l2_construct
1203 def GetAlgoState(self, theSubObject):
1204 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1206 ## Returns a geometrical object on which the given element was built.
1207 # The returned geometrical object, if not nil, is either found in the
1208 # study or published by this method with the given name
1209 # @param theElementID the id of the mesh element
1210 # @param theGeomName the user-defined name of the geometrical object
1211 # @return GEOM::GEOM_Object instance
1212 # @ingroup l2_construct
1213 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1214 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1216 ## Returns the mesh dimension depending on the dimension of the underlying shape
1217 # or, if the mesh is not based on any shape, basing on deimension of elements
1218 # @return mesh dimension as an integer value [0,3]
1219 # @ingroup l1_auxiliary
1220 def MeshDimension(self):
1221 if self.mesh.HasShapeToMesh():
1222 shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
1223 if len( shells ) > 0 :
1225 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1227 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1232 if self.NbVolumes() > 0: return 3
1233 if self.NbFaces() > 0: return 2
1234 if self.NbEdges() > 0: return 1
1237 ## Evaluates size of prospective mesh on a shape
1238 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1239 # To know predicted number of e.g. edges, inquire it this way
1240 # Evaluate()[ EnumToLong( Entity_Edge )]
1241 def Evaluate(self, geom=0):
1242 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1244 geom = self.mesh.GetShapeToMesh()
1247 return self.smeshpyD.Evaluate(self.mesh, geom)
1250 ## Computes the mesh and returns the status of the computation
1251 # @param geom geomtrical shape on which mesh data should be computed
1252 # @param discardModifs if True and the mesh has been edited since
1253 # a last total re-compute and that may prevent successful partial re-compute,
1254 # then the mesh is cleaned before Compute()
1255 # @return True or False
1256 # @ingroup l2_construct
1257 def Compute(self, geom=0, discardModifs=False):
1258 if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1260 geom = self.mesh.GetShapeToMesh()
1265 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1267 ok = self.smeshpyD.Compute(self.mesh, geom)
1268 except SALOME.SALOME_Exception, ex:
1269 print "Mesh computation failed, exception caught:"
1270 print " ", ex.details.text
1273 print "Mesh computation failed, exception caught:"
1274 traceback.print_exc()
1278 # Treat compute errors
1279 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1280 for err in computeErrors:
1282 if self.mesh.HasShapeToMesh():
1284 mainIOR = salome.orb.object_to_string(geom)
1285 for sname in salome.myStudyManager.GetOpenStudies():
1286 s = salome.myStudyManager.GetStudyByName(sname)
1288 mainSO = s.FindObjectIOR(mainIOR)
1289 if not mainSO: continue
1290 if err.subShapeID == 1:
1291 shapeText = ' on "%s"' % mainSO.GetName()
1292 subIt = s.NewChildIterator(mainSO)
1294 subSO = subIt.Value()
1296 obj = subSO.GetObject()
1297 if not obj: continue
1298 go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
1300 ids = go.GetSubShapeIndices()
1301 if len(ids) == 1 and ids[0] == err.subShapeID:
1302 shapeText = ' on "%s"' % subSO.GetName()
1305 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1307 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1309 shapeText = " on subshape #%s" % (err.subShapeID)
1311 shapeText = " on subshape #%s" % (err.subShapeID)
1313 stdErrors = ["OK", #COMPERR_OK
1314 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1315 "std::exception", #COMPERR_STD_EXCEPTION
1316 "OCC exception", #COMPERR_OCC_EXCEPTION
1317 "..", #COMPERR_SLM_EXCEPTION
1318 "Unknown exception", #COMPERR_EXCEPTION
1319 "Memory allocation problem", #COMPERR_MEMORY_PB
1320 "Algorithm failed", #COMPERR_ALGO_FAILED
1321 "Unexpected geometry", #COMPERR_BAD_SHAPE
1322 "Warning", #COMPERR_WARNING
1323 "Computation cancelled",#COMPERR_CANCELED
1324 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1326 if err.code < len(stdErrors): errText = stdErrors[err.code]
1328 errText = "code %s" % -err.code
1329 if errText: errText += ". "
1330 errText += err.comment
1331 if allReasons != "":allReasons += "\n"
1332 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1336 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1338 if err.isGlobalAlgo:
1346 reason = '%s %sD algorithm is missing' % (glob, dim)
1347 elif err.state == HYP_MISSING:
1348 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1349 % (glob, dim, name, dim))
1350 elif err.state == HYP_NOTCONFORM:
1351 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1352 elif err.state == HYP_BAD_PARAMETER:
1353 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1354 % ( glob, dim, name ))
1355 elif err.state == HYP_BAD_GEOMETRY:
1356 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1357 'geometry' % ( glob, dim, name ))
1358 elif err.state == HYP_HIDDEN_ALGO:
1359 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1360 'algorithm of upper dimension generating %sD mesh'
1361 % ( glob, dim, name, glob, dim ))
1363 reason = ("For unknown reason. "
1364 "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1366 if allReasons != "":allReasons += "\n"
1367 allReasons += "- " + reason
1369 if not ok or allReasons != "":
1370 msg = '"' + GetName(self.mesh) + '"'
1371 if ok: msg += " has been computed with warnings"
1372 else: msg += " has not been computed"
1373 if allReasons != "": msg += ":"
1378 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1379 smeshgui = salome.ImportComponentGUI("SMESH")
1380 smeshgui.Init(self.mesh.GetStudyId())
1381 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1382 salome.sg.updateObjBrowser(1)
1386 ## Return submesh objects list in meshing order
1387 # @return list of list of submesh objects
1388 # @ingroup l2_construct
1389 def GetMeshOrder(self):
1390 return self.mesh.GetMeshOrder()
1392 ## Return submesh objects list in meshing order
1393 # @return list of list of submesh objects
1394 # @ingroup l2_construct
1395 def SetMeshOrder(self, submeshes):
1396 return self.mesh.SetMeshOrder(submeshes)
1398 ## Removes all nodes and elements
1399 # @ingroup l2_construct
1402 if ( salome.sg.hasDesktop() and
1403 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1404 smeshgui = salome.ImportComponentGUI("SMESH")
1405 smeshgui.Init(self.mesh.GetStudyId())
1406 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1407 salome.sg.updateObjBrowser(1)
1409 ## Removes all nodes and elements of indicated shape
1410 # @ingroup l2_construct
1411 def ClearSubMesh(self, geomId):
1412 self.mesh.ClearSubMesh(geomId)
1413 if salome.sg.hasDesktop():
1414 smeshgui = salome.ImportComponentGUI("SMESH")
1415 smeshgui.Init(self.mesh.GetStudyId())
1416 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1417 salome.sg.updateObjBrowser(1)
1419 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1420 # @param fineness [0.0,1.0] defines mesh fineness
1421 # @return True or False
1422 # @ingroup l3_algos_basic
1423 def AutomaticTetrahedralization(self, fineness=0):
1424 dim = self.MeshDimension()
1426 self.RemoveGlobalHypotheses()
1427 self.Segment().AutomaticLength(fineness)
1429 self.Triangle().LengthFromEdges()
1432 from salome.NETGENPlugin.NETGENPluginBuilder import NETGEN
1433 self.Tetrahedron(NETGEN)
1435 return self.Compute()
1437 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1438 # @param fineness [0.0, 1.0] defines mesh fineness
1439 # @return True or False
1440 # @ingroup l3_algos_basic
1441 def AutomaticHexahedralization(self, fineness=0):
1442 dim = self.MeshDimension()
1443 # assign the hypotheses
1444 self.RemoveGlobalHypotheses()
1445 self.Segment().AutomaticLength(fineness)
1452 return self.Compute()
1454 ## Assigns a hypothesis
1455 # @param hyp a hypothesis to assign
1456 # @param geom a subhape of mesh geometry
1457 # @return SMESH.Hypothesis_Status
1458 # @ingroup l2_hypotheses
1459 def AddHypothesis(self, hyp, geom=0):
1460 if isinstance( hyp, Mesh_Algorithm ):
1461 hyp = hyp.GetAlgorithm()
1466 geom = self.mesh.GetShapeToMesh()
1468 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1469 status = self.mesh.AddHypothesis(geom, hyp)
1470 isAlgo = hyp._narrow( SMESH_Algo )
1471 hyp_name = GetName( hyp )
1474 geom_name = GetName( geom )
1475 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1478 ## Return True if an algorithm of hypothesis is assigned to a given shape
1479 # @param hyp a hypothesis to check
1480 # @param geom a subhape of mesh geometry
1481 # @return True of False
1482 # @ingroup l2_hypotheses
1483 def IsUsedHypothesis(self, hyp, geom):
1484 if not hyp: # or not geom
1486 if isinstance( hyp, Mesh_Algorithm ):
1487 hyp = hyp.GetAlgorithm()
1489 hyps = self.GetHypothesisList(geom)
1491 if h.GetId() == hyp.GetId():
1495 ## Unassigns a hypothesis
1496 # @param hyp a hypothesis to unassign
1497 # @param geom a sub-shape of mesh geometry
1498 # @return SMESH.Hypothesis_Status
1499 # @ingroup l2_hypotheses
1500 def RemoveHypothesis(self, hyp, geom=0):
1501 if isinstance( hyp, Mesh_Algorithm ):
1502 hyp = hyp.GetAlgorithm()
1508 if self.IsUsedHypothesis( hyp, shape ):
1509 return self.mesh.RemoveHypothesis( shape, hyp )
1510 hypName = GetName( hyp )
1511 geoName = GetName( shape )
1512 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1515 ## Gets the list of hypotheses added on a geometry
1516 # @param geom a sub-shape of mesh geometry
1517 # @return the sequence of SMESH_Hypothesis
1518 # @ingroup l2_hypotheses
1519 def GetHypothesisList(self, geom):
1520 return self.mesh.GetHypothesisList( geom )
1522 ## Removes all global hypotheses
1523 # @ingroup l2_hypotheses
1524 def RemoveGlobalHypotheses(self):
1525 current_hyps = self.mesh.GetHypothesisList( self.geom )
1526 for hyp in current_hyps:
1527 self.mesh.RemoveHypothesis( self.geom, hyp )
1531 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1532 ## allowing to overwrite the file if it exists or add the exported data to its contents
1533 # @param f is the file name
1534 # @param auto_groups boolean parameter for creating/not creating
1535 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1536 # the typical use is auto_groups=false.
1537 # @param version MED format version(MED_V2_1 or MED_V2_2)
1538 # @param overwrite boolean parameter for overwriting/not overwriting the file
1539 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1540 # @ingroup l2_impexp
1541 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1543 if isinstance( meshPart, list ):
1544 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1545 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1547 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1549 ## Exports the mesh in a file in SAUV format
1550 # @param f is the file name
1551 # @param auto_groups boolean parameter for creating/not creating
1552 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1553 # the typical use is auto_groups=false.
1554 # @ingroup l2_impexp
1555 def ExportSAUV(self, f, auto_groups=0):
1556 self.mesh.ExportSAUV(f, auto_groups)
1558 ## Exports the mesh in a file in DAT format
1559 # @param f the file name
1560 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1561 # @ingroup l2_impexp
1562 def ExportDAT(self, f, meshPart=None):
1564 if isinstance( meshPart, list ):
1565 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1566 self.mesh.ExportPartToDAT( meshPart, f )
1568 self.mesh.ExportDAT(f)
1570 ## Exports the mesh in a file in UNV format
1571 # @param f the file name
1572 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1573 # @ingroup l2_impexp
1574 def ExportUNV(self, f, meshPart=None):
1576 if isinstance( meshPart, list ):
1577 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1578 self.mesh.ExportPartToUNV( meshPart, f )
1580 self.mesh.ExportUNV(f)
1582 ## Export the mesh in a file in STL format
1583 # @param f the file name
1584 # @param ascii defines the file encoding
1585 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1586 # @ingroup l2_impexp
1587 def ExportSTL(self, f, ascii=1, meshPart=None):
1589 if isinstance( meshPart, list ):
1590 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1591 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1593 self.mesh.ExportSTL(f, ascii)
1595 ## Exports the mesh in a file in CGNS format
1596 # @param f is the file name
1597 # @param overwrite boolean parameter for overwriting/not overwriting the file
1598 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1599 # @ingroup l2_impexp
1600 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1601 if isinstance( meshPart, list ):
1602 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1603 if isinstance( meshPart, Mesh ):
1604 meshPart = meshPart.mesh
1606 meshPart = self.mesh
1607 self.mesh.ExportCGNS(meshPart, f, overwrite)
1609 ## Exports the mesh in a file in GMF format
1610 # @param f is the file name
1611 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1612 # @ingroup l2_impexp
1613 def ExportGMF(self, f, meshPart=None):
1614 if isinstance( meshPart, list ):
1615 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1616 if isinstance( meshPart, Mesh ):
1617 meshPart = meshPart.mesh
1619 meshPart = self.mesh
1620 self.mesh.ExportGMF(meshPart, f, True)
1622 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1623 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1624 ## allowing to overwrite the file if it exists or add the exported data to its contents
1625 # @param f the file name
1626 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1627 # @param opt boolean parameter for creating/not creating
1628 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1629 # @param overwrite boolean parameter for overwriting/not overwriting the file
1630 # @ingroup l2_impexp
1631 def ExportToMED(self, f, version, opt=0, overwrite=1):
1632 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1634 # Operations with groups:
1635 # ----------------------
1637 ## Creates an empty mesh group
1638 # @param elementType the type of elements in the group
1639 # @param name the name of the mesh group
1640 # @return SMESH_Group
1641 # @ingroup l2_grps_create
1642 def CreateEmptyGroup(self, elementType, name):
1643 return self.mesh.CreateGroup(elementType, name)
1645 ## Creates a mesh group based on the geometric object \a grp
1646 # and gives a \a name, \n if this parameter is not defined
1647 # the name is the same as the geometric group name \n
1648 # Note: Works like GroupOnGeom().
1649 # @param grp a geometric group, a vertex, an edge, a face or a solid
1650 # @param name the name of the mesh group
1651 # @return SMESH_GroupOnGeom
1652 # @ingroup l2_grps_create
1653 def Group(self, grp, name=""):
1654 return self.GroupOnGeom(grp, name)
1656 ## Creates a mesh group based on the geometrical object \a grp
1657 # and gives a \a name, \n if this parameter is not defined
1658 # the name is the same as the geometrical group name
1659 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1660 # @param name the name of the mesh group
1661 # @param typ the type of elements in the group. If not set, it is
1662 # automatically detected by the type of the geometry
1663 # @return SMESH_GroupOnGeom
1664 # @ingroup l2_grps_create
1665 def GroupOnGeom(self, grp, name="", typ=None):
1666 AssureGeomPublished( self, grp, name )
1668 name = grp.GetName()
1670 typ = self._groupTypeFromShape( grp )
1671 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1673 ## Pivate method to get a type of group on geometry
1674 def _groupTypeFromShape( self, shape ):
1675 tgeo = str(shape.GetShapeType())
1676 if tgeo == "VERTEX":
1678 elif tgeo == "EDGE":
1680 elif tgeo == "FACE" or tgeo == "SHELL":
1682 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1684 elif tgeo == "COMPOUND":
1685 sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
1687 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1688 return self._groupTypeFromShape( sub[0] )
1691 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1694 ## Creates a mesh group with given \a name based on the \a filter which
1695 ## is a special type of group dynamically updating it's contents during
1696 ## mesh modification
1697 # @param typ the type of elements in the group
1698 # @param name the name of the mesh group
1699 # @param filter the filter defining group contents
1700 # @return SMESH_GroupOnFilter
1701 # @ingroup l2_grps_create
1702 def GroupOnFilter(self, typ, name, filter):
1703 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1705 ## Creates a mesh group by the given ids of elements
1706 # @param groupName the name of the mesh group
1707 # @param elementType the type of elements in the group
1708 # @param elemIDs the list of ids
1709 # @return SMESH_Group
1710 # @ingroup l2_grps_create
1711 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1712 group = self.mesh.CreateGroup(elementType, groupName)
1716 ## Creates a mesh group by the given conditions
1717 # @param groupName the name of the mesh group
1718 # @param elementType the type of elements in the group
1719 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1720 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1721 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1722 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1723 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1724 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1725 # @return SMESH_Group
1726 # @ingroup l2_grps_create
1730 CritType=FT_Undefined,
1733 UnaryOp=FT_Undefined,
1735 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1736 group = self.MakeGroupByCriterion(groupName, aCriterion)
1739 ## Creates a mesh group by the given criterion
1740 # @param groupName the name of the mesh group
1741 # @param Criterion the instance of Criterion class
1742 # @return SMESH_Group
1743 # @ingroup l2_grps_create
1744 def MakeGroupByCriterion(self, groupName, Criterion):
1745 aFilterMgr = self.smeshpyD.CreateFilterManager()
1746 aFilter = aFilterMgr.CreateFilter()
1748 aCriteria.append(Criterion)
1749 aFilter.SetCriteria(aCriteria)
1750 group = self.MakeGroupByFilter(groupName, aFilter)
1751 aFilterMgr.UnRegister()
1754 ## Creates a mesh group by the given criteria (list of criteria)
1755 # @param groupName the name of the mesh group
1756 # @param theCriteria the list of criteria
1757 # @return SMESH_Group
1758 # @ingroup l2_grps_create
1759 def MakeGroupByCriteria(self, groupName, theCriteria):
1760 aFilterMgr = self.smeshpyD.CreateFilterManager()
1761 aFilter = aFilterMgr.CreateFilter()
1762 aFilter.SetCriteria(theCriteria)
1763 group = self.MakeGroupByFilter(groupName, aFilter)
1764 aFilterMgr.UnRegister()
1767 ## Creates a mesh group by the given filter
1768 # @param groupName the name of the mesh group
1769 # @param theFilter the instance of Filter class
1770 # @return SMESH_Group
1771 # @ingroup l2_grps_create
1772 def MakeGroupByFilter(self, groupName, theFilter):
1773 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1774 theFilter.SetMesh( self.mesh )
1775 group.AddFrom( theFilter )
1779 # @ingroup l2_grps_delete
1780 def RemoveGroup(self, group):
1781 self.mesh.RemoveGroup(group)
1783 ## Removes a group with its contents
1784 # @ingroup l2_grps_delete
1785 def RemoveGroupWithContents(self, group):
1786 self.mesh.RemoveGroupWithContents(group)
1788 ## Gets the list of groups existing in the mesh
1789 # @return a sequence of SMESH_GroupBase
1790 # @ingroup l2_grps_create
1791 def GetGroups(self):
1792 return self.mesh.GetGroups()
1794 ## Gets the number of groups existing in the mesh
1795 # @return the quantity of groups as an integer value
1796 # @ingroup l2_grps_create
1798 return self.mesh.NbGroups()
1800 ## Gets the list of names of groups existing in the mesh
1801 # @return list of strings
1802 # @ingroup l2_grps_create
1803 def GetGroupNames(self):
1804 groups = self.GetGroups()
1806 for group in groups:
1807 names.append(group.GetName())
1810 ## Produces a union of two groups
1811 # A new group is created. All mesh elements that are
1812 # present in the initial groups are added to the new one
1813 # @return an instance of SMESH_Group
1814 # @ingroup l2_grps_operon
1815 def UnionGroups(self, group1, group2, name):
1816 return self.mesh.UnionGroups(group1, group2, name)
1818 ## Produces a union list of groups
1819 # New group is created. All mesh elements that are present in
1820 # initial groups are added to the new one
1821 # @return an instance of SMESH_Group
1822 # @ingroup l2_grps_operon
1823 def UnionListOfGroups(self, groups, name):
1824 return self.mesh.UnionListOfGroups(groups, name)
1826 ## Prodices an intersection of two groups
1827 # A new group is created. All mesh elements that are common
1828 # for the two initial groups are added to the new one.
1829 # @return an instance of SMESH_Group
1830 # @ingroup l2_grps_operon
1831 def IntersectGroups(self, group1, group2, name):
1832 return self.mesh.IntersectGroups(group1, group2, name)
1834 ## Produces an intersection of groups
1835 # New group is created. All mesh elements that are present in all
1836 # initial groups simultaneously are added to the new one
1837 # @return an instance of SMESH_Group
1838 # @ingroup l2_grps_operon
1839 def IntersectListOfGroups(self, groups, name):
1840 return self.mesh.IntersectListOfGroups(groups, name)
1842 ## Produces a cut of two groups
1843 # A new group is created. All mesh elements that are present in
1844 # the main group but are not present in the tool group are added to the new one
1845 # @return an instance of SMESH_Group
1846 # @ingroup l2_grps_operon
1847 def CutGroups(self, main_group, tool_group, name):
1848 return self.mesh.CutGroups(main_group, tool_group, name)
1850 ## Produces a cut of groups
1851 # A new group is created. All mesh elements that are present in main groups
1852 # but do not present in tool groups are added to the new one
1853 # @return an instance of SMESH_Group
1854 # @ingroup l2_grps_operon
1855 def CutListOfGroups(self, main_groups, tool_groups, name):
1856 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1858 ## Produces a group of elements of specified type using list of existing groups
1859 # A new group is created. System
1860 # 1) extracts all nodes on which groups elements are built
1861 # 2) combines all elements of specified dimension laying on these nodes
1862 # @return an instance of SMESH_Group
1863 # @ingroup l2_grps_operon
1864 def CreateDimGroup(self, groups, elem_type, name):
1865 return self.mesh.CreateDimGroup(groups, elem_type, name)
1868 ## Convert group on geom into standalone group
1869 # @ingroup l2_grps_delete
1870 def ConvertToStandalone(self, group):
1871 return self.mesh.ConvertToStandalone(group)
1873 # Get some info about mesh:
1874 # ------------------------
1876 ## Returns the log of nodes and elements added or removed
1877 # since the previous clear of the log.
1878 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1879 # @return list of log_block structures:
1884 # @ingroup l1_auxiliary
1885 def GetLog(self, clearAfterGet):
1886 return self.mesh.GetLog(clearAfterGet)
1888 ## Clears the log of nodes and elements added or removed since the previous
1889 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1890 # @ingroup l1_auxiliary
1892 self.mesh.ClearLog()
1894 ## Toggles auto color mode on the object.
1895 # @param theAutoColor the flag which toggles auto color mode.
1896 # @ingroup l1_auxiliary
1897 def SetAutoColor(self, theAutoColor):
1898 self.mesh.SetAutoColor(theAutoColor)
1900 ## Gets flag of object auto color mode.
1901 # @return True or False
1902 # @ingroup l1_auxiliary
1903 def GetAutoColor(self):
1904 return self.mesh.GetAutoColor()
1906 ## Gets the internal ID
1907 # @return integer value, which is the internal Id of the mesh
1908 # @ingroup l1_auxiliary
1910 return self.mesh.GetId()
1913 # @return integer value, which is the study Id of the mesh
1914 # @ingroup l1_auxiliary
1915 def GetStudyId(self):
1916 return self.mesh.GetStudyId()
1918 ## Checks the group names for duplications.
1919 # Consider the maximum group name length stored in MED file.
1920 # @return True or False
1921 # @ingroup l1_auxiliary
1922 def HasDuplicatedGroupNamesMED(self):
1923 return self.mesh.HasDuplicatedGroupNamesMED()
1925 ## Obtains the mesh editor tool
1926 # @return an instance of SMESH_MeshEditor
1927 # @ingroup l1_modifying
1928 def GetMeshEditor(self):
1931 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1932 # can be passed as argument to a method accepting mesh, group or sub-mesh
1933 # @return an instance of SMESH_IDSource
1934 # @ingroup l1_auxiliary
1935 def GetIDSource(self, ids, elemType):
1936 return self.editor.MakeIDSource(ids, elemType)
1939 # @return an instance of SALOME_MED::MESH
1940 # @ingroup l1_auxiliary
1941 def GetMEDMesh(self):
1942 return self.mesh.GetMEDMesh()
1945 # Get informations about mesh contents:
1946 # ------------------------------------
1948 ## Gets the mesh stattistic
1949 # @return dictionary type element - count of elements
1950 # @ingroup l1_meshinfo
1951 def GetMeshInfo(self, obj = None):
1952 if not obj: obj = self.mesh
1953 return self.smeshpyD.GetMeshInfo(obj)
1955 ## Returns the number of nodes in the mesh
1956 # @return an integer value
1957 # @ingroup l1_meshinfo
1959 return self.mesh.NbNodes()
1961 ## Returns the number of elements in the mesh
1962 # @return an integer value
1963 # @ingroup l1_meshinfo
1964 def NbElements(self):
1965 return self.mesh.NbElements()
1967 ## Returns the number of 0d elements in the mesh
1968 # @return an integer value
1969 # @ingroup l1_meshinfo
1970 def Nb0DElements(self):
1971 return self.mesh.Nb0DElements()
1973 ## Returns the number of ball discrete elements in the mesh
1974 # @return an integer value
1975 # @ingroup l1_meshinfo
1977 return self.mesh.NbBalls()
1979 ## Returns the number of edges in the mesh
1980 # @return an integer value
1981 # @ingroup l1_meshinfo
1983 return self.mesh.NbEdges()
1985 ## Returns the number of edges with the given order in the mesh
1986 # @param elementOrder the order of elements:
1987 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1988 # @return an integer value
1989 # @ingroup l1_meshinfo
1990 def NbEdgesOfOrder(self, elementOrder):
1991 return self.mesh.NbEdgesOfOrder(elementOrder)
1993 ## Returns the number of faces in the mesh
1994 # @return an integer value
1995 # @ingroup l1_meshinfo
1997 return self.mesh.NbFaces()
1999 ## Returns the number of faces with the given order in the mesh
2000 # @param elementOrder the order of elements:
2001 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2002 # @return an integer value
2003 # @ingroup l1_meshinfo
2004 def NbFacesOfOrder(self, elementOrder):
2005 return self.mesh.NbFacesOfOrder(elementOrder)
2007 ## Returns the number of triangles in the mesh
2008 # @return an integer value
2009 # @ingroup l1_meshinfo
2010 def NbTriangles(self):
2011 return self.mesh.NbTriangles()
2013 ## Returns the number of triangles with the given order in the mesh
2014 # @param elementOrder is the order of elements:
2015 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2016 # @return an integer value
2017 # @ingroup l1_meshinfo
2018 def NbTrianglesOfOrder(self, elementOrder):
2019 return self.mesh.NbTrianglesOfOrder(elementOrder)
2021 ## Returns the number of quadrangles in the mesh
2022 # @return an integer value
2023 # @ingroup l1_meshinfo
2024 def NbQuadrangles(self):
2025 return self.mesh.NbQuadrangles()
2027 ## Returns the number of quadrangles with the given order in the mesh
2028 # @param elementOrder the order of elements:
2029 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2030 # @return an integer value
2031 # @ingroup l1_meshinfo
2032 def NbQuadranglesOfOrder(self, elementOrder):
2033 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2035 ## Returns the number of biquadratic quadrangles in the mesh
2036 # @return an integer value
2037 # @ingroup l1_meshinfo
2038 def NbBiQuadQuadrangles(self):
2039 return self.mesh.NbBiQuadQuadrangles()
2041 ## Returns the number of polygons in the mesh
2042 # @return an integer value
2043 # @ingroup l1_meshinfo
2044 def NbPolygons(self):
2045 return self.mesh.NbPolygons()
2047 ## Returns the number of volumes in the mesh
2048 # @return an integer value
2049 # @ingroup l1_meshinfo
2050 def NbVolumes(self):
2051 return self.mesh.NbVolumes()
2053 ## Returns the number of volumes with the given order in the mesh
2054 # @param elementOrder the order of elements:
2055 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2056 # @return an integer value
2057 # @ingroup l1_meshinfo
2058 def NbVolumesOfOrder(self, elementOrder):
2059 return self.mesh.NbVolumesOfOrder(elementOrder)
2061 ## Returns the number of tetrahedrons in the mesh
2062 # @return an integer value
2063 # @ingroup l1_meshinfo
2065 return self.mesh.NbTetras()
2067 ## Returns the number of tetrahedrons with the given order in the mesh
2068 # @param elementOrder the order of elements:
2069 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2070 # @return an integer value
2071 # @ingroup l1_meshinfo
2072 def NbTetrasOfOrder(self, elementOrder):
2073 return self.mesh.NbTetrasOfOrder(elementOrder)
2075 ## Returns the number of hexahedrons in the mesh
2076 # @return an integer value
2077 # @ingroup l1_meshinfo
2079 return self.mesh.NbHexas()
2081 ## Returns the number of hexahedrons with the given order in the mesh
2082 # @param elementOrder the order of elements:
2083 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2084 # @return an integer value
2085 # @ingroup l1_meshinfo
2086 def NbHexasOfOrder(self, elementOrder):
2087 return self.mesh.NbHexasOfOrder(elementOrder)
2089 ## Returns the number of triquadratic hexahedrons in the mesh
2090 # @return an integer value
2091 # @ingroup l1_meshinfo
2092 def NbTriQuadraticHexas(self):
2093 return self.mesh.NbTriQuadraticHexas()
2095 ## Returns the number of pyramids in the mesh
2096 # @return an integer value
2097 # @ingroup l1_meshinfo
2098 def NbPyramids(self):
2099 return self.mesh.NbPyramids()
2101 ## Returns the number of pyramids with the given order in the mesh
2102 # @param elementOrder the order of elements:
2103 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2104 # @return an integer value
2105 # @ingroup l1_meshinfo
2106 def NbPyramidsOfOrder(self, elementOrder):
2107 return self.mesh.NbPyramidsOfOrder(elementOrder)
2109 ## Returns the number of prisms in the mesh
2110 # @return an integer value
2111 # @ingroup l1_meshinfo
2113 return self.mesh.NbPrisms()
2115 ## Returns the number of prisms with the given order in the mesh
2116 # @param elementOrder the order of elements:
2117 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2118 # @return an integer value
2119 # @ingroup l1_meshinfo
2120 def NbPrismsOfOrder(self, elementOrder):
2121 return self.mesh.NbPrismsOfOrder(elementOrder)
2123 ## Returns the number of hexagonal prisms in the mesh
2124 # @return an integer value
2125 # @ingroup l1_meshinfo
2126 def NbHexagonalPrisms(self):
2127 return self.mesh.NbHexagonalPrisms()
2129 ## Returns the number of polyhedrons in the mesh
2130 # @return an integer value
2131 # @ingroup l1_meshinfo
2132 def NbPolyhedrons(self):
2133 return self.mesh.NbPolyhedrons()
2135 ## Returns the number of submeshes in the mesh
2136 # @return an integer value
2137 # @ingroup l1_meshinfo
2138 def NbSubMesh(self):
2139 return self.mesh.NbSubMesh()
2141 ## Returns the list of mesh elements IDs
2142 # @return the list of integer values
2143 # @ingroup l1_meshinfo
2144 def GetElementsId(self):
2145 return self.mesh.GetElementsId()
2147 ## Returns the list of IDs of mesh elements with the given type
2148 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2149 # @return list of integer values
2150 # @ingroup l1_meshinfo
2151 def GetElementsByType(self, elementType):
2152 return self.mesh.GetElementsByType(elementType)
2154 ## Returns the list of mesh nodes IDs
2155 # @return the list of integer values
2156 # @ingroup l1_meshinfo
2157 def GetNodesId(self):
2158 return self.mesh.GetNodesId()
2160 # Get the information about mesh elements:
2161 # ------------------------------------
2163 ## Returns the type of mesh element
2164 # @return the value from SMESH::ElementType enumeration
2165 # @ingroup l1_meshinfo
2166 def GetElementType(self, id, iselem):
2167 return self.mesh.GetElementType(id, iselem)
2169 ## Returns the geometric type of mesh element
2170 # @return the value from SMESH::EntityType enumeration
2171 # @ingroup l1_meshinfo
2172 def GetElementGeomType(self, id):
2173 return self.mesh.GetElementGeomType(id)
2175 ## Returns the list of submesh elements IDs
2176 # @param Shape a geom object(sub-shape) IOR
2177 # Shape must be the sub-shape of a ShapeToMesh()
2178 # @return the list of integer values
2179 # @ingroup l1_meshinfo
2180 def GetSubMeshElementsId(self, Shape):
2181 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2182 ShapeID = Shape.GetSubShapeIndices()[0]
2185 return self.mesh.GetSubMeshElementsId(ShapeID)
2187 ## Returns the list of submesh nodes IDs
2188 # @param Shape a geom object(sub-shape) IOR
2189 # Shape must be the sub-shape of a ShapeToMesh()
2190 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2191 # @return the list of integer values
2192 # @ingroup l1_meshinfo
2193 def GetSubMeshNodesId(self, Shape, all):
2194 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2195 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2198 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2200 ## Returns type of elements on given shape
2201 # @param Shape a geom object(sub-shape) IOR
2202 # Shape must be a sub-shape of a ShapeToMesh()
2203 # @return element type
2204 # @ingroup l1_meshinfo
2205 def GetSubMeshElementType(self, Shape):
2206 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2207 ShapeID = Shape.GetSubShapeIndices()[0]
2210 return self.mesh.GetSubMeshElementType(ShapeID)
2212 ## Gets the mesh description
2213 # @return string value
2214 # @ingroup l1_meshinfo
2216 return self.mesh.Dump()
2219 # Get the information about nodes and elements of a mesh by its IDs:
2220 # -----------------------------------------------------------
2222 ## Gets XYZ coordinates of a node
2223 # \n If there is no nodes for the given ID - returns an empty list
2224 # @return a list of double precision values
2225 # @ingroup l1_meshinfo
2226 def GetNodeXYZ(self, id):
2227 return self.mesh.GetNodeXYZ(id)
2229 ## Returns list of IDs of inverse elements for the given node
2230 # \n If there is no node for the given ID - returns an empty list
2231 # @return a list of integer values
2232 # @ingroup l1_meshinfo
2233 def GetNodeInverseElements(self, id):
2234 return self.mesh.GetNodeInverseElements(id)
2236 ## @brief Returns the position of a node on the shape
2237 # @return SMESH::NodePosition
2238 # @ingroup l1_meshinfo
2239 def GetNodePosition(self,NodeID):
2240 return self.mesh.GetNodePosition(NodeID)
2242 ## @brief Returns the position of an element on the shape
2243 # @return SMESH::ElementPosition
2244 # @ingroup l1_meshinfo
2245 def GetElementPosition(self,ElemID):
2246 return self.mesh.GetElementPosition(ElemID)
2248 ## If the given element is a node, returns the ID of shape
2249 # \n If there is no node for the given ID - returns -1
2250 # @return an integer value
2251 # @ingroup l1_meshinfo
2252 def GetShapeID(self, id):
2253 return self.mesh.GetShapeID(id)
2255 ## Returns the ID of the result shape after
2256 # FindShape() from SMESH_MeshEditor for the given element
2257 # \n If there is no element for the given ID - returns -1
2258 # @return an integer value
2259 # @ingroup l1_meshinfo
2260 def GetShapeIDForElem(self,id):
2261 return self.mesh.GetShapeIDForElem(id)
2263 ## Returns the number of nodes for the given element
2264 # \n If there is no element for the given ID - returns -1
2265 # @return an integer value
2266 # @ingroup l1_meshinfo
2267 def GetElemNbNodes(self, id):
2268 return self.mesh.GetElemNbNodes(id)
2270 ## Returns the node ID the given (zero based) index for the given element
2271 # \n If there is no element for the given ID - returns -1
2272 # \n If there is no node for the given index - returns -2
2273 # @return an integer value
2274 # @ingroup l1_meshinfo
2275 def GetElemNode(self, id, index):
2276 return self.mesh.GetElemNode(id, index)
2278 ## Returns the IDs of nodes of the given element
2279 # @return a list of integer values
2280 # @ingroup l1_meshinfo
2281 def GetElemNodes(self, id):
2282 return self.mesh.GetElemNodes(id)
2284 ## Returns true if the given node is the medium node in the given quadratic element
2285 # @ingroup l1_meshinfo
2286 def IsMediumNode(self, elementID, nodeID):
2287 return self.mesh.IsMediumNode(elementID, nodeID)
2289 ## Returns true if the given node is the medium node in one of quadratic elements
2290 # @ingroup l1_meshinfo
2291 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2292 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2294 ## Returns the number of edges for the given element
2295 # @ingroup l1_meshinfo
2296 def ElemNbEdges(self, id):
2297 return self.mesh.ElemNbEdges(id)
2299 ## Returns the number of faces for the given element
2300 # @ingroup l1_meshinfo
2301 def ElemNbFaces(self, id):
2302 return self.mesh.ElemNbFaces(id)
2304 ## Returns nodes of given face (counted from zero) for given volumic element.
2305 # @ingroup l1_meshinfo
2306 def GetElemFaceNodes(self,elemId, faceIndex):
2307 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2309 ## Returns an element based on all given nodes.
2310 # @ingroup l1_meshinfo
2311 def FindElementByNodes(self,nodes):
2312 return self.mesh.FindElementByNodes(nodes)
2314 ## Returns true if the given element is a polygon
2315 # @ingroup l1_meshinfo
2316 def IsPoly(self, id):
2317 return self.mesh.IsPoly(id)
2319 ## Returns true if the given element is quadratic
2320 # @ingroup l1_meshinfo
2321 def IsQuadratic(self, id):
2322 return self.mesh.IsQuadratic(id)
2324 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2325 # @ingroup l1_meshinfo
2326 def GetBallDiameter(self, id):
2327 return self.mesh.GetBallDiameter(id)
2329 ## Returns XYZ coordinates of the barycenter of the given element
2330 # \n If there is no element for the given ID - returns an empty list
2331 # @return a list of three double values
2332 # @ingroup l1_meshinfo
2333 def BaryCenter(self, id):
2334 return self.mesh.BaryCenter(id)
2336 ## Passes mesh elements through the given filter and return IDs of fitting elements
2337 # @param theFilter SMESH_Filter
2338 # @return a list of ids
2339 # @ingroup l1_controls
2340 def GetIdsFromFilter(self, theFilter):
2341 theFilter.SetMesh( self.mesh )
2342 return theFilter.GetIDs()
2344 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2345 # Returns a list of special structures (borders).
2346 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2347 # @ingroup l1_controls
2348 def GetFreeBorders(self):
2349 aFilterMgr = self.smeshpyD.CreateFilterManager()
2350 aPredicate = aFilterMgr.CreateFreeEdges()
2351 aPredicate.SetMesh(self.mesh)
2352 aBorders = aPredicate.GetBorders()
2353 aFilterMgr.UnRegister()
2357 # Get mesh measurements information:
2358 # ------------------------------------
2360 ## Get minimum distance between two nodes, elements or distance to the origin
2361 # @param id1 first node/element id
2362 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2363 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2364 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2365 # @return minimum distance value
2366 # @sa GetMinDistance()
2367 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2368 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2369 return aMeasure.value
2371 ## Get measure structure specifying minimum distance data between two objects
2372 # @param id1 first node/element id
2373 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2374 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2375 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2376 # @return Measure structure
2378 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2380 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2382 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2385 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2387 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2392 aMeasurements = self.smeshpyD.CreateMeasurements()
2393 aMeasure = aMeasurements.MinDistance(id1, id2)
2394 aMeasurements.UnRegister()
2397 ## Get bounding box of the specified object(s)
2398 # @param objects single source object or list of source objects or list of nodes/elements IDs
2399 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2400 # @c False specifies that @a objects are nodes
2401 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2402 # @sa GetBoundingBox()
2403 def BoundingBox(self, objects=None, isElem=False):
2404 result = self.GetBoundingBox(objects, isElem)
2408 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2411 ## Get measure structure specifying bounding box data of the specified object(s)
2412 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2413 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2414 # @c False specifies that @a objects are nodes
2415 # @return Measure structure
2417 def GetBoundingBox(self, IDs=None, isElem=False):
2420 elif isinstance(IDs, tuple):
2422 if not isinstance(IDs, list):
2424 if len(IDs) > 0 and isinstance(IDs[0], int):
2428 if isinstance(o, Mesh):
2429 srclist.append(o.mesh)
2430 elif hasattr(o, "_narrow"):
2431 src = o._narrow(SMESH.SMESH_IDSource)
2432 if src: srclist.append(src)
2434 elif isinstance(o, list):
2436 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2438 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2441 aMeasurements = self.smeshpyD.CreateMeasurements()
2442 aMeasure = aMeasurements.BoundingBox(srclist)
2443 aMeasurements.UnRegister()
2446 # Mesh edition (SMESH_MeshEditor functionality):
2447 # ---------------------------------------------
2449 ## Removes the elements from the mesh by ids
2450 # @param IDsOfElements is a list of ids of elements to remove
2451 # @return True or False
2452 # @ingroup l2_modif_del
2453 def RemoveElements(self, IDsOfElements):
2454 return self.editor.RemoveElements(IDsOfElements)
2456 ## Removes nodes from mesh by ids
2457 # @param IDsOfNodes is a list of ids of nodes to remove
2458 # @return True or False
2459 # @ingroup l2_modif_del
2460 def RemoveNodes(self, IDsOfNodes):
2461 return self.editor.RemoveNodes(IDsOfNodes)
2463 ## Removes all orphan (free) nodes from mesh
2464 # @return number of the removed nodes
2465 # @ingroup l2_modif_del
2466 def RemoveOrphanNodes(self):
2467 return self.editor.RemoveOrphanNodes()
2469 ## Add a node to the mesh by coordinates
2470 # @return Id of the new node
2471 # @ingroup l2_modif_add
2472 def AddNode(self, x, y, z):
2473 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2474 if hasVars: self.mesh.SetParameters(Parameters)
2475 return self.editor.AddNode( x, y, z)
2477 ## Creates a 0D element on a node with given number.
2478 # @param IDOfNode the ID of node for creation of the element.
2479 # @return the Id of the new 0D element
2480 # @ingroup l2_modif_add
2481 def Add0DElement(self, IDOfNode):
2482 return self.editor.Add0DElement(IDOfNode)
2484 ## Create 0D elements on all nodes of the given elements except those
2485 # nodes on which a 0D element already exists.
2486 # @param theObject an object on whose nodes 0D elements will be created.
2487 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2488 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2489 # @param theGroupName optional name of a group to add 0D elements created
2490 # and/or found on nodes of \a theObject.
2491 # @return an object (a new group or a temporary SMESH_IDSource) holding
2492 # IDs of new and/or found 0D elements. IDs of 0D elements
2493 # can be retrieved from the returned object by calling GetIDs()
2494 # @ingroup l2_modif_add
2495 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2496 if isinstance( theObject, Mesh ):
2497 theObject = theObject.GetMesh()
2498 if isinstance( theObject, list ):
2499 theObject = self.GetIDSource( theObject, SMESH.ALL )
2500 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2502 ## Creates a ball element on a node with given ID.
2503 # @param IDOfNode the ID of node for creation of the element.
2504 # @param diameter the bal diameter.
2505 # @return the Id of the new ball element
2506 # @ingroup l2_modif_add
2507 def AddBall(self, IDOfNode, diameter):
2508 return self.editor.AddBall( IDOfNode, diameter )
2510 ## Creates a linear or quadratic edge (this is determined
2511 # by the number of given nodes).
2512 # @param IDsOfNodes the list of node IDs for creation of the element.
2513 # The order of nodes in this list should correspond to the description
2514 # of MED. \n This description is located by the following link:
2515 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2516 # @return the Id of the new edge
2517 # @ingroup l2_modif_add
2518 def AddEdge(self, IDsOfNodes):
2519 return self.editor.AddEdge(IDsOfNodes)
2521 ## Creates a linear or quadratic face (this is determined
2522 # by the number of given nodes).
2523 # @param IDsOfNodes the list of node IDs for creation of the element.
2524 # The order of nodes in this list should correspond to the description
2525 # of MED. \n This description is located by the following link:
2526 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2527 # @return the Id of the new face
2528 # @ingroup l2_modif_add
2529 def AddFace(self, IDsOfNodes):
2530 return self.editor.AddFace(IDsOfNodes)
2532 ## Adds a polygonal face to the mesh by the list of node IDs
2533 # @param IdsOfNodes the list of node IDs for creation of the element.
2534 # @return the Id of the new face
2535 # @ingroup l2_modif_add
2536 def AddPolygonalFace(self, IdsOfNodes):
2537 return self.editor.AddPolygonalFace(IdsOfNodes)
2539 ## Creates both simple and quadratic volume (this is determined
2540 # by the number of given nodes).
2541 # @param IDsOfNodes the list of node IDs for creation of the element.
2542 # The order of nodes in this list should correspond to the description
2543 # of MED. \n This description is located by the following link:
2544 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2545 # @return the Id of the new volumic element
2546 # @ingroup l2_modif_add
2547 def AddVolume(self, IDsOfNodes):
2548 return self.editor.AddVolume(IDsOfNodes)
2550 ## Creates a volume of many faces, giving nodes for each face.
2551 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2552 # @param Quantities the list of integer values, Quantities[i]
2553 # gives the quantity of nodes in face number i.
2554 # @return the Id of the new volumic element
2555 # @ingroup l2_modif_add
2556 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2557 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2559 ## Creates a volume of many faces, giving the IDs of the existing faces.
2560 # @param IdsOfFaces the list of face IDs for volume creation.
2562 # Note: The created volume will refer only to the nodes
2563 # of the given faces, not to the faces themselves.
2564 # @return the Id of the new volumic element
2565 # @ingroup l2_modif_add
2566 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2567 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2570 ## @brief Binds a node to a vertex
2571 # @param NodeID a node ID
2572 # @param Vertex a vertex or vertex ID
2573 # @return True if succeed else raises an exception
2574 # @ingroup l2_modif_add
2575 def SetNodeOnVertex(self, NodeID, Vertex):
2576 if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
2577 VertexID = Vertex.GetSubShapeIndices()[0]
2581 self.editor.SetNodeOnVertex(NodeID, VertexID)
2582 except SALOME.SALOME_Exception, inst:
2583 raise ValueError, inst.details.text
2587 ## @brief Stores the node position on an edge
2588 # @param NodeID a node ID
2589 # @param Edge an edge or edge ID
2590 # @param paramOnEdge a parameter on the edge where the node is located
2591 # @return True if succeed else raises an exception
2592 # @ingroup l2_modif_add
2593 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2594 if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
2595 EdgeID = Edge.GetSubShapeIndices()[0]
2599 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2600 except SALOME.SALOME_Exception, inst:
2601 raise ValueError, inst.details.text
2604 ## @brief Stores node position on a face
2605 # @param NodeID a node ID
2606 # @param Face a face or face ID
2607 # @param u U parameter on the face where the node is located
2608 # @param v V parameter on the face where the node is located
2609 # @return True if succeed else raises an exception
2610 # @ingroup l2_modif_add
2611 def SetNodeOnFace(self, NodeID, Face, u, v):
2612 if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
2613 FaceID = Face.GetSubShapeIndices()[0]
2617 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2618 except SALOME.SALOME_Exception, inst:
2619 raise ValueError, inst.details.text
2622 ## @brief Binds a node to a solid
2623 # @param NodeID a node ID
2624 # @param Solid a solid or solid ID
2625 # @return True if succeed else raises an exception
2626 # @ingroup l2_modif_add
2627 def SetNodeInVolume(self, NodeID, Solid):
2628 if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
2629 SolidID = Solid.GetSubShapeIndices()[0]
2633 self.editor.SetNodeInVolume(NodeID, SolidID)
2634 except SALOME.SALOME_Exception, inst:
2635 raise ValueError, inst.details.text
2638 ## @brief Bind an element to a shape
2639 # @param ElementID an element ID
2640 # @param Shape a shape or shape ID
2641 # @return True if succeed else raises an exception
2642 # @ingroup l2_modif_add
2643 def SetMeshElementOnShape(self, ElementID, Shape):
2644 if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
2645 ShapeID = Shape.GetSubShapeIndices()[0]
2649 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2650 except SALOME.SALOME_Exception, inst:
2651 raise ValueError, inst.details.text
2655 ## Moves the node with the given id
2656 # @param NodeID the id of the node
2657 # @param x a new X coordinate
2658 # @param y a new Y coordinate
2659 # @param z a new Z coordinate
2660 # @return True if succeed else False
2661 # @ingroup l2_modif_movenode
2662 def MoveNode(self, NodeID, x, y, z):
2663 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2664 if hasVars: self.mesh.SetParameters(Parameters)
2665 return self.editor.MoveNode(NodeID, x, y, z)
2667 ## Finds the node closest to a point and moves it to a point location
2668 # @param x the X coordinate of a point
2669 # @param y the Y coordinate of a point
2670 # @param z the Z coordinate of a point
2671 # @param NodeID if specified (>0), the node with this ID is moved,
2672 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2673 # @return the ID of a node
2674 # @ingroup l2_modif_throughp
2675 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2676 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2677 if hasVars: self.mesh.SetParameters(Parameters)
2678 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2680 ## Finds the node closest to a point
2681 # @param x the X coordinate of a point
2682 # @param y the Y coordinate of a point
2683 # @param z the Z coordinate of a point
2684 # @return the ID of a node
2685 # @ingroup l2_modif_throughp
2686 def FindNodeClosestTo(self, x, y, z):
2687 #preview = self.mesh.GetMeshEditPreviewer()
2688 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2689 return self.editor.FindNodeClosestTo(x, y, z)
2691 ## Finds the elements where a point lays IN or ON
2692 # @param x the X coordinate of a point
2693 # @param y the Y coordinate of a point
2694 # @param z the Z coordinate of a point
2695 # @param elementType type of elements to find (SMESH.ALL type
2696 # means elements of any type excluding nodes, discrete and 0D elements)
2697 # @param meshPart a part of mesh (group, sub-mesh) to search within
2698 # @return list of IDs of found elements
2699 # @ingroup l2_modif_throughp
2700 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2702 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2704 return self.editor.FindElementsByPoint(x, y, z, elementType)
2706 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2707 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2708 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2710 def GetPointState(self, x, y, z):
2711 return self.editor.GetPointState(x, y, z)
2713 ## Finds the node closest to a point and moves it to a point location
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 moved node
2718 # @ingroup l2_modif_throughp
2719 def MeshToPassThroughAPoint(self, x, y, z):
2720 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2722 ## Replaces two neighbour triangles sharing Node1-Node2 link
2723 # with the triangles built on the same 4 nodes but having other common link.
2724 # @param NodeID1 the ID of the first node
2725 # @param NodeID2 the ID of the second node
2726 # @return false if proper faces were not found
2727 # @ingroup l2_modif_invdiag
2728 def InverseDiag(self, NodeID1, NodeID2):
2729 return self.editor.InverseDiag(NodeID1, NodeID2)
2731 ## Replaces two neighbour triangles sharing Node1-Node2 link
2732 # with a quadrangle built on the same 4 nodes.
2733 # @param NodeID1 the ID of the first node
2734 # @param NodeID2 the ID of the second node
2735 # @return false if proper faces were not found
2736 # @ingroup l2_modif_unitetri
2737 def DeleteDiag(self, NodeID1, NodeID2):
2738 return self.editor.DeleteDiag(NodeID1, NodeID2)
2740 ## Reorients elements by ids
2741 # @param IDsOfElements if undefined reorients all mesh elements
2742 # @return True if succeed else False
2743 # @ingroup l2_modif_changori
2744 def Reorient(self, IDsOfElements=None):
2745 if IDsOfElements == None:
2746 IDsOfElements = self.GetElementsId()
2747 return self.editor.Reorient(IDsOfElements)
2749 ## Reorients all elements of the object
2750 # @param theObject mesh, submesh or group
2751 # @return True if succeed else False
2752 # @ingroup l2_modif_changori
2753 def ReorientObject(self, theObject):
2754 if ( isinstance( theObject, Mesh )):
2755 theObject = theObject.GetMesh()
2756 return self.editor.ReorientObject(theObject)
2758 ## Reorient faces contained in \a the2DObject.
2759 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2760 # @param theDirection is a desired direction of normal of \a theFace.
2761 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2762 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2763 # compared with theDirection. It can be either ID of face or a point
2764 # by which the face will be found. The point can be given as either
2765 # a GEOM vertex or a list of point coordinates.
2766 # @return number of reoriented faces
2767 # @ingroup l2_modif_changori
2768 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2770 if isinstance( the2DObject, Mesh ):
2771 the2DObject = the2DObject.GetMesh()
2772 if isinstance( the2DObject, list ):
2773 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2774 # check theDirection
2775 if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
2776 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2777 if isinstance( theDirection, list ):
2778 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2779 # prepare theFace and thePoint
2780 theFace = theFaceOrPoint
2781 thePoint = PointStruct(0,0,0)
2782 if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
2783 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2785 if isinstance( theFaceOrPoint, list ):
2786 thePoint = PointStruct( *theFaceOrPoint )
2788 if isinstance( theFaceOrPoint, PointStruct ):
2789 thePoint = theFaceOrPoint
2791 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2793 ## Fuses the neighbouring triangles into quadrangles.
2794 # @param IDsOfElements The triangles to be fused,
2795 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2796 # choose a neighbour to fuse with.
2797 # @param MaxAngle is the maximum angle between element normals at which the fusion
2798 # is still performed; theMaxAngle is mesured in radians.
2799 # Also it could be a name of variable which defines angle in degrees.
2800 # @return TRUE in case of success, FALSE otherwise.
2801 # @ingroup l2_modif_unitetri
2802 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2803 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2804 self.mesh.SetParameters(Parameters)
2805 if not IDsOfElements:
2806 IDsOfElements = self.GetElementsId()
2807 Functor = self.smeshpyD.GetFunctor(theCriterion)
2808 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2810 ## Fuses the neighbouring triangles of the object into quadrangles
2811 # @param theObject is mesh, submesh or group
2812 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2813 # choose a neighbour to fuse with.
2814 # @param MaxAngle a max angle between element normals at which the fusion
2815 # is still performed; theMaxAngle is mesured in radians.
2816 # @return TRUE in case of success, FALSE otherwise.
2817 # @ingroup l2_modif_unitetri
2818 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2819 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2820 self.mesh.SetParameters(Parameters)
2821 if isinstance( theObject, Mesh ):
2822 theObject = theObject.GetMesh()
2823 Functor = self.smeshpyD.GetFunctor(theCriterion)
2824 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2826 ## Splits quadrangles into triangles.
2828 # @param IDsOfElements the faces to be splitted.
2829 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2830 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2831 # value, then quadrangles will be split by the smallest diagonal.
2832 # @return TRUE in case of success, FALSE otherwise.
2833 # @ingroup l2_modif_cutquadr
2834 def QuadToTri (self, IDsOfElements, theCriterion = None):
2835 if IDsOfElements == []:
2836 IDsOfElements = self.GetElementsId()
2837 if theCriterion is None:
2838 theCriterion = FT_MaxElementLength2D
2839 Functor = self.smeshpyD.GetFunctor(theCriterion)
2840 return self.editor.QuadToTri(IDsOfElements, Functor)
2842 ## Splits quadrangles into triangles.
2843 # @param theObject the object from which the list of elements is taken,
2844 # this is mesh, submesh or group
2845 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2846 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2847 # value, then quadrangles will be split by the smallest diagonal.
2848 # @return TRUE in case of success, FALSE otherwise.
2849 # @ingroup l2_modif_cutquadr
2850 def QuadToTriObject (self, theObject, theCriterion = None):
2851 if ( isinstance( theObject, Mesh )):
2852 theObject = theObject.GetMesh()
2853 if theCriterion is None:
2854 theCriterion = FT_MaxElementLength2D
2855 Functor = self.smeshpyD.GetFunctor(theCriterion)
2856 return self.editor.QuadToTriObject(theObject, Functor)
2858 ## Splits quadrangles into triangles.
2859 # @param IDsOfElements the faces to be splitted
2860 # @param Diag13 is used to choose a diagonal for splitting.
2861 # @return TRUE in case of success, FALSE otherwise.
2862 # @ingroup l2_modif_cutquadr
2863 def SplitQuad (self, IDsOfElements, Diag13):
2864 if IDsOfElements == []:
2865 IDsOfElements = self.GetElementsId()
2866 return self.editor.SplitQuad(IDsOfElements, Diag13)
2868 ## Splits quadrangles into triangles.
2869 # @param theObject the object from which the list of elements is taken,
2870 # this is mesh, submesh or group
2871 # @param Diag13 is used to choose a diagonal for splitting.
2872 # @return TRUE in case of success, FALSE otherwise.
2873 # @ingroup l2_modif_cutquadr
2874 def SplitQuadObject (self, theObject, Diag13):
2875 if ( isinstance( theObject, Mesh )):
2876 theObject = theObject.GetMesh()
2877 return self.editor.SplitQuadObject(theObject, Diag13)
2879 ## Finds a better splitting of the given quadrangle.
2880 # @param IDOfQuad the ID of the quadrangle to be splitted.
2881 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2882 # choose a diagonal for splitting.
2883 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2884 # diagonal is better, 0 if error occurs.
2885 # @ingroup l2_modif_cutquadr
2886 def BestSplit (self, IDOfQuad, theCriterion):
2887 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2889 ## Splits volumic elements into tetrahedrons
2890 # @param elemIDs either list of elements or mesh or group or submesh
2891 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2892 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2893 # @ingroup l2_modif_cutquadr
2894 def SplitVolumesIntoTetra(self, elemIDs, method=smeshBuilder.Hex_5Tet ):
2895 if isinstance( elemIDs, Mesh ):
2896 elemIDs = elemIDs.GetMesh()
2897 if ( isinstance( elemIDs, list )):
2898 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2899 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2901 ## Splits quadrangle faces near triangular facets of volumes
2903 # @ingroup l1_auxiliary
2904 def SplitQuadsNearTriangularFacets(self):
2905 faces_array = self.GetElementsByType(SMESH.FACE)
2906 for face_id in faces_array:
2907 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2908 quad_nodes = self.mesh.GetElemNodes(face_id)
2909 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2910 isVolumeFound = False
2911 for node1_elem in node1_elems:
2912 if not isVolumeFound:
2913 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2914 nb_nodes = self.GetElemNbNodes(node1_elem)
2915 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2916 volume_elem = node1_elem
2917 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2918 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2919 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2920 isVolumeFound = True
2921 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2922 self.SplitQuad([face_id], False) # diagonal 2-4
2923 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2924 isVolumeFound = True
2925 self.SplitQuad([face_id], True) # diagonal 1-3
2926 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2927 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2928 isVolumeFound = True
2929 self.SplitQuad([face_id], True) # diagonal 1-3
2931 ## @brief Splits hexahedrons into tetrahedrons.
2933 # This operation uses pattern mapping functionality for splitting.
2934 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2935 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2936 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2937 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2938 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2939 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2940 # @return TRUE in case of success, FALSE otherwise.
2941 # @ingroup l1_auxiliary
2942 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2943 # Pattern: 5.---------.6
2948 # (0,0,1) 4.---------.7 * |
2955 # (0,0,0) 0.---------.3
2956 pattern_tetra = "!!! Nb of points: \n 8 \n\
2966 !!! Indices of points of 6 tetras: \n\
2974 pattern = self.smeshpyD.GetPattern()
2975 isDone = pattern.LoadFromFile(pattern_tetra)
2977 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2980 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2981 isDone = pattern.MakeMesh(self.mesh, False, False)
2982 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2984 # split quafrangle faces near triangular facets of volumes
2985 self.SplitQuadsNearTriangularFacets()
2989 ## @brief Split hexahedrons into prisms.
2991 # Uses the pattern mapping functionality for splitting.
2992 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2993 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2994 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2995 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2996 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2997 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2998 # @return TRUE in case of success, FALSE otherwise.
2999 # @ingroup l1_auxiliary
3000 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3001 # Pattern: 5.---------.6
3006 # (0,0,1) 4.---------.7 |
3013 # (0,0,0) 0.---------.3
3014 pattern_prism = "!!! Nb of points: \n 8 \n\
3024 !!! Indices of points of 2 prisms: \n\
3028 pattern = self.smeshpyD.GetPattern()
3029 isDone = pattern.LoadFromFile(pattern_prism)
3031 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3034 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3035 isDone = pattern.MakeMesh(self.mesh, False, False)
3036 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3038 # Splits quafrangle faces near triangular facets of volumes
3039 self.SplitQuadsNearTriangularFacets()
3043 ## Smoothes elements
3044 # @param IDsOfElements the list if ids of elements to smooth
3045 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3046 # Note that nodes built on edges and boundary nodes are always fixed.
3047 # @param MaxNbOfIterations the maximum number of iterations
3048 # @param MaxAspectRatio varies in range [1.0, inf]
3049 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3050 # @return TRUE in case of success, FALSE otherwise.
3051 # @ingroup l2_modif_smooth
3052 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3053 MaxNbOfIterations, MaxAspectRatio, Method):
3054 if IDsOfElements == []:
3055 IDsOfElements = self.GetElementsId()
3056 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3057 self.mesh.SetParameters(Parameters)
3058 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3059 MaxNbOfIterations, MaxAspectRatio, Method)
3061 ## Smoothes elements which belong to the given object
3062 # @param theObject the object to smooth
3063 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3064 # Note that nodes built on edges and boundary nodes are always fixed.
3065 # @param MaxNbOfIterations the maximum number of iterations
3066 # @param MaxAspectRatio varies in range [1.0, inf]
3067 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3068 # @return TRUE in case of success, FALSE otherwise.
3069 # @ingroup l2_modif_smooth
3070 def SmoothObject(self, theObject, IDsOfFixedNodes,
3071 MaxNbOfIterations, MaxAspectRatio, Method):
3072 if ( isinstance( theObject, Mesh )):
3073 theObject = theObject.GetMesh()
3074 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3075 MaxNbOfIterations, MaxAspectRatio, Method)
3077 ## Parametrically smoothes the given elements
3078 # @param IDsOfElements the list if ids of elements to smooth
3079 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3080 # Note that nodes built on edges and boundary nodes are always fixed.
3081 # @param MaxNbOfIterations the maximum number of iterations
3082 # @param MaxAspectRatio varies in range [1.0, inf]
3083 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3084 # @return TRUE in case of success, FALSE otherwise.
3085 # @ingroup l2_modif_smooth
3086 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3087 MaxNbOfIterations, MaxAspectRatio, Method):
3088 if IDsOfElements == []:
3089 IDsOfElements = self.GetElementsId()
3090 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3091 self.mesh.SetParameters(Parameters)
3092 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3093 MaxNbOfIterations, MaxAspectRatio, Method)
3095 ## Parametrically smoothes the elements which belong to the given object
3096 # @param theObject the object to smooth
3097 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3098 # Note that nodes built on edges and boundary nodes are always fixed.
3099 # @param MaxNbOfIterations the maximum number of iterations
3100 # @param MaxAspectRatio varies in range [1.0, inf]
3101 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3102 # @return TRUE in case of success, FALSE otherwise.
3103 # @ingroup l2_modif_smooth
3104 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3105 MaxNbOfIterations, MaxAspectRatio, Method):
3106 if ( isinstance( theObject, Mesh )):
3107 theObject = theObject.GetMesh()
3108 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3109 MaxNbOfIterations, MaxAspectRatio, Method)
3111 ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3112 # them with quadratic with the same id.
3113 # @param theForce3d new node creation method:
3114 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3115 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3116 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3117 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3118 # @ingroup l2_modif_tofromqu
3119 def ConvertToQuadratic(self, theForce3d, theSubMesh=None, theToBiQuad=False):
3121 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3124 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3126 self.editor.ConvertToQuadratic(theForce3d)
3128 ## Converts the mesh from quadratic to ordinary,
3129 # deletes old quadratic elements, \n replacing
3130 # them with ordinary mesh elements with the same id.
3131 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3132 # @ingroup l2_modif_tofromqu
3133 def ConvertFromQuadratic(self, theSubMesh=None):
3135 self.editor.ConvertFromQuadraticObject(theSubMesh)
3137 return self.editor.ConvertFromQuadratic()
3139 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3140 # @return TRUE if operation has been completed successfully, FALSE otherwise
3141 # @ingroup l2_modif_edit
3142 def Make2DMeshFrom3D(self):
3143 return self.editor. Make2DMeshFrom3D()
3145 ## Creates missing boundary elements
3146 # @param elements - elements whose boundary is to be checked:
3147 # mesh, group, sub-mesh or list of elements
3148 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3149 # @param dimension - defines type of boundary elements to create:
3150 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3151 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3152 # @param groupName - a name of group to store created boundary elements in,
3153 # "" means not to create the group
3154 # @param meshName - a name of new mesh to store created boundary elements in,
3155 # "" means not to create the new mesh
3156 # @param toCopyElements - if true, the checked elements will be copied into
3157 # the new mesh else only boundary elements will be copied into the new mesh
3158 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3159 # boundary elements will be copied into the new mesh
3160 # @return tuple (mesh, group) where bondary elements were added to
3161 # @ingroup l2_modif_edit
3162 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3163 toCopyElements=False, toCopyExistingBondary=False):
3164 if isinstance( elements, Mesh ):
3165 elements = elements.GetMesh()
3166 if ( isinstance( elements, list )):
3167 elemType = SMESH.ALL
3168 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3169 elements = self.editor.MakeIDSource(elements, elemType)
3170 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3171 toCopyElements,toCopyExistingBondary)
3172 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3176 # @brief Creates missing boundary elements around either the whole mesh or
3177 # groups of 2D elements
3178 # @param dimension - defines type of boundary elements to create
3179 # @param groupName - a name of group to store all boundary elements in,
3180 # "" means not to create the group
3181 # @param meshName - a name of a new mesh, which is a copy of the initial
3182 # mesh + created boundary elements; "" means not to create the new mesh
3183 # @param toCopyAll - if true, the whole initial mesh will be copied into
3184 # the new mesh else only boundary elements will be copied into the new mesh
3185 # @param groups - groups of 2D elements to make boundary around
3186 # @retval tuple( long, mesh, groups )
3187 # long - number of added boundary elements
3188 # mesh - the mesh where elements were added to
3189 # group - the group of boundary elements or None
3191 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3192 toCopyAll=False, groups=[]):
3193 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3195 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3196 return nb, mesh, group
3198 ## Renumber mesh nodes
3199 # @ingroup l2_modif_renumber
3200 def RenumberNodes(self):
3201 self.editor.RenumberNodes()
3203 ## Renumber mesh elements
3204 # @ingroup l2_modif_renumber
3205 def RenumberElements(self):
3206 self.editor.RenumberElements()
3208 ## Generates new elements by rotation of the elements around the axis
3209 # @param IDsOfElements the list of ids of elements to sweep
3210 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3211 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3212 # @param NbOfSteps the number of steps
3213 # @param Tolerance tolerance
3214 # @param MakeGroups forces the generation of new groups from existing ones
3215 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3216 # of all steps, else - size of each step
3217 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3218 # @ingroup l2_modif_extrurev
3219 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3220 MakeGroups=False, TotalAngle=False):
3221 if IDsOfElements == []:
3222 IDsOfElements = self.GetElementsId()
3223 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3224 Axis = self.smeshpyD.GetAxisStruct(Axis)
3225 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3226 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3227 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3228 self.mesh.SetParameters(Parameters)
3229 if TotalAngle and NbOfSteps:
3230 AngleInRadians /= NbOfSteps
3232 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3233 AngleInRadians, NbOfSteps, Tolerance)
3234 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3237 ## Generates new elements by rotation of the elements of object around the axis
3238 # @param theObject object which elements should be sweeped.
3239 # It can be a mesh, a sub mesh or a group.
3240 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3241 # @param AngleInRadians the angle of Rotation
3242 # @param NbOfSteps number of steps
3243 # @param Tolerance tolerance
3244 # @param MakeGroups forces the generation of new groups from existing ones
3245 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3246 # of all steps, else - size of each step
3247 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3248 # @ingroup l2_modif_extrurev
3249 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3250 MakeGroups=False, TotalAngle=False):
3251 if ( isinstance( theObject, Mesh )):
3252 theObject = theObject.GetMesh()
3253 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3254 Axis = self.smeshpyD.GetAxisStruct(Axis)
3255 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3256 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3257 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3258 self.mesh.SetParameters(Parameters)
3259 if TotalAngle and NbOfSteps:
3260 AngleInRadians /= NbOfSteps
3262 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3263 NbOfSteps, Tolerance)
3264 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3267 ## Generates new elements by rotation of the elements of object around the axis
3268 # @param theObject object which elements should be sweeped.
3269 # It can be a mesh, a sub mesh or a group.
3270 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3271 # @param AngleInRadians the angle of Rotation
3272 # @param NbOfSteps number of steps
3273 # @param Tolerance tolerance
3274 # @param MakeGroups forces the generation of new groups from existing ones
3275 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3276 # of all steps, else - size of each step
3277 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3278 # @ingroup l2_modif_extrurev
3279 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3280 MakeGroups=False, TotalAngle=False):
3281 if ( isinstance( theObject, Mesh )):
3282 theObject = theObject.GetMesh()
3283 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3284 Axis = self.smeshpyD.GetAxisStruct(Axis)
3285 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3286 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3287 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3288 self.mesh.SetParameters(Parameters)
3289 if TotalAngle and NbOfSteps:
3290 AngleInRadians /= NbOfSteps
3292 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3293 NbOfSteps, Tolerance)
3294 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3297 ## Generates new elements by rotation of the elements of object around the axis
3298 # @param theObject object which elements should be sweeped.
3299 # It can be a mesh, a sub mesh or a group.
3300 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3301 # @param AngleInRadians the angle of Rotation
3302 # @param NbOfSteps number of steps
3303 # @param Tolerance tolerance
3304 # @param MakeGroups forces the generation of new groups from existing ones
3305 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3306 # of all steps, else - size of each step
3307 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3308 # @ingroup l2_modif_extrurev
3309 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3310 MakeGroups=False, TotalAngle=False):
3311 if ( isinstance( theObject, Mesh )):
3312 theObject = theObject.GetMesh()
3313 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3314 Axis = self.smeshpyD.GetAxisStruct(Axis)
3315 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3316 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3317 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3318 self.mesh.SetParameters(Parameters)
3319 if TotalAngle and NbOfSteps:
3320 AngleInRadians /= NbOfSteps
3322 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3323 NbOfSteps, Tolerance)
3324 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3327 ## Generates new elements by extrusion of the elements with given ids
3328 # @param IDsOfElements the list of elements ids for extrusion
3329 # @param StepVector vector or DirStruct or 3 vector components, defining
3330 # the direction and value of extrusion for one step (the total extrusion
3331 # length will be NbOfSteps * ||StepVector||)
3332 # @param NbOfSteps the number of steps
3333 # @param MakeGroups forces the generation of new groups from existing ones
3334 # @param IsNodes is True if elements with given ids are nodes
3335 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3336 # @ingroup l2_modif_extrurev
3337 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3338 if IDsOfElements == []:
3339 IDsOfElements = self.GetElementsId()
3340 if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3341 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3342 if isinstance( StepVector, list ):
3343 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3344 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3345 Parameters = StepVector.PS.parameters + var_separator + Parameters
3346 self.mesh.SetParameters(Parameters)
3349 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3351 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3353 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3355 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3358 ## Generates new elements by extrusion of the elements with given ids
3359 # @param IDsOfElements is ids of elements
3360 # @param StepVector vector or DirStruct or 3 vector components, defining
3361 # the direction and value of extrusion for one step (the total extrusion
3362 # length will be NbOfSteps * ||StepVector||)
3363 # @param NbOfSteps the number of steps
3364 # @param ExtrFlags sets flags for extrusion
3365 # @param SewTolerance uses for comparing locations of nodes if flag
3366 # EXTRUSION_FLAG_SEW is set
3367 # @param MakeGroups forces the generation of new groups from existing ones
3368 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3369 # @ingroup l2_modif_extrurev
3370 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3371 ExtrFlags, SewTolerance, MakeGroups=False):
3372 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3373 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3374 if isinstance( StepVector, list ):
3375 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3377 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3378 ExtrFlags, SewTolerance)
3379 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3380 ExtrFlags, SewTolerance)
3383 ## Generates new elements by extrusion of the elements which belong to the object
3384 # @param theObject the object which elements should be processed.
3385 # It can be a mesh, a sub mesh or a group.
3386 # @param StepVector vector or DirStruct or 3 vector components, defining
3387 # the direction and value of extrusion for one step (the total extrusion
3388 # length will be NbOfSteps * ||StepVector||)
3389 # @param NbOfSteps the number of steps
3390 # @param MakeGroups forces the generation of new groups from existing ones
3391 # @param IsNodes is True if elements which belong to the object are nodes
3392 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3393 # @ingroup l2_modif_extrurev
3394 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3395 if ( isinstance( theObject, Mesh )):
3396 theObject = theObject.GetMesh()
3397 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3398 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3399 if isinstance( StepVector, list ):
3400 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3401 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3402 Parameters = StepVector.PS.parameters + var_separator + Parameters
3403 self.mesh.SetParameters(Parameters)
3406 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3408 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3410 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3412 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3415 ## Generates new elements by extrusion of the elements which belong to the object
3416 # @param theObject object which elements should be processed.
3417 # It can be a mesh, a sub mesh or a group.
3418 # @param StepVector vector or DirStruct or 3 vector components, defining
3419 # the direction and value of extrusion for one step (the total extrusion
3420 # length will be NbOfSteps * ||StepVector||)
3421 # @param NbOfSteps the number of steps
3422 # @param MakeGroups to generate new groups from existing ones
3423 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3424 # @ingroup l2_modif_extrurev
3425 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3426 if ( isinstance( theObject, Mesh )):
3427 theObject = theObject.GetMesh()
3428 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3429 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3430 if isinstance( StepVector, list ):
3431 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3432 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3433 Parameters = StepVector.PS.parameters + var_separator + Parameters
3434 self.mesh.SetParameters(Parameters)
3436 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3437 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3440 ## Generates new elements by extrusion of the elements which belong to the object
3441 # @param theObject object which elements should be processed.
3442 # It can be a mesh, a sub mesh or a group.
3443 # @param StepVector vector or DirStruct or 3 vector components, defining
3444 # the direction and value of extrusion for one step (the total extrusion
3445 # length will be NbOfSteps * ||StepVector||)
3446 # @param NbOfSteps the number of steps
3447 # @param MakeGroups forces the generation of new groups from existing ones
3448 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3449 # @ingroup l2_modif_extrurev
3450 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3451 if ( isinstance( theObject, Mesh )):
3452 theObject = theObject.GetMesh()
3453 if ( isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object)):
3454 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3455 if isinstance( StepVector, list ):
3456 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3457 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3458 Parameters = StepVector.PS.parameters + var_separator + Parameters
3459 self.mesh.SetParameters(Parameters)
3461 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3462 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3467 ## Generates new elements by extrusion of the given elements
3468 # The path of extrusion must be a meshed edge.
3469 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3470 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3471 # @param NodeStart the start node from Path. Defines the direction of extrusion
3472 # @param HasAngles allows the shape to be rotated around the path
3473 # to get the resulting mesh in a helical fashion
3474 # @param Angles list of angles in radians
3475 # @param LinearVariation forces the computation of rotation angles as linear
3476 # variation of the given Angles along path steps
3477 # @param HasRefPoint allows using the reference point
3478 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3479 # The User can specify any point as the Reference Point.
3480 # @param MakeGroups forces the generation of new groups from existing ones
3481 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3482 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3483 # only SMESH::Extrusion_Error otherwise
3484 # @ingroup l2_modif_extrurev
3485 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3486 HasAngles, Angles, LinearVariation,
3487 HasRefPoint, RefPoint, MakeGroups, ElemType):
3488 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3489 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3491 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3492 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3493 self.mesh.SetParameters(Parameters)
3495 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3497 if isinstance(Base, list):
3499 if Base == []: IDsOfElements = self.GetElementsId()
3500 else: IDsOfElements = Base
3501 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3502 HasAngles, Angles, LinearVariation,
3503 HasRefPoint, RefPoint, MakeGroups, ElemType)
3505 if isinstance(Base, Mesh): Base = Base.GetMesh()
3506 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3507 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3508 HasAngles, Angles, LinearVariation,
3509 HasRefPoint, RefPoint, MakeGroups, ElemType)
3511 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3514 ## Generates new elements by extrusion of the given elements
3515 # The path of extrusion must be a meshed edge.
3516 # @param IDsOfElements ids of elements
3517 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3518 # @param PathShape shape(edge) defines the sub-mesh for the path
3519 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3520 # @param HasAngles allows the shape to be rotated around the path
3521 # to get the resulting mesh in a helical fashion
3522 # @param Angles list of angles in radians
3523 # @param HasRefPoint allows using the reference point
3524 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3525 # The User can specify any point as the Reference Point.
3526 # @param MakeGroups forces the generation of new groups from existing ones
3527 # @param LinearVariation forces the computation of rotation angles as linear
3528 # variation of the given Angles along path steps
3529 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3530 # only SMESH::Extrusion_Error otherwise
3531 # @ingroup l2_modif_extrurev
3532 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3533 HasAngles, Angles, HasRefPoint, RefPoint,
3534 MakeGroups=False, LinearVariation=False):
3535 if IDsOfElements == []:
3536 IDsOfElements = self.GetElementsId()
3537 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3538 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3540 if ( isinstance( PathMesh, Mesh )):
3541 PathMesh = PathMesh.GetMesh()
3542 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3543 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3544 self.mesh.SetParameters(Parameters)
3545 if HasAngles and Angles and LinearVariation:
3546 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3549 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3550 PathShape, NodeStart, HasAngles,
3551 Angles, HasRefPoint, RefPoint)
3552 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3553 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3555 ## Generates new elements by extrusion of the elements which belong to the object
3556 # The path of extrusion must be a meshed edge.
3557 # @param theObject the object which elements should be processed.
3558 # It can be a mesh, a sub mesh or a group.
3559 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3560 # @param PathShape shape(edge) defines the sub-mesh for the path
3561 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3562 # @param HasAngles allows the shape to be rotated around the path
3563 # to get the resulting mesh in a helical fashion
3564 # @param Angles list of angles
3565 # @param HasRefPoint allows using the reference point
3566 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3567 # The User can specify any point as the Reference Point.
3568 # @param MakeGroups forces the generation of new groups from existing ones
3569 # @param LinearVariation forces the computation of rotation angles as linear
3570 # variation of the given Angles along path steps
3571 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3572 # only SMESH::Extrusion_Error otherwise
3573 # @ingroup l2_modif_extrurev
3574 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3575 HasAngles, Angles, HasRefPoint, RefPoint,
3576 MakeGroups=False, LinearVariation=False):
3577 if ( isinstance( theObject, Mesh )):
3578 theObject = theObject.GetMesh()
3579 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3580 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3581 if ( isinstance( PathMesh, Mesh )):
3582 PathMesh = PathMesh.GetMesh()
3583 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3584 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3585 self.mesh.SetParameters(Parameters)
3586 if HasAngles and Angles and LinearVariation:
3587 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3590 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3591 PathShape, NodeStart, HasAngles,
3592 Angles, HasRefPoint, RefPoint)
3593 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3594 NodeStart, HasAngles, Angles, HasRefPoint,
3597 ## Generates new elements by extrusion of the elements which belong to the object
3598 # The path of extrusion must be a meshed edge.
3599 # @param theObject the object which elements should be processed.
3600 # It can be a mesh, a sub mesh or a group.
3601 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3602 # @param PathShape shape(edge) defines the sub-mesh for the path
3603 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3604 # @param HasAngles allows the shape to be rotated around the path
3605 # to get the resulting mesh in a helical fashion
3606 # @param Angles list of angles
3607 # @param HasRefPoint allows using the reference point
3608 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3609 # The User can specify any point as the Reference Point.
3610 # @param MakeGroups forces the generation of new groups from existing ones
3611 # @param LinearVariation forces the computation of rotation angles as linear
3612 # variation of the given Angles along path steps
3613 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3614 # only SMESH::Extrusion_Error otherwise
3615 # @ingroup l2_modif_extrurev
3616 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3617 HasAngles, Angles, HasRefPoint, RefPoint,
3618 MakeGroups=False, LinearVariation=False):
3619 if ( isinstance( theObject, Mesh )):
3620 theObject = theObject.GetMesh()
3621 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3622 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3623 if ( isinstance( PathMesh, Mesh )):
3624 PathMesh = PathMesh.GetMesh()
3625 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3626 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3627 self.mesh.SetParameters(Parameters)
3628 if HasAngles and Angles and LinearVariation:
3629 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3632 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3633 PathShape, NodeStart, HasAngles,
3634 Angles, HasRefPoint, RefPoint)
3635 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3636 NodeStart, HasAngles, Angles, HasRefPoint,
3639 ## Generates new elements by extrusion of the elements which belong to the object
3640 # The path of extrusion must be a meshed edge.
3641 # @param theObject the object which elements should be processed.
3642 # It can be a mesh, a sub mesh or a group.
3643 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3644 # @param PathShape shape(edge) defines the sub-mesh for the path
3645 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3646 # @param HasAngles allows the shape to be rotated around the path
3647 # to get the resulting mesh in a helical fashion
3648 # @param Angles list of angles
3649 # @param HasRefPoint allows using the reference point
3650 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3651 # The User can specify any point as the Reference Point.
3652 # @param MakeGroups forces the generation of new groups from existing ones
3653 # @param LinearVariation forces the computation of rotation angles as linear
3654 # variation of the given Angles along path steps
3655 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3656 # only SMESH::Extrusion_Error otherwise
3657 # @ingroup l2_modif_extrurev
3658 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3659 HasAngles, Angles, HasRefPoint, RefPoint,
3660 MakeGroups=False, LinearVariation=False):
3661 if ( isinstance( theObject, Mesh )):
3662 theObject = theObject.GetMesh()
3663 if ( isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object)):
3664 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3665 if ( isinstance( PathMesh, Mesh )):
3666 PathMesh = PathMesh.GetMesh()
3667 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3668 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3669 self.mesh.SetParameters(Parameters)
3670 if HasAngles and Angles and LinearVariation:
3671 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3674 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3675 PathShape, NodeStart, HasAngles,
3676 Angles, HasRefPoint, RefPoint)
3677 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3678 NodeStart, HasAngles, Angles, HasRefPoint,
3681 ## Creates a symmetrical copy of mesh elements
3682 # @param IDsOfElements list of elements ids
3683 # @param Mirror is AxisStruct or geom object(point, line, plane)
3684 # @param theMirrorType is POINT, AXIS or PLANE
3685 # If the Mirror is a geom object this parameter is unnecessary
3686 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3687 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3688 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3689 # @ingroup l2_modif_trsf
3690 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3691 if IDsOfElements == []:
3692 IDsOfElements = self.GetElementsId()
3693 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3694 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3695 self.mesh.SetParameters(Mirror.parameters)
3696 if Copy and MakeGroups:
3697 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3698 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3701 ## Creates a new mesh by a symmetrical copy of mesh elements
3702 # @param IDsOfElements the list of elements ids
3703 # @param Mirror is AxisStruct or geom object (point, line, plane)
3704 # @param theMirrorType is POINT, AXIS or PLANE
3705 # If the Mirror is a geom object this parameter is unnecessary
3706 # @param MakeGroups to generate new groups from existing ones
3707 # @param NewMeshName a name of the new mesh to create
3708 # @return instance of Mesh class
3709 # @ingroup l2_modif_trsf
3710 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3711 if IDsOfElements == []:
3712 IDsOfElements = self.GetElementsId()
3713 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3714 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3715 self.mesh.SetParameters(Mirror.parameters)
3716 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3717 MakeGroups, NewMeshName)
3718 return Mesh(self.smeshpyD,self.geompyD,mesh)
3720 ## Creates a symmetrical copy of the object
3721 # @param theObject mesh, submesh or group
3722 # @param Mirror AxisStruct or geom object (point, line, plane)
3723 # @param theMirrorType is POINT, AXIS or PLANE
3724 # If the Mirror is a geom object this parameter is unnecessary
3725 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3726 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3727 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3728 # @ingroup l2_modif_trsf
3729 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3730 if ( isinstance( theObject, Mesh )):
3731 theObject = theObject.GetMesh()
3732 if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3733 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3734 self.mesh.SetParameters(Mirror.parameters)
3735 if Copy and MakeGroups:
3736 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3737 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3740 ## Creates a new mesh by a symmetrical copy of the object
3741 # @param theObject mesh, submesh or group
3742 # @param Mirror AxisStruct or geom object (point, line, plane)
3743 # @param theMirrorType POINT, AXIS or PLANE
3744 # If the Mirror is a geom object this parameter is unnecessary
3745 # @param MakeGroups forces the generation of new groups from existing ones
3746 # @param NewMeshName the name of the new mesh to create
3747 # @return instance of Mesh class
3748 # @ingroup l2_modif_trsf
3749 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3750 if ( isinstance( theObject, Mesh )):
3751 theObject = theObject.GetMesh()
3752 if (isinstance(Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
3753 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3754 self.mesh.SetParameters(Mirror.parameters)
3755 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3756 MakeGroups, NewMeshName)
3757 return Mesh( self.smeshpyD,self.geompyD,mesh )
3759 ## Translates the elements
3760 # @param IDsOfElements list of elements ids
3761 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3762 # @param Copy allows copying the translated elements
3763 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3764 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3765 # @ingroup l2_modif_trsf
3766 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3767 if IDsOfElements == []:
3768 IDsOfElements = self.GetElementsId()
3769 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3770 Vector = self.smeshpyD.GetDirStruct(Vector)
3771 if isinstance( Vector, list ):
3772 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3773 self.mesh.SetParameters(Vector.PS.parameters)
3774 if Copy and MakeGroups:
3775 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3776 self.editor.Translate(IDsOfElements, Vector, Copy)
3779 ## Creates a new mesh of translated elements
3780 # @param IDsOfElements list of elements ids
3781 # @param Vector the direction of translation (DirStruct or vector or 3 vector components)
3782 # @param MakeGroups forces the generation of new groups from existing ones
3783 # @param NewMeshName the name of the newly created mesh
3784 # @return instance of Mesh class
3785 # @ingroup l2_modif_trsf
3786 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3787 if IDsOfElements == []:
3788 IDsOfElements = self.GetElementsId()
3789 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3790 Vector = self.smeshpyD.GetDirStruct(Vector)
3791 if isinstance( Vector, list ):
3792 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3793 self.mesh.SetParameters(Vector.PS.parameters)
3794 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3795 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3797 ## Translates the object
3798 # @param theObject the object to translate (mesh, submesh, or group)
3799 # @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
3800 # @param Copy allows copying the translated elements
3801 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3802 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3803 # @ingroup l2_modif_trsf
3804 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3805 if ( isinstance( theObject, Mesh )):
3806 theObject = theObject.GetMesh()
3807 if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
3808 Vector = self.smeshpyD.GetDirStruct(Vector)
3809 if isinstance( Vector, list ):
3810 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3811 self.mesh.SetParameters(Vector.PS.parameters)
3812 if Copy and MakeGroups:
3813 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3814 self.editor.TranslateObject(theObject, Vector, Copy)
3817 ## Creates a new mesh from the translated object
3818 # @param theObject the object to translate (mesh, submesh, or group)
3819 # @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
3820 # @param MakeGroups forces the generation of new groups from existing ones
3821 # @param NewMeshName the name of the newly created mesh
3822 # @return instance of Mesh class
3823 # @ingroup l2_modif_trsf
3824 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3825 if isinstance( theObject, Mesh ):
3826 theObject = theObject.GetMesh()
3827 if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
3828 Vector = self.smeshpyD.GetDirStruct(Vector)
3829 if isinstance( Vector, list ):
3830 Vector = self.smeshpyD.MakeDirStruct(*Vector)
3831 self.mesh.SetParameters(Vector.PS.parameters)
3832 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3833 return Mesh( self.smeshpyD, self.geompyD, mesh )
3837 ## Scales the object
3838 # @param theObject - the object to translate (mesh, submesh, or group)
3839 # @param thePoint - base point for scale
3840 # @param theScaleFact - list of 1-3 scale factors for axises
3841 # @param Copy - allows copying the translated elements
3842 # @param MakeGroups - forces the generation of new groups from existing
3844 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3845 # empty list otherwise
3846 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3847 if ( isinstance( theObject, Mesh )):
3848 theObject = theObject.GetMesh()
3849 if ( isinstance( theObject, list )):
3850 theObject = self.GetIDSource(theObject, SMESH.ALL)
3851 if ( isinstance( theScaleFact, float )):
3852 theScaleFact = [theScaleFact]
3853 if ( isinstance( theScaleFact, int )):
3854 theScaleFact = [ float(theScaleFact)]
3856 self.mesh.SetParameters(thePoint.parameters)
3858 if Copy and MakeGroups:
3859 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3860 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3863 ## Creates a new mesh from the translated object
3864 # @param theObject - the object to translate (mesh, submesh, or group)
3865 # @param thePoint - base point for scale
3866 # @param theScaleFact - list of 1-3 scale factors for axises
3867 # @param MakeGroups - forces the generation of new groups from existing ones
3868 # @param NewMeshName - the name of the newly created mesh
3869 # @return instance of Mesh class
3870 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3871 if (isinstance(theObject, Mesh)):
3872 theObject = theObject.GetMesh()
3873 if ( isinstance( theObject, list )):
3874 theObject = self.GetIDSource(theObject,SMESH.ALL)
3875 if ( isinstance( theScaleFact, float )):
3876 theScaleFact = [theScaleFact]
3877 if ( isinstance( theScaleFact, int )):
3878 theScaleFact = [ float(theScaleFact)]
3880 self.mesh.SetParameters(thePoint.parameters)
3881 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3882 MakeGroups, NewMeshName)
3883 return Mesh( self.smeshpyD, self.geompyD, mesh )
3887 ## Rotates the elements
3888 # @param IDsOfElements list of elements ids
3889 # @param Axis the axis of rotation (AxisStruct or geom line)
3890 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3891 # @param Copy allows copying the rotated elements
3892 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3893 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3894 # @ingroup l2_modif_trsf
3895 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3896 if IDsOfElements == []:
3897 IDsOfElements = self.GetElementsId()
3898 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3899 Axis = self.smeshpyD.GetAxisStruct(Axis)
3900 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3901 Parameters = Axis.parameters + var_separator + Parameters
3902 self.mesh.SetParameters(Parameters)
3903 if Copy and MakeGroups:
3904 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3905 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3908 ## Creates a new mesh of rotated elements
3909 # @param IDsOfElements list of element ids
3910 # @param Axis the axis of rotation (AxisStruct or geom line)
3911 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3912 # @param MakeGroups forces the generation of new groups from existing ones
3913 # @param NewMeshName the name of the newly created mesh
3914 # @return instance of Mesh class
3915 # @ingroup l2_modif_trsf
3916 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3917 if IDsOfElements == []:
3918 IDsOfElements = self.GetElementsId()
3919 if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3920 Axis = self.smeshpyD.GetAxisStruct(Axis)
3921 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3922 Parameters = Axis.parameters + var_separator + Parameters
3923 self.mesh.SetParameters(Parameters)
3924 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3925 MakeGroups, NewMeshName)
3926 return Mesh( self.smeshpyD, self.geompyD, mesh )
3928 ## Rotates the object
3929 # @param theObject the object to rotate( mesh, submesh, or group)
3930 # @param Axis the axis of rotation (AxisStruct or geom line)
3931 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3932 # @param Copy allows copying the rotated elements
3933 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3934 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3935 # @ingroup l2_modif_trsf
3936 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3937 if (isinstance(theObject, Mesh)):
3938 theObject = theObject.GetMesh()
3939 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3940 Axis = self.smeshpyD.GetAxisStruct(Axis)
3941 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3942 Parameters = Axis.parameters + ":" + Parameters
3943 self.mesh.SetParameters(Parameters)
3944 if Copy and MakeGroups:
3945 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3946 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3949 ## Creates a new mesh from the rotated object
3950 # @param theObject the object to rotate (mesh, submesh, or group)
3951 # @param Axis the axis of rotation (AxisStruct or geom line)
3952 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3953 # @param MakeGroups forces the generation of new groups from existing ones
3954 # @param NewMeshName the name of the newly created mesh
3955 # @return instance of Mesh class
3956 # @ingroup l2_modif_trsf
3957 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3958 if (isinstance( theObject, Mesh )):
3959 theObject = theObject.GetMesh()
3960 if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
3961 Axis = self.smeshpyD.GetAxisStruct(Axis)
3962 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3963 Parameters = Axis.parameters + ":" + Parameters
3964 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3965 MakeGroups, NewMeshName)
3966 self.mesh.SetParameters(Parameters)
3967 return Mesh( self.smeshpyD, self.geompyD, mesh )
3969 ## Finds groups of ajacent nodes within Tolerance.
3970 # @param Tolerance the value of tolerance
3971 # @return the list of groups of nodes
3972 # @ingroup l2_modif_trsf
3973 def FindCoincidentNodes (self, Tolerance):
3974 return self.editor.FindCoincidentNodes(Tolerance)
3976 ## Finds groups of ajacent nodes within Tolerance.
3977 # @param Tolerance the value of tolerance
3978 # @param SubMeshOrGroup SubMesh or Group
3979 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3980 # @return the list of groups of nodes
3981 # @ingroup l2_modif_trsf
3982 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3983 if (isinstance( SubMeshOrGroup, Mesh )):
3984 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3985 if not isinstance( exceptNodes, list):
3986 exceptNodes = [ exceptNodes ]
3987 if exceptNodes and isinstance( exceptNodes[0], int):
3988 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3989 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3992 # @param GroupsOfNodes the list of groups of nodes
3993 # @ingroup l2_modif_trsf
3994 def MergeNodes (self, GroupsOfNodes):
3995 self.editor.MergeNodes(GroupsOfNodes)
3997 ## Finds the elements built on the same nodes.
3998 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3999 # @return a list of groups of equal elements
4000 # @ingroup l2_modif_trsf
4001 def FindEqualElements (self, MeshOrSubMeshOrGroup):
4002 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
4003 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4004 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
4006 ## Merges elements in each given group.
4007 # @param GroupsOfElementsID groups of elements for merging
4008 # @ingroup l2_modif_trsf
4009 def MergeElements(self, GroupsOfElementsID):
4010 self.editor.MergeElements(GroupsOfElementsID)
4012 ## Leaves one element and removes all other elements built on the same nodes.
4013 # @ingroup l2_modif_trsf
4014 def MergeEqualElements(self):
4015 self.editor.MergeEqualElements()
4017 ## Sews free borders
4018 # @return SMESH::Sew_Error
4019 # @ingroup l2_modif_trsf
4020 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4021 FirstNodeID2, SecondNodeID2, LastNodeID2,
4022 CreatePolygons, CreatePolyedrs):
4023 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4024 FirstNodeID2, SecondNodeID2, LastNodeID2,
4025 CreatePolygons, CreatePolyedrs)
4027 ## Sews conform free borders
4028 # @return SMESH::Sew_Error
4029 # @ingroup l2_modif_trsf
4030 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4031 FirstNodeID2, SecondNodeID2):
4032 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4033 FirstNodeID2, SecondNodeID2)
4035 ## Sews border to side
4036 # @return SMESH::Sew_Error
4037 # @ingroup l2_modif_trsf
4038 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4039 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4040 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4041 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4043 ## Sews two sides of a mesh. The nodes belonging to Side1 are
4044 # merged with the nodes of elements of Side2.
4045 # The number of elements in theSide1 and in theSide2 must be
4046 # equal and they should have similar nodal connectivity.
4047 # The nodes to merge should belong to side borders and
4048 # the first node should be linked to the second.
4049 # @return SMESH::Sew_Error
4050 # @ingroup l2_modif_trsf
4051 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4052 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4053 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4054 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4055 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4056 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4058 ## Sets new nodes for the given element.
4059 # @param ide the element id
4060 # @param newIDs nodes ids
4061 # @return If the number of nodes does not correspond to the type of element - returns false
4062 # @ingroup l2_modif_edit
4063 def ChangeElemNodes(self, ide, newIDs):
4064 return self.editor.ChangeElemNodes(ide, newIDs)
4066 ## If during the last operation of MeshEditor some nodes were
4067 # created, this method returns the list of their IDs, \n
4068 # if new nodes were not created - returns empty list
4069 # @return the list of integer values (can be empty)
4070 # @ingroup l1_auxiliary
4071 def GetLastCreatedNodes(self):
4072 return self.editor.GetLastCreatedNodes()
4074 ## If during the last operation of MeshEditor some elements were
4075 # created this method returns the list of their IDs, \n
4076 # if new elements were not created - returns empty list
4077 # @return the list of integer values (can be empty)
4078 # @ingroup l1_auxiliary
4079 def GetLastCreatedElems(self):
4080 return self.editor.GetLastCreatedElems()
4082 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4083 # @param theNodes identifiers of nodes to be doubled
4084 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4085 # nodes. If list of element identifiers is empty then nodes are doubled but
4086 # they not assigned to elements
4087 # @return TRUE if operation has been completed successfully, FALSE otherwise
4088 # @ingroup l2_modif_edit
4089 def DoubleNodes(self, theNodes, theModifiedElems):
4090 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4092 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4093 # This method provided for convenience works as DoubleNodes() described above.
4094 # @param theNodeId identifiers of node to be doubled
4095 # @param theModifiedElems identifiers of elements to be updated
4096 # @return TRUE if operation has been completed successfully, FALSE otherwise
4097 # @ingroup l2_modif_edit
4098 def DoubleNode(self, theNodeId, theModifiedElems):
4099 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4101 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4102 # This method provided for convenience works as DoubleNodes() described above.
4103 # @param theNodes group of nodes to be doubled
4104 # @param theModifiedElems group of elements to be updated.
4105 # @param theMakeGroup forces the generation of a group containing new nodes.
4106 # @return TRUE or a created group if operation has been completed successfully,
4107 # FALSE or None otherwise
4108 # @ingroup l2_modif_edit
4109 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4111 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4112 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4114 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4115 # This method provided for convenience works as DoubleNodes() described above.
4116 # @param theNodes list of groups of nodes to be doubled
4117 # @param theModifiedElems list of groups of elements to be updated.
4118 # @param theMakeGroup forces the generation of a group containing new nodes.
4119 # @return TRUE if operation has been completed successfully, FALSE otherwise
4120 # @ingroup l2_modif_edit
4121 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4123 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4124 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4126 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4127 # @param theElems - the list of elements (edges or faces) to be replicated
4128 # The nodes for duplication could be found from these elements
4129 # @param theNodesNot - list of nodes to NOT replicate
4130 # @param theAffectedElems - the list of elements (cells and edges) to which the
4131 # replicated nodes should be associated to.
4132 # @return TRUE if operation has been completed successfully, FALSE otherwise
4133 # @ingroup l2_modif_edit
4134 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4135 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4137 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4138 # @param theElems - the list of elements (edges or faces) to be replicated
4139 # The nodes for duplication could be found from these elements
4140 # @param theNodesNot - list of nodes to NOT replicate
4141 # @param theShape - shape to detect affected elements (element which geometric center
4142 # located on or inside shape).
4143 # The replicated nodes should be associated to affected elements.
4144 # @return TRUE if operation has been completed successfully, FALSE otherwise
4145 # @ingroup l2_modif_edit
4146 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4147 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4149 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4150 # This method provided for convenience works as DoubleNodes() described above.
4151 # @param theElems - group of of elements (edges or faces) to be replicated
4152 # @param theNodesNot - group of nodes not to replicated
4153 # @param theAffectedElems - group of elements to which the replicated nodes
4154 # should be associated to.
4155 # @param theMakeGroup forces the generation of a group containing new elements.
4156 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4157 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4158 # FALSE or None otherwise
4159 # @ingroup l2_modif_edit
4160 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4161 theMakeGroup=False, theMakeNodeGroup=False):
4162 if theMakeGroup or theMakeNodeGroup:
4163 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4165 theMakeGroup, theMakeNodeGroup)
4166 if theMakeGroup and theMakeNodeGroup:
4169 return twoGroups[ int(theMakeNodeGroup) ]
4170 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4172 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4173 # This method provided for convenience works as DoubleNodes() described above.
4174 # @param theElems - group of of elements (edges or faces) to be replicated
4175 # @param theNodesNot - group of nodes not to replicated
4176 # @param theShape - shape to detect affected elements (element which geometric center
4177 # located on or inside shape).
4178 # The replicated nodes should be associated to affected elements.
4179 # @ingroup l2_modif_edit
4180 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4181 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4183 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4184 # This method provided for convenience works as DoubleNodes() described above.
4185 # @param theElems - list of groups of elements (edges or faces) to be replicated
4186 # @param theNodesNot - list of groups of nodes not to replicated
4187 # @param theAffectedElems - group of elements to which the replicated nodes
4188 # should be associated to.
4189 # @param theMakeGroup forces the generation of a group containing new elements.
4190 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4191 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4192 # FALSE or None otherwise
4193 # @ingroup l2_modif_edit
4194 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4195 theMakeGroup=False, theMakeNodeGroup=False):
4196 if theMakeGroup or theMakeNodeGroup:
4197 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4199 theMakeGroup, theMakeNodeGroup)
4200 if theMakeGroup and theMakeNodeGroup:
4203 return twoGroups[ int(theMakeNodeGroup) ]
4204 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4206 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4207 # This method provided for convenience works as DoubleNodes() described above.
4208 # @param theElems - list of groups of elements (edges or faces) to be replicated
4209 # @param theNodesNot - list of groups of nodes not to replicated
4210 # @param theShape - shape to detect affected elements (element which geometric center
4211 # located on or inside shape).
4212 # The replicated nodes should be associated to affected elements.
4213 # @return TRUE if operation has been completed successfully, FALSE otherwise
4214 # @ingroup l2_modif_edit
4215 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4216 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4218 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4219 # This method is the first step of DoubleNodeElemGroupsInRegion.
4220 # @param theElems - list of groups of elements (edges or faces) to be replicated
4221 # @param theNodesNot - list of groups of nodes not to replicated
4222 # @param theShape - shape to detect affected elements (element which geometric center
4223 # located on or inside shape).
4224 # The replicated nodes should be associated to affected elements.
4225 # @return groups of affected elements
4226 # @ingroup l2_modif_edit
4227 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4228 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4230 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4231 # The list of groups must describe a partition of the mesh volumes.
4232 # The nodes of the internal faces at the boundaries of the groups are doubled.
4233 # In option, the internal faces are replaced by flat elements.
4234 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4235 # @param theDomains - list of groups of volumes
4236 # @param createJointElems - if TRUE, create the elements
4237 # @return TRUE if operation has been completed successfully, FALSE otherwise
4238 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4239 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4241 ## Double nodes on some external faces and create flat elements.
4242 # Flat elements are mainly used by some types of mechanic calculations.
4244 # Each group of the list must be constituted of faces.
4245 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4246 # @param theGroupsOfFaces - list of groups of faces
4247 # @return TRUE if operation has been completed successfully, FALSE otherwise
4248 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4249 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4251 ## identify all the elements around a geom shape, get the faces delimiting the hole
4253 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4254 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4256 def _getFunctor(self, funcType ):
4257 fn = self.functors[ funcType._v ]
4259 fn = self.smeshpyD.GetFunctor(funcType)
4260 fn.SetMesh(self.mesh)
4261 self.functors[ funcType._v ] = fn
4264 def _valueFromFunctor(self, funcType, elemId):
4265 fn = self._getFunctor( funcType )
4266 if fn.GetElementType() == self.GetElementType(elemId, True):
4267 val = fn.GetValue(elemId)
4272 ## Get length of 1D element.
4273 # @param elemId mesh element ID
4274 # @return element's length value
4275 # @ingroup l1_measurements
4276 def GetLength(self, elemId):
4277 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4279 ## Get area of 2D element.
4280 # @param elemId mesh element ID
4281 # @return element's area value
4282 # @ingroup l1_measurements
4283 def GetArea(self, elemId):
4284 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4286 ## Get volume of 3D element.
4287 # @param elemId mesh element ID
4288 # @return element's volume value
4289 # @ingroup l1_measurements
4290 def GetVolume(self, elemId):
4291 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4293 ## Get maximum element length.
4294 # @param elemId mesh element ID
4295 # @return element's maximum length value
4296 # @ingroup l1_measurements
4297 def GetMaxElementLength(self, elemId):
4298 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4299 ftype = SMESH.FT_MaxElementLength3D
4301 ftype = SMESH.FT_MaxElementLength2D
4302 return self._valueFromFunctor(ftype, elemId)
4304 ## Get aspect ratio of 2D or 3D element.
4305 # @param elemId mesh element ID
4306 # @return element's aspect ratio value
4307 # @ingroup l1_measurements
4308 def GetAspectRatio(self, elemId):
4309 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4310 ftype = SMESH.FT_AspectRatio3D
4312 ftype = SMESH.FT_AspectRatio
4313 return self._valueFromFunctor(ftype, elemId)
4315 ## Get warping angle of 2D element.
4316 # @param elemId mesh element ID
4317 # @return element's warping angle value
4318 # @ingroup l1_measurements
4319 def GetWarping(self, elemId):
4320 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4322 ## Get minimum angle of 2D element.
4323 # @param elemId mesh element ID
4324 # @return element's minimum angle value
4325 # @ingroup l1_measurements
4326 def GetMinimumAngle(self, elemId):
4327 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4329 ## Get taper of 2D element.
4330 # @param elemId mesh element ID
4331 # @return element's taper value
4332 # @ingroup l1_measurements
4333 def GetTaper(self, elemId):
4334 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4336 ## Get skew of 2D element.
4337 # @param elemId mesh element ID
4338 # @return element's skew value
4339 # @ingroup l1_measurements
4340 def GetSkew(self, elemId):
4341 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4343 pass # end of Mesh class
4345 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4347 class Pattern(SMESH._objref_SMESH_Pattern):
4349 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4350 decrFun = lambda i: i-1
4351 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4352 theMesh.SetParameters(Parameters)
4353 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4355 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4356 decrFun = lambda i: i-1
4357 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4358 theMesh.SetParameters(Parameters)
4359 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4361 # Registering the new proxy for Pattern
4362 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4364 ## Private class used to bind methods creating algorithms to the class Mesh
4369 self.defaultAlgoType = ""
4370 self.algoTypeToClass = {}
4372 # Stores a python class of algorithm
4373 def add(self, algoClass):
4374 if type( algoClass ).__name__ == 'classobj' and \
4375 hasattr( algoClass, "algoType"):
4376 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4377 if not self.defaultAlgoType and \
4378 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4379 self.defaultAlgoType = algoClass.algoType
4380 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4382 # creates a copy of self and assign mesh to the copy
4383 def copy(self, mesh):
4384 other = algoCreator()
4385 other.defaultAlgoType = self.defaultAlgoType
4386 other.algoTypeToClass = self.algoTypeToClass
4390 # creates an instance of algorithm
4391 def __call__(self,algo="",geom=0,*args):
4392 algoType = self.defaultAlgoType
4393 for arg in args + (algo,geom):
4394 if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
4396 if isinstance( arg, str ) and arg:
4398 if not algoType and self.algoTypeToClass:
4399 algoType = self.algoTypeToClass.keys()[0]
4400 if self.algoTypeToClass.has_key( algoType ):
4401 #print "Create algo",algoType
4402 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4403 raise RuntimeError, "No class found for algo type %s" % algoType
4406 # Private class used to substitute and store variable parameters of hypotheses.
4408 class hypMethodWrapper:
4409 def __init__(self, hyp, method):
4411 self.method = method
4412 #print "REBIND:", method.__name__
4415 # call a method of hypothesis with calling SetVarParameter() before
4416 def __call__(self,*args):
4418 return self.method( self.hyp, *args ) # hypothesis method with no args
4420 #print "MethWrapper.__call__",self.method.__name__, args
4422 parsed = ParseParameters(*args) # replace variables with their values
4423 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4424 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4425 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4426 # maybe there is a replaced string arg which is not variable
4427 result = self.method( self.hyp, *args )
4428 except ValueError, detail: # raised by ParseParameters()
4430 result = self.method( self.hyp, *args )
4431 except omniORB.CORBA.BAD_PARAM:
4432 raise ValueError, detail # wrong variable name
4436 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4438 #print "pluginName: ", pluginName
4439 pluginBuilderName = pluginName + "Builder"
4441 exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
4442 except Exception, e:
4443 print "Exception while loading %s: %s" % ( pluginBuilderName, e )
4445 exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
4446 plugin = eval( pluginBuilderName )
4447 #print " plugin:" , str(plugin)
4449 # add methods creating algorithms to Mesh
4450 for k in dir( plugin ):
4451 if k[0] == '_': continue
4452 algo = getattr( plugin, k )
4453 #print " algo:", str(algo)
4454 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4455 #print " meshMethod:" , str(algo.meshMethod)
4456 if not hasattr( Mesh, algo.meshMethod ):
4457 setattr( Mesh, algo.meshMethod, algoCreator() )
4459 getattr( Mesh, algo.meshMethod ).add( algo )