1 # Copyright (C) 2007-2012 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
20 # Author : Francis KLOSS, OCC
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
88 import SMESH # This is necessary for back compatibility
90 from smesh_algorithm import Mesh_Algorithm
96 ## @addtogroup l1_auxiliary
99 # MirrorType enumeration
100 POINT = SMESH_MeshEditor.POINT
101 AXIS = SMESH_MeshEditor.AXIS
102 PLANE = SMESH_MeshEditor.PLANE
104 # Smooth_Method enumeration
105 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
106 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
108 PrecisionConfusion = 1e-07
110 # TopAbs_State enumeration
111 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
113 # Methods of splitting a hexahedron into tetrahedra
114 Hex_5Tet, Hex_6Tet, Hex_24Tet = 1, 2, 3
116 ## Converts an angle from degrees to radians
117 def DegreesToRadians(AngleInDegrees):
119 return AngleInDegrees * pi / 180.0
121 import salome_notebook
122 notebook = salome_notebook.notebook
123 # Salome notebook variable separator
126 ## Return list of variable values from salome notebook.
127 # The last argument, if is callable, is used to modify values got from notebook
128 def ParseParameters(*args):
133 if args and callable( args[-1] ):
134 args, varModifFun = args[:-1], args[-1]
135 for parameter in args:
137 Parameters += str(parameter) + var_separator
139 if isinstance(parameter,str):
140 # check if there is an inexistent variable name
141 if not notebook.isVariable(parameter):
142 raise ValueError, "Variable with name '" + parameter + "' doesn't exist!!!"
143 parameter = notebook.get(parameter)
146 parameter = varModifFun(parameter)
149 Result.append(parameter)
152 Parameters = Parameters[:-1]
153 Result.append( Parameters )
154 Result.append( hasVariables )
157 # Parse parameters converting variables to radians
158 def ParseAngles(*args):
159 return ParseParameters( *( args + (DegreesToRadians, )))
161 # Substitute PointStruct.__init__() to create SMESH.PointStruct using notebook variables.
162 # Parameters are stored in PointStruct.parameters attribute
163 def __initPointStruct(point,*args):
164 point.x, point.y, point.z, point.parameters,hasVars = ParseParameters(*args)
166 SMESH.PointStruct.__init__ = __initPointStruct
168 # Substitute AxisStruct.__init__() to create SMESH.AxisStruct using notebook variables.
169 # Parameters are stored in AxisStruct.parameters attribute
170 def __initAxisStruct(ax,*args):
171 ax.x, ax.y, ax.z, ax.vx, ax.vy, ax.vz, ax.parameters,hasVars = ParseParameters(*args)
173 SMESH.AxisStruct.__init__ = __initAxisStruct
176 def IsEqual(val1, val2, tol=PrecisionConfusion):
177 if abs(val1 - val2) < tol:
187 if isinstance(obj, SALOMEDS._objref_SObject):
191 ior = salome.orb.object_to_string(obj)
196 studies = salome.myStudyManager.GetOpenStudies()
197 for sname in studies:
198 s = salome.myStudyManager.GetStudyByName(sname)
200 sobj = s.FindObjectIOR(ior)
201 if not sobj: continue
202 return sobj.GetName()
203 if hasattr(obj, "GetName"):
204 # unknown CORBA object, having GetName() method
207 # unknown CORBA object, no GetName() method
210 if hasattr(obj, "GetName"):
211 # unknown non-CORBA object, having GetName() method
214 raise RuntimeError, "Null or invalid object"
216 ## Prints error message if a hypothesis was not assigned.
217 def TreatHypoStatus(status, hypName, geomName, isAlgo):
219 hypType = "algorithm"
221 hypType = "hypothesis"
223 if status == HYP_UNKNOWN_FATAL :
224 reason = "for unknown reason"
225 elif status == HYP_INCOMPATIBLE :
226 reason = "this hypothesis mismatches the algorithm"
227 elif status == HYP_NOTCONFORM :
228 reason = "a non-conform mesh would be built"
229 elif status == HYP_ALREADY_EXIST :
230 if isAlgo: return # it does not influence anything
231 reason = hypType + " of the same dimension is already assigned to this shape"
232 elif status == HYP_BAD_DIM :
233 reason = hypType + " mismatches the shape"
234 elif status == HYP_CONCURENT :
235 reason = "there are concurrent hypotheses on sub-shapes"
236 elif status == HYP_BAD_SUBSHAPE :
237 reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
238 elif status == HYP_BAD_GEOMETRY:
239 reason = "geometry mismatches the expectation of the algorithm"
240 elif status == HYP_HIDDEN_ALGO:
241 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
242 elif status == HYP_HIDING_ALGO:
243 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
244 elif status == HYP_NEED_SHAPE:
245 reason = "Algorithm can't work without shape"
248 hypName = '"' + hypName + '"'
249 geomName= '"' + geomName+ '"'
250 if status < HYP_UNKNOWN_FATAL and not geomName =='""':
251 print hypName, "was assigned to", geomName,"but", reason
252 elif not geomName == '""':
253 print hypName, "was not assigned to",geomName,":", reason
255 print hypName, "was not assigned:", reason
258 ## Private method. Add geom (sub-shape of the main shape) into the study if not yet there
259 def AssureGeomPublished(mesh, geom, name=''):
260 if not isinstance( geom, geompyDC.GEOM._objref_GEOM_Object ):
262 if not geom.GetStudyEntry() and \
263 mesh.smeshpyD.GetCurrentStudy():
265 studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
266 if studyID != mesh.geompyD.myStudyId:
267 mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
269 if not name and geom.GetShapeType() != geompyDC.GEOM.COMPOUND:
270 # for all groups SubShapeName() returns "Compound_-1"
271 name = mesh.geompyD.SubShapeName(geom, mesh.geom)
273 name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
275 mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
278 ## Return the first vertex of a geometrical edge by ignoring orientation
279 def FirstVertexOnCurve(edge):
280 vv = geompyDC.SubShapeAll( edge, geompyDC.ShapeType["VERTEX"])
282 raise TypeError, "Given object has no vertices"
283 if len( vv ) == 1: return vv[0]
284 info = geompyDC.KindOfShape(edge)
285 xyz = info[1:4] # coords of the first vertex
286 xyz1 = geompyDC.PointCoordinates( vv[0] )
287 xyz2 = geompyDC.PointCoordinates( vv[1] )
290 dist1 += abs( xyz[i] - xyz1[i] )
291 dist2 += abs( xyz[i] - xyz2[i] )
297 # end of l1_auxiliary
301 # Warning: smeshInst is a singleton
306 class smeshDC(object, SMESH._objref_SMESH_Gen):
312 print "__new__", engine, smeshInst, doLcc
314 if smeshInst is None:
315 # smesh engine is either retrieved from engine, or created
317 # Following test avoids a recursive loop
319 if smeshInst is not None:
320 # smesh engine not created: existing engine found
324 # FindOrLoadComponent called:
325 # 1. CORBA resolution of server
326 # 2. the __new__ method is called again
327 print "smeshInst = lcc.FindOrLoadComponent ", engine, smeshInst, doLcc
328 smeshInst = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
330 # FindOrLoadComponent not called
331 if smeshInst is None:
332 # smeshDC instance is created from lcc.FindOrLoadComponent
333 print "smeshInst = super(smeshDC,cls).__new__(cls) ", engine, smeshInst, doLcc
334 smeshInst = super(smeshDC,cls).__new__(cls)
336 # smesh engine not created: existing engine found
337 print "existing ", engine, smeshInst, doLcc
346 SMESH._objref_SMESH_Gen.__init__(self)
348 ## Dump component to the Python script
349 # This method overrides IDL function to allow default values for the parameters.
350 def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
351 return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
353 ## Set mode of DumpPython(), \a historical or \a snapshot.
354 # In the \a historical mode, the Python Dump script includes all commands
355 # performed by SMESH engine. In the \a snapshot mode, commands
356 # relating to objects removed from the Study are excluded from the script
357 # as well as commands not influencing the current state of meshes
358 def SetDumpPythonHistorical(self, isHistorical):
359 if isHistorical: val = "true"
361 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
363 ## Sets the current study and Geometry component
364 # @ingroup l1_auxiliary
365 def init_smesh(self,theStudy,geompyD = None):
367 self.SetCurrentStudy(theStudy,geompyD)
369 ## Creates an empty Mesh. This mesh can have an underlying geometry.
370 # @param obj the Geometrical object on which the mesh is built. If not defined,
371 # the mesh will have no underlying geometry.
372 # @param name the name for the new mesh.
373 # @return an instance of Mesh class.
374 # @ingroup l2_construct
375 def Mesh(self, obj=0, name=0):
376 if isinstance(obj,str):
378 return Mesh(self,self.geompyD,obj,name)
380 ## Returns a long value from enumeration
381 # @ingroup l1_controls
382 def EnumToLong(self,theItem):
385 ## Returns a string representation of the color.
386 # To be used with filters.
387 # @param c color value (SALOMEDS.Color)
388 # @ingroup l1_controls
389 def ColorToString(self,c):
391 if isinstance(c, SALOMEDS.Color):
392 val = "%s;%s;%s" % (c.R, c.G, c.B)
393 elif isinstance(c, str):
396 raise ValueError, "Color value should be of string or SALOMEDS.Color type"
399 ## Gets PointStruct from vertex
400 # @param theVertex a GEOM object(vertex)
401 # @return SMESH.PointStruct
402 # @ingroup l1_auxiliary
403 def GetPointStruct(self,theVertex):
404 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
405 return PointStruct(x,y,z)
407 ## Gets DirStruct from vector
408 # @param theVector a GEOM object(vector)
409 # @return SMESH.DirStruct
410 # @ingroup l1_auxiliary
411 def GetDirStruct(self,theVector):
412 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
413 if(len(vertices) != 2):
414 print "Error: vector object is incorrect."
416 p1 = self.geompyD.PointCoordinates(vertices[0])
417 p2 = self.geompyD.PointCoordinates(vertices[1])
418 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
419 dirst = DirStruct(pnt)
422 ## Makes DirStruct from a triplet
423 # @param x,y,z vector components
424 # @return SMESH.DirStruct
425 # @ingroup l1_auxiliary
426 def MakeDirStruct(self,x,y,z):
427 pnt = PointStruct(x,y,z)
428 return DirStruct(pnt)
430 ## Get AxisStruct from object
431 # @param theObj a GEOM object (line or plane)
432 # @return SMESH.AxisStruct
433 # @ingroup l1_auxiliary
434 def GetAxisStruct(self,theObj):
435 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
437 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
438 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
439 vertex1 = self.geompyD.PointCoordinates(vertex1)
440 vertex2 = self.geompyD.PointCoordinates(vertex2)
441 vertex3 = self.geompyD.PointCoordinates(vertex3)
442 vertex4 = self.geompyD.PointCoordinates(vertex4)
443 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
444 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
445 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] ]
446 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
448 elif len(edges) == 1:
449 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
450 p1 = self.geompyD.PointCoordinates( vertex1 )
451 p2 = self.geompyD.PointCoordinates( vertex2 )
452 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
456 # From SMESH_Gen interface:
457 # ------------------------
459 ## Sets the given name to the object
460 # @param obj the object to rename
461 # @param name a new object name
462 # @ingroup l1_auxiliary
463 def SetName(self, obj, name):
464 if isinstance( obj, Mesh ):
466 elif isinstance( obj, Mesh_Algorithm ):
467 obj = obj.GetAlgorithm()
468 ior = salome.orb.object_to_string(obj)
469 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
471 ## Sets the current mode
472 # @ingroup l1_auxiliary
473 def SetEmbeddedMode( self,theMode ):
474 #self.SetEmbeddedMode(theMode)
475 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
477 ## Gets the current mode
478 # @ingroup l1_auxiliary
479 def IsEmbeddedMode(self):
480 #return self.IsEmbeddedMode()
481 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
483 ## Sets the current study
484 # @ingroup l1_auxiliary
485 def SetCurrentStudy( self, theStudy, geompyD = None ):
486 #self.SetCurrentStudy(theStudy)
489 geompyD = geompyDC.geom
492 self.SetGeomEngine(geompyD)
493 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
496 notebook = salome_notebook.NoteBook( theStudy )
498 notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
500 ## Gets the current study
501 # @ingroup l1_auxiliary
502 def GetCurrentStudy(self):
503 #return self.GetCurrentStudy()
504 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
506 ## Creates a Mesh object importing data from the given UNV file
507 # @return an instance of Mesh class
509 def CreateMeshesFromUNV( self,theFileName ):
510 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
511 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
514 ## Creates a Mesh object(s) importing data from the given MED file
515 # @return a list of Mesh class instances
517 def CreateMeshesFromMED( self,theFileName ):
518 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
520 for iMesh in range(len(aSmeshMeshes)) :
521 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
522 aMeshes.append(aMesh)
523 return aMeshes, aStatus
525 ## Creates a Mesh object(s) importing data from the given SAUV file
526 # @return a list of Mesh class instances
528 def CreateMeshesFromSAUV( self,theFileName ):
529 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
531 for iMesh in range(len(aSmeshMeshes)) :
532 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
533 aMeshes.append(aMesh)
534 return aMeshes, aStatus
536 ## Creates a Mesh object importing data from the given STL file
537 # @return an instance of Mesh class
539 def CreateMeshesFromSTL( self, theFileName ):
540 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
541 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
544 ## Creates Mesh objects importing data from the given CGNS file
545 # @return an instance of Mesh class
547 def CreateMeshesFromCGNS( self, theFileName ):
548 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
550 for iMesh in range(len(aSmeshMeshes)) :
551 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
552 aMeshes.append(aMesh)
553 return aMeshes, aStatus
555 ## Creates a Mesh object importing data from the given GMF file
556 # @return [ an instance of Mesh class, SMESH::ComputeError ]
558 def CreateMeshesFromGMF( self, theFileName ):
559 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
562 if error.comment: print "*** CreateMeshesFromGMF() errors:\n", error.comment
563 return Mesh(self, self.geompyD, aSmeshMesh), error
565 ## Concatenate the given meshes into one mesh.
566 # @return an instance of Mesh class
567 # @param meshes the meshes to combine into one mesh
568 # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
569 # @param mergeNodesAndElements if true, equal nodes and elements aremerged
570 # @param mergeTolerance tolerance for merging nodes
571 # @param allGroups forces creation of groups of all elements
572 # @param name name of a new mesh
573 def Concatenate( self, meshes, uniteIdenticalGroups,
574 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
576 if not meshes: return None
577 for i,m in enumerate(meshes):
578 if isinstance(m, Mesh):
579 meshes[i] = m.GetMesh()
580 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
581 meshes[0].SetParameters(Parameters)
583 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
584 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
586 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
587 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
588 aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
591 ## Create a mesh by copying a part of another mesh.
592 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
593 # to copy nodes or elements not contained in any mesh object,
594 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
595 # @param meshName a name of the new mesh
596 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
597 # @param toKeepIDs to preserve IDs of the copied elements or not
598 # @return an instance of Mesh class
599 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
600 if (isinstance( meshPart, Mesh )):
601 meshPart = meshPart.GetMesh()
602 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
603 return Mesh(self, self.geompyD, mesh)
605 ## From SMESH_Gen interface
606 # @return the list of integer values
607 # @ingroup l1_auxiliary
608 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
609 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
611 ## From SMESH_Gen interface. Creates a pattern
612 # @return an instance of SMESH_Pattern
614 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
615 # @ingroup l2_modif_patterns
616 def GetPattern(self):
617 return SMESH._objref_SMESH_Gen.GetPattern(self)
619 ## Sets number of segments per diagonal of boundary box of geometry by which
620 # default segment length of appropriate 1D hypotheses is defined.
621 # Default value is 10
622 # @ingroup l1_auxiliary
623 def SetBoundaryBoxSegmentation(self, nbSegments):
624 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
626 # Filtering. Auxiliary functions:
627 # ------------------------------
629 ## Creates an empty criterion
630 # @return SMESH.Filter.Criterion
631 # @ingroup l1_controls
632 def GetEmptyCriterion(self):
633 Type = self.EnumToLong(FT_Undefined)
634 Compare = self.EnumToLong(FT_Undefined)
638 UnaryOp = self.EnumToLong(FT_Undefined)
639 BinaryOp = self.EnumToLong(FT_Undefined)
642 Precision = -1 ##@1e-07
643 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
644 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
646 ## Creates a criterion by the given parameters
647 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
648 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
649 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
650 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
651 # @param Threshold the threshold value (range of ids as string, shape, numeric)
652 # @param UnaryOp FT_LogicalNOT or FT_Undefined
653 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
654 # FT_Undefined (must be for the last criterion of all criteria)
655 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
656 # FT_LyingOnGeom, FT_CoplanarFaces criteria
657 # @return SMESH.Filter.Criterion
659 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
660 # @ingroup l1_controls
661 def GetCriterion(self,elementType,
663 Compare = FT_EqualTo,
665 UnaryOp=FT_Undefined,
666 BinaryOp=FT_Undefined,
668 if not CritType in SMESH.FunctorType._items:
669 raise TypeError, "CritType should be of SMESH.FunctorType"
670 aCriterion = self.GetEmptyCriterion()
671 aCriterion.TypeOfElement = elementType
672 aCriterion.Type = self.EnumToLong(CritType)
673 aCriterion.Tolerance = Tolerance
675 aThreshold = Threshold
677 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
678 aCriterion.Compare = self.EnumToLong(Compare)
679 elif Compare == "=" or Compare == "==":
680 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
682 aCriterion.Compare = self.EnumToLong(FT_LessThan)
684 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
685 elif Compare != FT_Undefined:
686 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
689 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
690 FT_BelongToCylinder, FT_LyingOnGeom]:
691 # Checks that Threshold is GEOM object
692 if isinstance(aThreshold, geompyDC.GEOM._objref_GEOM_Object):
693 aCriterion.ThresholdStr = GetName(aThreshold)
694 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
695 if not aCriterion.ThresholdID:
696 name = aCriterion.ThresholdStr
698 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
699 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
700 #raise RuntimeError, "Threshold shape must be published"
702 print "Error: The Threshold should be a shape."
704 if isinstance(UnaryOp,float):
705 aCriterion.Tolerance = UnaryOp
706 UnaryOp = FT_Undefined
708 elif CritType == FT_RangeOfIds:
709 # Checks that Threshold is string
710 if isinstance(aThreshold, str):
711 aCriterion.ThresholdStr = aThreshold
713 print "Error: The Threshold should be a string."
715 elif CritType == FT_CoplanarFaces:
716 # Checks the Threshold
717 if isinstance(aThreshold, int):
718 aCriterion.ThresholdID = str(aThreshold)
719 elif isinstance(aThreshold, str):
722 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
723 aCriterion.ThresholdID = aThreshold
726 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
727 elif CritType == FT_ElemGeomType:
728 # Checks the Threshold
730 aCriterion.Threshold = self.EnumToLong(aThreshold)
731 assert( aThreshold in SMESH.GeometryType._items )
733 if isinstance(aThreshold, int):
734 aCriterion.Threshold = aThreshold
736 print "Error: The Threshold should be an integer or SMESH.GeometryType."
740 elif CritType == FT_EntityType:
741 # Checks the Threshold
743 aCriterion.Threshold = self.EnumToLong(aThreshold)
744 assert( aThreshold in SMESH.EntityType._items )
746 if isinstance(aThreshold, int):
747 aCriterion.Threshold = aThreshold
749 print "Error: The Threshold should be an integer or SMESH.EntityType."
754 elif CritType == FT_GroupColor:
755 # Checks the Threshold
757 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
759 print "Error: The threshold value should be of SALOMEDS.Color type"
762 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
763 FT_LinearOrQuadratic, FT_BadOrientedVolume,
764 FT_BareBorderFace, FT_BareBorderVolume,
765 FT_OverConstrainedFace, FT_OverConstrainedVolume,
766 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
767 # At this point the Threshold is unnecessary
768 if aThreshold == FT_LogicalNOT:
769 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
770 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
771 aCriterion.BinaryOp = aThreshold
775 aThreshold = float(aThreshold)
776 aCriterion.Threshold = aThreshold
778 print "Error: The Threshold should be a number."
781 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
782 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
784 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
785 aCriterion.BinaryOp = self.EnumToLong(Threshold)
787 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
788 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
790 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
791 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
795 ## Creates a filter with the given parameters
796 # @param elementType the type of elements in the group
797 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
798 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
799 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
800 # @param UnaryOp FT_LogicalNOT or FT_Undefined
801 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
802 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
803 # @return SMESH_Filter
805 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
806 # @ingroup l1_controls
807 def GetFilter(self,elementType,
808 CritType=FT_Undefined,
811 UnaryOp=FT_Undefined,
813 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
814 aFilterMgr = self.CreateFilterManager()
815 aFilter = aFilterMgr.CreateFilter()
817 aCriteria.append(aCriterion)
818 aFilter.SetCriteria(aCriteria)
819 aFilterMgr.UnRegister()
822 ## Creates a filter from criteria
823 # @param criteria a list of criteria
824 # @return SMESH_Filter
826 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
827 # @ingroup l1_controls
828 def GetFilterFromCriteria(self,criteria):
829 aFilterMgr = self.CreateFilterManager()
830 aFilter = aFilterMgr.CreateFilter()
831 aFilter.SetCriteria(criteria)
832 aFilterMgr.UnRegister()
835 ## Creates a numerical functor by its type
836 # @param theCriterion FT_...; functor type
837 # @return SMESH_NumericalFunctor
838 # @ingroup l1_controls
839 def GetFunctor(self,theCriterion):
840 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
842 aFilterMgr = self.CreateFilterManager()
844 if theCriterion == FT_AspectRatio:
845 functor = aFilterMgr.CreateAspectRatio()
846 elif theCriterion == FT_AspectRatio3D:
847 functor = aFilterMgr.CreateAspectRatio3D()
848 elif theCriterion == FT_Warping:
849 functor = aFilterMgr.CreateWarping()
850 elif theCriterion == FT_MinimumAngle:
851 functor = aFilterMgr.CreateMinimumAngle()
852 elif theCriterion == FT_Taper:
853 functor = aFilterMgr.CreateTaper()
854 elif theCriterion == FT_Skew:
855 functor = aFilterMgr.CreateSkew()
856 elif theCriterion == FT_Area:
857 functor = aFilterMgr.CreateArea()
858 elif theCriterion == FT_Volume3D:
859 functor = aFilterMgr.CreateVolume3D()
860 elif theCriterion == FT_MaxElementLength2D:
861 functor = aFilterMgr.CreateMaxElementLength2D()
862 elif theCriterion == FT_MaxElementLength3D:
863 functor = aFilterMgr.CreateMaxElementLength3D()
864 elif theCriterion == FT_MultiConnection:
865 functor = aFilterMgr.CreateMultiConnection()
866 elif theCriterion == FT_MultiConnection2D:
867 functor = aFilterMgr.CreateMultiConnection2D()
868 elif theCriterion == FT_Length:
869 functor = aFilterMgr.CreateLength()
870 elif theCriterion == FT_Length2D:
871 functor = aFilterMgr.CreateLength2D()
873 print "Error: given parameter is not numerical functor type."
874 aFilterMgr.UnRegister()
877 ## Creates hypothesis
878 # @param theHType mesh hypothesis type (string)
879 # @param theLibName mesh plug-in library name
880 # @return created hypothesis instance
881 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
882 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
884 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
887 # wrap hypothesis methods
888 #print "HYPOTHESIS", theHType
889 for meth_name in dir( hyp.__class__ ):
890 if not meth_name.startswith("Get") and \
891 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
892 method = getattr ( hyp.__class__, meth_name )
894 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
898 ## Gets the mesh statistic
899 # @return dictionary "element type" - "count of elements"
900 # @ingroup l1_meshinfo
901 def GetMeshInfo(self, obj):
902 if isinstance( obj, Mesh ):
905 if hasattr(obj, "GetMeshInfo"):
906 values = obj.GetMeshInfo()
907 for i in range(SMESH.Entity_Last._v):
908 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
912 ## Get minimum distance between two objects
914 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
915 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
917 # @param src1 first source object
918 # @param src2 second source object
919 # @param id1 node/element id from the first source
920 # @param id2 node/element id from the second (or first) source
921 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
922 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
923 # @return minimum distance value
924 # @sa GetMinDistance()
925 # @ingroup l1_measurements
926 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
927 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
931 result = result.value
934 ## Get measure structure specifying minimum distance data between two objects
936 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
937 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
939 # @param src1 first source object
940 # @param src2 second source object
941 # @param id1 node/element id from the first source
942 # @param id2 node/element id from the second (or first) source
943 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
944 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
945 # @return Measure structure or None if input data is invalid
947 # @ingroup l1_measurements
948 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
949 if isinstance(src1, Mesh): src1 = src1.mesh
950 if isinstance(src2, Mesh): src2 = src2.mesh
951 if src2 is None and id2 != 0: src2 = src1
952 if not hasattr(src1, "_narrow"): return None
953 src1 = src1._narrow(SMESH.SMESH_IDSource)
954 if not src1: return None
957 e = m.GetMeshEditor()
959 src1 = e.MakeIDSource([id1], SMESH.FACE)
961 src1 = e.MakeIDSource([id1], SMESH.NODE)
963 if hasattr(src2, "_narrow"):
964 src2 = src2._narrow(SMESH.SMESH_IDSource)
965 if src2 and id2 != 0:
967 e = m.GetMeshEditor()
969 src2 = e.MakeIDSource([id2], SMESH.FACE)
971 src2 = e.MakeIDSource([id2], SMESH.NODE)
974 aMeasurements = self.CreateMeasurements()
975 result = aMeasurements.MinDistance(src1, src2)
976 aMeasurements.UnRegister()
979 ## Get bounding box of the specified object(s)
980 # @param objects single source object or list of source objects
981 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
982 # @sa GetBoundingBox()
983 # @ingroup l1_measurements
984 def BoundingBox(self, objects):
985 result = self.GetBoundingBox(objects)
989 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
992 ## Get measure structure specifying bounding box data of the specified object(s)
993 # @param objects single source object or list of source objects
994 # @return Measure structure
996 # @ingroup l1_measurements
997 def GetBoundingBox(self, objects):
998 if isinstance(objects, tuple):
999 objects = list(objects)
1000 if not isinstance(objects, list):
1004 if isinstance(o, Mesh):
1005 srclist.append(o.mesh)
1006 elif hasattr(o, "_narrow"):
1007 src = o._narrow(SMESH.SMESH_IDSource)
1008 if src: srclist.append(src)
1011 aMeasurements = self.CreateMeasurements()
1012 result = aMeasurements.BoundingBox(srclist)
1013 aMeasurements.UnRegister()
1017 #Registering the new proxy for SMESH_Gen
1018 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
1021 def smeshInstance( study, instance=None):
1028 smeshInst = smeshDC()
1029 assert isinstance(smeshInst,smeshDC), "Smesh engine class is %s but should be smeshDC.smeshDC. Import smeshmapi before creating the instance."%smeshInst.__class__
1030 smeshInst.init_smesh(study)
1034 # Public class: Mesh
1035 # ==================
1037 ## This class allows defining and managing a mesh.
1038 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1039 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1040 # new nodes and elements and by changing the existing entities), to get information
1041 # about a mesh and to export a mesh into different formats.
1050 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1051 # sets the GUI name of this mesh to \a name.
1052 # @param smeshpyD an instance of smeshDC class
1053 # @param geompyD an instance of geompyDC class
1054 # @param obj Shape to be meshed or SMESH_Mesh object
1055 # @param name Study name of the mesh
1056 # @ingroup l2_construct
1057 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1058 self.smeshpyD=smeshpyD
1059 self.geompyD=geompyD
1064 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
1067 # publish geom of mesh (issue 0021122)
1068 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
1070 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
1071 if studyID != geompyD.myStudyId:
1072 geompyD.init_geom( smeshpyD.GetCurrentStudy())
1075 geo_name = name + " shape"
1077 geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1078 geompyD.addToStudy( self.geom, geo_name )
1079 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1081 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1084 self.mesh = self.smeshpyD.CreateEmptyMesh()
1086 self.smeshpyD.SetName(self.mesh, name)
1088 self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1091 self.geom = self.mesh.GetShapeToMesh()
1093 self.editor = self.mesh.GetMeshEditor()
1094 self.functors = [None] * SMESH.FT_Undefined._v
1096 # set self to algoCreator's
1097 for attrName in dir(self):
1098 attr = getattr( self, attrName )
1099 if isinstance( attr, algoCreator ):
1100 print "algoCreator ", attrName
1101 setattr( self, attrName, attr.copy( self ))
1103 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1104 # @param theMesh a SMESH_Mesh object
1105 # @ingroup l2_construct
1106 def SetMesh(self, theMesh):
1107 if self.mesh: self.mesh.UnRegister()
1110 self.mesh.Register()
1111 self.geom = self.mesh.GetShapeToMesh()
1113 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1114 # @return a SMESH_Mesh object
1115 # @ingroup l2_construct
1119 ## Gets the name of the mesh
1120 # @return the name of the mesh as a string
1121 # @ingroup l2_construct
1123 name = GetName(self.GetMesh())
1126 ## Sets a name to the mesh
1127 # @param name a new name of the mesh
1128 # @ingroup l2_construct
1129 def SetName(self, name):
1130 self.smeshpyD.SetName(self.GetMesh(), name)
1132 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1133 # The subMesh object gives access to the IDs of nodes and elements.
1134 # @param geom a geometrical object (shape)
1135 # @param name a name for the submesh
1136 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1137 # @ingroup l2_submeshes
1138 def GetSubMesh(self, geom, name):
1139 AssureGeomPublished( self, geom, name )
1140 submesh = self.mesh.GetSubMesh( geom, name )
1143 ## Returns the shape associated to the mesh
1144 # @return a GEOM_Object
1145 # @ingroup l2_construct
1149 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1150 # @param geom the shape to be meshed (GEOM_Object)
1151 # @ingroup l2_construct
1152 def SetShape(self, geom):
1153 self.mesh = self.smeshpyD.CreateMesh(geom)
1155 ## Loads mesh from the study after opening the study
1159 ## Returns true if the hypotheses are defined well
1160 # @param theSubObject a sub-shape of a mesh shape
1161 # @return True or False
1162 # @ingroup l2_construct
1163 def IsReadyToCompute(self, theSubObject):
1164 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1166 ## Returns errors of hypotheses definition.
1167 # The list of errors is empty if everything is OK.
1168 # @param theSubObject a sub-shape of a mesh shape
1169 # @return a list of errors
1170 # @ingroup l2_construct
1171 def GetAlgoState(self, theSubObject):
1172 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1174 ## Returns a geometrical object on which the given element was built.
1175 # The returned geometrical object, if not nil, is either found in the
1176 # study or published by this method with the given name
1177 # @param theElementID the id of the mesh element
1178 # @param theGeomName the user-defined name of the geometrical object
1179 # @return GEOM::GEOM_Object instance
1180 # @ingroup l2_construct
1181 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1182 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1184 ## Returns the mesh dimension depending on the dimension of the underlying shape
1185 # or, if the mesh is not based on any shape, basing on deimension of elements
1186 # @return mesh dimension as an integer value [0,3]
1187 # @ingroup l1_auxiliary
1188 def MeshDimension(self):
1189 if self.mesh.HasShapeToMesh():
1190 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SOLID"] )
1191 if len( shells ) > 0 :
1193 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1195 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1200 if self.NbVolumes() > 0: return 3
1201 if self.NbFaces() > 0: return 2
1202 if self.NbEdges() > 0: return 1
1205 ## Evaluates size of prospective mesh on a shape
1206 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1207 # To know predicted number of e.g. edges, inquire it this way
1208 # Evaluate()[ EnumToLong( Entity_Edge )]
1209 def Evaluate(self, geom=0):
1210 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1212 geom = self.mesh.GetShapeToMesh()
1215 return self.smeshpyD.Evaluate(self.mesh, geom)
1218 ## Computes the mesh and returns the status of the computation
1219 # @param geom geomtrical shape on which mesh data should be computed
1220 # @param discardModifs if True and the mesh has been edited since
1221 # a last total re-compute and that may prevent successful partial re-compute,
1222 # then the mesh is cleaned before Compute()
1223 # @return True or False
1224 # @ingroup l2_construct
1225 def Compute(self, geom=0, discardModifs=False):
1226 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1228 geom = self.mesh.GetShapeToMesh()
1233 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1235 ok = self.smeshpyD.Compute(self.mesh, geom)
1236 except SALOME.SALOME_Exception, ex:
1237 print "Mesh computation failed, exception caught:"
1238 print " ", ex.details.text
1241 print "Mesh computation failed, exception caught:"
1242 traceback.print_exc()
1246 # Treat compute errors
1247 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1248 for err in computeErrors:
1250 if self.mesh.HasShapeToMesh():
1252 mainIOR = salome.orb.object_to_string(geom)
1253 for sname in salome.myStudyManager.GetOpenStudies():
1254 s = salome.myStudyManager.GetStudyByName(sname)
1256 mainSO = s.FindObjectIOR(mainIOR)
1257 if not mainSO: continue
1258 if err.subShapeID == 1:
1259 shapeText = ' on "%s"' % mainSO.GetName()
1260 subIt = s.NewChildIterator(mainSO)
1262 subSO = subIt.Value()
1264 obj = subSO.GetObject()
1265 if not obj: continue
1266 go = obj._narrow( geompyDC.GEOM._objref_GEOM_Object )
1268 ids = go.GetSubShapeIndices()
1269 if len(ids) == 1 and ids[0] == err.subShapeID:
1270 shapeText = ' on "%s"' % subSO.GetName()
1273 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1275 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1277 shapeText = " on subshape #%s" % (err.subShapeID)
1279 shapeText = " on subshape #%s" % (err.subShapeID)
1281 stdErrors = ["OK", #COMPERR_OK
1282 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1283 "std::exception", #COMPERR_STD_EXCEPTION
1284 "OCC exception", #COMPERR_OCC_EXCEPTION
1285 "..", #COMPERR_SLM_EXCEPTION
1286 "Unknown exception", #COMPERR_EXCEPTION
1287 "Memory allocation problem", #COMPERR_MEMORY_PB
1288 "Algorithm failed", #COMPERR_ALGO_FAILED
1289 "Unexpected geometry", #COMPERR_BAD_SHAPE
1290 "Warning", #COMPERR_WARNING
1291 "Computation cancelled",#COMPERR_CANCELED
1292 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1294 if err.code < len(stdErrors): errText = stdErrors[err.code]
1296 errText = "code %s" % -err.code
1297 if errText: errText += ". "
1298 errText += err.comment
1299 if allReasons != "":allReasons += "\n"
1300 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1304 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1306 if err.isGlobalAlgo:
1314 reason = '%s %sD algorithm is missing' % (glob, dim)
1315 elif err.state == HYP_MISSING:
1316 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1317 % (glob, dim, name, dim))
1318 elif err.state == HYP_NOTCONFORM:
1319 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1320 elif err.state == HYP_BAD_PARAMETER:
1321 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1322 % ( glob, dim, name ))
1323 elif err.state == HYP_BAD_GEOMETRY:
1324 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1325 'geometry' % ( glob, dim, name ))
1326 elif err.state == HYP_HIDDEN_ALGO:
1327 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1328 'algorithm of upper dimension generating %sD mesh'
1329 % ( glob, dim, name, glob, dim ))
1331 reason = ("For unknown reason. "
1332 "Developer, revise Mesh.Compute() implementation in smeshDC.py!")
1334 if allReasons != "":allReasons += "\n"
1335 allReasons += "- " + reason
1337 if not ok or allReasons != "":
1338 msg = '"' + GetName(self.mesh) + '"'
1339 if ok: msg += " has been computed with warnings"
1340 else: msg += " has not been computed"
1341 if allReasons != "": msg += ":"
1346 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1347 smeshgui = salome.ImportComponentGUI("SMESH")
1348 smeshgui.Init(self.mesh.GetStudyId())
1349 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1350 salome.sg.updateObjBrowser(1)
1354 ## Return submesh objects list in meshing order
1355 # @return list of list of submesh objects
1356 # @ingroup l2_construct
1357 def GetMeshOrder(self):
1358 return self.mesh.GetMeshOrder()
1360 ## Return submesh objects list in meshing order
1361 # @return list of list of submesh objects
1362 # @ingroup l2_construct
1363 def SetMeshOrder(self, submeshes):
1364 return self.mesh.SetMeshOrder(submeshes)
1366 ## Removes all nodes and elements
1367 # @ingroup l2_construct
1370 if ( salome.sg.hasDesktop() and
1371 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1372 smeshgui = salome.ImportComponentGUI("SMESH")
1373 smeshgui.Init(self.mesh.GetStudyId())
1374 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1375 salome.sg.updateObjBrowser(1)
1377 ## Removes all nodes and elements of indicated shape
1378 # @ingroup l2_construct
1379 def ClearSubMesh(self, geomId):
1380 self.mesh.ClearSubMesh(geomId)
1381 if salome.sg.hasDesktop():
1382 smeshgui = salome.ImportComponentGUI("SMESH")
1383 smeshgui.Init(self.mesh.GetStudyId())
1384 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1385 salome.sg.updateObjBrowser(1)
1387 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1388 # @param fineness [0.0,1.0] defines mesh fineness
1389 # @return True or False
1390 # @ingroup l3_algos_basic
1391 def AutomaticTetrahedralization(self, fineness=0):
1392 dim = self.MeshDimension()
1394 self.RemoveGlobalHypotheses()
1395 self.Segment().AutomaticLength(fineness)
1397 self.Triangle().LengthFromEdges()
1400 from NETGENPluginDC import NETGEN
1401 self.Tetrahedron(NETGEN)
1403 return self.Compute()
1405 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1406 # @param fineness [0.0, 1.0] defines mesh fineness
1407 # @return True or False
1408 # @ingroup l3_algos_basic
1409 def AutomaticHexahedralization(self, fineness=0):
1410 dim = self.MeshDimension()
1411 # assign the hypotheses
1412 self.RemoveGlobalHypotheses()
1413 self.Segment().AutomaticLength(fineness)
1420 return self.Compute()
1422 ## Assigns a hypothesis
1423 # @param hyp a hypothesis to assign
1424 # @param geom a subhape of mesh geometry
1425 # @return SMESH.Hypothesis_Status
1426 # @ingroup l2_hypotheses
1427 def AddHypothesis(self, hyp, geom=0):
1428 if isinstance( hyp, Mesh_Algorithm ):
1429 hyp = hyp.GetAlgorithm()
1434 geom = self.mesh.GetShapeToMesh()
1436 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1437 status = self.mesh.AddHypothesis(geom, hyp)
1438 isAlgo = hyp._narrow( SMESH_Algo )
1439 hyp_name = GetName( hyp )
1442 geom_name = GetName( geom )
1443 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1446 ## Return True if an algorithm of hypothesis is assigned to a given shape
1447 # @param hyp a hypothesis to check
1448 # @param geom a subhape of mesh geometry
1449 # @return True of False
1450 # @ingroup l2_hypotheses
1451 def IsUsedHypothesis(self, hyp, geom):
1452 if not hyp: # or not geom
1454 if isinstance( hyp, Mesh_Algorithm ):
1455 hyp = hyp.GetAlgorithm()
1457 hyps = self.GetHypothesisList(geom)
1459 if h.GetId() == hyp.GetId():
1463 ## Unassigns a hypothesis
1464 # @param hyp a hypothesis to unassign
1465 # @param geom a sub-shape of mesh geometry
1466 # @return SMESH.Hypothesis_Status
1467 # @ingroup l2_hypotheses
1468 def RemoveHypothesis(self, hyp, geom=0):
1469 if isinstance( hyp, Mesh_Algorithm ):
1470 hyp = hyp.GetAlgorithm()
1476 if self.IsUsedHypothesis( hyp, shape ):
1477 return self.mesh.RemoveHypothesis( shape, hyp )
1478 hypName = GetName( hyp )
1479 geoName = GetName( shape )
1480 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1483 ## Gets the list of hypotheses added on a geometry
1484 # @param geom a sub-shape of mesh geometry
1485 # @return the sequence of SMESH_Hypothesis
1486 # @ingroup l2_hypotheses
1487 def GetHypothesisList(self, geom):
1488 return self.mesh.GetHypothesisList( geom )
1490 ## Removes all global hypotheses
1491 # @ingroup l2_hypotheses
1492 def RemoveGlobalHypotheses(self):
1493 current_hyps = self.mesh.GetHypothesisList( self.geom )
1494 for hyp in current_hyps:
1495 self.mesh.RemoveHypothesis( self.geom, hyp )
1499 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1500 ## allowing to overwrite the file if it exists or add the exported data to its contents
1501 # @param f is the file name
1502 # @param auto_groups boolean parameter for creating/not creating
1503 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1504 # the typical use is auto_groups=false.
1505 # @param version MED format version(MED_V2_1 or MED_V2_2)
1506 # @param overwrite boolean parameter for overwriting/not overwriting the file
1507 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1508 # @ingroup l2_impexp
1509 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1511 if isinstance( meshPart, list ):
1512 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1513 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1515 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1517 ## Exports the mesh in a file in SAUV format
1518 # @param f is the file name
1519 # @param auto_groups boolean parameter for creating/not creating
1520 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1521 # the typical use is auto_groups=false.
1522 # @ingroup l2_impexp
1523 def ExportSAUV(self, f, auto_groups=0):
1524 self.mesh.ExportSAUV(f, auto_groups)
1526 ## Exports the mesh in a file in DAT format
1527 # @param f the file name
1528 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1529 # @ingroup l2_impexp
1530 def ExportDAT(self, f, meshPart=None):
1532 if isinstance( meshPart, list ):
1533 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1534 self.mesh.ExportPartToDAT( meshPart, f )
1536 self.mesh.ExportDAT(f)
1538 ## Exports the mesh in a file in UNV format
1539 # @param f the file name
1540 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1541 # @ingroup l2_impexp
1542 def ExportUNV(self, f, meshPart=None):
1544 if isinstance( meshPart, list ):
1545 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1546 self.mesh.ExportPartToUNV( meshPart, f )
1548 self.mesh.ExportUNV(f)
1550 ## Export the mesh in a file in STL format
1551 # @param f the file name
1552 # @param ascii defines the file encoding
1553 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1554 # @ingroup l2_impexp
1555 def ExportSTL(self, f, ascii=1, meshPart=None):
1557 if isinstance( meshPart, list ):
1558 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1559 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1561 self.mesh.ExportSTL(f, ascii)
1563 ## Exports the mesh in a file in CGNS format
1564 # @param f is the file name
1565 # @param overwrite boolean parameter for overwriting/not overwriting the file
1566 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1567 # @ingroup l2_impexp
1568 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1569 if isinstance( meshPart, list ):
1570 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1571 if isinstance( meshPart, Mesh ):
1572 meshPart = meshPart.mesh
1574 meshPart = self.mesh
1575 self.mesh.ExportCGNS(meshPart, f, overwrite)
1577 ## Exports the mesh in a file in GMF format
1578 # @param f is the file name
1579 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1580 # @ingroup l2_impexp
1581 def ExportGMF(self, f, meshPart=None):
1582 if isinstance( meshPart, list ):
1583 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1584 if isinstance( meshPart, Mesh ):
1585 meshPart = meshPart.mesh
1587 meshPart = self.mesh
1588 self.mesh.ExportGMF(meshPart, f, True)
1590 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1591 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1592 ## allowing to overwrite the file if it exists or add the exported data to its contents
1593 # @param f the file name
1594 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1595 # @param opt boolean parameter for creating/not creating
1596 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1597 # @param overwrite boolean parameter for overwriting/not overwriting the file
1598 # @ingroup l2_impexp
1599 def ExportToMED(self, f, version, opt=0, overwrite=1):
1600 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1602 # Operations with groups:
1603 # ----------------------
1605 ## Creates an empty mesh group
1606 # @param elementType the type of elements in the group
1607 # @param name the name of the mesh group
1608 # @return SMESH_Group
1609 # @ingroup l2_grps_create
1610 def CreateEmptyGroup(self, elementType, name):
1611 return self.mesh.CreateGroup(elementType, name)
1613 ## Creates a mesh group based on the geometric object \a grp
1614 # and gives a \a name, \n if this parameter is not defined
1615 # the name is the same as the geometric group name \n
1616 # Note: Works like GroupOnGeom().
1617 # @param grp a geometric group, a vertex, an edge, a face or a solid
1618 # @param name the name of the mesh group
1619 # @return SMESH_GroupOnGeom
1620 # @ingroup l2_grps_create
1621 def Group(self, grp, name=""):
1622 return self.GroupOnGeom(grp, name)
1624 ## Creates a mesh group based on the geometrical object \a grp
1625 # and gives a \a name, \n if this parameter is not defined
1626 # the name is the same as the geometrical group name
1627 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1628 # @param name the name of the mesh group
1629 # @param typ the type of elements in the group. If not set, it is
1630 # automatically detected by the type of the geometry
1631 # @return SMESH_GroupOnGeom
1632 # @ingroup l2_grps_create
1633 def GroupOnGeom(self, grp, name="", typ=None):
1634 AssureGeomPublished( self, grp, name )
1636 name = grp.GetName()
1638 typ = self._groupTypeFromShape( grp )
1639 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1641 ## Pivate method to get a type of group on geometry
1642 def _groupTypeFromShape( self, shape ):
1643 tgeo = str(shape.GetShapeType())
1644 if tgeo == "VERTEX":
1646 elif tgeo == "EDGE":
1648 elif tgeo == "FACE" or tgeo == "SHELL":
1650 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1652 elif tgeo == "COMPOUND":
1653 sub = self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHAPE"])
1655 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1656 return self._groupTypeFromShape( sub[0] )
1659 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1662 ## Creates a mesh group with given \a name based on the \a filter which
1663 ## is a special type of group dynamically updating it's contents during
1664 ## mesh modification
1665 # @param typ the type of elements in the group
1666 # @param name the name of the mesh group
1667 # @param filter the filter defining group contents
1668 # @return SMESH_GroupOnFilter
1669 # @ingroup l2_grps_create
1670 def GroupOnFilter(self, typ, name, filter):
1671 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1673 ## Creates a mesh group by the given ids of elements
1674 # @param groupName the name of the mesh group
1675 # @param elementType the type of elements in the group
1676 # @param elemIDs the list of ids
1677 # @return SMESH_Group
1678 # @ingroup l2_grps_create
1679 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1680 group = self.mesh.CreateGroup(elementType, groupName)
1684 ## Creates a mesh group by the given conditions
1685 # @param groupName the name of the mesh group
1686 # @param elementType the type of elements in the group
1687 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1688 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1689 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1690 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1691 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1692 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1693 # @return SMESH_Group
1694 # @ingroup l2_grps_create
1698 CritType=FT_Undefined,
1701 UnaryOp=FT_Undefined,
1703 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1704 group = self.MakeGroupByCriterion(groupName, aCriterion)
1707 ## Creates a mesh group by the given criterion
1708 # @param groupName the name of the mesh group
1709 # @param Criterion the instance of Criterion class
1710 # @return SMESH_Group
1711 # @ingroup l2_grps_create
1712 def MakeGroupByCriterion(self, groupName, Criterion):
1713 aFilterMgr = self.smeshpyD.CreateFilterManager()
1714 aFilter = aFilterMgr.CreateFilter()
1716 aCriteria.append(Criterion)
1717 aFilter.SetCriteria(aCriteria)
1718 group = self.MakeGroupByFilter(groupName, aFilter)
1719 aFilterMgr.UnRegister()
1722 ## Creates a mesh group by the given criteria (list of criteria)
1723 # @param groupName the name of the mesh group
1724 # @param theCriteria the list of criteria
1725 # @return SMESH_Group
1726 # @ingroup l2_grps_create
1727 def MakeGroupByCriteria(self, groupName, theCriteria):
1728 aFilterMgr = self.smeshpyD.CreateFilterManager()
1729 aFilter = aFilterMgr.CreateFilter()
1730 aFilter.SetCriteria(theCriteria)
1731 group = self.MakeGroupByFilter(groupName, aFilter)
1732 aFilterMgr.UnRegister()
1735 ## Creates a mesh group by the given filter
1736 # @param groupName the name of the mesh group
1737 # @param theFilter the instance of Filter class
1738 # @return SMESH_Group
1739 # @ingroup l2_grps_create
1740 def MakeGroupByFilter(self, groupName, theFilter):
1741 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1742 theFilter.SetMesh( self.mesh )
1743 group.AddFrom( theFilter )
1747 # @ingroup l2_grps_delete
1748 def RemoveGroup(self, group):
1749 self.mesh.RemoveGroup(group)
1751 ## Removes a group with its contents
1752 # @ingroup l2_grps_delete
1753 def RemoveGroupWithContents(self, group):
1754 self.mesh.RemoveGroupWithContents(group)
1756 ## Gets the list of groups existing in the mesh
1757 # @return a sequence of SMESH_GroupBase
1758 # @ingroup l2_grps_create
1759 def GetGroups(self):
1760 return self.mesh.GetGroups()
1762 ## Gets the number of groups existing in the mesh
1763 # @return the quantity of groups as an integer value
1764 # @ingroup l2_grps_create
1766 return self.mesh.NbGroups()
1768 ## Gets the list of names of groups existing in the mesh
1769 # @return list of strings
1770 # @ingroup l2_grps_create
1771 def GetGroupNames(self):
1772 groups = self.GetGroups()
1774 for group in groups:
1775 names.append(group.GetName())
1778 ## Produces a union of two groups
1779 # A new group is created. All mesh elements that are
1780 # present in the initial groups are added to the new one
1781 # @return an instance of SMESH_Group
1782 # @ingroup l2_grps_operon
1783 def UnionGroups(self, group1, group2, name):
1784 return self.mesh.UnionGroups(group1, group2, name)
1786 ## Produces a union list of groups
1787 # New group is created. All mesh elements that are present in
1788 # initial groups are added to the new one
1789 # @return an instance of SMESH_Group
1790 # @ingroup l2_grps_operon
1791 def UnionListOfGroups(self, groups, name):
1792 return self.mesh.UnionListOfGroups(groups, name)
1794 ## Prodices an intersection of two groups
1795 # A new group is created. All mesh elements that are common
1796 # for the two initial groups are added to the new one.
1797 # @return an instance of SMESH_Group
1798 # @ingroup l2_grps_operon
1799 def IntersectGroups(self, group1, group2, name):
1800 return self.mesh.IntersectGroups(group1, group2, name)
1802 ## Produces an intersection of groups
1803 # New group is created. All mesh elements that are present in all
1804 # initial groups simultaneously are added to the new one
1805 # @return an instance of SMESH_Group
1806 # @ingroup l2_grps_operon
1807 def IntersectListOfGroups(self, groups, name):
1808 return self.mesh.IntersectListOfGroups(groups, name)
1810 ## Produces a cut of two groups
1811 # A new group is created. All mesh elements that are present in
1812 # the main group but are not present in the tool group are added to the new one
1813 # @return an instance of SMESH_Group
1814 # @ingroup l2_grps_operon
1815 def CutGroups(self, main_group, tool_group, name):
1816 return self.mesh.CutGroups(main_group, tool_group, name)
1818 ## Produces a cut of groups
1819 # A new group is created. All mesh elements that are present in main groups
1820 # but do not present in tool groups are added to the new one
1821 # @return an instance of SMESH_Group
1822 # @ingroup l2_grps_operon
1823 def CutListOfGroups(self, main_groups, tool_groups, name):
1824 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1826 ## Produces a group of elements of specified type using list of existing groups
1827 # A new group is created. System
1828 # 1) extracts all nodes on which groups elements are built
1829 # 2) combines all elements of specified dimension laying on these nodes
1830 # @return an instance of SMESH_Group
1831 # @ingroup l2_grps_operon
1832 def CreateDimGroup(self, groups, elem_type, name):
1833 return self.mesh.CreateDimGroup(groups, elem_type, name)
1836 ## Convert group on geom into standalone group
1837 # @ingroup l2_grps_delete
1838 def ConvertToStandalone(self, group):
1839 return self.mesh.ConvertToStandalone(group)
1841 # Get some info about mesh:
1842 # ------------------------
1844 ## Returns the log of nodes and elements added or removed
1845 # since the previous clear of the log.
1846 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1847 # @return list of log_block structures:
1852 # @ingroup l1_auxiliary
1853 def GetLog(self, clearAfterGet):
1854 return self.mesh.GetLog(clearAfterGet)
1856 ## Clears the log of nodes and elements added or removed since the previous
1857 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1858 # @ingroup l1_auxiliary
1860 self.mesh.ClearLog()
1862 ## Toggles auto color mode on the object.
1863 # @param theAutoColor the flag which toggles auto color mode.
1864 # @ingroup l1_auxiliary
1865 def SetAutoColor(self, theAutoColor):
1866 self.mesh.SetAutoColor(theAutoColor)
1868 ## Gets flag of object auto color mode.
1869 # @return True or False
1870 # @ingroup l1_auxiliary
1871 def GetAutoColor(self):
1872 return self.mesh.GetAutoColor()
1874 ## Gets the internal ID
1875 # @return integer value, which is the internal Id of the mesh
1876 # @ingroup l1_auxiliary
1878 return self.mesh.GetId()
1881 # @return integer value, which is the study Id of the mesh
1882 # @ingroup l1_auxiliary
1883 def GetStudyId(self):
1884 return self.mesh.GetStudyId()
1886 ## Checks the group names for duplications.
1887 # Consider the maximum group name length stored in MED file.
1888 # @return True or False
1889 # @ingroup l1_auxiliary
1890 def HasDuplicatedGroupNamesMED(self):
1891 return self.mesh.HasDuplicatedGroupNamesMED()
1893 ## Obtains the mesh editor tool
1894 # @return an instance of SMESH_MeshEditor
1895 # @ingroup l1_modifying
1896 def GetMeshEditor(self):
1899 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1900 # can be passed as argument to a method accepting mesh, group or sub-mesh
1901 # @return an instance of SMESH_IDSource
1902 # @ingroup l1_auxiliary
1903 def GetIDSource(self, ids, elemType):
1904 return self.editor.MakeIDSource(ids, elemType)
1907 # @return an instance of SALOME_MED::MESH
1908 # @ingroup l1_auxiliary
1909 def GetMEDMesh(self):
1910 return self.mesh.GetMEDMesh()
1913 # Get informations about mesh contents:
1914 # ------------------------------------
1916 ## Gets the mesh stattistic
1917 # @return dictionary type element - count of elements
1918 # @ingroup l1_meshinfo
1919 def GetMeshInfo(self, obj = None):
1920 if not obj: obj = self.mesh
1921 return self.smeshpyD.GetMeshInfo(obj)
1923 ## Returns the number of nodes in the mesh
1924 # @return an integer value
1925 # @ingroup l1_meshinfo
1927 return self.mesh.NbNodes()
1929 ## Returns the number of elements in the mesh
1930 # @return an integer value
1931 # @ingroup l1_meshinfo
1932 def NbElements(self):
1933 return self.mesh.NbElements()
1935 ## Returns the number of 0d elements in the mesh
1936 # @return an integer value
1937 # @ingroup l1_meshinfo
1938 def Nb0DElements(self):
1939 return self.mesh.Nb0DElements()
1941 ## Returns the number of ball discrete elements in the mesh
1942 # @return an integer value
1943 # @ingroup l1_meshinfo
1945 return self.mesh.NbBalls()
1947 ## Returns the number of edges in the mesh
1948 # @return an integer value
1949 # @ingroup l1_meshinfo
1951 return self.mesh.NbEdges()
1953 ## Returns the number of edges with the given order in the mesh
1954 # @param elementOrder the order of elements:
1955 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1956 # @return an integer value
1957 # @ingroup l1_meshinfo
1958 def NbEdgesOfOrder(self, elementOrder):
1959 return self.mesh.NbEdgesOfOrder(elementOrder)
1961 ## Returns the number of faces in the mesh
1962 # @return an integer value
1963 # @ingroup l1_meshinfo
1965 return self.mesh.NbFaces()
1967 ## Returns the number of faces with the given order in the mesh
1968 # @param elementOrder the order of elements:
1969 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1970 # @return an integer value
1971 # @ingroup l1_meshinfo
1972 def NbFacesOfOrder(self, elementOrder):
1973 return self.mesh.NbFacesOfOrder(elementOrder)
1975 ## Returns the number of triangles in the mesh
1976 # @return an integer value
1977 # @ingroup l1_meshinfo
1978 def NbTriangles(self):
1979 return self.mesh.NbTriangles()
1981 ## Returns the number of triangles with the given order in the mesh
1982 # @param elementOrder is the order of elements:
1983 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1984 # @return an integer value
1985 # @ingroup l1_meshinfo
1986 def NbTrianglesOfOrder(self, elementOrder):
1987 return self.mesh.NbTrianglesOfOrder(elementOrder)
1989 ## Returns the number of quadrangles in the mesh
1990 # @return an integer value
1991 # @ingroup l1_meshinfo
1992 def NbQuadrangles(self):
1993 return self.mesh.NbQuadrangles()
1995 ## Returns the number of quadrangles with the given order in the mesh
1996 # @param elementOrder the order of elements:
1997 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1998 # @return an integer value
1999 # @ingroup l1_meshinfo
2000 def NbQuadranglesOfOrder(self, elementOrder):
2001 return self.mesh.NbQuadranglesOfOrder(elementOrder)
2003 ## Returns the number of biquadratic quadrangles in the mesh
2004 # @return an integer value
2005 # @ingroup l1_meshinfo
2006 def NbBiQuadQuadrangles(self):
2007 return self.mesh.NbBiQuadQuadrangles()
2009 ## Returns the number of polygons in the mesh
2010 # @return an integer value
2011 # @ingroup l1_meshinfo
2012 def NbPolygons(self):
2013 return self.mesh.NbPolygons()
2015 ## Returns the number of volumes in the mesh
2016 # @return an integer value
2017 # @ingroup l1_meshinfo
2018 def NbVolumes(self):
2019 return self.mesh.NbVolumes()
2021 ## Returns the number of volumes with the given order in the mesh
2022 # @param elementOrder the order of elements:
2023 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2024 # @return an integer value
2025 # @ingroup l1_meshinfo
2026 def NbVolumesOfOrder(self, elementOrder):
2027 return self.mesh.NbVolumesOfOrder(elementOrder)
2029 ## Returns the number of tetrahedrons in the mesh
2030 # @return an integer value
2031 # @ingroup l1_meshinfo
2033 return self.mesh.NbTetras()
2035 ## Returns the number of tetrahedrons with the given order in the mesh
2036 # @param elementOrder the order of elements:
2037 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2038 # @return an integer value
2039 # @ingroup l1_meshinfo
2040 def NbTetrasOfOrder(self, elementOrder):
2041 return self.mesh.NbTetrasOfOrder(elementOrder)
2043 ## Returns the number of hexahedrons in the mesh
2044 # @return an integer value
2045 # @ingroup l1_meshinfo
2047 return self.mesh.NbHexas()
2049 ## Returns the number of hexahedrons with the given order in the mesh
2050 # @param elementOrder the order of elements:
2051 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2052 # @return an integer value
2053 # @ingroup l1_meshinfo
2054 def NbHexasOfOrder(self, elementOrder):
2055 return self.mesh.NbHexasOfOrder(elementOrder)
2057 ## Returns the number of triquadratic hexahedrons in the mesh
2058 # @return an integer value
2059 # @ingroup l1_meshinfo
2060 def NbTriQuadraticHexas(self):
2061 return self.mesh.NbTriQuadraticHexas()
2063 ## Returns the number of pyramids in the mesh
2064 # @return an integer value
2065 # @ingroup l1_meshinfo
2066 def NbPyramids(self):
2067 return self.mesh.NbPyramids()
2069 ## Returns the number of pyramids with the given order in the mesh
2070 # @param elementOrder the order of elements:
2071 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2072 # @return an integer value
2073 # @ingroup l1_meshinfo
2074 def NbPyramidsOfOrder(self, elementOrder):
2075 return self.mesh.NbPyramidsOfOrder(elementOrder)
2077 ## Returns the number of prisms in the mesh
2078 # @return an integer value
2079 # @ingroup l1_meshinfo
2081 return self.mesh.NbPrisms()
2083 ## Returns the number of prisms with the given order in the mesh
2084 # @param elementOrder the order of elements:
2085 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2086 # @return an integer value
2087 # @ingroup l1_meshinfo
2088 def NbPrismsOfOrder(self, elementOrder):
2089 return self.mesh.NbPrismsOfOrder(elementOrder)
2091 ## Returns the number of hexagonal prisms in the mesh
2092 # @return an integer value
2093 # @ingroup l1_meshinfo
2094 def NbHexagonalPrisms(self):
2095 return self.mesh.NbHexagonalPrisms()
2097 ## Returns the number of polyhedrons in the mesh
2098 # @return an integer value
2099 # @ingroup l1_meshinfo
2100 def NbPolyhedrons(self):
2101 return self.mesh.NbPolyhedrons()
2103 ## Returns the number of submeshes in the mesh
2104 # @return an integer value
2105 # @ingroup l1_meshinfo
2106 def NbSubMesh(self):
2107 return self.mesh.NbSubMesh()
2109 ## Returns the list of mesh elements IDs
2110 # @return the list of integer values
2111 # @ingroup l1_meshinfo
2112 def GetElementsId(self):
2113 return self.mesh.GetElementsId()
2115 ## Returns the list of IDs of mesh elements with the given type
2116 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2117 # @return list of integer values
2118 # @ingroup l1_meshinfo
2119 def GetElementsByType(self, elementType):
2120 return self.mesh.GetElementsByType(elementType)
2122 ## Returns the list of mesh nodes IDs
2123 # @return the list of integer values
2124 # @ingroup l1_meshinfo
2125 def GetNodesId(self):
2126 return self.mesh.GetNodesId()
2128 # Get the information about mesh elements:
2129 # ------------------------------------
2131 ## Returns the type of mesh element
2132 # @return the value from SMESH::ElementType enumeration
2133 # @ingroup l1_meshinfo
2134 def GetElementType(self, id, iselem):
2135 return self.mesh.GetElementType(id, iselem)
2137 ## Returns the geometric type of mesh element
2138 # @return the value from SMESH::EntityType enumeration
2139 # @ingroup l1_meshinfo
2140 def GetElementGeomType(self, id):
2141 return self.mesh.GetElementGeomType(id)
2143 ## Returns the list of submesh elements IDs
2144 # @param Shape a geom object(sub-shape) IOR
2145 # Shape must be the sub-shape of a ShapeToMesh()
2146 # @return the list of integer values
2147 # @ingroup l1_meshinfo
2148 def GetSubMeshElementsId(self, Shape):
2149 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2150 ShapeID = Shape.GetSubShapeIndices()[0]
2153 return self.mesh.GetSubMeshElementsId(ShapeID)
2155 ## Returns the list of submesh nodes IDs
2156 # @param Shape a geom object(sub-shape) IOR
2157 # Shape must be the sub-shape of a ShapeToMesh()
2158 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2159 # @return the list of integer values
2160 # @ingroup l1_meshinfo
2161 def GetSubMeshNodesId(self, Shape, all):
2162 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2163 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2166 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2168 ## Returns type of elements on given shape
2169 # @param Shape a geom object(sub-shape) IOR
2170 # Shape must be a sub-shape of a ShapeToMesh()
2171 # @return element type
2172 # @ingroup l1_meshinfo
2173 def GetSubMeshElementType(self, Shape):
2174 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2175 ShapeID = Shape.GetSubShapeIndices()[0]
2178 return self.mesh.GetSubMeshElementType(ShapeID)
2180 ## Gets the mesh description
2181 # @return string value
2182 # @ingroup l1_meshinfo
2184 return self.mesh.Dump()
2187 # Get the information about nodes and elements of a mesh by its IDs:
2188 # -----------------------------------------------------------
2190 ## Gets XYZ coordinates of a node
2191 # \n If there is no nodes for the given ID - returns an empty list
2192 # @return a list of double precision values
2193 # @ingroup l1_meshinfo
2194 def GetNodeXYZ(self, id):
2195 return self.mesh.GetNodeXYZ(id)
2197 ## Returns list of IDs of inverse elements for the given node
2198 # \n If there is no node for the given ID - returns an empty list
2199 # @return a list of integer values
2200 # @ingroup l1_meshinfo
2201 def GetNodeInverseElements(self, id):
2202 return self.mesh.GetNodeInverseElements(id)
2204 ## @brief Returns the position of a node on the shape
2205 # @return SMESH::NodePosition
2206 # @ingroup l1_meshinfo
2207 def GetNodePosition(self,NodeID):
2208 return self.mesh.GetNodePosition(NodeID)
2210 ## @brief Returns the position of an element on the shape
2211 # @return SMESH::ElementPosition
2212 # @ingroup l1_meshinfo
2213 def GetElementPosition(self,ElemID):
2214 return self.mesh.GetElementPosition(ElemID)
2216 ## If the given element is a node, returns the ID of shape
2217 # \n If there is no node for the given ID - returns -1
2218 # @return an integer value
2219 # @ingroup l1_meshinfo
2220 def GetShapeID(self, id):
2221 return self.mesh.GetShapeID(id)
2223 ## Returns the ID of the result shape after
2224 # FindShape() from SMESH_MeshEditor for the given element
2225 # \n If there is no element for the given ID - returns -1
2226 # @return an integer value
2227 # @ingroup l1_meshinfo
2228 def GetShapeIDForElem(self,id):
2229 return self.mesh.GetShapeIDForElem(id)
2231 ## Returns the number of nodes for the given element
2232 # \n If there is no element for the given ID - returns -1
2233 # @return an integer value
2234 # @ingroup l1_meshinfo
2235 def GetElemNbNodes(self, id):
2236 return self.mesh.GetElemNbNodes(id)
2238 ## Returns the node ID the given (zero based) index for the given element
2239 # \n If there is no element for the given ID - returns -1
2240 # \n If there is no node for the given index - returns -2
2241 # @return an integer value
2242 # @ingroup l1_meshinfo
2243 def GetElemNode(self, id, index):
2244 return self.mesh.GetElemNode(id, index)
2246 ## Returns the IDs of nodes of the given element
2247 # @return a list of integer values
2248 # @ingroup l1_meshinfo
2249 def GetElemNodes(self, id):
2250 return self.mesh.GetElemNodes(id)
2252 ## Returns true if the given node is the medium node in the given quadratic element
2253 # @ingroup l1_meshinfo
2254 def IsMediumNode(self, elementID, nodeID):
2255 return self.mesh.IsMediumNode(elementID, nodeID)
2257 ## Returns true if the given node is the medium node in one of quadratic elements
2258 # @ingroup l1_meshinfo
2259 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2260 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2262 ## Returns the number of edges for the given element
2263 # @ingroup l1_meshinfo
2264 def ElemNbEdges(self, id):
2265 return self.mesh.ElemNbEdges(id)
2267 ## Returns the number of faces for the given element
2268 # @ingroup l1_meshinfo
2269 def ElemNbFaces(self, id):
2270 return self.mesh.ElemNbFaces(id)
2272 ## Returns nodes of given face (counted from zero) for given volumic element.
2273 # @ingroup l1_meshinfo
2274 def GetElemFaceNodes(self,elemId, faceIndex):
2275 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2277 ## Returns an element based on all given nodes.
2278 # @ingroup l1_meshinfo
2279 def FindElementByNodes(self,nodes):
2280 return self.mesh.FindElementByNodes(nodes)
2282 ## Returns true if the given element is a polygon
2283 # @ingroup l1_meshinfo
2284 def IsPoly(self, id):
2285 return self.mesh.IsPoly(id)
2287 ## Returns true if the given element is quadratic
2288 # @ingroup l1_meshinfo
2289 def IsQuadratic(self, id):
2290 return self.mesh.IsQuadratic(id)
2292 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2293 # @ingroup l1_meshinfo
2294 def GetBallDiameter(self, id):
2295 return self.mesh.GetBallDiameter(id)
2297 ## Returns XYZ coordinates of the barycenter of the given element
2298 # \n If there is no element for the given ID - returns an empty list
2299 # @return a list of three double values
2300 # @ingroup l1_meshinfo
2301 def BaryCenter(self, id):
2302 return self.mesh.BaryCenter(id)
2304 ## Passes mesh elements through the given filter and return IDs of fitting elements
2305 # @param theFilter SMESH_Filter
2306 # @return a list of ids
2307 # @ingroup l1_controls
2308 def GetIdsFromFilter(self, theFilter):
2309 theFilter.SetMesh( self.mesh )
2310 return theFilter.GetIDs()
2312 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2313 # Returns a list of special structures (borders).
2314 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2315 # @ingroup l1_controls
2316 def GetFreeBorders(self):
2317 aFilterMgr = self.smeshpyD.CreateFilterManager()
2318 aPredicate = aFilterMgr.CreateFreeEdges()
2319 aPredicate.SetMesh(self.mesh)
2320 aBorders = aPredicate.GetBorders()
2321 aFilterMgr.UnRegister()
2325 # Get mesh measurements information:
2326 # ------------------------------------
2328 ## Get minimum distance between two nodes, elements or distance to the origin
2329 # @param id1 first node/element id
2330 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2331 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2332 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2333 # @return minimum distance value
2334 # @sa GetMinDistance()
2335 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2336 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2337 return aMeasure.value
2339 ## Get measure structure specifying minimum distance data between two objects
2340 # @param id1 first node/element id
2341 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2342 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2343 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2344 # @return Measure structure
2346 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2348 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2350 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2353 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2355 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2360 aMeasurements = self.smeshpyD.CreateMeasurements()
2361 aMeasure = aMeasurements.MinDistance(id1, id2)
2362 aMeasurements.UnRegister()
2365 ## Get bounding box of the specified object(s)
2366 # @param objects single source object or list of source objects or list of nodes/elements IDs
2367 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2368 # @c False specifies that @a objects are nodes
2369 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2370 # @sa GetBoundingBox()
2371 def BoundingBox(self, objects=None, isElem=False):
2372 result = self.GetBoundingBox(objects, isElem)
2376 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2379 ## Get measure structure specifying bounding box data of the specified object(s)
2380 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2381 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2382 # @c False specifies that @a objects are nodes
2383 # @return Measure structure
2385 def GetBoundingBox(self, IDs=None, isElem=False):
2388 elif isinstance(IDs, tuple):
2390 if not isinstance(IDs, list):
2392 if len(IDs) > 0 and isinstance(IDs[0], int):
2396 if isinstance(o, Mesh):
2397 srclist.append(o.mesh)
2398 elif hasattr(o, "_narrow"):
2399 src = o._narrow(SMESH.SMESH_IDSource)
2400 if src: srclist.append(src)
2402 elif isinstance(o, list):
2404 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2406 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2409 aMeasurements = self.smeshpyD.CreateMeasurements()
2410 aMeasure = aMeasurements.BoundingBox(srclist)
2411 aMeasurements.UnRegister()
2414 # Mesh edition (SMESH_MeshEditor functionality):
2415 # ---------------------------------------------
2417 ## Removes the elements from the mesh by ids
2418 # @param IDsOfElements is a list of ids of elements to remove
2419 # @return True or False
2420 # @ingroup l2_modif_del
2421 def RemoveElements(self, IDsOfElements):
2422 return self.editor.RemoveElements(IDsOfElements)
2424 ## Removes nodes from mesh by ids
2425 # @param IDsOfNodes is a list of ids of nodes to remove
2426 # @return True or False
2427 # @ingroup l2_modif_del
2428 def RemoveNodes(self, IDsOfNodes):
2429 return self.editor.RemoveNodes(IDsOfNodes)
2431 ## Removes all orphan (free) nodes from mesh
2432 # @return number of the removed nodes
2433 # @ingroup l2_modif_del
2434 def RemoveOrphanNodes(self):
2435 return self.editor.RemoveOrphanNodes()
2437 ## Add a node to the mesh by coordinates
2438 # @return Id of the new node
2439 # @ingroup l2_modif_add
2440 def AddNode(self, x, y, z):
2441 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2442 if hasVars: self.mesh.SetParameters(Parameters)
2443 return self.editor.AddNode( x, y, z)
2445 ## Creates a 0D element on a node with given number.
2446 # @param IDOfNode the ID of node for creation of the element.
2447 # @return the Id of the new 0D element
2448 # @ingroup l2_modif_add
2449 def Add0DElement(self, IDOfNode):
2450 return self.editor.Add0DElement(IDOfNode)
2452 ## Create 0D elements on all nodes of the given elements except those
2453 # nodes on which a 0D element already exists.
2454 # @param theObject an object on whose nodes 0D elements will be created.
2455 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2456 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2457 # @param theGroupName optional name of a group to add 0D elements created
2458 # and/or found on nodes of \a theObject.
2459 # @return an object (a new group or a temporary SMESH_IDSource) holding
2460 # IDs of new and/or found 0D elements. IDs of 0D elements
2461 # can be retrieved from the returned object by calling GetIDs()
2462 # @ingroup l2_modif_add
2463 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2464 if isinstance( theObject, Mesh ):
2465 theObject = theObject.GetMesh()
2466 if isinstance( theObject, list ):
2467 theObject = self.GetIDSource( theObject, SMESH.ALL )
2468 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2470 ## Creates a ball element on a node with given ID.
2471 # @param IDOfNode the ID of node for creation of the element.
2472 # @param diameter the bal diameter.
2473 # @return the Id of the new ball element
2474 # @ingroup l2_modif_add
2475 def AddBall(self, IDOfNode, diameter):
2476 return self.editor.AddBall( IDOfNode, diameter )
2478 ## Creates a linear or quadratic edge (this is determined
2479 # by the number of given nodes).
2480 # @param IDsOfNodes the list of node IDs for creation of the element.
2481 # The order of nodes in this list should correspond to the description
2482 # of MED. \n This description is located by the following link:
2483 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2484 # @return the Id of the new edge
2485 # @ingroup l2_modif_add
2486 def AddEdge(self, IDsOfNodes):
2487 return self.editor.AddEdge(IDsOfNodes)
2489 ## Creates a linear or quadratic face (this is determined
2490 # by the number of given nodes).
2491 # @param IDsOfNodes the list of node IDs for creation of the element.
2492 # The order of nodes in this list should correspond to the description
2493 # of MED. \n This description is located by the following link:
2494 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2495 # @return the Id of the new face
2496 # @ingroup l2_modif_add
2497 def AddFace(self, IDsOfNodes):
2498 return self.editor.AddFace(IDsOfNodes)
2500 ## Adds a polygonal face to the mesh by the list of node IDs
2501 # @param IdsOfNodes the list of node IDs for creation of the element.
2502 # @return the Id of the new face
2503 # @ingroup l2_modif_add
2504 def AddPolygonalFace(self, IdsOfNodes):
2505 return self.editor.AddPolygonalFace(IdsOfNodes)
2507 ## Creates both simple and quadratic volume (this is determined
2508 # by the number of given nodes).
2509 # @param IDsOfNodes the list of node IDs for creation of the element.
2510 # The order of nodes in this list should correspond to the description
2511 # of MED. \n This description is located by the following link:
2512 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2513 # @return the Id of the new volumic element
2514 # @ingroup l2_modif_add
2515 def AddVolume(self, IDsOfNodes):
2516 return self.editor.AddVolume(IDsOfNodes)
2518 ## Creates a volume of many faces, giving nodes for each face.
2519 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2520 # @param Quantities the list of integer values, Quantities[i]
2521 # gives the quantity of nodes in face number i.
2522 # @return the Id of the new volumic element
2523 # @ingroup l2_modif_add
2524 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2525 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2527 ## Creates a volume of many faces, giving the IDs of the existing faces.
2528 # @param IdsOfFaces the list of face IDs for volume creation.
2530 # Note: The created volume will refer only to the nodes
2531 # of the given faces, not to the faces themselves.
2532 # @return the Id of the new volumic element
2533 # @ingroup l2_modif_add
2534 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2535 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2538 ## @brief Binds a node to a vertex
2539 # @param NodeID a node ID
2540 # @param Vertex a vertex or vertex ID
2541 # @return True if succeed else raises an exception
2542 # @ingroup l2_modif_add
2543 def SetNodeOnVertex(self, NodeID, Vertex):
2544 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2545 VertexID = Vertex.GetSubShapeIndices()[0]
2549 self.editor.SetNodeOnVertex(NodeID, VertexID)
2550 except SALOME.SALOME_Exception, inst:
2551 raise ValueError, inst.details.text
2555 ## @brief Stores the node position on an edge
2556 # @param NodeID a node ID
2557 # @param Edge an edge or edge ID
2558 # @param paramOnEdge a parameter on the edge where the node is located
2559 # @return True if succeed else raises an exception
2560 # @ingroup l2_modif_add
2561 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2562 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2563 EdgeID = Edge.GetSubShapeIndices()[0]
2567 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2568 except SALOME.SALOME_Exception, inst:
2569 raise ValueError, inst.details.text
2572 ## @brief Stores node position on a face
2573 # @param NodeID a node ID
2574 # @param Face a face or face ID
2575 # @param u U parameter on the face where the node is located
2576 # @param v V parameter on the face where the node is located
2577 # @return True if succeed else raises an exception
2578 # @ingroup l2_modif_add
2579 def SetNodeOnFace(self, NodeID, Face, u, v):
2580 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2581 FaceID = Face.GetSubShapeIndices()[0]
2585 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2586 except SALOME.SALOME_Exception, inst:
2587 raise ValueError, inst.details.text
2590 ## @brief Binds a node to a solid
2591 # @param NodeID a node ID
2592 # @param Solid a solid or solid ID
2593 # @return True if succeed else raises an exception
2594 # @ingroup l2_modif_add
2595 def SetNodeInVolume(self, NodeID, Solid):
2596 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2597 SolidID = Solid.GetSubShapeIndices()[0]
2601 self.editor.SetNodeInVolume(NodeID, SolidID)
2602 except SALOME.SALOME_Exception, inst:
2603 raise ValueError, inst.details.text
2606 ## @brief Bind an element to a shape
2607 # @param ElementID an element ID
2608 # @param Shape a shape or shape ID
2609 # @return True if succeed else raises an exception
2610 # @ingroup l2_modif_add
2611 def SetMeshElementOnShape(self, ElementID, Shape):
2612 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2613 ShapeID = Shape.GetSubShapeIndices()[0]
2617 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2618 except SALOME.SALOME_Exception, inst:
2619 raise ValueError, inst.details.text
2623 ## Moves the node with the given id
2624 # @param NodeID the id of the node
2625 # @param x a new X coordinate
2626 # @param y a new Y coordinate
2627 # @param z a new Z coordinate
2628 # @return True if succeed else False
2629 # @ingroup l2_modif_movenode
2630 def MoveNode(self, NodeID, x, y, z):
2631 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2632 if hasVars: self.mesh.SetParameters(Parameters)
2633 return self.editor.MoveNode(NodeID, x, y, z)
2635 ## Finds the node closest to a point and moves it to a point location
2636 # @param x the X coordinate of a point
2637 # @param y the Y coordinate of a point
2638 # @param z the Z coordinate of a point
2639 # @param NodeID if specified (>0), the node with this ID is moved,
2640 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2641 # @return the ID of a node
2642 # @ingroup l2_modif_throughp
2643 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2644 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2645 if hasVars: self.mesh.SetParameters(Parameters)
2646 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2648 ## Finds the node closest to a point
2649 # @param x the X coordinate of a point
2650 # @param y the Y coordinate of a point
2651 # @param z the Z coordinate of a point
2652 # @return the ID of a node
2653 # @ingroup l2_modif_throughp
2654 def FindNodeClosestTo(self, x, y, z):
2655 #preview = self.mesh.GetMeshEditPreviewer()
2656 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2657 return self.editor.FindNodeClosestTo(x, y, z)
2659 ## Finds the elements where a point lays IN or ON
2660 # @param x the X coordinate of a point
2661 # @param y the Y coordinate of a point
2662 # @param z the Z coordinate of a point
2663 # @param elementType type of elements to find (SMESH.ALL type
2664 # means elements of any type excluding nodes, discrete and 0D elements)
2665 # @param meshPart a part of mesh (group, sub-mesh) to search within
2666 # @return list of IDs of found elements
2667 # @ingroup l2_modif_throughp
2668 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2670 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2672 return self.editor.FindElementsByPoint(x, y, z, elementType)
2674 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2675 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2676 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2678 def GetPointState(self, x, y, z):
2679 return self.editor.GetPointState(x, y, z)
2681 ## Finds the node closest to a point and moves it to a point location
2682 # @param x the X coordinate of a point
2683 # @param y the Y coordinate of a point
2684 # @param z the Z coordinate of a point
2685 # @return the ID of a moved node
2686 # @ingroup l2_modif_throughp
2687 def MeshToPassThroughAPoint(self, x, y, z):
2688 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2690 ## Replaces two neighbour triangles sharing Node1-Node2 link
2691 # with the triangles built on the same 4 nodes but having other common link.
2692 # @param NodeID1 the ID of the first node
2693 # @param NodeID2 the ID of the second node
2694 # @return false if proper faces were not found
2695 # @ingroup l2_modif_invdiag
2696 def InverseDiag(self, NodeID1, NodeID2):
2697 return self.editor.InverseDiag(NodeID1, NodeID2)
2699 ## Replaces two neighbour triangles sharing Node1-Node2 link
2700 # with a quadrangle built on the same 4 nodes.
2701 # @param NodeID1 the ID of the first node
2702 # @param NodeID2 the ID of the second node
2703 # @return false if proper faces were not found
2704 # @ingroup l2_modif_unitetri
2705 def DeleteDiag(self, NodeID1, NodeID2):
2706 return self.editor.DeleteDiag(NodeID1, NodeID2)
2708 ## Reorients elements by ids
2709 # @param IDsOfElements if undefined reorients all mesh elements
2710 # @return True if succeed else False
2711 # @ingroup l2_modif_changori
2712 def Reorient(self, IDsOfElements=None):
2713 if IDsOfElements == None:
2714 IDsOfElements = self.GetElementsId()
2715 return self.editor.Reorient(IDsOfElements)
2717 ## Reorients all elements of the object
2718 # @param theObject mesh, submesh or group
2719 # @return True if succeed else False
2720 # @ingroup l2_modif_changori
2721 def ReorientObject(self, theObject):
2722 if ( isinstance( theObject, Mesh )):
2723 theObject = theObject.GetMesh()
2724 return self.editor.ReorientObject(theObject)
2726 ## Reorient faces contained in \a the2DObject.
2727 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2728 # @param theDirection is a desired direction of normal of \a theFace.
2729 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2730 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2731 # compared with theDirection. It can be either ID of face or a point
2732 # by which the face will be found. The point can be given as either
2733 # a GEOM vertex or a list of point coordinates.
2734 # @return number of reoriented faces
2735 # @ingroup l2_modif_changori
2736 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2738 if isinstance( the2DObject, Mesh ):
2739 the2DObject = the2DObject.GetMesh()
2740 if isinstance( the2DObject, list ):
2741 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2742 # check theDirection
2743 if isinstance( theDirection, geompyDC.GEOM._objref_GEOM_Object):
2744 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2745 if isinstance( theDirection, list ):
2746 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2747 # prepare theFace and thePoint
2748 theFace = theFaceOrPoint
2749 thePoint = PointStruct(0,0,0)
2750 if isinstance( theFaceOrPoint, geompyDC.GEOM._objref_GEOM_Object):
2751 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2753 if isinstance( theFaceOrPoint, list ):
2754 thePoint = PointStruct( *theFaceOrPoint )
2756 if isinstance( theFaceOrPoint, PointStruct ):
2757 thePoint = theFaceOrPoint
2759 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2761 ## Fuses the neighbouring triangles into quadrangles.
2762 # @param IDsOfElements The triangles to be fused,
2763 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2764 # choose a neighbour to fuse with.
2765 # @param MaxAngle is the maximum angle between element normals at which the fusion
2766 # is still performed; theMaxAngle is mesured in radians.
2767 # Also it could be a name of variable which defines angle in degrees.
2768 # @return TRUE in case of success, FALSE otherwise.
2769 # @ingroup l2_modif_unitetri
2770 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2771 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2772 self.mesh.SetParameters(Parameters)
2773 if not IDsOfElements:
2774 IDsOfElements = self.GetElementsId()
2775 Functor = self.smeshpyD.GetFunctor(theCriterion)
2776 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2778 ## Fuses the neighbouring triangles of the object into quadrangles
2779 # @param theObject is mesh, submesh or group
2780 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2781 # choose a neighbour to fuse with.
2782 # @param MaxAngle a max angle between element normals at which the fusion
2783 # is still performed; theMaxAngle is mesured in radians.
2784 # @return TRUE in case of success, FALSE otherwise.
2785 # @ingroup l2_modif_unitetri
2786 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2787 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2788 self.mesh.SetParameters(Parameters)
2789 if isinstance( theObject, Mesh ):
2790 theObject = theObject.GetMesh()
2791 Functor = self.smeshpyD.GetFunctor(theCriterion)
2792 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2794 ## Splits quadrangles into triangles.
2796 # @param IDsOfElements the faces to be splitted.
2797 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2798 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2799 # value, then quadrangles will be split by the smallest diagonal.
2800 # @return TRUE in case of success, FALSE otherwise.
2801 # @ingroup l2_modif_cutquadr
2802 def QuadToTri (self, IDsOfElements, theCriterion = None):
2803 if IDsOfElements == []:
2804 IDsOfElements = self.GetElementsId()
2805 if theCriterion is None:
2806 theCriterion = FT_MaxElementLength2D
2807 Functor = self.smeshpyD.GetFunctor(theCriterion)
2808 return self.editor.QuadToTri(IDsOfElements, Functor)
2810 ## Splits quadrangles into triangles.
2811 # @param theObject the object from which the list of elements is taken,
2812 # this is mesh, submesh or group
2813 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2814 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2815 # value, then quadrangles will be split by the smallest diagonal.
2816 # @return TRUE in case of success, FALSE otherwise.
2817 # @ingroup l2_modif_cutquadr
2818 def QuadToTriObject (self, theObject, theCriterion = None):
2819 if ( isinstance( theObject, Mesh )):
2820 theObject = theObject.GetMesh()
2821 if theCriterion is None:
2822 theCriterion = FT_MaxElementLength2D
2823 Functor = self.smeshpyD.GetFunctor(theCriterion)
2824 return self.editor.QuadToTriObject(theObject, Functor)
2826 ## Splits quadrangles into triangles.
2827 # @param IDsOfElements the faces to be splitted
2828 # @param Diag13 is used to choose a diagonal for splitting.
2829 # @return TRUE in case of success, FALSE otherwise.
2830 # @ingroup l2_modif_cutquadr
2831 def SplitQuad (self, IDsOfElements, Diag13):
2832 if IDsOfElements == []:
2833 IDsOfElements = self.GetElementsId()
2834 return self.editor.SplitQuad(IDsOfElements, Diag13)
2836 ## Splits quadrangles into triangles.
2837 # @param theObject the object from which the list of elements is taken,
2838 # this is mesh, submesh or group
2839 # @param Diag13 is used to choose a diagonal for splitting.
2840 # @return TRUE in case of success, FALSE otherwise.
2841 # @ingroup l2_modif_cutquadr
2842 def SplitQuadObject (self, theObject, Diag13):
2843 if ( isinstance( theObject, Mesh )):
2844 theObject = theObject.GetMesh()
2845 return self.editor.SplitQuadObject(theObject, Diag13)
2847 ## Finds a better splitting of the given quadrangle.
2848 # @param IDOfQuad the ID of the quadrangle to be splitted.
2849 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2850 # choose a diagonal for splitting.
2851 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2852 # diagonal is better, 0 if error occurs.
2853 # @ingroup l2_modif_cutquadr
2854 def BestSplit (self, IDOfQuad, theCriterion):
2855 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2857 ## Splits volumic elements into tetrahedrons
2858 # @param elemIDs either list of elements or mesh or group or submesh
2859 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2860 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2861 # @ingroup l2_modif_cutquadr
2862 def SplitVolumesIntoTetra(self, elemIDs, method=Hex_5Tet ):
2863 if isinstance( elemIDs, Mesh ):
2864 elemIDs = elemIDs.GetMesh()
2865 if ( isinstance( elemIDs, list )):
2866 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2867 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2869 ## Splits quadrangle faces near triangular facets of volumes
2871 # @ingroup l1_auxiliary
2872 def SplitQuadsNearTriangularFacets(self):
2873 faces_array = self.GetElementsByType(SMESH.FACE)
2874 for face_id in faces_array:
2875 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2876 quad_nodes = self.mesh.GetElemNodes(face_id)
2877 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2878 isVolumeFound = False
2879 for node1_elem in node1_elems:
2880 if not isVolumeFound:
2881 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2882 nb_nodes = self.GetElemNbNodes(node1_elem)
2883 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2884 volume_elem = node1_elem
2885 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2886 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2887 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2888 isVolumeFound = True
2889 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2890 self.SplitQuad([face_id], False) # diagonal 2-4
2891 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2892 isVolumeFound = True
2893 self.SplitQuad([face_id], True) # diagonal 1-3
2894 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2895 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2896 isVolumeFound = True
2897 self.SplitQuad([face_id], True) # diagonal 1-3
2899 ## @brief Splits hexahedrons into tetrahedrons.
2901 # This operation uses pattern mapping functionality for splitting.
2902 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2903 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2904 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2905 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2906 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2907 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2908 # @return TRUE in case of success, FALSE otherwise.
2909 # @ingroup l1_auxiliary
2910 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2911 # Pattern: 5.---------.6
2916 # (0,0,1) 4.---------.7 * |
2923 # (0,0,0) 0.---------.3
2924 pattern_tetra = "!!! Nb of points: \n 8 \n\
2934 !!! Indices of points of 6 tetras: \n\
2942 pattern = self.smeshpyD.GetPattern()
2943 isDone = pattern.LoadFromFile(pattern_tetra)
2945 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2948 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2949 isDone = pattern.MakeMesh(self.mesh, False, False)
2950 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2952 # split quafrangle faces near triangular facets of volumes
2953 self.SplitQuadsNearTriangularFacets()
2957 ## @brief Split hexahedrons into prisms.
2959 # Uses the pattern mapping functionality for splitting.
2960 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2961 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2962 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2963 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2964 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2965 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2966 # @return TRUE in case of success, FALSE otherwise.
2967 # @ingroup l1_auxiliary
2968 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2969 # Pattern: 5.---------.6
2974 # (0,0,1) 4.---------.7 |
2981 # (0,0,0) 0.---------.3
2982 pattern_prism = "!!! Nb of points: \n 8 \n\
2992 !!! Indices of points of 2 prisms: \n\
2996 pattern = self.smeshpyD.GetPattern()
2997 isDone = pattern.LoadFromFile(pattern_prism)
2999 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3002 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3003 isDone = pattern.MakeMesh(self.mesh, False, False)
3004 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3006 # Splits quafrangle faces near triangular facets of volumes
3007 self.SplitQuadsNearTriangularFacets()
3011 ## Smoothes elements
3012 # @param IDsOfElements the list if ids of elements to smooth
3013 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3014 # Note that nodes built on edges and boundary nodes are always fixed.
3015 # @param MaxNbOfIterations the maximum number of iterations
3016 # @param MaxAspectRatio varies in range [1.0, inf]
3017 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3018 # @return TRUE in case of success, FALSE otherwise.
3019 # @ingroup l2_modif_smooth
3020 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3021 MaxNbOfIterations, MaxAspectRatio, Method):
3022 if IDsOfElements == []:
3023 IDsOfElements = self.GetElementsId()
3024 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3025 self.mesh.SetParameters(Parameters)
3026 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3027 MaxNbOfIterations, MaxAspectRatio, Method)
3029 ## Smoothes elements which belong to the given object
3030 # @param theObject the object to smooth
3031 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3032 # Note that nodes built on edges and boundary nodes are always fixed.
3033 # @param MaxNbOfIterations the maximum number of iterations
3034 # @param MaxAspectRatio varies in range [1.0, inf]
3035 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3036 # @return TRUE in case of success, FALSE otherwise.
3037 # @ingroup l2_modif_smooth
3038 def SmoothObject(self, theObject, IDsOfFixedNodes,
3039 MaxNbOfIterations, MaxAspectRatio, Method):
3040 if ( isinstance( theObject, Mesh )):
3041 theObject = theObject.GetMesh()
3042 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3043 MaxNbOfIterations, MaxAspectRatio, Method)
3045 ## Parametrically smoothes the given elements
3046 # @param IDsOfElements the list if ids of elements to smooth
3047 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3048 # Note that nodes built on edges and boundary nodes are always fixed.
3049 # @param MaxNbOfIterations the maximum number of iterations
3050 # @param MaxAspectRatio varies in range [1.0, inf]
3051 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3052 # @return TRUE in case of success, FALSE otherwise.
3053 # @ingroup l2_modif_smooth
3054 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3055 MaxNbOfIterations, MaxAspectRatio, Method):
3056 if IDsOfElements == []:
3057 IDsOfElements = self.GetElementsId()
3058 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3059 self.mesh.SetParameters(Parameters)
3060 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3061 MaxNbOfIterations, MaxAspectRatio, Method)
3063 ## Parametrically smoothes the elements which belong to the given object
3064 # @param theObject the object to smooth
3065 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3066 # Note that nodes built on edges and boundary nodes are always fixed.
3067 # @param MaxNbOfIterations the maximum number of iterations
3068 # @param MaxAspectRatio varies in range [1.0, inf]
3069 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3070 # @return TRUE in case of success, FALSE otherwise.
3071 # @ingroup l2_modif_smooth
3072 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3073 MaxNbOfIterations, MaxAspectRatio, Method):
3074 if ( isinstance( theObject, Mesh )):
3075 theObject = theObject.GetMesh()
3076 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3077 MaxNbOfIterations, MaxAspectRatio, Method)
3079 ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3080 # them with quadratic with the same id.
3081 # @param theForce3d new node creation method:
3082 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3083 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3084 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3085 # @param theToBiQuad If True, converts the mesh to bi-quadratic
3086 # @ingroup l2_modif_tofromqu
3087 def ConvertToQuadratic(self, theForce3d, theSubMesh=None, theToBiQuad=False):
3089 self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3092 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3094 self.editor.ConvertToQuadratic(theForce3d)
3096 ## Converts the mesh from quadratic to ordinary,
3097 # deletes old quadratic elements, \n replacing
3098 # them with ordinary mesh elements with the same id.
3099 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3100 # @ingroup l2_modif_tofromqu
3101 def ConvertFromQuadratic(self, theSubMesh=None):
3103 self.editor.ConvertFromQuadraticObject(theSubMesh)
3105 return self.editor.ConvertFromQuadratic()
3107 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3108 # @return TRUE if operation has been completed successfully, FALSE otherwise
3109 # @ingroup l2_modif_edit
3110 def Make2DMeshFrom3D(self):
3111 return self.editor. Make2DMeshFrom3D()
3113 ## Creates missing boundary elements
3114 # @param elements - elements whose boundary is to be checked:
3115 # mesh, group, sub-mesh or list of elements
3116 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3117 # @param dimension - defines type of boundary elements to create:
3118 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3119 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3120 # @param groupName - a name of group to store created boundary elements in,
3121 # "" means not to create the group
3122 # @param meshName - a name of new mesh to store created boundary elements in,
3123 # "" means not to create the new mesh
3124 # @param toCopyElements - if true, the checked elements will be copied into
3125 # the new mesh else only boundary elements will be copied into the new mesh
3126 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3127 # boundary elements will be copied into the new mesh
3128 # @return tuple (mesh, group) where bondary elements were added to
3129 # @ingroup l2_modif_edit
3130 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3131 toCopyElements=False, toCopyExistingBondary=False):
3132 if isinstance( elements, Mesh ):
3133 elements = elements.GetMesh()
3134 if ( isinstance( elements, list )):
3135 elemType = SMESH.ALL
3136 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3137 elements = self.editor.MakeIDSource(elements, elemType)
3138 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3139 toCopyElements,toCopyExistingBondary)
3140 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3144 # @brief Creates missing boundary elements around either the whole mesh or
3145 # groups of 2D elements
3146 # @param dimension - defines type of boundary elements to create
3147 # @param groupName - a name of group to store all boundary elements in,
3148 # "" means not to create the group
3149 # @param meshName - a name of a new mesh, which is a copy of the initial
3150 # mesh + created boundary elements; "" means not to create the new mesh
3151 # @param toCopyAll - if true, the whole initial mesh will be copied into
3152 # the new mesh else only boundary elements will be copied into the new mesh
3153 # @param groups - groups of 2D elements to make boundary around
3154 # @retval tuple( long, mesh, groups )
3155 # long - number of added boundary elements
3156 # mesh - the mesh where elements were added to
3157 # group - the group of boundary elements or None
3159 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3160 toCopyAll=False, groups=[]):
3161 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3163 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3164 return nb, mesh, group
3166 ## Renumber mesh nodes
3167 # @ingroup l2_modif_renumber
3168 def RenumberNodes(self):
3169 self.editor.RenumberNodes()
3171 ## Renumber mesh elements
3172 # @ingroup l2_modif_renumber
3173 def RenumberElements(self):
3174 self.editor.RenumberElements()
3176 ## Generates new elements by rotation of the elements around the axis
3177 # @param IDsOfElements the list of ids of elements to sweep
3178 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3179 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3180 # @param NbOfSteps the number of steps
3181 # @param Tolerance tolerance
3182 # @param MakeGroups forces the generation of new groups from existing ones
3183 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3184 # of all steps, else - size of each step
3185 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3186 # @ingroup l2_modif_extrurev
3187 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3188 MakeGroups=False, TotalAngle=False):
3189 if IDsOfElements == []:
3190 IDsOfElements = self.GetElementsId()
3191 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3192 Axis = self.smeshpyD.GetAxisStruct(Axis)
3193 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3194 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3195 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3196 self.mesh.SetParameters(Parameters)
3197 if TotalAngle and NbOfSteps:
3198 AngleInRadians /= NbOfSteps
3200 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3201 AngleInRadians, NbOfSteps, Tolerance)
3202 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3205 ## Generates new elements by rotation of the elements of object around the axis
3206 # @param theObject object which elements should be sweeped.
3207 # It can be a mesh, a sub mesh or a group.
3208 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3209 # @param AngleInRadians the angle of Rotation
3210 # @param NbOfSteps number of steps
3211 # @param Tolerance tolerance
3212 # @param MakeGroups forces the generation of new groups from existing ones
3213 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3214 # of all steps, else - size of each step
3215 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3216 # @ingroup l2_modif_extrurev
3217 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3218 MakeGroups=False, TotalAngle=False):
3219 if ( isinstance( theObject, Mesh )):
3220 theObject = theObject.GetMesh()
3221 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3222 Axis = self.smeshpyD.GetAxisStruct(Axis)
3223 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3224 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3225 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3226 self.mesh.SetParameters(Parameters)
3227 if TotalAngle and NbOfSteps:
3228 AngleInRadians /= NbOfSteps
3230 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3231 NbOfSteps, Tolerance)
3232 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3235 ## Generates new elements by rotation of the elements of object around the axis
3236 # @param theObject object which elements should be sweeped.
3237 # It can be a mesh, a sub mesh or a group.
3238 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3239 # @param AngleInRadians the angle of Rotation
3240 # @param NbOfSteps number of steps
3241 # @param Tolerance tolerance
3242 # @param MakeGroups forces the generation of new groups from existing ones
3243 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3244 # of all steps, else - size of each step
3245 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3246 # @ingroup l2_modif_extrurev
3247 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3248 MakeGroups=False, TotalAngle=False):
3249 if ( isinstance( theObject, Mesh )):
3250 theObject = theObject.GetMesh()
3251 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3252 Axis = self.smeshpyD.GetAxisStruct(Axis)
3253 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3254 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3255 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3256 self.mesh.SetParameters(Parameters)
3257 if TotalAngle and NbOfSteps:
3258 AngleInRadians /= NbOfSteps
3260 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3261 NbOfSteps, Tolerance)
3262 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3265 ## Generates new elements by rotation of the elements of object around the axis
3266 # @param theObject object which elements should be sweeped.
3267 # It can be a mesh, a sub mesh or a group.
3268 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3269 # @param AngleInRadians the angle of Rotation
3270 # @param NbOfSteps number of steps
3271 # @param Tolerance tolerance
3272 # @param MakeGroups forces the generation of new groups from existing ones
3273 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3274 # of all steps, else - size of each step
3275 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3276 # @ingroup l2_modif_extrurev
3277 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3278 MakeGroups=False, TotalAngle=False):
3279 if ( isinstance( theObject, Mesh )):
3280 theObject = theObject.GetMesh()
3281 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3282 Axis = self.smeshpyD.GetAxisStruct(Axis)
3283 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3284 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3285 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3286 self.mesh.SetParameters(Parameters)
3287 if TotalAngle and NbOfSteps:
3288 AngleInRadians /= NbOfSteps
3290 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3291 NbOfSteps, Tolerance)
3292 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3295 ## Generates new elements by extrusion of the elements with given ids
3296 # @param IDsOfElements the list of elements ids for extrusion
3297 # @param StepVector vector or DirStruct or 3 vector components, defining
3298 # the direction and value of extrusion for one step (the total extrusion
3299 # length will be NbOfSteps * ||StepVector||)
3300 # @param NbOfSteps the number of steps
3301 # @param MakeGroups forces the generation of new groups from existing ones
3302 # @param IsNodes is True if elements with given ids are nodes
3303 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3304 # @ingroup l2_modif_extrurev
3305 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3306 if IDsOfElements == []:
3307 IDsOfElements = self.GetElementsId()
3308 if isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object):
3309 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3310 if isinstance( StepVector, list ):
3311 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3312 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3313 Parameters = StepVector.PS.parameters + var_separator + Parameters
3314 self.mesh.SetParameters(Parameters)
3317 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3319 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3321 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3323 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3326 ## Generates new elements by extrusion of the elements with given ids
3327 # @param IDsOfElements is ids of elements
3328 # @param StepVector vector or DirStruct or 3 vector components, defining
3329 # the direction and value of extrusion for one step (the total extrusion
3330 # length will be NbOfSteps * ||StepVector||)
3331 # @param NbOfSteps the number of steps
3332 # @param ExtrFlags sets flags for extrusion
3333 # @param SewTolerance uses for comparing locations of nodes if flag
3334 # EXTRUSION_FLAG_SEW is set
3335 # @param MakeGroups forces the generation of new groups from existing ones
3336 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3337 # @ingroup l2_modif_extrurev
3338 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3339 ExtrFlags, SewTolerance, MakeGroups=False):
3340 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3341 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3342 if isinstance( StepVector, list ):
3343 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3345 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3346 ExtrFlags, SewTolerance)
3347 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3348 ExtrFlags, SewTolerance)
3351 ## Generates new elements by extrusion of the elements which belong to the object
3352 # @param theObject the object which elements should be processed.
3353 # It can be a mesh, a sub mesh or a group.
3354 # @param StepVector vector or DirStruct or 3 vector components, defining
3355 # the direction and value of extrusion for one step (the total extrusion
3356 # length will be NbOfSteps * ||StepVector||)
3357 # @param NbOfSteps the number of steps
3358 # @param MakeGroups forces the generation of new groups from existing ones
3359 # @param IsNodes is True if elements which belong to the object are nodes
3360 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3361 # @ingroup l2_modif_extrurev
3362 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3363 if ( isinstance( theObject, Mesh )):
3364 theObject = theObject.GetMesh()
3365 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3366 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3367 if isinstance( StepVector, list ):
3368 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3369 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3370 Parameters = StepVector.PS.parameters + var_separator + Parameters
3371 self.mesh.SetParameters(Parameters)
3374 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3376 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3378 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3380 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3383 ## Generates new elements by extrusion of the elements which belong to the object
3384 # @param theObject 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 to generate new groups from existing ones
3391 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3392 # @ingroup l2_modif_extrurev
3393 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3394 if ( isinstance( theObject, Mesh )):
3395 theObject = theObject.GetMesh()
3396 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3397 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3398 if isinstance( StepVector, list ):
3399 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3400 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3401 Parameters = StepVector.PS.parameters + var_separator + Parameters
3402 self.mesh.SetParameters(Parameters)
3404 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3405 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3408 ## Generates new elements by extrusion of the elements which belong to the object
3409 # @param theObject object which elements should be processed.
3410 # It can be a mesh, a sub mesh or a group.
3411 # @param StepVector vector or DirStruct or 3 vector components, defining
3412 # the direction and value of extrusion for one step (the total extrusion
3413 # length will be NbOfSteps * ||StepVector||)
3414 # @param NbOfSteps the number of steps
3415 # @param MakeGroups forces the generation of new groups from existing ones
3416 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3417 # @ingroup l2_modif_extrurev
3418 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3419 if ( isinstance( theObject, Mesh )):
3420 theObject = theObject.GetMesh()
3421 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3422 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3423 if isinstance( StepVector, list ):
3424 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3425 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3426 Parameters = StepVector.PS.parameters + var_separator + Parameters
3427 self.mesh.SetParameters(Parameters)
3429 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3430 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3435 ## Generates new elements by extrusion of the given elements
3436 # The path of extrusion must be a meshed edge.
3437 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3438 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3439 # @param NodeStart the start node from Path. Defines the direction of extrusion
3440 # @param HasAngles allows the shape to be rotated around the path
3441 # to get the resulting mesh in a helical fashion
3442 # @param Angles list of angles in radians
3443 # @param LinearVariation forces the computation of rotation angles as linear
3444 # variation of the given Angles along path steps
3445 # @param HasRefPoint allows using the reference point
3446 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3447 # The User can specify any point as the Reference Point.
3448 # @param MakeGroups forces the generation of new groups from existing ones
3449 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3450 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3451 # only SMESH::Extrusion_Error otherwise
3452 # @ingroup l2_modif_extrurev
3453 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3454 HasAngles, Angles, LinearVariation,
3455 HasRefPoint, RefPoint, MakeGroups, ElemType):
3456 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3457 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3459 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3460 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3461 self.mesh.SetParameters(Parameters)
3463 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3465 if isinstance(Base, list):
3467 if Base == []: IDsOfElements = self.GetElementsId()
3468 else: IDsOfElements = Base
3469 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3470 HasAngles, Angles, LinearVariation,
3471 HasRefPoint, RefPoint, MakeGroups, ElemType)
3473 if isinstance(Base, Mesh): Base = Base.GetMesh()
3474 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3475 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3476 HasAngles, Angles, LinearVariation,
3477 HasRefPoint, RefPoint, MakeGroups, ElemType)
3479 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3482 ## Generates new elements by extrusion of the given elements
3483 # The path of extrusion must be a meshed edge.
3484 # @param IDsOfElements ids of elements
3485 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3486 # @param PathShape shape(edge) defines the sub-mesh for the path
3487 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3488 # @param HasAngles allows the shape to be rotated around the path
3489 # to get the resulting mesh in a helical fashion
3490 # @param Angles list of angles in radians
3491 # @param HasRefPoint allows using the reference point
3492 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3493 # The User can specify any point as the Reference Point.
3494 # @param MakeGroups forces the generation of new groups from existing ones
3495 # @param LinearVariation forces the computation of rotation angles as linear
3496 # variation of the given Angles along path steps
3497 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3498 # only SMESH::Extrusion_Error otherwise
3499 # @ingroup l2_modif_extrurev
3500 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3501 HasAngles, Angles, HasRefPoint, RefPoint,
3502 MakeGroups=False, LinearVariation=False):
3503 if IDsOfElements == []:
3504 IDsOfElements = self.GetElementsId()
3505 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3506 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3508 if ( isinstance( PathMesh, Mesh )):
3509 PathMesh = PathMesh.GetMesh()
3510 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3511 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3512 self.mesh.SetParameters(Parameters)
3513 if HasAngles and Angles and LinearVariation:
3514 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3517 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3518 PathShape, NodeStart, HasAngles,
3519 Angles, HasRefPoint, RefPoint)
3520 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3521 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3523 ## Generates new elements by extrusion of the elements which belong to the object
3524 # The path of extrusion must be a meshed edge.
3525 # @param theObject the object which elements should be processed.
3526 # It can be a mesh, a sub mesh or a group.
3527 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3528 # @param PathShape shape(edge) defines the sub-mesh for the path
3529 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3530 # @param HasAngles allows the shape to be rotated around the path
3531 # to get the resulting mesh in a helical fashion
3532 # @param Angles list of angles
3533 # @param HasRefPoint allows using the reference point
3534 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3535 # The User can specify any point as the Reference Point.
3536 # @param MakeGroups forces the generation of new groups from existing ones
3537 # @param LinearVariation forces the computation of rotation angles as linear
3538 # variation of the given Angles along path steps
3539 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3540 # only SMESH::Extrusion_Error otherwise
3541 # @ingroup l2_modif_extrurev
3542 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3543 HasAngles, Angles, HasRefPoint, RefPoint,
3544 MakeGroups=False, LinearVariation=False):
3545 if ( isinstance( theObject, Mesh )):
3546 theObject = theObject.GetMesh()
3547 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3548 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3549 if ( isinstance( PathMesh, Mesh )):
3550 PathMesh = PathMesh.GetMesh()
3551 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3552 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3553 self.mesh.SetParameters(Parameters)
3554 if HasAngles and Angles and LinearVariation:
3555 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3558 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3559 PathShape, NodeStart, HasAngles,
3560 Angles, HasRefPoint, RefPoint)
3561 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3562 NodeStart, HasAngles, Angles, HasRefPoint,
3565 ## Generates new elements by extrusion of the elements which belong to the object
3566 # The path of extrusion must be a meshed edge.
3567 # @param theObject the object which elements should be processed.
3568 # It can be a mesh, a sub mesh or a group.
3569 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3570 # @param PathShape shape(edge) defines the sub-mesh for the path
3571 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3572 # @param HasAngles allows the shape to be rotated around the path
3573 # to get the resulting mesh in a helical fashion
3574 # @param Angles list of angles
3575 # @param HasRefPoint allows using the reference point
3576 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3577 # The User can specify any point as the Reference Point.
3578 # @param MakeGroups forces the generation of new groups from existing ones
3579 # @param LinearVariation forces the computation of rotation angles as linear
3580 # variation of the given Angles along path steps
3581 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3582 # only SMESH::Extrusion_Error otherwise
3583 # @ingroup l2_modif_extrurev
3584 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3585 HasAngles, Angles, HasRefPoint, RefPoint,
3586 MakeGroups=False, LinearVariation=False):
3587 if ( isinstance( theObject, Mesh )):
3588 theObject = theObject.GetMesh()
3589 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3590 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3591 if ( isinstance( PathMesh, Mesh )):
3592 PathMesh = PathMesh.GetMesh()
3593 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3594 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3595 self.mesh.SetParameters(Parameters)
3596 if HasAngles and Angles and LinearVariation:
3597 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3600 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3601 PathShape, NodeStart, HasAngles,
3602 Angles, HasRefPoint, RefPoint)
3603 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3604 NodeStart, HasAngles, Angles, HasRefPoint,
3607 ## Generates new elements by extrusion of the elements which belong to the object
3608 # The path of extrusion must be a meshed edge.
3609 # @param theObject the object which elements should be processed.
3610 # It can be a mesh, a sub mesh or a group.
3611 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3612 # @param PathShape shape(edge) defines the sub-mesh for the path
3613 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3614 # @param HasAngles allows the shape to be rotated around the path
3615 # to get the resulting mesh in a helical fashion
3616 # @param Angles list of angles
3617 # @param HasRefPoint allows using the reference point
3618 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3619 # The User can specify any point as the Reference Point.
3620 # @param MakeGroups forces the generation of new groups from existing ones
3621 # @param LinearVariation forces the computation of rotation angles as linear
3622 # variation of the given Angles along path steps
3623 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3624 # only SMESH::Extrusion_Error otherwise
3625 # @ingroup l2_modif_extrurev
3626 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3627 HasAngles, Angles, HasRefPoint, RefPoint,
3628 MakeGroups=False, LinearVariation=False):
3629 if ( isinstance( theObject, Mesh )):
3630 theObject = theObject.GetMesh()
3631 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3632 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3633 if ( isinstance( PathMesh, Mesh )):
3634 PathMesh = PathMesh.GetMesh()
3635 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3636 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3637 self.mesh.SetParameters(Parameters)
3638 if HasAngles and Angles and LinearVariation:
3639 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3642 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3643 PathShape, NodeStart, HasAngles,
3644 Angles, HasRefPoint, RefPoint)
3645 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3646 NodeStart, HasAngles, Angles, HasRefPoint,
3649 ## Creates a symmetrical copy of mesh elements
3650 # @param IDsOfElements list of elements ids
3651 # @param Mirror is AxisStruct or geom object(point, line, plane)
3652 # @param theMirrorType is POINT, AXIS or PLANE
3653 # If the Mirror is a geom object this parameter is unnecessary
3654 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3655 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3656 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3657 # @ingroup l2_modif_trsf
3658 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3659 if IDsOfElements == []:
3660 IDsOfElements = self.GetElementsId()
3661 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3662 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3663 self.mesh.SetParameters(Mirror.parameters)
3664 if Copy and MakeGroups:
3665 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3666 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3669 ## Creates a new mesh by a symmetrical copy of mesh elements
3670 # @param IDsOfElements the list of elements ids
3671 # @param Mirror is AxisStruct or geom object (point, line, plane)
3672 # @param theMirrorType is POINT, AXIS or PLANE
3673 # If the Mirror is a geom object this parameter is unnecessary
3674 # @param MakeGroups to generate new groups from existing ones
3675 # @param NewMeshName a name of the new mesh to create
3676 # @return instance of Mesh class
3677 # @ingroup l2_modif_trsf
3678 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3679 if IDsOfElements == []:
3680 IDsOfElements = self.GetElementsId()
3681 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3682 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3683 self.mesh.SetParameters(Mirror.parameters)
3684 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3685 MakeGroups, NewMeshName)
3686 return Mesh(self.smeshpyD,self.geompyD,mesh)
3688 ## Creates a symmetrical copy of the object
3689 # @param theObject mesh, submesh or group
3690 # @param Mirror AxisStruct or geom object (point, line, plane)
3691 # @param theMirrorType is POINT, AXIS or PLANE
3692 # If the Mirror is a geom object this parameter is unnecessary
3693 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3694 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3695 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3696 # @ingroup l2_modif_trsf
3697 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3698 if ( isinstance( theObject, Mesh )):
3699 theObject = theObject.GetMesh()
3700 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3701 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3702 self.mesh.SetParameters(Mirror.parameters)
3703 if Copy and MakeGroups:
3704 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3705 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3708 ## Creates a new mesh by a symmetrical copy of the object
3709 # @param theObject mesh, submesh or group
3710 # @param Mirror AxisStruct or geom object (point, line, plane)
3711 # @param theMirrorType POINT, AXIS or PLANE
3712 # If the Mirror is a geom object this parameter is unnecessary
3713 # @param MakeGroups forces the generation of new groups from existing ones
3714 # @param NewMeshName the name of the new mesh to create
3715 # @return instance of Mesh class
3716 # @ingroup l2_modif_trsf
3717 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3718 if ( isinstance( theObject, Mesh )):
3719 theObject = theObject.GetMesh()
3720 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3721 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3722 self.mesh.SetParameters(Mirror.parameters)
3723 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3724 MakeGroups, NewMeshName)
3725 return Mesh( self.smeshpyD,self.geompyD,mesh )
3727 ## Translates the elements
3728 # @param IDsOfElements list of elements ids
3729 # @param Vector the direction of translation (DirStruct or vector)
3730 # @param Copy allows copying the translated elements
3731 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3732 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3733 # @ingroup l2_modif_trsf
3734 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3735 if IDsOfElements == []:
3736 IDsOfElements = self.GetElementsId()
3737 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3738 Vector = self.smeshpyD.GetDirStruct(Vector)
3739 self.mesh.SetParameters(Vector.PS.parameters)
3740 if Copy and MakeGroups:
3741 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3742 self.editor.Translate(IDsOfElements, Vector, Copy)
3745 ## Creates a new mesh of translated elements
3746 # @param IDsOfElements list of elements ids
3747 # @param Vector the direction of translation (DirStruct or vector)
3748 # @param MakeGroups forces the generation of new groups from existing ones
3749 # @param NewMeshName the name of the newly created mesh
3750 # @return instance of Mesh class
3751 # @ingroup l2_modif_trsf
3752 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3753 if IDsOfElements == []:
3754 IDsOfElements = self.GetElementsId()
3755 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3756 Vector = self.smeshpyD.GetDirStruct(Vector)
3757 self.mesh.SetParameters(Vector.PS.parameters)
3758 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3759 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3761 ## Translates the object
3762 # @param theObject the object to translate (mesh, submesh, or group)
3763 # @param Vector direction of translation (DirStruct or geom vector)
3764 # @param Copy allows copying the translated elements
3765 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3766 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3767 # @ingroup l2_modif_trsf
3768 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3769 if ( isinstance( theObject, Mesh )):
3770 theObject = theObject.GetMesh()
3771 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3772 Vector = self.smeshpyD.GetDirStruct(Vector)
3773 self.mesh.SetParameters(Vector.PS.parameters)
3774 if Copy and MakeGroups:
3775 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3776 self.editor.TranslateObject(theObject, Vector, Copy)
3779 ## Creates a new mesh from the translated object
3780 # @param theObject the object to translate (mesh, submesh, or group)
3781 # @param Vector the direction of translation (DirStruct or geom vector)
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 TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3787 if (isinstance(theObject, Mesh)):
3788 theObject = theObject.GetMesh()
3789 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3790 Vector = self.smeshpyD.GetDirStruct(Vector)
3791 self.mesh.SetParameters(Vector.PS.parameters)
3792 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3793 return Mesh( self.smeshpyD, self.geompyD, mesh )
3797 ## Scales the object
3798 # @param theObject - the object to translate (mesh, submesh, or group)
3799 # @param thePoint - base point for scale
3800 # @param theScaleFact - list of 1-3 scale factors for axises
3801 # @param Copy - allows copying the translated elements
3802 # @param MakeGroups - forces the generation of new groups from existing
3804 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3805 # empty list otherwise
3806 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3807 if ( isinstance( theObject, Mesh )):
3808 theObject = theObject.GetMesh()
3809 if ( isinstance( theObject, list )):
3810 theObject = self.GetIDSource(theObject, SMESH.ALL)
3811 if ( isinstance( theScaleFact, float )):
3812 theScaleFact = [theScaleFact]
3813 if ( isinstance( theScaleFact, int )):
3814 theScaleFact = [ float(theScaleFact)]
3816 self.mesh.SetParameters(thePoint.parameters)
3818 if Copy and MakeGroups:
3819 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3820 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3823 ## Creates a new mesh from the translated object
3824 # @param theObject - the object to translate (mesh, submesh, or group)
3825 # @param thePoint - base point for scale
3826 # @param theScaleFact - list of 1-3 scale factors for axises
3827 # @param MakeGroups - forces the generation of new groups from existing ones
3828 # @param NewMeshName - the name of the newly created mesh
3829 # @return instance of Mesh class
3830 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3831 if (isinstance(theObject, Mesh)):
3832 theObject = theObject.GetMesh()
3833 if ( isinstance( theObject, list )):
3834 theObject = self.GetIDSource(theObject,SMESH.ALL)
3835 if ( isinstance( theScaleFact, float )):
3836 theScaleFact = [theScaleFact]
3837 if ( isinstance( theScaleFact, int )):
3838 theScaleFact = [ float(theScaleFact)]
3840 self.mesh.SetParameters(thePoint.parameters)
3841 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3842 MakeGroups, NewMeshName)
3843 return Mesh( self.smeshpyD, self.geompyD, mesh )
3847 ## Rotates the elements
3848 # @param IDsOfElements list of elements ids
3849 # @param Axis the axis of rotation (AxisStruct or geom line)
3850 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3851 # @param Copy allows copying the rotated elements
3852 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3853 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3854 # @ingroup l2_modif_trsf
3855 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3856 if IDsOfElements == []:
3857 IDsOfElements = self.GetElementsId()
3858 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3859 Axis = self.smeshpyD.GetAxisStruct(Axis)
3860 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3861 Parameters = Axis.parameters + var_separator + Parameters
3862 self.mesh.SetParameters(Parameters)
3863 if Copy and MakeGroups:
3864 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3865 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3868 ## Creates a new mesh of rotated elements
3869 # @param IDsOfElements list of element ids
3870 # @param Axis the axis of rotation (AxisStruct or geom line)
3871 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3872 # @param MakeGroups forces the generation of new groups from existing ones
3873 # @param NewMeshName the name of the newly created mesh
3874 # @return instance of Mesh class
3875 # @ingroup l2_modif_trsf
3876 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3877 if IDsOfElements == []:
3878 IDsOfElements = self.GetElementsId()
3879 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3880 Axis = self.smeshpyD.GetAxisStruct(Axis)
3881 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3882 Parameters = Axis.parameters + var_separator + Parameters
3883 self.mesh.SetParameters(Parameters)
3884 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3885 MakeGroups, NewMeshName)
3886 return Mesh( self.smeshpyD, self.geompyD, mesh )
3888 ## Rotates the object
3889 # @param theObject the object to rotate( mesh, submesh, or group)
3890 # @param Axis the axis of rotation (AxisStruct or geom line)
3891 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3892 # @param Copy allows copying the rotated elements
3893 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3894 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3895 # @ingroup l2_modif_trsf
3896 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3897 if (isinstance(theObject, Mesh)):
3898 theObject = theObject.GetMesh()
3899 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3900 Axis = self.smeshpyD.GetAxisStruct(Axis)
3901 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3902 Parameters = Axis.parameters + ":" + Parameters
3903 self.mesh.SetParameters(Parameters)
3904 if Copy and MakeGroups:
3905 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3906 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3909 ## Creates a new mesh from the rotated object
3910 # @param theObject the object to rotate (mesh, submesh, or group)
3911 # @param Axis the axis of rotation (AxisStruct or geom line)
3912 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3913 # @param MakeGroups forces the generation of new groups from existing ones
3914 # @param NewMeshName the name of the newly created mesh
3915 # @return instance of Mesh class
3916 # @ingroup l2_modif_trsf
3917 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3918 if (isinstance( theObject, Mesh )):
3919 theObject = theObject.GetMesh()
3920 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3921 Axis = self.smeshpyD.GetAxisStruct(Axis)
3922 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3923 Parameters = Axis.parameters + ":" + Parameters
3924 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3925 MakeGroups, NewMeshName)
3926 self.mesh.SetParameters(Parameters)
3927 return Mesh( self.smeshpyD, self.geompyD, mesh )
3929 ## Finds groups of ajacent nodes within Tolerance.
3930 # @param Tolerance the value of tolerance
3931 # @return the list of groups of nodes
3932 # @ingroup l2_modif_trsf
3933 def FindCoincidentNodes (self, Tolerance):
3934 return self.editor.FindCoincidentNodes(Tolerance)
3936 ## Finds groups of ajacent nodes within Tolerance.
3937 # @param Tolerance the value of tolerance
3938 # @param SubMeshOrGroup SubMesh or Group
3939 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3940 # @return the list of groups of nodes
3941 # @ingroup l2_modif_trsf
3942 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3943 if (isinstance( SubMeshOrGroup, Mesh )):
3944 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3945 if not isinstance( exceptNodes, list):
3946 exceptNodes = [ exceptNodes ]
3947 if exceptNodes and isinstance( exceptNodes[0], int):
3948 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3949 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3952 # @param GroupsOfNodes the list of groups of nodes
3953 # @ingroup l2_modif_trsf
3954 def MergeNodes (self, GroupsOfNodes):
3955 self.editor.MergeNodes(GroupsOfNodes)
3957 ## Finds the elements built on the same nodes.
3958 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3959 # @return a list of groups of equal elements
3960 # @ingroup l2_modif_trsf
3961 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3962 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
3963 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
3964 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3966 ## Merges elements in each given group.
3967 # @param GroupsOfElementsID groups of elements for merging
3968 # @ingroup l2_modif_trsf
3969 def MergeElements(self, GroupsOfElementsID):
3970 self.editor.MergeElements(GroupsOfElementsID)
3972 ## Leaves one element and removes all other elements built on the same nodes.
3973 # @ingroup l2_modif_trsf
3974 def MergeEqualElements(self):
3975 self.editor.MergeEqualElements()
3977 ## Sews free borders
3978 # @return SMESH::Sew_Error
3979 # @ingroup l2_modif_trsf
3980 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3981 FirstNodeID2, SecondNodeID2, LastNodeID2,
3982 CreatePolygons, CreatePolyedrs):
3983 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3984 FirstNodeID2, SecondNodeID2, LastNodeID2,
3985 CreatePolygons, CreatePolyedrs)
3987 ## Sews conform free borders
3988 # @return SMESH::Sew_Error
3989 # @ingroup l2_modif_trsf
3990 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3991 FirstNodeID2, SecondNodeID2):
3992 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3993 FirstNodeID2, SecondNodeID2)
3995 ## Sews border to side
3996 # @return SMESH::Sew_Error
3997 # @ingroup l2_modif_trsf
3998 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3999 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4000 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4001 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4003 ## Sews two sides of a mesh. The nodes belonging to Side1 are
4004 # merged with the nodes of elements of Side2.
4005 # The number of elements in theSide1 and in theSide2 must be
4006 # equal and they should have similar nodal connectivity.
4007 # The nodes to merge should belong to side borders and
4008 # the first node should be linked to the second.
4009 # @return SMESH::Sew_Error
4010 # @ingroup l2_modif_trsf
4011 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4012 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4013 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4014 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4015 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4016 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4018 ## Sets new nodes for the given element.
4019 # @param ide the element id
4020 # @param newIDs nodes ids
4021 # @return If the number of nodes does not correspond to the type of element - returns false
4022 # @ingroup l2_modif_edit
4023 def ChangeElemNodes(self, ide, newIDs):
4024 return self.editor.ChangeElemNodes(ide, newIDs)
4026 ## If during the last operation of MeshEditor some nodes were
4027 # created, this method returns the list of their IDs, \n
4028 # if new nodes were not created - returns empty list
4029 # @return the list of integer values (can be empty)
4030 # @ingroup l1_auxiliary
4031 def GetLastCreatedNodes(self):
4032 return self.editor.GetLastCreatedNodes()
4034 ## If during the last operation of MeshEditor some elements were
4035 # created this method returns the list of their IDs, \n
4036 # if new elements were not created - returns empty list
4037 # @return the list of integer values (can be empty)
4038 # @ingroup l1_auxiliary
4039 def GetLastCreatedElems(self):
4040 return self.editor.GetLastCreatedElems()
4042 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4043 # @param theNodes identifiers of nodes to be doubled
4044 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4045 # nodes. If list of element identifiers is empty then nodes are doubled but
4046 # they not assigned to elements
4047 # @return TRUE if operation has been completed successfully, FALSE otherwise
4048 # @ingroup l2_modif_edit
4049 def DoubleNodes(self, theNodes, theModifiedElems):
4050 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4052 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4053 # This method provided for convenience works as DoubleNodes() described above.
4054 # @param theNodeId identifiers of node to be doubled
4055 # @param theModifiedElems identifiers of elements to be updated
4056 # @return TRUE if operation has been completed successfully, FALSE otherwise
4057 # @ingroup l2_modif_edit
4058 def DoubleNode(self, theNodeId, theModifiedElems):
4059 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4061 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4062 # This method provided for convenience works as DoubleNodes() described above.
4063 # @param theNodes group of nodes to be doubled
4064 # @param theModifiedElems group of elements to be updated.
4065 # @param theMakeGroup forces the generation of a group containing new nodes.
4066 # @return TRUE or a created group if operation has been completed successfully,
4067 # FALSE or None otherwise
4068 # @ingroup l2_modif_edit
4069 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4071 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4072 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4074 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4075 # This method provided for convenience works as DoubleNodes() described above.
4076 # @param theNodes list of groups of nodes to be doubled
4077 # @param theModifiedElems list of groups of elements to be updated.
4078 # @param theMakeGroup forces the generation of a group containing new nodes.
4079 # @return TRUE if operation has been completed successfully, FALSE otherwise
4080 # @ingroup l2_modif_edit
4081 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4083 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4084 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4086 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4087 # @param theElems - the list of elements (edges or faces) to be replicated
4088 # The nodes for duplication could be found from these elements
4089 # @param theNodesNot - list of nodes to NOT replicate
4090 # @param theAffectedElems - the list of elements (cells and edges) to which the
4091 # replicated nodes should be associated to.
4092 # @return TRUE if operation has been completed successfully, FALSE otherwise
4093 # @ingroup l2_modif_edit
4094 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4095 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4097 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4098 # @param theElems - the list of elements (edges or faces) to be replicated
4099 # The nodes for duplication could be found from these elements
4100 # @param theNodesNot - list of nodes to NOT replicate
4101 # @param theShape - shape to detect affected elements (element which geometric center
4102 # located on or inside shape).
4103 # The replicated nodes should be associated to affected elements.
4104 # @return TRUE if operation has been completed successfully, FALSE otherwise
4105 # @ingroup l2_modif_edit
4106 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4107 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4109 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4110 # This method provided for convenience works as DoubleNodes() described above.
4111 # @param theElems - group of of elements (edges or faces) to be replicated
4112 # @param theNodesNot - group of nodes not to replicated
4113 # @param theAffectedElems - group of elements to which the replicated nodes
4114 # should be associated to.
4115 # @param theMakeGroup forces the generation of a group containing new elements.
4116 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4117 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4118 # FALSE or None otherwise
4119 # @ingroup l2_modif_edit
4120 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4121 theMakeGroup=False, theMakeNodeGroup=False):
4122 if theMakeGroup or theMakeNodeGroup:
4123 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4125 theMakeGroup, theMakeNodeGroup)
4126 if theMakeGroup and theMakeNodeGroup:
4129 return twoGroups[ int(theMakeNodeGroup) ]
4130 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4132 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4133 # This method provided for convenience works as DoubleNodes() described above.
4134 # @param theElems - group of of elements (edges or faces) to be replicated
4135 # @param theNodesNot - group of nodes not to replicated
4136 # @param theShape - shape to detect affected elements (element which geometric center
4137 # located on or inside shape).
4138 # The replicated nodes should be associated to affected elements.
4139 # @ingroup l2_modif_edit
4140 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4141 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4143 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4144 # This method provided for convenience works as DoubleNodes() described above.
4145 # @param theElems - list of groups of elements (edges or faces) to be replicated
4146 # @param theNodesNot - list of groups of nodes not to replicated
4147 # @param theAffectedElems - group of elements to which the replicated nodes
4148 # should be associated to.
4149 # @param theMakeGroup forces the generation of a group containing new elements.
4150 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4151 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4152 # FALSE or None otherwise
4153 # @ingroup l2_modif_edit
4154 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4155 theMakeGroup=False, theMakeNodeGroup=False):
4156 if theMakeGroup or theMakeNodeGroup:
4157 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4159 theMakeGroup, theMakeNodeGroup)
4160 if theMakeGroup and theMakeNodeGroup:
4163 return twoGroups[ int(theMakeNodeGroup) ]
4164 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4166 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4167 # This method provided for convenience works as DoubleNodes() described above.
4168 # @param theElems - list of groups of elements (edges or faces) to be replicated
4169 # @param theNodesNot - list of groups of nodes not to replicated
4170 # @param theShape - shape to detect affected elements (element which geometric center
4171 # located on or inside shape).
4172 # The replicated nodes should be associated to affected elements.
4173 # @return TRUE if operation has been completed successfully, FALSE otherwise
4174 # @ingroup l2_modif_edit
4175 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4176 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4178 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4179 # This method is the first step of DoubleNodeElemGroupsInRegion.
4180 # @param theElems - list of groups of elements (edges or faces) to be replicated
4181 # @param theNodesNot - list of groups of nodes not to replicated
4182 # @param theShape - shape to detect affected elements (element which geometric center
4183 # located on or inside shape).
4184 # The replicated nodes should be associated to affected elements.
4185 # @return groups of affected elements
4186 # @ingroup l2_modif_edit
4187 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4188 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4190 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4191 # The list of groups must describe a partition of the mesh volumes.
4192 # The nodes of the internal faces at the boundaries of the groups are doubled.
4193 # In option, the internal faces are replaced by flat elements.
4194 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4195 # @param theDomains - list of groups of volumes
4196 # @param createJointElems - if TRUE, create the elements
4197 # @return TRUE if operation has been completed successfully, FALSE otherwise
4198 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4199 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4201 ## Double nodes on some external faces and create flat elements.
4202 # Flat elements are mainly used by some types of mechanic calculations.
4204 # Each group of the list must be constituted of faces.
4205 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4206 # @param theGroupsOfFaces - list of groups of faces
4207 # @return TRUE if operation has been completed successfully, FALSE otherwise
4208 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4209 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4211 ## identify all the elements around a geom shape, get the faces delimiting the hole
4213 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4214 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4216 def _getFunctor(self, funcType ):
4217 fn = self.functors[ funcType._v ]
4219 fn = self.smeshpyD.GetFunctor(funcType)
4220 fn.SetMesh(self.mesh)
4221 self.functors[ funcType._v ] = fn
4224 def _valueFromFunctor(self, funcType, elemId):
4225 fn = self._getFunctor( funcType )
4226 if fn.GetElementType() == self.GetElementType(elemId, True):
4227 val = fn.GetValue(elemId)
4232 ## Get length of 1D element.
4233 # @param elemId mesh element ID
4234 # @return element's length value
4235 # @ingroup l1_measurements
4236 def GetLength(self, elemId):
4237 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4239 ## Get area of 2D element.
4240 # @param elemId mesh element ID
4241 # @return element's area value
4242 # @ingroup l1_measurements
4243 def GetArea(self, elemId):
4244 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4246 ## Get volume of 3D element.
4247 # @param elemId mesh element ID
4248 # @return element's volume value
4249 # @ingroup l1_measurements
4250 def GetVolume(self, elemId):
4251 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4253 ## Get maximum element length.
4254 # @param elemId mesh element ID
4255 # @return element's maximum length value
4256 # @ingroup l1_measurements
4257 def GetMaxElementLength(self, elemId):
4258 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4259 ftype = SMESH.FT_MaxElementLength3D
4261 ftype = SMESH.FT_MaxElementLength2D
4262 return self._valueFromFunctor(ftype, elemId)
4264 ## Get aspect ratio of 2D or 3D element.
4265 # @param elemId mesh element ID
4266 # @return element's aspect ratio value
4267 # @ingroup l1_measurements
4268 def GetAspectRatio(self, elemId):
4269 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4270 ftype = SMESH.FT_AspectRatio3D
4272 ftype = SMESH.FT_AspectRatio
4273 return self._valueFromFunctor(ftype, elemId)
4275 ## Get warping angle of 2D element.
4276 # @param elemId mesh element ID
4277 # @return element's warping angle value
4278 # @ingroup l1_measurements
4279 def GetWarping(self, elemId):
4280 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4282 ## Get minimum angle of 2D element.
4283 # @param elemId mesh element ID
4284 # @return element's minimum angle value
4285 # @ingroup l1_measurements
4286 def GetMinimumAngle(self, elemId):
4287 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4289 ## Get taper of 2D element.
4290 # @param elemId mesh element ID
4291 # @return element's taper value
4292 # @ingroup l1_measurements
4293 def GetTaper(self, elemId):
4294 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4296 ## Get skew of 2D element.
4297 # @param elemId mesh element ID
4298 # @return element's skew value
4299 # @ingroup l1_measurements
4300 def GetSkew(self, elemId):
4301 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4303 pass # end of Mesh class
4305 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4307 class Pattern(SMESH._objref_SMESH_Pattern):
4309 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4310 decrFun = lambda i: i-1
4311 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4312 theMesh.SetParameters(Parameters)
4313 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4315 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4316 decrFun = lambda i: i-1
4317 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4318 theMesh.SetParameters(Parameters)
4319 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4321 # Registering the new proxy for Pattern
4322 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4324 ## Private class used to bind methods creating algorithms to the class Mesh
4329 self.defaultAlgoType = ""
4330 self.algoTypeToClass = {}
4332 # Stores a python class of algorithm
4333 def add(self, algoClass):
4334 if type( algoClass ).__name__ == 'classobj' and \
4335 hasattr( algoClass, "algoType"):
4336 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4337 if not self.defaultAlgoType and \
4338 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4339 self.defaultAlgoType = algoClass.algoType
4340 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4342 # creates a copy of self and assign mesh to the copy
4343 def copy(self, mesh):
4344 other = algoCreator()
4345 other.defaultAlgoType = self.defaultAlgoType
4346 other.algoTypeToClass = self.algoTypeToClass
4350 # creates an instance of algorithm
4351 def __call__(self,algo="",geom=0,*args):
4352 algoType = self.defaultAlgoType
4353 for arg in args + (algo,geom):
4354 if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ):
4356 if isinstance( arg, str ) and arg:
4358 if not algoType and self.algoTypeToClass:
4359 algoType = self.algoTypeToClass.keys()[0]
4360 if self.algoTypeToClass.has_key( algoType ):
4361 #print "Create algo",algoType
4362 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4363 raise RuntimeError, "No class found for algo type %s" % algoType
4366 # Private class used to substitute and store variable parameters of hypotheses.
4368 class hypMethodWrapper:
4369 def __init__(self, hyp, method):
4371 self.method = method
4372 #print "REBIND:", method.__name__
4375 # call a method of hypothesis with calling SetVarParameter() before
4376 def __call__(self,*args):
4378 return self.method( self.hyp, *args ) # hypothesis method with no args
4380 #print "MethWrapper.__call__",self.method.__name__, args
4382 parsed = ParseParameters(*args) # replace variables with their values
4383 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4384 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4385 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4386 # maybe there is a replaced string arg which is not variable
4387 result = self.method( self.hyp, *args )
4388 except ValueError, detail: # raised by ParseParameters()
4390 result = self.method( self.hyp, *args )
4391 except omniORB.CORBA.BAD_PARAM:
4392 raise ValueError, detail # wrong variable name
4396 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4398 print "pluginName: ", pluginName
4401 exec( "from %s import *" % pluginName )
4402 except Exception, e:
4403 print "Exception while loading %s: %s" % ( pluginName, e )
4405 exec( "import %s" % pluginName )
4406 plugin = eval( pluginName )
4407 print " plugin:" , str(plugin)
4409 # add methods creating algorithms to Mesh
4410 for k in dir( plugin ):
4411 if k[0] == '_': continue
4412 algo = getattr( plugin, k )
4413 print " algo:", str(algo)
4414 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4415 print " meshMethod:" , str(algo.meshMethod)
4416 if not hasattr( Mesh, algo.meshMethod ):
4417 setattr( Mesh, algo.meshMethod, algoCreator() )
4419 getattr( Mesh, algo.meshMethod ).add( algo )