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_GroupColor:
741 # Checks the Threshold
743 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
745 print "Error: The threshold value should be of SALOMEDS.Color type"
748 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
749 FT_LinearOrQuadratic, FT_BadOrientedVolume,
750 FT_BareBorderFace, FT_BareBorderVolume,
751 FT_OverConstrainedFace, FT_OverConstrainedVolume,
752 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
753 # At this point the Threshold is unnecessary
754 if aThreshold == FT_LogicalNOT:
755 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
756 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
757 aCriterion.BinaryOp = aThreshold
761 aThreshold = float(aThreshold)
762 aCriterion.Threshold = aThreshold
764 print "Error: The Threshold should be a number."
767 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
768 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
770 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
771 aCriterion.BinaryOp = self.EnumToLong(Threshold)
773 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
774 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
776 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
777 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
781 ## Creates a filter with the given parameters
782 # @param elementType the type of elements in the group
783 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
784 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
785 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
786 # @param UnaryOp FT_LogicalNOT or FT_Undefined
787 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
788 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
789 # @return SMESH_Filter
791 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
792 # @ingroup l1_controls
793 def GetFilter(self,elementType,
794 CritType=FT_Undefined,
797 UnaryOp=FT_Undefined,
799 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
800 aFilterMgr = self.CreateFilterManager()
801 aFilter = aFilterMgr.CreateFilter()
803 aCriteria.append(aCriterion)
804 aFilter.SetCriteria(aCriteria)
805 aFilterMgr.UnRegister()
808 ## Creates a filter from criteria
809 # @param criteria a list of criteria
810 # @return SMESH_Filter
812 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
813 # @ingroup l1_controls
814 def GetFilterFromCriteria(self,criteria):
815 aFilterMgr = self.CreateFilterManager()
816 aFilter = aFilterMgr.CreateFilter()
817 aFilter.SetCriteria(criteria)
818 aFilterMgr.UnRegister()
821 ## Creates a numerical functor by its type
822 # @param theCriterion FT_...; functor type
823 # @return SMESH_NumericalFunctor
824 # @ingroup l1_controls
825 def GetFunctor(self,theCriterion):
826 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
828 aFilterMgr = self.CreateFilterManager()
830 if theCriterion == FT_AspectRatio:
831 functor = aFilterMgr.CreateAspectRatio()
832 elif theCriterion == FT_AspectRatio3D:
833 functor = aFilterMgr.CreateAspectRatio3D()
834 elif theCriterion == FT_Warping:
835 functor = aFilterMgr.CreateWarping()
836 elif theCriterion == FT_MinimumAngle:
837 functor = aFilterMgr.CreateMinimumAngle()
838 elif theCriterion == FT_Taper:
839 functor = aFilterMgr.CreateTaper()
840 elif theCriterion == FT_Skew:
841 functor = aFilterMgr.CreateSkew()
842 elif theCriterion == FT_Area:
843 functor = aFilterMgr.CreateArea()
844 elif theCriterion == FT_Volume3D:
845 functor = aFilterMgr.CreateVolume3D()
846 elif theCriterion == FT_MaxElementLength2D:
847 functor = aFilterMgr.CreateMaxElementLength2D()
848 elif theCriterion == FT_MaxElementLength3D:
849 functor = aFilterMgr.CreateMaxElementLength3D()
850 elif theCriterion == FT_MultiConnection:
851 functor = aFilterMgr.CreateMultiConnection()
852 elif theCriterion == FT_MultiConnection2D:
853 functor = aFilterMgr.CreateMultiConnection2D()
854 elif theCriterion == FT_Length:
855 functor = aFilterMgr.CreateLength()
856 elif theCriterion == FT_Length2D:
857 functor = aFilterMgr.CreateLength2D()
859 print "Error: given parameter is not numerical functor type."
860 aFilterMgr.UnRegister()
863 ## Creates hypothesis
864 # @param theHType mesh hypothesis type (string)
865 # @param theLibName mesh plug-in library name
866 # @return created hypothesis instance
867 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
868 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
870 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
873 # wrap hypothesis methods
874 #print "HYPOTHESIS", theHType
875 for meth_name in dir( hyp.__class__ ):
876 if not meth_name.startswith("Get") and \
877 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
878 method = getattr ( hyp.__class__, meth_name )
880 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
884 ## Gets the mesh statistic
885 # @return dictionary "element type" - "count of elements"
886 # @ingroup l1_meshinfo
887 def GetMeshInfo(self, obj):
888 if isinstance( obj, Mesh ):
891 if hasattr(obj, "GetMeshInfo"):
892 values = obj.GetMeshInfo()
893 for i in range(SMESH.Entity_Last._v):
894 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
898 ## Get minimum distance between two objects
900 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
901 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
903 # @param src1 first source object
904 # @param src2 second source object
905 # @param id1 node/element id from the first source
906 # @param id2 node/element id from the second (or first) source
907 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
908 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
909 # @return minimum distance value
910 # @sa GetMinDistance()
911 # @ingroup l1_measurements
912 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
913 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
917 result = result.value
920 ## Get measure structure specifying minimum distance data between two objects
922 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
923 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
925 # @param src1 first source object
926 # @param src2 second source object
927 # @param id1 node/element id from the first source
928 # @param id2 node/element id from the second (or first) source
929 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
930 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
931 # @return Measure structure or None if input data is invalid
933 # @ingroup l1_measurements
934 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
935 if isinstance(src1, Mesh): src1 = src1.mesh
936 if isinstance(src2, Mesh): src2 = src2.mesh
937 if src2 is None and id2 != 0: src2 = src1
938 if not hasattr(src1, "_narrow"): return None
939 src1 = src1._narrow(SMESH.SMESH_IDSource)
940 if not src1: return None
943 e = m.GetMeshEditor()
945 src1 = e.MakeIDSource([id1], SMESH.FACE)
947 src1 = e.MakeIDSource([id1], SMESH.NODE)
949 if hasattr(src2, "_narrow"):
950 src2 = src2._narrow(SMESH.SMESH_IDSource)
951 if src2 and id2 != 0:
953 e = m.GetMeshEditor()
955 src2 = e.MakeIDSource([id2], SMESH.FACE)
957 src2 = e.MakeIDSource([id2], SMESH.NODE)
960 aMeasurements = self.CreateMeasurements()
961 result = aMeasurements.MinDistance(src1, src2)
962 aMeasurements.UnRegister()
965 ## Get bounding box of the specified object(s)
966 # @param objects single source object or list of source objects
967 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
968 # @sa GetBoundingBox()
969 # @ingroup l1_measurements
970 def BoundingBox(self, objects):
971 result = self.GetBoundingBox(objects)
975 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
978 ## Get measure structure specifying bounding box data of the specified object(s)
979 # @param objects single source object or list of source objects
980 # @return Measure structure
982 # @ingroup l1_measurements
983 def GetBoundingBox(self, objects):
984 if isinstance(objects, tuple):
985 objects = list(objects)
986 if not isinstance(objects, list):
990 if isinstance(o, Mesh):
991 srclist.append(o.mesh)
992 elif hasattr(o, "_narrow"):
993 src = o._narrow(SMESH.SMESH_IDSource)
994 if src: srclist.append(src)
997 aMeasurements = self.CreateMeasurements()
998 result = aMeasurements.BoundingBox(srclist)
999 aMeasurements.UnRegister()
1003 #Registering the new proxy for SMESH_Gen
1004 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
1007 def smeshInstance( study, instance=None):
1014 smeshInst = smeshDC()
1015 assert isinstance(smeshInst,smeshDC), "Smesh engine class is %s but should be smeshDC.smeshDC. Import smeshmapi before creating the instance."%smeshInst.__class__
1016 smeshInst.init_smesh(study)
1020 # Public class: Mesh
1021 # ==================
1023 ## This class allows defining and managing a mesh.
1024 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1025 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1026 # new nodes and elements and by changing the existing entities), to get information
1027 # about a mesh and to export a mesh into different formats.
1036 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1037 # sets the GUI name of this mesh to \a name.
1038 # @param smeshpyD an instance of smeshDC class
1039 # @param geompyD an instance of geompyDC class
1040 # @param obj Shape to be meshed or SMESH_Mesh object
1041 # @param name Study name of the mesh
1042 # @ingroup l2_construct
1043 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1044 self.smeshpyD=smeshpyD
1045 self.geompyD=geompyD
1050 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
1053 # publish geom of mesh (issue 0021122)
1054 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
1056 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
1057 if studyID != geompyD.myStudyId:
1058 geompyD.init_geom( smeshpyD.GetCurrentStudy())
1061 geo_name = name + " shape"
1063 geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1064 geompyD.addToStudy( self.geom, geo_name )
1065 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1067 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1070 self.mesh = self.smeshpyD.CreateEmptyMesh()
1072 self.smeshpyD.SetName(self.mesh, name)
1074 self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1077 self.geom = self.mesh.GetShapeToMesh()
1079 self.editor = self.mesh.GetMeshEditor()
1080 self.functors = [None] * SMESH.FT_Undefined._v
1082 # set self to algoCreator's
1083 for attrName in dir(self):
1084 attr = getattr( self, attrName )
1085 if isinstance( attr, algoCreator ):
1086 print "algoCreator ", attrName
1087 setattr( self, attrName, attr.copy( self ))
1089 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1090 # @param theMesh a SMESH_Mesh object
1091 # @ingroup l2_construct
1092 def SetMesh(self, theMesh):
1093 if self.mesh: self.mesh.UnRegister()
1096 self.mesh.Register()
1097 self.geom = self.mesh.GetShapeToMesh()
1099 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1100 # @return a SMESH_Mesh object
1101 # @ingroup l2_construct
1105 ## Gets the name of the mesh
1106 # @return the name of the mesh as a string
1107 # @ingroup l2_construct
1109 name = GetName(self.GetMesh())
1112 ## Sets a name to the mesh
1113 # @param name a new name of the mesh
1114 # @ingroup l2_construct
1115 def SetName(self, name):
1116 self.smeshpyD.SetName(self.GetMesh(), name)
1118 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1119 # The subMesh object gives access to the IDs of nodes and elements.
1120 # @param geom a geometrical object (shape)
1121 # @param name a name for the submesh
1122 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1123 # @ingroup l2_submeshes
1124 def GetSubMesh(self, geom, name):
1125 AssureGeomPublished( self, geom, name )
1126 submesh = self.mesh.GetSubMesh( geom, name )
1129 ## Returns the shape associated to the mesh
1130 # @return a GEOM_Object
1131 # @ingroup l2_construct
1135 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1136 # @param geom the shape to be meshed (GEOM_Object)
1137 # @ingroup l2_construct
1138 def SetShape(self, geom):
1139 self.mesh = self.smeshpyD.CreateMesh(geom)
1141 ## Loads mesh from the study after opening the study
1145 ## Returns true if the hypotheses are defined well
1146 # @param theSubObject a sub-shape of a mesh shape
1147 # @return True or False
1148 # @ingroup l2_construct
1149 def IsReadyToCompute(self, theSubObject):
1150 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1152 ## Returns errors of hypotheses definition.
1153 # The list of errors is empty if everything is OK.
1154 # @param theSubObject a sub-shape of a mesh shape
1155 # @return a list of errors
1156 # @ingroup l2_construct
1157 def GetAlgoState(self, theSubObject):
1158 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1160 ## Returns a geometrical object on which the given element was built.
1161 # The returned geometrical object, if not nil, is either found in the
1162 # study or published by this method with the given name
1163 # @param theElementID the id of the mesh element
1164 # @param theGeomName the user-defined name of the geometrical object
1165 # @return GEOM::GEOM_Object instance
1166 # @ingroup l2_construct
1167 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1168 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1170 ## Returns the mesh dimension depending on the dimension of the underlying shape
1171 # or, if the mesh is not based on any shape, basing on deimension of elements
1172 # @return mesh dimension as an integer value [0,3]
1173 # @ingroup l1_auxiliary
1174 def MeshDimension(self):
1175 if self.mesh.HasShapeToMesh():
1176 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SOLID"] )
1177 if len( shells ) > 0 :
1179 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1181 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1186 if self.NbVolumes() > 0: return 3
1187 if self.NbFaces() > 0: return 2
1188 if self.NbEdges() > 0: return 1
1191 ## Evaluates size of prospective mesh on a shape
1192 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1193 # To know predicted number of e.g. edges, inquire it this way
1194 # Evaluate()[ EnumToLong( Entity_Edge )]
1195 def Evaluate(self, geom=0):
1196 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1198 geom = self.mesh.GetShapeToMesh()
1201 return self.smeshpyD.Evaluate(self.mesh, geom)
1204 ## Computes the mesh and returns the status of the computation
1205 # @param geom geomtrical shape on which mesh data should be computed
1206 # @param discardModifs if True and the mesh has been edited since
1207 # a last total re-compute and that may prevent successful partial re-compute,
1208 # then the mesh is cleaned before Compute()
1209 # @return True or False
1210 # @ingroup l2_construct
1211 def Compute(self, geom=0, discardModifs=False):
1212 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1214 geom = self.mesh.GetShapeToMesh()
1219 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1221 ok = self.smeshpyD.Compute(self.mesh, geom)
1222 except SALOME.SALOME_Exception, ex:
1223 print "Mesh computation failed, exception caught:"
1224 print " ", ex.details.text
1227 print "Mesh computation failed, exception caught:"
1228 traceback.print_exc()
1232 # Treat compute errors
1233 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1234 for err in computeErrors:
1236 if self.mesh.HasShapeToMesh():
1238 mainIOR = salome.orb.object_to_string(geom)
1239 for sname in salome.myStudyManager.GetOpenStudies():
1240 s = salome.myStudyManager.GetStudyByName(sname)
1242 mainSO = s.FindObjectIOR(mainIOR)
1243 if not mainSO: continue
1244 if err.subShapeID == 1:
1245 shapeText = ' on "%s"' % mainSO.GetName()
1246 subIt = s.NewChildIterator(mainSO)
1248 subSO = subIt.Value()
1250 obj = subSO.GetObject()
1251 if not obj: continue
1252 go = obj._narrow( geompyDC.GEOM._objref_GEOM_Object )
1254 ids = go.GetSubShapeIndices()
1255 if len(ids) == 1 and ids[0] == err.subShapeID:
1256 shapeText = ' on "%s"' % subSO.GetName()
1259 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1261 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1263 shapeText = " on subshape #%s" % (err.subShapeID)
1265 shapeText = " on subshape #%s" % (err.subShapeID)
1267 stdErrors = ["OK", #COMPERR_OK
1268 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1269 "std::exception", #COMPERR_STD_EXCEPTION
1270 "OCC exception", #COMPERR_OCC_EXCEPTION
1271 "..", #COMPERR_SLM_EXCEPTION
1272 "Unknown exception", #COMPERR_EXCEPTION
1273 "Memory allocation problem", #COMPERR_MEMORY_PB
1274 "Algorithm failed", #COMPERR_ALGO_FAILED
1275 "Unexpected geometry", #COMPERR_BAD_SHAPE
1276 "Warning", #COMPERR_WARNING
1277 "Computation cancelled",#COMPERR_CANCELED
1278 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1280 if err.code < len(stdErrors): errText = stdErrors[err.code]
1282 errText = "code %s" % -err.code
1283 if errText: errText += ". "
1284 errText += err.comment
1285 if allReasons != "":allReasons += "\n"
1286 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1290 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1292 if err.isGlobalAlgo:
1300 reason = '%s %sD algorithm is missing' % (glob, dim)
1301 elif err.state == HYP_MISSING:
1302 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1303 % (glob, dim, name, dim))
1304 elif err.state == HYP_NOTCONFORM:
1305 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1306 elif err.state == HYP_BAD_PARAMETER:
1307 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1308 % ( glob, dim, name ))
1309 elif err.state == HYP_BAD_GEOMETRY:
1310 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1311 'geometry' % ( glob, dim, name ))
1312 elif err.state == HYP_HIDDEN_ALGO:
1313 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1314 'algorithm of upper dimension generating %sD mesh'
1315 % ( glob, dim, name, glob, dim ))
1317 reason = ("For unknown reason. "
1318 "Developer, revise Mesh.Compute() implementation in smeshDC.py!")
1320 if allReasons != "":allReasons += "\n"
1321 allReasons += "- " + reason
1323 if not ok or allReasons != "":
1324 msg = '"' + GetName(self.mesh) + '"'
1325 if ok: msg += " has been computed with warnings"
1326 else: msg += " has not been computed"
1327 if allReasons != "": msg += ":"
1332 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1333 smeshgui = salome.ImportComponentGUI("SMESH")
1334 smeshgui.Init(self.mesh.GetStudyId())
1335 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1336 salome.sg.updateObjBrowser(1)
1340 ## Return submesh objects list in meshing order
1341 # @return list of list of submesh objects
1342 # @ingroup l2_construct
1343 def GetMeshOrder(self):
1344 return self.mesh.GetMeshOrder()
1346 ## Return submesh objects list in meshing order
1347 # @return list of list of submesh objects
1348 # @ingroup l2_construct
1349 def SetMeshOrder(self, submeshes):
1350 return self.mesh.SetMeshOrder(submeshes)
1352 ## Removes all nodes and elements
1353 # @ingroup l2_construct
1356 if ( salome.sg.hasDesktop() and
1357 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1358 smeshgui = salome.ImportComponentGUI("SMESH")
1359 smeshgui.Init(self.mesh.GetStudyId())
1360 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1361 salome.sg.updateObjBrowser(1)
1363 ## Removes all nodes and elements of indicated shape
1364 # @ingroup l2_construct
1365 def ClearSubMesh(self, geomId):
1366 self.mesh.ClearSubMesh(geomId)
1367 if salome.sg.hasDesktop():
1368 smeshgui = salome.ImportComponentGUI("SMESH")
1369 smeshgui.Init(self.mesh.GetStudyId())
1370 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1371 salome.sg.updateObjBrowser(1)
1373 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1374 # @param fineness [0.0,1.0] defines mesh fineness
1375 # @return True or False
1376 # @ingroup l3_algos_basic
1377 def AutomaticTetrahedralization(self, fineness=0):
1378 dim = self.MeshDimension()
1380 self.RemoveGlobalHypotheses()
1381 self.Segment().AutomaticLength(fineness)
1383 self.Triangle().LengthFromEdges()
1386 from NETGENPluginDC import NETGEN
1387 self.Tetrahedron(NETGEN)
1389 return self.Compute()
1391 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1392 # @param fineness [0.0, 1.0] defines mesh fineness
1393 # @return True or False
1394 # @ingroup l3_algos_basic
1395 def AutomaticHexahedralization(self, fineness=0):
1396 dim = self.MeshDimension()
1397 # assign the hypotheses
1398 self.RemoveGlobalHypotheses()
1399 self.Segment().AutomaticLength(fineness)
1406 return self.Compute()
1408 ## Assigns a hypothesis
1409 # @param hyp a hypothesis to assign
1410 # @param geom a subhape of mesh geometry
1411 # @return SMESH.Hypothesis_Status
1412 # @ingroup l2_hypotheses
1413 def AddHypothesis(self, hyp, geom=0):
1414 if isinstance( hyp, Mesh_Algorithm ):
1415 hyp = hyp.GetAlgorithm()
1420 geom = self.mesh.GetShapeToMesh()
1422 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1423 status = self.mesh.AddHypothesis(geom, hyp)
1424 isAlgo = hyp._narrow( SMESH_Algo )
1425 hyp_name = GetName( hyp )
1428 geom_name = GetName( geom )
1429 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1432 ## Return True if an algorithm of hypothesis is assigned to a given shape
1433 # @param hyp a hypothesis to check
1434 # @param geom a subhape of mesh geometry
1435 # @return True of False
1436 # @ingroup l2_hypotheses
1437 def IsUsedHypothesis(self, hyp, geom):
1438 if not hyp: # or not geom
1440 if isinstance( hyp, Mesh_Algorithm ):
1441 hyp = hyp.GetAlgorithm()
1443 hyps = self.GetHypothesisList(geom)
1445 if h.GetId() == hyp.GetId():
1449 ## Unassigns a hypothesis
1450 # @param hyp a hypothesis to unassign
1451 # @param geom a sub-shape of mesh geometry
1452 # @return SMESH.Hypothesis_Status
1453 # @ingroup l2_hypotheses
1454 def RemoveHypothesis(self, hyp, geom=0):
1455 if isinstance( hyp, Mesh_Algorithm ):
1456 hyp = hyp.GetAlgorithm()
1462 if self.IsUsedHypothesis( hyp, shape ):
1463 return self.mesh.RemoveHypothesis( shape, hyp )
1464 hypName = GetName( hyp )
1465 geoName = GetName( shape )
1466 print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1469 ## Gets the list of hypotheses added on a geometry
1470 # @param geom a sub-shape of mesh geometry
1471 # @return the sequence of SMESH_Hypothesis
1472 # @ingroup l2_hypotheses
1473 def GetHypothesisList(self, geom):
1474 return self.mesh.GetHypothesisList( geom )
1476 ## Removes all global hypotheses
1477 # @ingroup l2_hypotheses
1478 def RemoveGlobalHypotheses(self):
1479 current_hyps = self.mesh.GetHypothesisList( self.geom )
1480 for hyp in current_hyps:
1481 self.mesh.RemoveHypothesis( self.geom, hyp )
1485 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1486 ## allowing to overwrite the file if it exists or add the exported data to its contents
1487 # @param f is the file name
1488 # @param auto_groups boolean parameter for creating/not creating
1489 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1490 # the typical use is auto_groups=false.
1491 # @param version MED format version(MED_V2_1 or MED_V2_2)
1492 # @param overwrite boolean parameter for overwriting/not overwriting the file
1493 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1494 # @ingroup l2_impexp
1495 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1497 if isinstance( meshPart, list ):
1498 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1499 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1501 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1503 ## Exports the mesh in a file in SAUV format
1504 # @param f is the file name
1505 # @param auto_groups boolean parameter for creating/not creating
1506 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1507 # the typical use is auto_groups=false.
1508 # @ingroup l2_impexp
1509 def ExportSAUV(self, f, auto_groups=0):
1510 self.mesh.ExportSAUV(f, auto_groups)
1512 ## Exports the mesh in a file in DAT format
1513 # @param f the file name
1514 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1515 # @ingroup l2_impexp
1516 def ExportDAT(self, f, meshPart=None):
1518 if isinstance( meshPart, list ):
1519 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1520 self.mesh.ExportPartToDAT( meshPart, f )
1522 self.mesh.ExportDAT(f)
1524 ## Exports the mesh in a file in UNV format
1525 # @param f the file name
1526 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1527 # @ingroup l2_impexp
1528 def ExportUNV(self, f, meshPart=None):
1530 if isinstance( meshPart, list ):
1531 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1532 self.mesh.ExportPartToUNV( meshPart, f )
1534 self.mesh.ExportUNV(f)
1536 ## Export the mesh in a file in STL format
1537 # @param f the file name
1538 # @param ascii defines the file encoding
1539 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1540 # @ingroup l2_impexp
1541 def ExportSTL(self, f, ascii=1, meshPart=None):
1543 if isinstance( meshPart, list ):
1544 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1545 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1547 self.mesh.ExportSTL(f, ascii)
1549 ## Exports the mesh in a file in CGNS format
1550 # @param f is the file name
1551 # @param overwrite boolean parameter for overwriting/not overwriting the file
1552 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1553 # @ingroup l2_impexp
1554 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1555 if isinstance( meshPart, list ):
1556 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1557 if isinstance( meshPart, Mesh ):
1558 meshPart = meshPart.mesh
1560 meshPart = self.mesh
1561 self.mesh.ExportCGNS(meshPart, f, overwrite)
1563 ## Exports the mesh in a file in GMF format
1564 # @param f is the file name
1565 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1566 # @ingroup l2_impexp
1567 def ExportGMF(self, f, meshPart=None):
1568 if isinstance( meshPart, list ):
1569 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1570 if isinstance( meshPart, Mesh ):
1571 meshPart = meshPart.mesh
1573 meshPart = self.mesh
1574 self.mesh.ExportGMF(meshPart, f, True)
1576 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1577 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1578 ## allowing to overwrite the file if it exists or add the exported data to its contents
1579 # @param f the file name
1580 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1581 # @param opt boolean parameter for creating/not creating
1582 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1583 # @param overwrite boolean parameter for overwriting/not overwriting the file
1584 # @ingroup l2_impexp
1585 def ExportToMED(self, f, version, opt=0, overwrite=1):
1586 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1588 # Operations with groups:
1589 # ----------------------
1591 ## Creates an empty mesh group
1592 # @param elementType the type of elements in the group
1593 # @param name the name of the mesh group
1594 # @return SMESH_Group
1595 # @ingroup l2_grps_create
1596 def CreateEmptyGroup(self, elementType, name):
1597 return self.mesh.CreateGroup(elementType, name)
1599 ## Creates a mesh group based on the geometric object \a grp
1600 # and gives a \a name, \n if this parameter is not defined
1601 # the name is the same as the geometric group name \n
1602 # Note: Works like GroupOnGeom().
1603 # @param grp a geometric group, a vertex, an edge, a face or a solid
1604 # @param name the name of the mesh group
1605 # @return SMESH_GroupOnGeom
1606 # @ingroup l2_grps_create
1607 def Group(self, grp, name=""):
1608 return self.GroupOnGeom(grp, name)
1610 ## Creates a mesh group based on the geometrical object \a grp
1611 # and gives a \a name, \n if this parameter is not defined
1612 # the name is the same as the geometrical group name
1613 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1614 # @param name the name of the mesh group
1615 # @param typ the type of elements in the group. If not set, it is
1616 # automatically detected by the type of the geometry
1617 # @return SMESH_GroupOnGeom
1618 # @ingroup l2_grps_create
1619 def GroupOnGeom(self, grp, name="", typ=None):
1620 AssureGeomPublished( self, grp, name )
1622 name = grp.GetName()
1624 typ = self._groupTypeFromShape( grp )
1625 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1627 ## Pivate method to get a type of group on geometry
1628 def _groupTypeFromShape( self, shape ):
1629 tgeo = str(shape.GetShapeType())
1630 if tgeo == "VERTEX":
1632 elif tgeo == "EDGE":
1634 elif tgeo == "FACE" or tgeo == "SHELL":
1636 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1638 elif tgeo == "COMPOUND":
1639 sub = self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHAPE"])
1641 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1642 return self._groupTypeFromShape( sub[0] )
1645 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1648 ## Creates a mesh group with given \a name based on the \a filter which
1649 ## is a special type of group dynamically updating it's contents during
1650 ## mesh modification
1651 # @param typ the type of elements in the group
1652 # @param name the name of the mesh group
1653 # @param filter the filter defining group contents
1654 # @return SMESH_GroupOnFilter
1655 # @ingroup l2_grps_create
1656 def GroupOnFilter(self, typ, name, filter):
1657 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1659 ## Creates a mesh group by the given ids of elements
1660 # @param groupName the name of the mesh group
1661 # @param elementType the type of elements in the group
1662 # @param elemIDs the list of ids
1663 # @return SMESH_Group
1664 # @ingroup l2_grps_create
1665 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1666 group = self.mesh.CreateGroup(elementType, groupName)
1670 ## Creates a mesh group by the given conditions
1671 # @param groupName the name of the mesh group
1672 # @param elementType the type of elements in the group
1673 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1674 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1675 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1676 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1677 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1678 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1679 # @return SMESH_Group
1680 # @ingroup l2_grps_create
1684 CritType=FT_Undefined,
1687 UnaryOp=FT_Undefined,
1689 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1690 group = self.MakeGroupByCriterion(groupName, aCriterion)
1693 ## Creates a mesh group by the given criterion
1694 # @param groupName the name of the mesh group
1695 # @param Criterion the instance of Criterion class
1696 # @return SMESH_Group
1697 # @ingroup l2_grps_create
1698 def MakeGroupByCriterion(self, groupName, Criterion):
1699 aFilterMgr = self.smeshpyD.CreateFilterManager()
1700 aFilter = aFilterMgr.CreateFilter()
1702 aCriteria.append(Criterion)
1703 aFilter.SetCriteria(aCriteria)
1704 group = self.MakeGroupByFilter(groupName, aFilter)
1705 aFilterMgr.UnRegister()
1708 ## Creates a mesh group by the given criteria (list of criteria)
1709 # @param groupName the name of the mesh group
1710 # @param theCriteria the list of criteria
1711 # @return SMESH_Group
1712 # @ingroup l2_grps_create
1713 def MakeGroupByCriteria(self, groupName, theCriteria):
1714 aFilterMgr = self.smeshpyD.CreateFilterManager()
1715 aFilter = aFilterMgr.CreateFilter()
1716 aFilter.SetCriteria(theCriteria)
1717 group = self.MakeGroupByFilter(groupName, aFilter)
1718 aFilterMgr.UnRegister()
1721 ## Creates a mesh group by the given filter
1722 # @param groupName the name of the mesh group
1723 # @param theFilter the instance of Filter class
1724 # @return SMESH_Group
1725 # @ingroup l2_grps_create
1726 def MakeGroupByFilter(self, groupName, theFilter):
1727 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1728 theFilter.SetMesh( self.mesh )
1729 group.AddFrom( theFilter )
1733 # @ingroup l2_grps_delete
1734 def RemoveGroup(self, group):
1735 self.mesh.RemoveGroup(group)
1737 ## Removes a group with its contents
1738 # @ingroup l2_grps_delete
1739 def RemoveGroupWithContents(self, group):
1740 self.mesh.RemoveGroupWithContents(group)
1742 ## Gets the list of groups existing in the mesh
1743 # @return a sequence of SMESH_GroupBase
1744 # @ingroup l2_grps_create
1745 def GetGroups(self):
1746 return self.mesh.GetGroups()
1748 ## Gets the number of groups existing in the mesh
1749 # @return the quantity of groups as an integer value
1750 # @ingroup l2_grps_create
1752 return self.mesh.NbGroups()
1754 ## Gets the list of names of groups existing in the mesh
1755 # @return list of strings
1756 # @ingroup l2_grps_create
1757 def GetGroupNames(self):
1758 groups = self.GetGroups()
1760 for group in groups:
1761 names.append(group.GetName())
1764 ## Produces a union of two groups
1765 # A new group is created. All mesh elements that are
1766 # present in the initial groups are added to the new one
1767 # @return an instance of SMESH_Group
1768 # @ingroup l2_grps_operon
1769 def UnionGroups(self, group1, group2, name):
1770 return self.mesh.UnionGroups(group1, group2, name)
1772 ## Produces a union list of groups
1773 # New group is created. All mesh elements that are present in
1774 # initial groups are added to the new one
1775 # @return an instance of SMESH_Group
1776 # @ingroup l2_grps_operon
1777 def UnionListOfGroups(self, groups, name):
1778 return self.mesh.UnionListOfGroups(groups, name)
1780 ## Prodices an intersection of two groups
1781 # A new group is created. All mesh elements that are common
1782 # for the two initial groups are added to the new one.
1783 # @return an instance of SMESH_Group
1784 # @ingroup l2_grps_operon
1785 def IntersectGroups(self, group1, group2, name):
1786 return self.mesh.IntersectGroups(group1, group2, name)
1788 ## Produces an intersection of groups
1789 # New group is created. All mesh elements that are present in all
1790 # initial groups simultaneously are added to the new one
1791 # @return an instance of SMESH_Group
1792 # @ingroup l2_grps_operon
1793 def IntersectListOfGroups(self, groups, name):
1794 return self.mesh.IntersectListOfGroups(groups, name)
1796 ## Produces a cut of two groups
1797 # A new group is created. All mesh elements that are present in
1798 # the main group but are not present in the tool group are added to the new one
1799 # @return an instance of SMESH_Group
1800 # @ingroup l2_grps_operon
1801 def CutGroups(self, main_group, tool_group, name):
1802 return self.mesh.CutGroups(main_group, tool_group, name)
1804 ## Produces a cut of groups
1805 # A new group is created. All mesh elements that are present in main groups
1806 # but do not present in tool groups are added to the new one
1807 # @return an instance of SMESH_Group
1808 # @ingroup l2_grps_operon
1809 def CutListOfGroups(self, main_groups, tool_groups, name):
1810 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1812 ## Produces a group of elements of specified type using list of existing groups
1813 # A new group is created. System
1814 # 1) extracts all nodes on which groups elements are built
1815 # 2) combines all elements of specified dimension laying on these nodes
1816 # @return an instance of SMESH_Group
1817 # @ingroup l2_grps_operon
1818 def CreateDimGroup(self, groups, elem_type, name):
1819 return self.mesh.CreateDimGroup(groups, elem_type, name)
1822 ## Convert group on geom into standalone group
1823 # @ingroup l2_grps_delete
1824 def ConvertToStandalone(self, group):
1825 return self.mesh.ConvertToStandalone(group)
1827 # Get some info about mesh:
1828 # ------------------------
1830 ## Returns the log of nodes and elements added or removed
1831 # since the previous clear of the log.
1832 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1833 # @return list of log_block structures:
1838 # @ingroup l1_auxiliary
1839 def GetLog(self, clearAfterGet):
1840 return self.mesh.GetLog(clearAfterGet)
1842 ## Clears the log of nodes and elements added or removed since the previous
1843 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1844 # @ingroup l1_auxiliary
1846 self.mesh.ClearLog()
1848 ## Toggles auto color mode on the object.
1849 # @param theAutoColor the flag which toggles auto color mode.
1850 # @ingroup l1_auxiliary
1851 def SetAutoColor(self, theAutoColor):
1852 self.mesh.SetAutoColor(theAutoColor)
1854 ## Gets flag of object auto color mode.
1855 # @return True or False
1856 # @ingroup l1_auxiliary
1857 def GetAutoColor(self):
1858 return self.mesh.GetAutoColor()
1860 ## Gets the internal ID
1861 # @return integer value, which is the internal Id of the mesh
1862 # @ingroup l1_auxiliary
1864 return self.mesh.GetId()
1867 # @return integer value, which is the study Id of the mesh
1868 # @ingroup l1_auxiliary
1869 def GetStudyId(self):
1870 return self.mesh.GetStudyId()
1872 ## Checks the group names for duplications.
1873 # Consider the maximum group name length stored in MED file.
1874 # @return True or False
1875 # @ingroup l1_auxiliary
1876 def HasDuplicatedGroupNamesMED(self):
1877 return self.mesh.HasDuplicatedGroupNamesMED()
1879 ## Obtains the mesh editor tool
1880 # @return an instance of SMESH_MeshEditor
1881 # @ingroup l1_modifying
1882 def GetMeshEditor(self):
1885 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1886 # can be passed as argument to a method accepting mesh, group or sub-mesh
1887 # @return an instance of SMESH_IDSource
1888 # @ingroup l1_auxiliary
1889 def GetIDSource(self, ids, elemType):
1890 return self.editor.MakeIDSource(ids, elemType)
1893 # @return an instance of SALOME_MED::MESH
1894 # @ingroup l1_auxiliary
1895 def GetMEDMesh(self):
1896 return self.mesh.GetMEDMesh()
1899 # Get informations about mesh contents:
1900 # ------------------------------------
1902 ## Gets the mesh stattistic
1903 # @return dictionary type element - count of elements
1904 # @ingroup l1_meshinfo
1905 def GetMeshInfo(self, obj = None):
1906 if not obj: obj = self.mesh
1907 return self.smeshpyD.GetMeshInfo(obj)
1909 ## Returns the number of nodes in the mesh
1910 # @return an integer value
1911 # @ingroup l1_meshinfo
1913 return self.mesh.NbNodes()
1915 ## Returns the number of elements in the mesh
1916 # @return an integer value
1917 # @ingroup l1_meshinfo
1918 def NbElements(self):
1919 return self.mesh.NbElements()
1921 ## Returns the number of 0d elements in the mesh
1922 # @return an integer value
1923 # @ingroup l1_meshinfo
1924 def Nb0DElements(self):
1925 return self.mesh.Nb0DElements()
1927 ## Returns the number of ball discrete elements in the mesh
1928 # @return an integer value
1929 # @ingroup l1_meshinfo
1931 return self.mesh.NbBalls()
1933 ## Returns the number of edges in the mesh
1934 # @return an integer value
1935 # @ingroup l1_meshinfo
1937 return self.mesh.NbEdges()
1939 ## Returns the number of edges with the given order in the mesh
1940 # @param elementOrder the order of elements:
1941 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1942 # @return an integer value
1943 # @ingroup l1_meshinfo
1944 def NbEdgesOfOrder(self, elementOrder):
1945 return self.mesh.NbEdgesOfOrder(elementOrder)
1947 ## Returns the number of faces in the mesh
1948 # @return an integer value
1949 # @ingroup l1_meshinfo
1951 return self.mesh.NbFaces()
1953 ## Returns the number of faces 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 NbFacesOfOrder(self, elementOrder):
1959 return self.mesh.NbFacesOfOrder(elementOrder)
1961 ## Returns the number of triangles in the mesh
1962 # @return an integer value
1963 # @ingroup l1_meshinfo
1964 def NbTriangles(self):
1965 return self.mesh.NbTriangles()
1967 ## Returns the number of triangles with the given order in the mesh
1968 # @param elementOrder is the order of elements:
1969 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1970 # @return an integer value
1971 # @ingroup l1_meshinfo
1972 def NbTrianglesOfOrder(self, elementOrder):
1973 return self.mesh.NbTrianglesOfOrder(elementOrder)
1975 ## Returns the number of quadrangles in the mesh
1976 # @return an integer value
1977 # @ingroup l1_meshinfo
1978 def NbQuadrangles(self):
1979 return self.mesh.NbQuadrangles()
1981 ## Returns the number of quadrangles with the given order in the mesh
1982 # @param elementOrder the order of elements:
1983 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1984 # @return an integer value
1985 # @ingroup l1_meshinfo
1986 def NbQuadranglesOfOrder(self, elementOrder):
1987 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1989 ## Returns the number of biquadratic quadrangles in the mesh
1990 # @return an integer value
1991 # @ingroup l1_meshinfo
1992 def NbBiQuadQuadrangles(self):
1993 return self.mesh.NbBiQuadQuadrangles()
1995 ## Returns the number of polygons in the mesh
1996 # @return an integer value
1997 # @ingroup l1_meshinfo
1998 def NbPolygons(self):
1999 return self.mesh.NbPolygons()
2001 ## Returns the number of volumes in the mesh
2002 # @return an integer value
2003 # @ingroup l1_meshinfo
2004 def NbVolumes(self):
2005 return self.mesh.NbVolumes()
2007 ## Returns the number of volumes with the given order in the mesh
2008 # @param elementOrder the order of elements:
2009 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2010 # @return an integer value
2011 # @ingroup l1_meshinfo
2012 def NbVolumesOfOrder(self, elementOrder):
2013 return self.mesh.NbVolumesOfOrder(elementOrder)
2015 ## Returns the number of tetrahedrons in the mesh
2016 # @return an integer value
2017 # @ingroup l1_meshinfo
2019 return self.mesh.NbTetras()
2021 ## Returns the number of tetrahedrons 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 NbTetrasOfOrder(self, elementOrder):
2027 return self.mesh.NbTetrasOfOrder(elementOrder)
2029 ## Returns the number of hexahedrons in the mesh
2030 # @return an integer value
2031 # @ingroup l1_meshinfo
2033 return self.mesh.NbHexas()
2035 ## Returns the number of hexahedrons 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 NbHexasOfOrder(self, elementOrder):
2041 return self.mesh.NbHexasOfOrder(elementOrder)
2043 ## Returns the number of triquadratic hexahedrons in the mesh
2044 # @return an integer value
2045 # @ingroup l1_meshinfo
2046 def NbTriQuadraticHexas(self):
2047 return self.mesh.NbTriQuadraticHexas()
2049 ## Returns the number of pyramids in the mesh
2050 # @return an integer value
2051 # @ingroup l1_meshinfo
2052 def NbPyramids(self):
2053 return self.mesh.NbPyramids()
2055 ## Returns the number of pyramids with the given order in the mesh
2056 # @param elementOrder the order of elements:
2057 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
2058 # @return an integer value
2059 # @ingroup l1_meshinfo
2060 def NbPyramidsOfOrder(self, elementOrder):
2061 return self.mesh.NbPyramidsOfOrder(elementOrder)
2063 ## Returns the number of prisms in the mesh
2064 # @return an integer value
2065 # @ingroup l1_meshinfo
2067 return self.mesh.NbPrisms()
2069 ## Returns the number of prisms 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 NbPrismsOfOrder(self, elementOrder):
2075 return self.mesh.NbPrismsOfOrder(elementOrder)
2077 ## Returns the number of hexagonal prisms in the mesh
2078 # @return an integer value
2079 # @ingroup l1_meshinfo
2080 def NbHexagonalPrisms(self):
2081 return self.mesh.NbHexagonalPrisms()
2083 ## Returns the number of polyhedrons in the mesh
2084 # @return an integer value
2085 # @ingroup l1_meshinfo
2086 def NbPolyhedrons(self):
2087 return self.mesh.NbPolyhedrons()
2089 ## Returns the number of submeshes in the mesh
2090 # @return an integer value
2091 # @ingroup l1_meshinfo
2092 def NbSubMesh(self):
2093 return self.mesh.NbSubMesh()
2095 ## Returns the list of mesh elements IDs
2096 # @return the list of integer values
2097 # @ingroup l1_meshinfo
2098 def GetElementsId(self):
2099 return self.mesh.GetElementsId()
2101 ## Returns the list of IDs of mesh elements with the given type
2102 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2103 # @return list of integer values
2104 # @ingroup l1_meshinfo
2105 def GetElementsByType(self, elementType):
2106 return self.mesh.GetElementsByType(elementType)
2108 ## Returns the list of mesh nodes IDs
2109 # @return the list of integer values
2110 # @ingroup l1_meshinfo
2111 def GetNodesId(self):
2112 return self.mesh.GetNodesId()
2114 # Get the information about mesh elements:
2115 # ------------------------------------
2117 ## Returns the type of mesh element
2118 # @return the value from SMESH::ElementType enumeration
2119 # @ingroup l1_meshinfo
2120 def GetElementType(self, id, iselem):
2121 return self.mesh.GetElementType(id, iselem)
2123 ## Returns the geometric type of mesh element
2124 # @return the value from SMESH::EntityType enumeration
2125 # @ingroup l1_meshinfo
2126 def GetElementGeomType(self, id):
2127 return self.mesh.GetElementGeomType(id)
2129 ## Returns the list of submesh elements IDs
2130 # @param Shape a geom object(sub-shape) IOR
2131 # Shape must be the sub-shape of a ShapeToMesh()
2132 # @return the list of integer values
2133 # @ingroup l1_meshinfo
2134 def GetSubMeshElementsId(self, Shape):
2135 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2136 ShapeID = Shape.GetSubShapeIndices()[0]
2139 return self.mesh.GetSubMeshElementsId(ShapeID)
2141 ## Returns the list of submesh nodes IDs
2142 # @param Shape a geom object(sub-shape) IOR
2143 # Shape must be the sub-shape of a ShapeToMesh()
2144 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2145 # @return the list of integer values
2146 # @ingroup l1_meshinfo
2147 def GetSubMeshNodesId(self, Shape, all):
2148 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2149 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2152 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2154 ## Returns type of elements on given shape
2155 # @param Shape a geom object(sub-shape) IOR
2156 # Shape must be a sub-shape of a ShapeToMesh()
2157 # @return element type
2158 # @ingroup l1_meshinfo
2159 def GetSubMeshElementType(self, Shape):
2160 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2161 ShapeID = Shape.GetSubShapeIndices()[0]
2164 return self.mesh.GetSubMeshElementType(ShapeID)
2166 ## Gets the mesh description
2167 # @return string value
2168 # @ingroup l1_meshinfo
2170 return self.mesh.Dump()
2173 # Get the information about nodes and elements of a mesh by its IDs:
2174 # -----------------------------------------------------------
2176 ## Gets XYZ coordinates of a node
2177 # \n If there is no nodes for the given ID - returns an empty list
2178 # @return a list of double precision values
2179 # @ingroup l1_meshinfo
2180 def GetNodeXYZ(self, id):
2181 return self.mesh.GetNodeXYZ(id)
2183 ## Returns list of IDs of inverse elements for the given node
2184 # \n If there is no node for the given ID - returns an empty list
2185 # @return a list of integer values
2186 # @ingroup l1_meshinfo
2187 def GetNodeInverseElements(self, id):
2188 return self.mesh.GetNodeInverseElements(id)
2190 ## @brief Returns the position of a node on the shape
2191 # @return SMESH::NodePosition
2192 # @ingroup l1_meshinfo
2193 def GetNodePosition(self,NodeID):
2194 return self.mesh.GetNodePosition(NodeID)
2196 ## @brief Returns the position of an element on the shape
2197 # @return SMESH::ElementPosition
2198 # @ingroup l1_meshinfo
2199 def GetElementPosition(self,ElemID):
2200 return self.mesh.GetElementPosition(ElemID)
2202 ## If the given element is a node, returns the ID of shape
2203 # \n If there is no node for the given ID - returns -1
2204 # @return an integer value
2205 # @ingroup l1_meshinfo
2206 def GetShapeID(self, id):
2207 return self.mesh.GetShapeID(id)
2209 ## Returns the ID of the result shape after
2210 # FindShape() from SMESH_MeshEditor for the given element
2211 # \n If there is no element for the given ID - returns -1
2212 # @return an integer value
2213 # @ingroup l1_meshinfo
2214 def GetShapeIDForElem(self,id):
2215 return self.mesh.GetShapeIDForElem(id)
2217 ## Returns the number of nodes for the given element
2218 # \n If there is no element for the given ID - returns -1
2219 # @return an integer value
2220 # @ingroup l1_meshinfo
2221 def GetElemNbNodes(self, id):
2222 return self.mesh.GetElemNbNodes(id)
2224 ## Returns the node ID the given index for the given element
2225 # \n If there is no element for the given ID - returns -1
2226 # \n If there is no node for the given index - returns -2
2227 # @return an integer value
2228 # @ingroup l1_meshinfo
2229 def GetElemNode(self, id, index):
2230 return self.mesh.GetElemNode(id, index)
2232 ## Returns the IDs of nodes of the given element
2233 # @return a list of integer values
2234 # @ingroup l1_meshinfo
2235 def GetElemNodes(self, id):
2236 return self.mesh.GetElemNodes(id)
2238 ## Returns true if the given node is the medium node in the given quadratic element
2239 # @ingroup l1_meshinfo
2240 def IsMediumNode(self, elementID, nodeID):
2241 return self.mesh.IsMediumNode(elementID, nodeID)
2243 ## Returns true if the given node is the medium node in one of quadratic elements
2244 # @ingroup l1_meshinfo
2245 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2246 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2248 ## Returns the number of edges for the given element
2249 # @ingroup l1_meshinfo
2250 def ElemNbEdges(self, id):
2251 return self.mesh.ElemNbEdges(id)
2253 ## Returns the number of faces for the given element
2254 # @ingroup l1_meshinfo
2255 def ElemNbFaces(self, id):
2256 return self.mesh.ElemNbFaces(id)
2258 ## Returns nodes of given face (counted from zero) for given volumic element.
2259 # @ingroup l1_meshinfo
2260 def GetElemFaceNodes(self,elemId, faceIndex):
2261 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2263 ## Returns an element based on all given nodes.
2264 # @ingroup l1_meshinfo
2265 def FindElementByNodes(self,nodes):
2266 return self.mesh.FindElementByNodes(nodes)
2268 ## Returns true if the given element is a polygon
2269 # @ingroup l1_meshinfo
2270 def IsPoly(self, id):
2271 return self.mesh.IsPoly(id)
2273 ## Returns true if the given element is quadratic
2274 # @ingroup l1_meshinfo
2275 def IsQuadratic(self, id):
2276 return self.mesh.IsQuadratic(id)
2278 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2279 # @ingroup l1_meshinfo
2280 def GetBallDiameter(self, id):
2281 return self.mesh.GetBallDiameter(id)
2283 ## Returns XYZ coordinates of the barycenter of the given element
2284 # \n If there is no element for the given ID - returns an empty list
2285 # @return a list of three double values
2286 # @ingroup l1_meshinfo
2287 def BaryCenter(self, id):
2288 return self.mesh.BaryCenter(id)
2290 ## Passes mesh elements through the given filter and return IDs of fitting elements
2291 # @param theFilter SMESH_Filter
2292 # @return a list of ids
2293 # @ingroup l1_controls
2294 def GetIdsFromFilter(self, theFilter):
2295 theFilter.SetMesh( self.mesh )
2296 return theFilter.GetIDs()
2298 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2299 # Returns a list of special structures (borders).
2300 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2301 # @ingroup l1_controls
2302 def GetFreeBorders(self):
2303 aFilterMgr = self.smeshpyD.CreateFilterManager()
2304 aPredicate = aFilterMgr.CreateFreeEdges()
2305 aPredicate.SetMesh(self.mesh)
2306 aBorders = aPredicate.GetBorders()
2307 aFilterMgr.UnRegister()
2311 # Get mesh measurements information:
2312 # ------------------------------------
2314 ## Get minimum distance between two nodes, elements or distance to the origin
2315 # @param id1 first node/element id
2316 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2317 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2318 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2319 # @return minimum distance value
2320 # @sa GetMinDistance()
2321 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2322 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2323 return aMeasure.value
2325 ## Get measure structure specifying minimum distance data between two objects
2326 # @param id1 first node/element id
2327 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2328 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2329 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2330 # @return Measure structure
2332 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2334 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2336 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2339 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2341 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2346 aMeasurements = self.smeshpyD.CreateMeasurements()
2347 aMeasure = aMeasurements.MinDistance(id1, id2)
2348 aMeasurements.UnRegister()
2351 ## Get bounding box of the specified object(s)
2352 # @param objects single source object or list of source objects or list of nodes/elements IDs
2353 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2354 # @c False specifies that @a objects are nodes
2355 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2356 # @sa GetBoundingBox()
2357 def BoundingBox(self, objects=None, isElem=False):
2358 result = self.GetBoundingBox(objects, isElem)
2362 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2365 ## Get measure structure specifying bounding box data of the specified object(s)
2366 # @param IDs 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 Measure structure
2371 def GetBoundingBox(self, IDs=None, isElem=False):
2374 elif isinstance(IDs, tuple):
2376 if not isinstance(IDs, list):
2378 if len(IDs) > 0 and isinstance(IDs[0], int):
2382 if isinstance(o, Mesh):
2383 srclist.append(o.mesh)
2384 elif hasattr(o, "_narrow"):
2385 src = o._narrow(SMESH.SMESH_IDSource)
2386 if src: srclist.append(src)
2388 elif isinstance(o, list):
2390 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2392 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2395 aMeasurements = self.smeshpyD.CreateMeasurements()
2396 aMeasure = aMeasurements.BoundingBox(srclist)
2397 aMeasurements.UnRegister()
2400 # Mesh edition (SMESH_MeshEditor functionality):
2401 # ---------------------------------------------
2403 ## Removes the elements from the mesh by ids
2404 # @param IDsOfElements is a list of ids of elements to remove
2405 # @return True or False
2406 # @ingroup l2_modif_del
2407 def RemoveElements(self, IDsOfElements):
2408 return self.editor.RemoveElements(IDsOfElements)
2410 ## Removes nodes from mesh by ids
2411 # @param IDsOfNodes is a list of ids of nodes to remove
2412 # @return True or False
2413 # @ingroup l2_modif_del
2414 def RemoveNodes(self, IDsOfNodes):
2415 return self.editor.RemoveNodes(IDsOfNodes)
2417 ## Removes all orphan (free) nodes from mesh
2418 # @return number of the removed nodes
2419 # @ingroup l2_modif_del
2420 def RemoveOrphanNodes(self):
2421 return self.editor.RemoveOrphanNodes()
2423 ## Add a node to the mesh by coordinates
2424 # @return Id of the new node
2425 # @ingroup l2_modif_add
2426 def AddNode(self, x, y, z):
2427 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2428 if hasVars: self.mesh.SetParameters(Parameters)
2429 return self.editor.AddNode( x, y, z)
2431 ## Creates a 0D element on a node with given number.
2432 # @param IDOfNode the ID of node for creation of the element.
2433 # @return the Id of the new 0D element
2434 # @ingroup l2_modif_add
2435 def Add0DElement(self, IDOfNode):
2436 return self.editor.Add0DElement(IDOfNode)
2438 ## Create 0D elements on all nodes of the given elements except those
2439 # nodes on which a 0D element already exists.
2440 # @param theObject an object on whose nodes 0D elements will be created.
2441 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2442 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2443 # @param theGroupName optional name of a group to add 0D elements created
2444 # and/or found on nodes of \a theObject.
2445 # @return an object (a new group or a temporary SMESH_IDSource) holding
2446 # IDs of new and/or found 0D elements. IDs of 0D elements
2447 # can be retrieved from the returned object by calling GetIDs()
2448 # @ingroup l2_modif_add
2449 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2450 if isinstance( theObject, Mesh ):
2451 theObject = theObject.GetMesh()
2452 if isinstance( theObject, list ):
2453 theObject = self.GetIDSource( theObject, SMESH.ALL )
2454 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2456 ## Creates a ball element on a node with given ID.
2457 # @param IDOfNode the ID of node for creation of the element.
2458 # @param diameter the bal diameter.
2459 # @return the Id of the new ball element
2460 # @ingroup l2_modif_add
2461 def AddBall(self, IDOfNode, diameter):
2462 return self.editor.AddBall( IDOfNode, diameter )
2464 ## Creates a linear or quadratic edge (this is determined
2465 # by the number of given nodes).
2466 # @param IDsOfNodes the list of node IDs for creation of the element.
2467 # The order of nodes in this list should correspond to the description
2468 # of MED. \n This description is located by the following link:
2469 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2470 # @return the Id of the new edge
2471 # @ingroup l2_modif_add
2472 def AddEdge(self, IDsOfNodes):
2473 return self.editor.AddEdge(IDsOfNodes)
2475 ## Creates a linear or quadratic face (this is determined
2476 # by the number of given nodes).
2477 # @param IDsOfNodes the list of node IDs for creation of the element.
2478 # The order of nodes in this list should correspond to the description
2479 # of MED. \n This description is located by the following link:
2480 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2481 # @return the Id of the new face
2482 # @ingroup l2_modif_add
2483 def AddFace(self, IDsOfNodes):
2484 return self.editor.AddFace(IDsOfNodes)
2486 ## Adds a polygonal face to the mesh by the list of node IDs
2487 # @param IdsOfNodes the list of node IDs for creation of the element.
2488 # @return the Id of the new face
2489 # @ingroup l2_modif_add
2490 def AddPolygonalFace(self, IdsOfNodes):
2491 return self.editor.AddPolygonalFace(IdsOfNodes)
2493 ## Creates both simple and quadratic volume (this is determined
2494 # by the number of given nodes).
2495 # @param IDsOfNodes the list of node IDs for creation of the element.
2496 # The order of nodes in this list should correspond to the description
2497 # of MED. \n This description is located by the following link:
2498 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2499 # @return the Id of the new volumic element
2500 # @ingroup l2_modif_add
2501 def AddVolume(self, IDsOfNodes):
2502 return self.editor.AddVolume(IDsOfNodes)
2504 ## Creates a volume of many faces, giving nodes for each face.
2505 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2506 # @param Quantities the list of integer values, Quantities[i]
2507 # gives the quantity of nodes in face number i.
2508 # @return the Id of the new volumic element
2509 # @ingroup l2_modif_add
2510 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2511 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2513 ## Creates a volume of many faces, giving the IDs of the existing faces.
2514 # @param IdsOfFaces the list of face IDs for volume creation.
2516 # Note: The created volume will refer only to the nodes
2517 # of the given faces, not to the faces themselves.
2518 # @return the Id of the new volumic element
2519 # @ingroup l2_modif_add
2520 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2521 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2524 ## @brief Binds a node to a vertex
2525 # @param NodeID a node ID
2526 # @param Vertex a vertex or vertex ID
2527 # @return True if succeed else raises an exception
2528 # @ingroup l2_modif_add
2529 def SetNodeOnVertex(self, NodeID, Vertex):
2530 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2531 VertexID = Vertex.GetSubShapeIndices()[0]
2535 self.editor.SetNodeOnVertex(NodeID, VertexID)
2536 except SALOME.SALOME_Exception, inst:
2537 raise ValueError, inst.details.text
2541 ## @brief Stores the node position on an edge
2542 # @param NodeID a node ID
2543 # @param Edge an edge or edge ID
2544 # @param paramOnEdge a parameter on the edge where the node is located
2545 # @return True if succeed else raises an exception
2546 # @ingroup l2_modif_add
2547 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2548 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2549 EdgeID = Edge.GetSubShapeIndices()[0]
2553 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2554 except SALOME.SALOME_Exception, inst:
2555 raise ValueError, inst.details.text
2558 ## @brief Stores node position on a face
2559 # @param NodeID a node ID
2560 # @param Face a face or face ID
2561 # @param u U parameter on the face where the node is located
2562 # @param v V parameter on the face where the node is located
2563 # @return True if succeed else raises an exception
2564 # @ingroup l2_modif_add
2565 def SetNodeOnFace(self, NodeID, Face, u, v):
2566 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2567 FaceID = Face.GetSubShapeIndices()[0]
2571 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2572 except SALOME.SALOME_Exception, inst:
2573 raise ValueError, inst.details.text
2576 ## @brief Binds a node to a solid
2577 # @param NodeID a node ID
2578 # @param Solid a solid or solid ID
2579 # @return True if succeed else raises an exception
2580 # @ingroup l2_modif_add
2581 def SetNodeInVolume(self, NodeID, Solid):
2582 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2583 SolidID = Solid.GetSubShapeIndices()[0]
2587 self.editor.SetNodeInVolume(NodeID, SolidID)
2588 except SALOME.SALOME_Exception, inst:
2589 raise ValueError, inst.details.text
2592 ## @brief Bind an element to a shape
2593 # @param ElementID an element ID
2594 # @param Shape a shape or shape ID
2595 # @return True if succeed else raises an exception
2596 # @ingroup l2_modif_add
2597 def SetMeshElementOnShape(self, ElementID, Shape):
2598 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2599 ShapeID = Shape.GetSubShapeIndices()[0]
2603 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2604 except SALOME.SALOME_Exception, inst:
2605 raise ValueError, inst.details.text
2609 ## Moves the node with the given id
2610 # @param NodeID the id of the node
2611 # @param x a new X coordinate
2612 # @param y a new Y coordinate
2613 # @param z a new Z coordinate
2614 # @return True if succeed else False
2615 # @ingroup l2_modif_movenode
2616 def MoveNode(self, NodeID, x, y, z):
2617 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2618 if hasVars: self.mesh.SetParameters(Parameters)
2619 return self.editor.MoveNode(NodeID, x, y, z)
2621 ## Finds the node closest to a point and moves it to a point location
2622 # @param x the X coordinate of a point
2623 # @param y the Y coordinate of a point
2624 # @param z the Z coordinate of a point
2625 # @param NodeID if specified (>0), the node with this ID is moved,
2626 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2627 # @return the ID of a node
2628 # @ingroup l2_modif_throughp
2629 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2630 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2631 if hasVars: self.mesh.SetParameters(Parameters)
2632 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2634 ## Finds the node closest to a point
2635 # @param x the X coordinate of a point
2636 # @param y the Y coordinate of a point
2637 # @param z the Z coordinate of a point
2638 # @return the ID of a node
2639 # @ingroup l2_modif_throughp
2640 def FindNodeClosestTo(self, x, y, z):
2641 #preview = self.mesh.GetMeshEditPreviewer()
2642 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2643 return self.editor.FindNodeClosestTo(x, y, z)
2645 ## Finds the elements where a point lays IN or ON
2646 # @param x the X coordinate of a point
2647 # @param y the Y coordinate of a point
2648 # @param z the Z coordinate of a point
2649 # @param elementType type of elements to find (SMESH.ALL type
2650 # means elements of any type excluding nodes, discrete and 0D elements)
2651 # @param meshPart a part of mesh (group, sub-mesh) to search within
2652 # @return list of IDs of found elements
2653 # @ingroup l2_modif_throughp
2654 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2656 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2658 return self.editor.FindElementsByPoint(x, y, z, elementType)
2660 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2661 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2662 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2664 def GetPointState(self, x, y, z):
2665 return self.editor.GetPointState(x, y, z)
2667 ## Finds the node closest to a point and moves it to a point location
2668 # @param x the X coordinate of a point
2669 # @param y the Y coordinate of a point
2670 # @param z the Z coordinate of a point
2671 # @return the ID of a moved node
2672 # @ingroup l2_modif_throughp
2673 def MeshToPassThroughAPoint(self, x, y, z):
2674 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2676 ## Replaces two neighbour triangles sharing Node1-Node2 link
2677 # with the triangles built on the same 4 nodes but having other common link.
2678 # @param NodeID1 the ID of the first node
2679 # @param NodeID2 the ID of the second node
2680 # @return false if proper faces were not found
2681 # @ingroup l2_modif_invdiag
2682 def InverseDiag(self, NodeID1, NodeID2):
2683 return self.editor.InverseDiag(NodeID1, NodeID2)
2685 ## Replaces two neighbour triangles sharing Node1-Node2 link
2686 # with a quadrangle built on the same 4 nodes.
2687 # @param NodeID1 the ID of the first node
2688 # @param NodeID2 the ID of the second node
2689 # @return false if proper faces were not found
2690 # @ingroup l2_modif_unitetri
2691 def DeleteDiag(self, NodeID1, NodeID2):
2692 return self.editor.DeleteDiag(NodeID1, NodeID2)
2694 ## Reorients elements by ids
2695 # @param IDsOfElements if undefined reorients all mesh elements
2696 # @return True if succeed else False
2697 # @ingroup l2_modif_changori
2698 def Reorient(self, IDsOfElements=None):
2699 if IDsOfElements == None:
2700 IDsOfElements = self.GetElementsId()
2701 return self.editor.Reorient(IDsOfElements)
2703 ## Reorients all elements of the object
2704 # @param theObject mesh, submesh or group
2705 # @return True if succeed else False
2706 # @ingroup l2_modif_changori
2707 def ReorientObject(self, theObject):
2708 if ( isinstance( theObject, Mesh )):
2709 theObject = theObject.GetMesh()
2710 return self.editor.ReorientObject(theObject)
2712 ## Reorient faces contained in \a the2DObject.
2713 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2714 # @param theDirection is a desired direction of normal of \a theFace.
2715 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2716 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2717 # compared with theDirection. It can be either ID of face or a point
2718 # by which the face will be found. The point can be given as either
2719 # a GEOM vertex or a list of point coordinates.
2720 # @return number of reoriented faces
2721 # @ingroup l2_modif_changori
2722 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2724 if isinstance( the2DObject, Mesh ):
2725 the2DObject = the2DObject.GetMesh()
2726 if isinstance( the2DObject, list ):
2727 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2728 # check theDirection
2729 if isinstance( theDirection, geompyDC.GEOM._objref_GEOM_Object):
2730 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2731 if isinstance( theDirection, list ):
2732 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2733 # prepare theFace and thePoint
2734 theFace = theFaceOrPoint
2735 thePoint = PointStruct(0,0,0)
2736 if isinstance( theFaceOrPoint, geompyDC.GEOM._objref_GEOM_Object):
2737 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2739 if isinstance( theFaceOrPoint, list ):
2740 thePoint = PointStruct( *theFaceOrPoint )
2742 if isinstance( theFaceOrPoint, PointStruct ):
2743 thePoint = theFaceOrPoint
2745 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2747 ## Fuses the neighbouring triangles into quadrangles.
2748 # @param IDsOfElements The triangles to be fused,
2749 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2750 # choose a neighbour to fuse with.
2751 # @param MaxAngle is the maximum angle between element normals at which the fusion
2752 # is still performed; theMaxAngle is mesured in radians.
2753 # Also it could be a name of variable which defines angle in degrees.
2754 # @return TRUE in case of success, FALSE otherwise.
2755 # @ingroup l2_modif_unitetri
2756 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2757 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2758 self.mesh.SetParameters(Parameters)
2759 if not IDsOfElements:
2760 IDsOfElements = self.GetElementsId()
2761 Functor = self.smeshpyD.GetFunctor(theCriterion)
2762 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2764 ## Fuses the neighbouring triangles of the object into quadrangles
2765 # @param theObject is mesh, submesh or group
2766 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2767 # choose a neighbour to fuse with.
2768 # @param MaxAngle a max angle between element normals at which the fusion
2769 # is still performed; theMaxAngle is mesured in radians.
2770 # @return TRUE in case of success, FALSE otherwise.
2771 # @ingroup l2_modif_unitetri
2772 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2773 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2774 self.mesh.SetParameters(Parameters)
2775 if isinstance( theObject, Mesh ):
2776 theObject = theObject.GetMesh()
2777 Functor = self.smeshpyD.GetFunctor(theCriterion)
2778 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2780 ## Splits quadrangles into triangles.
2782 # @param IDsOfElements the faces to be splitted.
2783 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2784 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2785 # value, then quadrangles will be split by the smallest diagonal.
2786 # @return TRUE in case of success, FALSE otherwise.
2787 # @ingroup l2_modif_cutquadr
2788 def QuadToTri (self, IDsOfElements, theCriterion = None):
2789 if IDsOfElements == []:
2790 IDsOfElements = self.GetElementsId()
2791 if theCriterion is None:
2792 theCriterion = FT_MaxElementLength2D
2793 Functor = self.smeshpyD.GetFunctor(theCriterion)
2794 return self.editor.QuadToTri(IDsOfElements, Functor)
2796 ## Splits quadrangles into triangles.
2797 # @param theObject the object from which the list of elements is taken,
2798 # this is mesh, submesh or group
2799 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2800 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2801 # value, then quadrangles will be split by the smallest diagonal.
2802 # @return TRUE in case of success, FALSE otherwise.
2803 # @ingroup l2_modif_cutquadr
2804 def QuadToTriObject (self, theObject, theCriterion = None):
2805 if ( isinstance( theObject, Mesh )):
2806 theObject = theObject.GetMesh()
2807 if theCriterion is None:
2808 theCriterion = FT_MaxElementLength2D
2809 Functor = self.smeshpyD.GetFunctor(theCriterion)
2810 return self.editor.QuadToTriObject(theObject, Functor)
2812 ## Splits quadrangles into triangles.
2813 # @param IDsOfElements the faces to be splitted
2814 # @param Diag13 is used to choose a diagonal for splitting.
2815 # @return TRUE in case of success, FALSE otherwise.
2816 # @ingroup l2_modif_cutquadr
2817 def SplitQuad (self, IDsOfElements, Diag13):
2818 if IDsOfElements == []:
2819 IDsOfElements = self.GetElementsId()
2820 return self.editor.SplitQuad(IDsOfElements, Diag13)
2822 ## Splits quadrangles into triangles.
2823 # @param theObject the object from which the list of elements is taken,
2824 # this is mesh, submesh or group
2825 # @param Diag13 is used to choose a diagonal for splitting.
2826 # @return TRUE in case of success, FALSE otherwise.
2827 # @ingroup l2_modif_cutquadr
2828 def SplitQuadObject (self, theObject, Diag13):
2829 if ( isinstance( theObject, Mesh )):
2830 theObject = theObject.GetMesh()
2831 return self.editor.SplitQuadObject(theObject, Diag13)
2833 ## Finds a better splitting of the given quadrangle.
2834 # @param IDOfQuad the ID of the quadrangle to be splitted.
2835 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2836 # choose a diagonal for splitting.
2837 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2838 # diagonal is better, 0 if error occurs.
2839 # @ingroup l2_modif_cutquadr
2840 def BestSplit (self, IDOfQuad, theCriterion):
2841 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2843 ## Splits volumic elements into tetrahedrons
2844 # @param elemIDs either list of elements or mesh or group or submesh
2845 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2846 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2847 # @ingroup l2_modif_cutquadr
2848 def SplitVolumesIntoTetra(self, elemIDs, method=Hex_5Tet ):
2849 if isinstance( elemIDs, Mesh ):
2850 elemIDs = elemIDs.GetMesh()
2851 if ( isinstance( elemIDs, list )):
2852 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2853 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2855 ## Splits quadrangle faces near triangular facets of volumes
2857 # @ingroup l1_auxiliary
2858 def SplitQuadsNearTriangularFacets(self):
2859 faces_array = self.GetElementsByType(SMESH.FACE)
2860 for face_id in faces_array:
2861 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2862 quad_nodes = self.mesh.GetElemNodes(face_id)
2863 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2864 isVolumeFound = False
2865 for node1_elem in node1_elems:
2866 if not isVolumeFound:
2867 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2868 nb_nodes = self.GetElemNbNodes(node1_elem)
2869 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2870 volume_elem = node1_elem
2871 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2872 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2873 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2874 isVolumeFound = True
2875 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2876 self.SplitQuad([face_id], False) # diagonal 2-4
2877 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2878 isVolumeFound = True
2879 self.SplitQuad([face_id], True) # diagonal 1-3
2880 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2881 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2882 isVolumeFound = True
2883 self.SplitQuad([face_id], True) # diagonal 1-3
2885 ## @brief Splits hexahedrons into tetrahedrons.
2887 # This operation uses pattern mapping functionality for splitting.
2888 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2889 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2890 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2891 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2892 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2893 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2894 # @return TRUE in case of success, FALSE otherwise.
2895 # @ingroup l1_auxiliary
2896 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2897 # Pattern: 5.---------.6
2902 # (0,0,1) 4.---------.7 * |
2909 # (0,0,0) 0.---------.3
2910 pattern_tetra = "!!! Nb of points: \n 8 \n\
2920 !!! Indices of points of 6 tetras: \n\
2928 pattern = self.smeshpyD.GetPattern()
2929 isDone = pattern.LoadFromFile(pattern_tetra)
2931 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2934 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2935 isDone = pattern.MakeMesh(self.mesh, False, False)
2936 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2938 # split quafrangle faces near triangular facets of volumes
2939 self.SplitQuadsNearTriangularFacets()
2943 ## @brief Split hexahedrons into prisms.
2945 # Uses the pattern mapping functionality for splitting.
2946 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2947 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2948 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2949 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2950 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2951 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2952 # @return TRUE in case of success, FALSE otherwise.
2953 # @ingroup l1_auxiliary
2954 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2955 # Pattern: 5.---------.6
2960 # (0,0,1) 4.---------.7 |
2967 # (0,0,0) 0.---------.3
2968 pattern_prism = "!!! Nb of points: \n 8 \n\
2978 !!! Indices of points of 2 prisms: \n\
2982 pattern = self.smeshpyD.GetPattern()
2983 isDone = pattern.LoadFromFile(pattern_prism)
2985 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2988 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2989 isDone = pattern.MakeMesh(self.mesh, False, False)
2990 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2992 # Splits quafrangle faces near triangular facets of volumes
2993 self.SplitQuadsNearTriangularFacets()
2997 ## Smoothes elements
2998 # @param IDsOfElements the list if ids of elements to smooth
2999 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3000 # Note that nodes built on edges and boundary nodes are always fixed.
3001 # @param MaxNbOfIterations the maximum number of iterations
3002 # @param MaxAspectRatio varies in range [1.0, inf]
3003 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3004 # @return TRUE in case of success, FALSE otherwise.
3005 # @ingroup l2_modif_smooth
3006 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3007 MaxNbOfIterations, MaxAspectRatio, Method):
3008 if IDsOfElements == []:
3009 IDsOfElements = self.GetElementsId()
3010 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3011 self.mesh.SetParameters(Parameters)
3012 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3013 MaxNbOfIterations, MaxAspectRatio, Method)
3015 ## Smoothes elements which belong to the given object
3016 # @param theObject the object to smooth
3017 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3018 # Note that nodes built on edges and boundary nodes are always fixed.
3019 # @param MaxNbOfIterations the maximum number of iterations
3020 # @param MaxAspectRatio varies in range [1.0, inf]
3021 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3022 # @return TRUE in case of success, FALSE otherwise.
3023 # @ingroup l2_modif_smooth
3024 def SmoothObject(self, theObject, IDsOfFixedNodes,
3025 MaxNbOfIterations, MaxAspectRatio, Method):
3026 if ( isinstance( theObject, Mesh )):
3027 theObject = theObject.GetMesh()
3028 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3029 MaxNbOfIterations, MaxAspectRatio, Method)
3031 ## Parametrically smoothes the given elements
3032 # @param IDsOfElements the list if ids of elements to smooth
3033 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3034 # Note that nodes built on edges and boundary nodes are always fixed.
3035 # @param MaxNbOfIterations the maximum number of iterations
3036 # @param MaxAspectRatio varies in range [1.0, inf]
3037 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3038 # @return TRUE in case of success, FALSE otherwise.
3039 # @ingroup l2_modif_smooth
3040 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3041 MaxNbOfIterations, MaxAspectRatio, Method):
3042 if IDsOfElements == []:
3043 IDsOfElements = self.GetElementsId()
3044 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3045 self.mesh.SetParameters(Parameters)
3046 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3047 MaxNbOfIterations, MaxAspectRatio, Method)
3049 ## Parametrically smoothes the elements which belong to the given object
3050 # @param theObject the object to smooth
3051 # @param IDsOfFixedNodes the list of ids of fixed nodes.
3052 # Note that nodes built on edges and boundary nodes are always fixed.
3053 # @param MaxNbOfIterations the maximum number of iterations
3054 # @param MaxAspectRatio varies in range [1.0, inf]
3055 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
3056 # @return TRUE in case of success, FALSE otherwise.
3057 # @ingroup l2_modif_smooth
3058 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3059 MaxNbOfIterations, MaxAspectRatio, Method):
3060 if ( isinstance( theObject, Mesh )):
3061 theObject = theObject.GetMesh()
3062 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3063 MaxNbOfIterations, MaxAspectRatio, Method)
3065 ## Converts the mesh to quadratic, deletes old elements, replacing
3066 # them with quadratic with the same id.
3067 # @param theForce3d new node creation method:
3068 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
3069 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
3070 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3071 # @ingroup l2_modif_tofromqu
3072 def ConvertToQuadratic(self, theForce3d, theSubMesh=None):
3074 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3076 self.editor.ConvertToQuadratic(theForce3d)
3078 ## Converts the mesh from quadratic to ordinary,
3079 # deletes old quadratic elements, \n replacing
3080 # them with ordinary mesh elements with the same id.
3081 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3082 # @ingroup l2_modif_tofromqu
3083 def ConvertFromQuadratic(self, theSubMesh=None):
3085 self.editor.ConvertFromQuadraticObject(theSubMesh)
3087 return self.editor.ConvertFromQuadratic()
3089 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3090 # @return TRUE if operation has been completed successfully, FALSE otherwise
3091 # @ingroup l2_modif_edit
3092 def Make2DMeshFrom3D(self):
3093 return self.editor. Make2DMeshFrom3D()
3095 ## Creates missing boundary elements
3096 # @param elements - elements whose boundary is to be checked:
3097 # mesh, group, sub-mesh or list of elements
3098 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3099 # @param dimension - defines type of boundary elements to create:
3100 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3101 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3102 # @param groupName - a name of group to store created boundary elements in,
3103 # "" means not to create the group
3104 # @param meshName - a name of new mesh to store created boundary elements in,
3105 # "" means not to create the new mesh
3106 # @param toCopyElements - if true, the checked elements will be copied into
3107 # the new mesh else only boundary elements will be copied into the new mesh
3108 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3109 # boundary elements will be copied into the new mesh
3110 # @return tuple (mesh, group) where bondary elements were added to
3111 # @ingroup l2_modif_edit
3112 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3113 toCopyElements=False, toCopyExistingBondary=False):
3114 if isinstance( elements, Mesh ):
3115 elements = elements.GetMesh()
3116 if ( isinstance( elements, list )):
3117 elemType = SMESH.ALL
3118 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3119 elements = self.editor.MakeIDSource(elements, elemType)
3120 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3121 toCopyElements,toCopyExistingBondary)
3122 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3126 # @brief Creates missing boundary elements around either the whole mesh or
3127 # groups of 2D elements
3128 # @param dimension - defines type of boundary elements to create
3129 # @param groupName - a name of group to store all boundary elements in,
3130 # "" means not to create the group
3131 # @param meshName - a name of a new mesh, which is a copy of the initial
3132 # mesh + created boundary elements; "" means not to create the new mesh
3133 # @param toCopyAll - if true, the whole initial mesh will be copied into
3134 # the new mesh else only boundary elements will be copied into the new mesh
3135 # @param groups - groups of 2D elements to make boundary around
3136 # @retval tuple( long, mesh, groups )
3137 # long - number of added boundary elements
3138 # mesh - the mesh where elements were added to
3139 # group - the group of boundary elements or None
3141 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3142 toCopyAll=False, groups=[]):
3143 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3145 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3146 return nb, mesh, group
3148 ## Renumber mesh nodes
3149 # @ingroup l2_modif_renumber
3150 def RenumberNodes(self):
3151 self.editor.RenumberNodes()
3153 ## Renumber mesh elements
3154 # @ingroup l2_modif_renumber
3155 def RenumberElements(self):
3156 self.editor.RenumberElements()
3158 ## Generates new elements by rotation of the elements around the axis
3159 # @param IDsOfElements the list of ids of elements to sweep
3160 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3161 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3162 # @param NbOfSteps the number of steps
3163 # @param Tolerance tolerance
3164 # @param MakeGroups forces the generation of new groups from existing ones
3165 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3166 # of all steps, else - size of each step
3167 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3168 # @ingroup l2_modif_extrurev
3169 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3170 MakeGroups=False, TotalAngle=False):
3171 if IDsOfElements == []:
3172 IDsOfElements = self.GetElementsId()
3173 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3174 Axis = self.smeshpyD.GetAxisStruct(Axis)
3175 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3176 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3177 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3178 self.mesh.SetParameters(Parameters)
3179 if TotalAngle and NbOfSteps:
3180 AngleInRadians /= NbOfSteps
3182 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3183 AngleInRadians, NbOfSteps, Tolerance)
3184 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3187 ## Generates new elements by rotation of the elements of object around the axis
3188 # @param theObject object which elements should be sweeped.
3189 # It can be a mesh, a sub mesh or a group.
3190 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3191 # @param AngleInRadians the angle of Rotation
3192 # @param NbOfSteps number of steps
3193 # @param Tolerance tolerance
3194 # @param MakeGroups forces the generation of new groups from existing ones
3195 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3196 # of all steps, else - size of each step
3197 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3198 # @ingroup l2_modif_extrurev
3199 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3200 MakeGroups=False, TotalAngle=False):
3201 if ( isinstance( theObject, Mesh )):
3202 theObject = theObject.GetMesh()
3203 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3204 Axis = self.smeshpyD.GetAxisStruct(Axis)
3205 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3206 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3207 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3208 self.mesh.SetParameters(Parameters)
3209 if TotalAngle and NbOfSteps:
3210 AngleInRadians /= NbOfSteps
3212 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3213 NbOfSteps, Tolerance)
3214 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3217 ## Generates new elements by rotation of the elements of object around the axis
3218 # @param theObject object which elements should be sweeped.
3219 # It can be a mesh, a sub mesh or a group.
3220 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3221 # @param AngleInRadians the angle of Rotation
3222 # @param NbOfSteps number of steps
3223 # @param Tolerance tolerance
3224 # @param MakeGroups forces the generation of new groups from existing ones
3225 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3226 # of all steps, else - size of each step
3227 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3228 # @ingroup l2_modif_extrurev
3229 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3230 MakeGroups=False, TotalAngle=False):
3231 if ( isinstance( theObject, Mesh )):
3232 theObject = theObject.GetMesh()
3233 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3234 Axis = self.smeshpyD.GetAxisStruct(Axis)
3235 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3236 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3237 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3238 self.mesh.SetParameters(Parameters)
3239 if TotalAngle and NbOfSteps:
3240 AngleInRadians /= NbOfSteps
3242 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3243 NbOfSteps, Tolerance)
3244 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3247 ## Generates new elements by rotation of the elements of object around the axis
3248 # @param theObject object which elements should be sweeped.
3249 # It can be a mesh, a sub mesh or a group.
3250 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3251 # @param AngleInRadians the angle of Rotation
3252 # @param NbOfSteps number of steps
3253 # @param Tolerance tolerance
3254 # @param MakeGroups forces the generation of new groups from existing ones
3255 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3256 # of all steps, else - size of each step
3257 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3258 # @ingroup l2_modif_extrurev
3259 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3260 MakeGroups=False, TotalAngle=False):
3261 if ( isinstance( theObject, Mesh )):
3262 theObject = theObject.GetMesh()
3263 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3264 Axis = self.smeshpyD.GetAxisStruct(Axis)
3265 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3266 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3267 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3268 self.mesh.SetParameters(Parameters)
3269 if TotalAngle and NbOfSteps:
3270 AngleInRadians /= NbOfSteps
3272 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3273 NbOfSteps, Tolerance)
3274 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3277 ## Generates new elements by extrusion of the elements with given ids
3278 # @param IDsOfElements the list of elements ids for extrusion
3279 # @param StepVector vector or DirStruct or 3 vector components, defining
3280 # the direction and value of extrusion for one step (the total extrusion
3281 # length will be NbOfSteps * ||StepVector||)
3282 # @param NbOfSteps the number of steps
3283 # @param MakeGroups forces the generation of new groups from existing ones
3284 # @param IsNodes is True if elements with given ids are nodes
3285 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3286 # @ingroup l2_modif_extrurev
3287 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3288 if IDsOfElements == []:
3289 IDsOfElements = self.GetElementsId()
3290 if isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object):
3291 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3292 if isinstance( StepVector, list ):
3293 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3294 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3295 Parameters = StepVector.PS.parameters + var_separator + Parameters
3296 self.mesh.SetParameters(Parameters)
3299 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3301 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3303 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3305 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3308 ## Generates new elements by extrusion of the elements with given ids
3309 # @param IDsOfElements is ids of elements
3310 # @param StepVector vector or DirStruct or 3 vector components, defining
3311 # the direction and value of extrusion for one step (the total extrusion
3312 # length will be NbOfSteps * ||StepVector||)
3313 # @param NbOfSteps the number of steps
3314 # @param ExtrFlags sets flags for extrusion
3315 # @param SewTolerance uses for comparing locations of nodes if flag
3316 # EXTRUSION_FLAG_SEW is set
3317 # @param MakeGroups forces the generation of new groups from existing ones
3318 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3319 # @ingroup l2_modif_extrurev
3320 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3321 ExtrFlags, SewTolerance, MakeGroups=False):
3322 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3323 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3324 if isinstance( StepVector, list ):
3325 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3327 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3328 ExtrFlags, SewTolerance)
3329 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3330 ExtrFlags, SewTolerance)
3333 ## Generates new elements by extrusion of the elements which belong to the object
3334 # @param theObject the object which elements should be processed.
3335 # It can be a mesh, a sub mesh or a group.
3336 # @param StepVector vector or DirStruct or 3 vector components, defining
3337 # the direction and value of extrusion for one step (the total extrusion
3338 # length will be NbOfSteps * ||StepVector||)
3339 # @param NbOfSteps the number of steps
3340 # @param MakeGroups forces the generation of new groups from existing ones
3341 # @param IsNodes is True if elements which belong to the object are nodes
3342 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3343 # @ingroup l2_modif_extrurev
3344 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3345 if ( isinstance( theObject, Mesh )):
3346 theObject = theObject.GetMesh()
3347 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3348 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3349 if isinstance( StepVector, list ):
3350 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3351 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3352 Parameters = StepVector.PS.parameters + var_separator + Parameters
3353 self.mesh.SetParameters(Parameters)
3356 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3358 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3360 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3362 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3365 ## Generates new elements by extrusion of the elements which belong to the object
3366 # @param theObject object which elements should be processed.
3367 # It can be a mesh, a sub mesh or a group.
3368 # @param StepVector vector or DirStruct or 3 vector components, defining
3369 # the direction and value of extrusion for one step (the total extrusion
3370 # length will be NbOfSteps * ||StepVector||)
3371 # @param NbOfSteps the number of steps
3372 # @param MakeGroups to generate new groups from existing ones
3373 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3374 # @ingroup l2_modif_extrurev
3375 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3376 if ( isinstance( theObject, Mesh )):
3377 theObject = theObject.GetMesh()
3378 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3379 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3380 if isinstance( StepVector, list ):
3381 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3382 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3383 Parameters = StepVector.PS.parameters + var_separator + Parameters
3384 self.mesh.SetParameters(Parameters)
3386 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3387 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3390 ## Generates new elements by extrusion of the elements which belong to the object
3391 # @param theObject object which elements should be processed.
3392 # It can be a mesh, a sub mesh or a group.
3393 # @param StepVector vector or DirStruct or 3 vector components, defining
3394 # the direction and value of extrusion for one step (the total extrusion
3395 # length will be NbOfSteps * ||StepVector||)
3396 # @param NbOfSteps the number of steps
3397 # @param MakeGroups forces the generation of new groups from existing ones
3398 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3399 # @ingroup l2_modif_extrurev
3400 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3401 if ( isinstance( theObject, Mesh )):
3402 theObject = theObject.GetMesh()
3403 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3404 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3405 if isinstance( StepVector, list ):
3406 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3407 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3408 Parameters = StepVector.PS.parameters + var_separator + Parameters
3409 self.mesh.SetParameters(Parameters)
3411 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3412 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3417 ## Generates new elements by extrusion of the given elements
3418 # The path of extrusion must be a meshed edge.
3419 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3420 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3421 # @param NodeStart the start node from Path. Defines the direction of extrusion
3422 # @param HasAngles allows the shape to be rotated around the path
3423 # to get the resulting mesh in a helical fashion
3424 # @param Angles list of angles in radians
3425 # @param LinearVariation forces the computation of rotation angles as linear
3426 # variation of the given Angles along path steps
3427 # @param HasRefPoint allows using the reference point
3428 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3429 # The User can specify any point as the Reference Point.
3430 # @param MakeGroups forces the generation of new groups from existing ones
3431 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3432 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3433 # only SMESH::Extrusion_Error otherwise
3434 # @ingroup l2_modif_extrurev
3435 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3436 HasAngles, Angles, LinearVariation,
3437 HasRefPoint, RefPoint, MakeGroups, ElemType):
3438 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3439 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3441 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3442 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3443 self.mesh.SetParameters(Parameters)
3445 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3447 if isinstance(Base, list):
3449 if Base == []: IDsOfElements = self.GetElementsId()
3450 else: IDsOfElements = Base
3451 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3452 HasAngles, Angles, LinearVariation,
3453 HasRefPoint, RefPoint, MakeGroups, ElemType)
3455 if isinstance(Base, Mesh): Base = Base.GetMesh()
3456 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3457 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3458 HasAngles, Angles, LinearVariation,
3459 HasRefPoint, RefPoint, MakeGroups, ElemType)
3461 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3464 ## Generates new elements by extrusion of the given elements
3465 # The path of extrusion must be a meshed edge.
3466 # @param IDsOfElements ids of elements
3467 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3468 # @param PathShape shape(edge) defines the sub-mesh for the path
3469 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3470 # @param HasAngles allows the shape to be rotated around the path
3471 # to get the resulting mesh in a helical fashion
3472 # @param Angles list of angles in radians
3473 # @param HasRefPoint allows using the reference point
3474 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3475 # The User can specify any point as the Reference Point.
3476 # @param MakeGroups forces the generation of new groups from existing ones
3477 # @param LinearVariation forces the computation of rotation angles as linear
3478 # variation of the given Angles along path steps
3479 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3480 # only SMESH::Extrusion_Error otherwise
3481 # @ingroup l2_modif_extrurev
3482 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3483 HasAngles, Angles, HasRefPoint, RefPoint,
3484 MakeGroups=False, LinearVariation=False):
3485 if IDsOfElements == []:
3486 IDsOfElements = self.GetElementsId()
3487 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3488 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3490 if ( isinstance( PathMesh, Mesh )):
3491 PathMesh = PathMesh.GetMesh()
3492 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3493 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3494 self.mesh.SetParameters(Parameters)
3495 if HasAngles and Angles and LinearVariation:
3496 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3499 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3500 PathShape, NodeStart, HasAngles,
3501 Angles, HasRefPoint, RefPoint)
3502 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3503 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3505 ## Generates new elements by extrusion of the elements which belong to the object
3506 # The path of extrusion must be a meshed edge.
3507 # @param theObject the object which elements should be processed.
3508 # It can be a mesh, a sub mesh or a group.
3509 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3510 # @param PathShape shape(edge) defines the sub-mesh for the path
3511 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3512 # @param HasAngles allows the shape to be rotated around the path
3513 # to get the resulting mesh in a helical fashion
3514 # @param Angles list of angles
3515 # @param HasRefPoint allows using the reference point
3516 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3517 # The User can specify any point as the Reference Point.
3518 # @param MakeGroups forces the generation of new groups from existing ones
3519 # @param LinearVariation forces the computation of rotation angles as linear
3520 # variation of the given Angles along path steps
3521 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3522 # only SMESH::Extrusion_Error otherwise
3523 # @ingroup l2_modif_extrurev
3524 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3525 HasAngles, Angles, HasRefPoint, RefPoint,
3526 MakeGroups=False, LinearVariation=False):
3527 if ( isinstance( theObject, Mesh )):
3528 theObject = theObject.GetMesh()
3529 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3530 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3531 if ( isinstance( PathMesh, Mesh )):
3532 PathMesh = PathMesh.GetMesh()
3533 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3534 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3535 self.mesh.SetParameters(Parameters)
3536 if HasAngles and Angles and LinearVariation:
3537 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3540 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3541 PathShape, NodeStart, HasAngles,
3542 Angles, HasRefPoint, RefPoint)
3543 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3544 NodeStart, HasAngles, Angles, HasRefPoint,
3547 ## Generates new elements by extrusion of the elements which belong to the object
3548 # The path of extrusion must be a meshed edge.
3549 # @param theObject the object which elements should be processed.
3550 # It can be a mesh, a sub mesh or a group.
3551 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3552 # @param PathShape shape(edge) defines the sub-mesh for the path
3553 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3554 # @param HasAngles allows the shape to be rotated around the path
3555 # to get the resulting mesh in a helical fashion
3556 # @param Angles list of angles
3557 # @param HasRefPoint allows using the reference point
3558 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3559 # The User can specify any point as the Reference Point.
3560 # @param MakeGroups forces the generation of new groups from existing ones
3561 # @param LinearVariation forces the computation of rotation angles as linear
3562 # variation of the given Angles along path steps
3563 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3564 # only SMESH::Extrusion_Error otherwise
3565 # @ingroup l2_modif_extrurev
3566 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3567 HasAngles, Angles, HasRefPoint, RefPoint,
3568 MakeGroups=False, LinearVariation=False):
3569 if ( isinstance( theObject, Mesh )):
3570 theObject = theObject.GetMesh()
3571 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3572 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3573 if ( isinstance( PathMesh, Mesh )):
3574 PathMesh = PathMesh.GetMesh()
3575 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3576 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3577 self.mesh.SetParameters(Parameters)
3578 if HasAngles and Angles and LinearVariation:
3579 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3582 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3583 PathShape, NodeStart, HasAngles,
3584 Angles, HasRefPoint, RefPoint)
3585 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3586 NodeStart, HasAngles, Angles, HasRefPoint,
3589 ## Generates new elements by extrusion of the elements which belong to the object
3590 # The path of extrusion must be a meshed edge.
3591 # @param theObject the object which elements should be processed.
3592 # It can be a mesh, a sub mesh or a group.
3593 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3594 # @param PathShape shape(edge) defines the sub-mesh for the path
3595 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3596 # @param HasAngles allows the shape to be rotated around the path
3597 # to get the resulting mesh in a helical fashion
3598 # @param Angles list of angles
3599 # @param HasRefPoint allows using the reference point
3600 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3601 # The User can specify any point as the Reference Point.
3602 # @param MakeGroups forces the generation of new groups from existing ones
3603 # @param LinearVariation forces the computation of rotation angles as linear
3604 # variation of the given Angles along path steps
3605 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3606 # only SMESH::Extrusion_Error otherwise
3607 # @ingroup l2_modif_extrurev
3608 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3609 HasAngles, Angles, HasRefPoint, RefPoint,
3610 MakeGroups=False, LinearVariation=False):
3611 if ( isinstance( theObject, Mesh )):
3612 theObject = theObject.GetMesh()
3613 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3614 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3615 if ( isinstance( PathMesh, Mesh )):
3616 PathMesh = PathMesh.GetMesh()
3617 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3618 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3619 self.mesh.SetParameters(Parameters)
3620 if HasAngles and Angles and LinearVariation:
3621 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3624 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3625 PathShape, NodeStart, HasAngles,
3626 Angles, HasRefPoint, RefPoint)
3627 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3628 NodeStart, HasAngles, Angles, HasRefPoint,
3631 ## Creates a symmetrical copy of mesh elements
3632 # @param IDsOfElements list of elements ids
3633 # @param Mirror is AxisStruct or geom object(point, line, plane)
3634 # @param theMirrorType is POINT, AXIS or PLANE
3635 # If the Mirror is a geom object this parameter is unnecessary
3636 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3637 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3638 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3639 # @ingroup l2_modif_trsf
3640 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3641 if IDsOfElements == []:
3642 IDsOfElements = self.GetElementsId()
3643 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3644 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3645 self.mesh.SetParameters(Mirror.parameters)
3646 if Copy and MakeGroups:
3647 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3648 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3651 ## Creates a new mesh by a symmetrical copy of mesh elements
3652 # @param IDsOfElements the list of elements ids
3653 # @param Mirror is AxisStruct or geom object (point, line, plane)
3654 # @param theMirrorType is POINT, AXIS or PLANE
3655 # If the Mirror is a geom object this parameter is unnecessary
3656 # @param MakeGroups to generate new groups from existing ones
3657 # @param NewMeshName a name of the new mesh to create
3658 # @return instance of Mesh class
3659 # @ingroup l2_modif_trsf
3660 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3661 if IDsOfElements == []:
3662 IDsOfElements = self.GetElementsId()
3663 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3664 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3665 self.mesh.SetParameters(Mirror.parameters)
3666 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3667 MakeGroups, NewMeshName)
3668 return Mesh(self.smeshpyD,self.geompyD,mesh)
3670 ## Creates a symmetrical copy of the object
3671 # @param theObject mesh, submesh or group
3672 # @param Mirror AxisStruct or geom object (point, line, plane)
3673 # @param theMirrorType is POINT, AXIS or PLANE
3674 # If the Mirror is a geom object this parameter is unnecessary
3675 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3676 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3677 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3678 # @ingroup l2_modif_trsf
3679 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3680 if ( isinstance( theObject, Mesh )):
3681 theObject = theObject.GetMesh()
3682 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3683 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3684 self.mesh.SetParameters(Mirror.parameters)
3685 if Copy and MakeGroups:
3686 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3687 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3690 ## Creates a new mesh by a symmetrical copy of the object
3691 # @param theObject mesh, submesh or group
3692 # @param Mirror AxisStruct or geom object (point, line, plane)
3693 # @param theMirrorType POINT, AXIS or PLANE
3694 # If the Mirror is a geom object this parameter is unnecessary
3695 # @param MakeGroups forces the generation of new groups from existing ones
3696 # @param NewMeshName the name of the new mesh to create
3697 # @return instance of Mesh class
3698 # @ingroup l2_modif_trsf
3699 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3700 if ( isinstance( theObject, Mesh )):
3701 theObject = theObject.GetMesh()
3702 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3703 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3704 self.mesh.SetParameters(Mirror.parameters)
3705 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3706 MakeGroups, NewMeshName)
3707 return Mesh( self.smeshpyD,self.geompyD,mesh )
3709 ## Translates the elements
3710 # @param IDsOfElements list of elements ids
3711 # @param Vector the direction of translation (DirStruct or vector)
3712 # @param Copy allows copying the translated elements
3713 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3714 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3715 # @ingroup l2_modif_trsf
3716 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3717 if IDsOfElements == []:
3718 IDsOfElements = self.GetElementsId()
3719 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3720 Vector = self.smeshpyD.GetDirStruct(Vector)
3721 self.mesh.SetParameters(Vector.PS.parameters)
3722 if Copy and MakeGroups:
3723 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3724 self.editor.Translate(IDsOfElements, Vector, Copy)
3727 ## Creates a new mesh of translated elements
3728 # @param IDsOfElements list of elements ids
3729 # @param Vector the direction of translation (DirStruct or vector)
3730 # @param MakeGroups forces the generation of new groups from existing ones
3731 # @param NewMeshName the name of the newly created mesh
3732 # @return instance of Mesh class
3733 # @ingroup l2_modif_trsf
3734 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
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 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3741 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3743 ## Translates the object
3744 # @param theObject the object to translate (mesh, submesh, or group)
3745 # @param Vector direction of translation (DirStruct or geom vector)
3746 # @param Copy allows copying the translated elements
3747 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3748 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3749 # @ingroup l2_modif_trsf
3750 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3751 if ( isinstance( theObject, Mesh )):
3752 theObject = theObject.GetMesh()
3753 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3754 Vector = self.smeshpyD.GetDirStruct(Vector)
3755 self.mesh.SetParameters(Vector.PS.parameters)
3756 if Copy and MakeGroups:
3757 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3758 self.editor.TranslateObject(theObject, Vector, Copy)
3761 ## Creates a new mesh from the translated object
3762 # @param theObject the object to translate (mesh, submesh, or group)
3763 # @param Vector the direction of translation (DirStruct or geom vector)
3764 # @param MakeGroups forces the generation of new groups from existing ones
3765 # @param NewMeshName the name of the newly created mesh
3766 # @return instance of Mesh class
3767 # @ingroup l2_modif_trsf
3768 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
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 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3775 return Mesh( self.smeshpyD, self.geompyD, mesh )
3779 ## Scales the object
3780 # @param theObject - the object to translate (mesh, submesh, or group)
3781 # @param thePoint - base point for scale
3782 # @param theScaleFact - list of 1-3 scale factors for axises
3783 # @param Copy - allows copying the translated elements
3784 # @param MakeGroups - forces the generation of new groups from existing
3786 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3787 # empty list otherwise
3788 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3789 if ( isinstance( theObject, Mesh )):
3790 theObject = theObject.GetMesh()
3791 if ( isinstance( theObject, list )):
3792 theObject = self.GetIDSource(theObject, SMESH.ALL)
3793 if ( isinstance( theScaleFact, float )):
3794 theScaleFact = [theScaleFact]
3795 if ( isinstance( theScaleFact, int )):
3796 theScaleFact = [ float(theScaleFact)]
3798 self.mesh.SetParameters(thePoint.parameters)
3800 if Copy and MakeGroups:
3801 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3802 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3805 ## Creates a new mesh from the translated object
3806 # @param theObject - the object to translate (mesh, submesh, or group)
3807 # @param thePoint - base point for scale
3808 # @param theScaleFact - list of 1-3 scale factors for axises
3809 # @param MakeGroups - forces the generation of new groups from existing ones
3810 # @param NewMeshName - the name of the newly created mesh
3811 # @return instance of Mesh class
3812 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3813 if (isinstance(theObject, Mesh)):
3814 theObject = theObject.GetMesh()
3815 if ( isinstance( theObject, list )):
3816 theObject = self.GetIDSource(theObject,SMESH.ALL)
3817 if ( isinstance( theScaleFact, float )):
3818 theScaleFact = [theScaleFact]
3819 if ( isinstance( theScaleFact, int )):
3820 theScaleFact = [ float(theScaleFact)]
3822 self.mesh.SetParameters(thePoint.parameters)
3823 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3824 MakeGroups, NewMeshName)
3825 return Mesh( self.smeshpyD, self.geompyD, mesh )
3829 ## Rotates the elements
3830 # @param IDsOfElements list of elements ids
3831 # @param Axis the axis of rotation (AxisStruct or geom line)
3832 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3833 # @param Copy allows copying the rotated elements
3834 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3835 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3836 # @ingroup l2_modif_trsf
3837 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3838 if IDsOfElements == []:
3839 IDsOfElements = self.GetElementsId()
3840 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3841 Axis = self.smeshpyD.GetAxisStruct(Axis)
3842 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3843 Parameters = Axis.parameters + var_separator + Parameters
3844 self.mesh.SetParameters(Parameters)
3845 if Copy and MakeGroups:
3846 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3847 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3850 ## Creates a new mesh of rotated elements
3851 # @param IDsOfElements list of element ids
3852 # @param Axis the axis of rotation (AxisStruct or geom line)
3853 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3854 # @param MakeGroups forces the generation of new groups from existing ones
3855 # @param NewMeshName the name of the newly created mesh
3856 # @return instance of Mesh class
3857 # @ingroup l2_modif_trsf
3858 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3859 if IDsOfElements == []:
3860 IDsOfElements = self.GetElementsId()
3861 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3862 Axis = self.smeshpyD.GetAxisStruct(Axis)
3863 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3864 Parameters = Axis.parameters + var_separator + Parameters
3865 self.mesh.SetParameters(Parameters)
3866 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3867 MakeGroups, NewMeshName)
3868 return Mesh( self.smeshpyD, self.geompyD, mesh )
3870 ## Rotates the object
3871 # @param theObject the object to rotate( mesh, submesh, or group)
3872 # @param Axis the axis of rotation (AxisStruct or geom line)
3873 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3874 # @param Copy allows copying the rotated elements
3875 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3876 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3877 # @ingroup l2_modif_trsf
3878 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3879 if (isinstance(theObject, Mesh)):
3880 theObject = theObject.GetMesh()
3881 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3882 Axis = self.smeshpyD.GetAxisStruct(Axis)
3883 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3884 Parameters = Axis.parameters + ":" + Parameters
3885 self.mesh.SetParameters(Parameters)
3886 if Copy and MakeGroups:
3887 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3888 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3891 ## Creates a new mesh from the rotated object
3892 # @param theObject the object to rotate (mesh, submesh, or group)
3893 # @param Axis the axis of rotation (AxisStruct or geom line)
3894 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3895 # @param MakeGroups forces the generation of new groups from existing ones
3896 # @param NewMeshName the name of the newly created mesh
3897 # @return instance of Mesh class
3898 # @ingroup l2_modif_trsf
3899 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3900 if (isinstance( theObject, Mesh )):
3901 theObject = theObject.GetMesh()
3902 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3903 Axis = self.smeshpyD.GetAxisStruct(Axis)
3904 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3905 Parameters = Axis.parameters + ":" + Parameters
3906 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3907 MakeGroups, NewMeshName)
3908 self.mesh.SetParameters(Parameters)
3909 return Mesh( self.smeshpyD, self.geompyD, mesh )
3911 ## Finds groups of ajacent nodes within Tolerance.
3912 # @param Tolerance the value of tolerance
3913 # @return the list of groups of nodes
3914 # @ingroup l2_modif_trsf
3915 def FindCoincidentNodes (self, Tolerance):
3916 return self.editor.FindCoincidentNodes(Tolerance)
3918 ## Finds groups of ajacent nodes within Tolerance.
3919 # @param Tolerance the value of tolerance
3920 # @param SubMeshOrGroup SubMesh or Group
3921 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3922 # @return the list of groups of nodes
3923 # @ingroup l2_modif_trsf
3924 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3925 if (isinstance( SubMeshOrGroup, Mesh )):
3926 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3927 if not isinstance( exceptNodes, list):
3928 exceptNodes = [ exceptNodes ]
3929 if exceptNodes and isinstance( exceptNodes[0], int):
3930 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3931 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3934 # @param GroupsOfNodes the list of groups of nodes
3935 # @ingroup l2_modif_trsf
3936 def MergeNodes (self, GroupsOfNodes):
3937 self.editor.MergeNodes(GroupsOfNodes)
3939 ## Finds the elements built on the same nodes.
3940 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3941 # @return a list of groups of equal elements
3942 # @ingroup l2_modif_trsf
3943 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3944 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
3945 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
3946 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3948 ## Merges elements in each given group.
3949 # @param GroupsOfElementsID groups of elements for merging
3950 # @ingroup l2_modif_trsf
3951 def MergeElements(self, GroupsOfElementsID):
3952 self.editor.MergeElements(GroupsOfElementsID)
3954 ## Leaves one element and removes all other elements built on the same nodes.
3955 # @ingroup l2_modif_trsf
3956 def MergeEqualElements(self):
3957 self.editor.MergeEqualElements()
3959 ## Sews free borders
3960 # @return SMESH::Sew_Error
3961 # @ingroup l2_modif_trsf
3962 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3963 FirstNodeID2, SecondNodeID2, LastNodeID2,
3964 CreatePolygons, CreatePolyedrs):
3965 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3966 FirstNodeID2, SecondNodeID2, LastNodeID2,
3967 CreatePolygons, CreatePolyedrs)
3969 ## Sews conform free borders
3970 # @return SMESH::Sew_Error
3971 # @ingroup l2_modif_trsf
3972 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3973 FirstNodeID2, SecondNodeID2):
3974 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3975 FirstNodeID2, SecondNodeID2)
3977 ## Sews border to side
3978 # @return SMESH::Sew_Error
3979 # @ingroup l2_modif_trsf
3980 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3981 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3982 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3983 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3985 ## Sews two sides of a mesh. The nodes belonging to Side1 are
3986 # merged with the nodes of elements of Side2.
3987 # The number of elements in theSide1 and in theSide2 must be
3988 # equal and they should have similar nodal connectivity.
3989 # The nodes to merge should belong to side borders and
3990 # the first node should be linked to the second.
3991 # @return SMESH::Sew_Error
3992 # @ingroup l2_modif_trsf
3993 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3994 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3995 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3996 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3997 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3998 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4000 ## Sets new nodes for the given element.
4001 # @param ide the element id
4002 # @param newIDs nodes ids
4003 # @return If the number of nodes does not correspond to the type of element - returns false
4004 # @ingroup l2_modif_edit
4005 def ChangeElemNodes(self, ide, newIDs):
4006 return self.editor.ChangeElemNodes(ide, newIDs)
4008 ## If during the last operation of MeshEditor some nodes were
4009 # created, this method returns the list of their IDs, \n
4010 # if new nodes were not created - returns empty list
4011 # @return the list of integer values (can be empty)
4012 # @ingroup l1_auxiliary
4013 def GetLastCreatedNodes(self):
4014 return self.editor.GetLastCreatedNodes()
4016 ## If during the last operation of MeshEditor some elements were
4017 # created this method returns the list of their IDs, \n
4018 # if new elements were not created - returns empty list
4019 # @return the list of integer values (can be empty)
4020 # @ingroup l1_auxiliary
4021 def GetLastCreatedElems(self):
4022 return self.editor.GetLastCreatedElems()
4024 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4025 # @param theNodes identifiers of nodes to be doubled
4026 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4027 # nodes. If list of element identifiers is empty then nodes are doubled but
4028 # they not assigned to elements
4029 # @return TRUE if operation has been completed successfully, FALSE otherwise
4030 # @ingroup l2_modif_edit
4031 def DoubleNodes(self, theNodes, theModifiedElems):
4032 return self.editor.DoubleNodes(theNodes, theModifiedElems)
4034 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4035 # This method provided for convenience works as DoubleNodes() described above.
4036 # @param theNodeId identifiers of node to be doubled
4037 # @param theModifiedElems identifiers of elements to be updated
4038 # @return TRUE if operation has been completed successfully, FALSE otherwise
4039 # @ingroup l2_modif_edit
4040 def DoubleNode(self, theNodeId, theModifiedElems):
4041 return self.editor.DoubleNode(theNodeId, theModifiedElems)
4043 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4044 # This method provided for convenience works as DoubleNodes() described above.
4045 # @param theNodes group of nodes to be doubled
4046 # @param theModifiedElems group of elements to be updated.
4047 # @param theMakeGroup forces the generation of a group containing new nodes.
4048 # @return TRUE or a created group if operation has been completed successfully,
4049 # FALSE or None otherwise
4050 # @ingroup l2_modif_edit
4051 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4053 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4054 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4056 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4057 # This method provided for convenience works as DoubleNodes() described above.
4058 # @param theNodes list of groups of nodes to be doubled
4059 # @param theModifiedElems list of groups of elements to be updated.
4060 # @param theMakeGroup forces the generation of a group containing new nodes.
4061 # @return TRUE if operation has been completed successfully, FALSE otherwise
4062 # @ingroup l2_modif_edit
4063 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4065 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4066 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4068 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4069 # @param theElems - the list of elements (edges or faces) to be replicated
4070 # The nodes for duplication could be found from these elements
4071 # @param theNodesNot - list of nodes to NOT replicate
4072 # @param theAffectedElems - the list of elements (cells and edges) to which the
4073 # replicated nodes should be associated to.
4074 # @return TRUE if operation has been completed successfully, FALSE otherwise
4075 # @ingroup l2_modif_edit
4076 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4077 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4079 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4080 # @param theElems - the list of elements (edges or faces) to be replicated
4081 # The nodes for duplication could be found from these elements
4082 # @param theNodesNot - list of nodes to NOT replicate
4083 # @param theShape - shape to detect affected elements (element which geometric center
4084 # located on or inside shape).
4085 # The replicated nodes should be associated to affected elements.
4086 # @return TRUE if operation has been completed successfully, FALSE otherwise
4087 # @ingroup l2_modif_edit
4088 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4089 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4091 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4092 # This method provided for convenience works as DoubleNodes() described above.
4093 # @param theElems - group of of elements (edges or faces) to be replicated
4094 # @param theNodesNot - group of nodes not to replicated
4095 # @param theAffectedElems - group of elements to which the replicated nodes
4096 # should be associated to.
4097 # @param theMakeGroup forces the generation of a group containing new elements.
4098 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4099 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4100 # FALSE or None otherwise
4101 # @ingroup l2_modif_edit
4102 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4103 theMakeGroup=False, theMakeNodeGroup=False):
4104 if theMakeGroup or theMakeNodeGroup:
4105 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4107 theMakeGroup, theMakeNodeGroup)
4108 if theMakeGroup and theMakeNodeGroup:
4111 return twoGroups[ int(theMakeNodeGroup) ]
4112 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4114 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4115 # This method provided for convenience works as DoubleNodes() described above.
4116 # @param theElems - group of of elements (edges or faces) to be replicated
4117 # @param theNodesNot - group of nodes not to replicated
4118 # @param theShape - shape to detect affected elements (element which geometric center
4119 # located on or inside shape).
4120 # The replicated nodes should be associated to affected elements.
4121 # @ingroup l2_modif_edit
4122 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4123 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4125 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4126 # This method provided for convenience works as DoubleNodes() described above.
4127 # @param theElems - list of groups of elements (edges or faces) to be replicated
4128 # @param theNodesNot - list of groups of nodes not to replicated
4129 # @param theAffectedElems - group of elements to which the replicated nodes
4130 # should be associated to.
4131 # @param theMakeGroup forces the generation of a group containing new elements.
4132 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4133 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4134 # FALSE or None otherwise
4135 # @ingroup l2_modif_edit
4136 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4137 theMakeGroup=False, theMakeNodeGroup=False):
4138 if theMakeGroup or theMakeNodeGroup:
4139 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4141 theMakeGroup, theMakeNodeGroup)
4142 if theMakeGroup and theMakeNodeGroup:
4145 return twoGroups[ int(theMakeNodeGroup) ]
4146 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4148 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4149 # This method provided for convenience works as DoubleNodes() described above.
4150 # @param theElems - list of groups of elements (edges or faces) to be replicated
4151 # @param theNodesNot - list of groups of nodes not to replicated
4152 # @param theShape - shape to detect affected elements (element which geometric center
4153 # located on or inside shape).
4154 # The replicated nodes should be associated to affected elements.
4155 # @return TRUE if operation has been completed successfully, FALSE otherwise
4156 # @ingroup l2_modif_edit
4157 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4158 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4160 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4161 # This method is the first step of DoubleNodeElemGroupsInRegion.
4162 # @param theElems - list of groups of elements (edges or faces) to be replicated
4163 # @param theNodesNot - list of groups of nodes not to replicated
4164 # @param theShape - shape to detect affected elements (element which geometric center
4165 # located on or inside shape).
4166 # The replicated nodes should be associated to affected elements.
4167 # @return groups of affected elements
4168 # @ingroup l2_modif_edit
4169 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4170 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4172 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4173 # The list of groups must describe a partition of the mesh volumes.
4174 # The nodes of the internal faces at the boundaries of the groups are doubled.
4175 # In option, the internal faces are replaced by flat elements.
4176 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4177 # @param theDomains - list of groups of volumes
4178 # @param createJointElems - if TRUE, create the elements
4179 # @return TRUE if operation has been completed successfully, FALSE otherwise
4180 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4181 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4183 ## Double nodes on some external faces and create flat elements.
4184 # Flat elements are mainly used by some types of mechanic calculations.
4186 # Each group of the list must be constituted of faces.
4187 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4188 # @param theGroupsOfFaces - list of groups of faces
4189 # @return TRUE if operation has been completed successfully, FALSE otherwise
4190 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4191 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4193 ## identify all the elements around a geom shape, get the faces delimiting the hole
4195 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4196 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4198 def _getFunctor(self, funcType ):
4199 fn = self.functors[ funcType._v ]
4201 fn = self.smeshpyD.GetFunctor(funcType)
4202 fn.SetMesh(self.mesh)
4203 self.functors[ funcType._v ] = fn
4206 def _valueFromFunctor(self, funcType, elemId):
4207 fn = self._getFunctor( funcType )
4208 if fn.GetElementType() == self.GetElementType(elemId, True):
4209 val = fn.GetValue(elemId)
4214 ## Get length of 1D element.
4215 # @param elemId mesh element ID
4216 # @return element's length value
4217 # @ingroup l1_measurements
4218 def GetLength(self, elemId):
4219 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4221 ## Get area of 2D element.
4222 # @param elemId mesh element ID
4223 # @return element's area value
4224 # @ingroup l1_measurements
4225 def GetArea(self, elemId):
4226 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4228 ## Get volume of 3D element.
4229 # @param elemId mesh element ID
4230 # @return element's volume value
4231 # @ingroup l1_measurements
4232 def GetVolume(self, elemId):
4233 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4235 ## Get maximum element length.
4236 # @param elemId mesh element ID
4237 # @return element's maximum length value
4238 # @ingroup l1_measurements
4239 def GetMaxElementLength(self, elemId):
4240 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4241 ftype = SMESH.FT_MaxElementLength3D
4243 ftype = SMESH.FT_MaxElementLength2D
4244 return self._valueFromFunctor(ftype, elemId)
4246 ## Get aspect ratio of 2D or 3D element.
4247 # @param elemId mesh element ID
4248 # @return element's aspect ratio value
4249 # @ingroup l1_measurements
4250 def GetAspectRatio(self, elemId):
4251 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4252 ftype = SMESH.FT_AspectRatio3D
4254 ftype = SMESH.FT_AspectRatio
4255 return self._valueFromFunctor(ftype, elemId)
4257 ## Get warping angle of 2D element.
4258 # @param elemId mesh element ID
4259 # @return element's warping angle value
4260 # @ingroup l1_measurements
4261 def GetWarping(self, elemId):
4262 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4264 ## Get minimum angle of 2D element.
4265 # @param elemId mesh element ID
4266 # @return element's minimum angle value
4267 # @ingroup l1_measurements
4268 def GetMinimumAngle(self, elemId):
4269 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4271 ## Get taper of 2D element.
4272 # @param elemId mesh element ID
4273 # @return element's taper value
4274 # @ingroup l1_measurements
4275 def GetTaper(self, elemId):
4276 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4278 ## Get skew of 2D element.
4279 # @param elemId mesh element ID
4280 # @return element's skew value
4281 # @ingroup l1_measurements
4282 def GetSkew(self, elemId):
4283 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4285 pass # end of Mesh class
4287 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4289 class Pattern(SMESH._objref_SMESH_Pattern):
4291 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4292 decrFun = lambda i: i-1
4293 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4294 theMesh.SetParameters(Parameters)
4295 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4297 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4298 decrFun = lambda i: i-1
4299 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4300 theMesh.SetParameters(Parameters)
4301 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4303 # Registering the new proxy for Pattern
4304 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4306 ## Private class used to bind methods creating algorithms to the class Mesh
4311 self.defaultAlgoType = ""
4312 self.algoTypeToClass = {}
4314 # Stores a python class of algorithm
4315 def add(self, algoClass):
4316 if type( algoClass ).__name__ == 'classobj' and \
4317 hasattr( algoClass, "algoType"):
4318 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4319 if not self.defaultAlgoType and \
4320 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4321 self.defaultAlgoType = algoClass.algoType
4322 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4324 # creates a copy of self and assign mesh to the copy
4325 def copy(self, mesh):
4326 other = algoCreator()
4327 other.defaultAlgoType = self.defaultAlgoType
4328 other.algoTypeToClass = self.algoTypeToClass
4332 # creates an instance of algorithm
4333 def __call__(self,algo="",geom=0,*args):
4334 algoType = self.defaultAlgoType
4335 for arg in args + (algo,geom):
4336 if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ):
4338 if isinstance( arg, str ) and arg:
4340 if not algoType and self.algoTypeToClass:
4341 algoType = self.algoTypeToClass.keys()[0]
4342 if self.algoTypeToClass.has_key( algoType ):
4343 #print "Create algo",algoType
4344 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4345 raise RuntimeError, "No class found for algo type %s" % algoType
4348 # Private class used to substitute and store variable parameters of hypotheses.
4350 class hypMethodWrapper:
4351 def __init__(self, hyp, method):
4353 self.method = method
4354 #print "REBIND:", method.__name__
4357 # call a method of hypothesis with calling SetVarParameter() before
4358 def __call__(self,*args):
4360 return self.method( self.hyp, *args ) # hypothesis method with no args
4362 #print "MethWrapper.__call__",self.method.__name__, args
4364 parsed = ParseParameters(*args) # replace variables with their values
4365 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4366 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4367 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4368 # maybe there is a replaced string arg which is not variable
4369 result = self.method( self.hyp, *args )
4370 except ValueError, detail: # raised by ParseParameters()
4372 result = self.method( self.hyp, *args )
4373 except omniORB.CORBA.BAD_PARAM:
4374 raise ValueError, detail # wrong variable name
4378 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
4380 print "pluginName: ", pluginName
4383 exec( "from %s import *" % pluginName )
4384 except Exception, e:
4385 print "Exception while loading %s: %s" % ( pluginName, e )
4387 exec( "import %s" % pluginName )
4388 plugin = eval( pluginName )
4389 print " plugin:" , str(plugin)
4391 # add methods creating algorithms to Mesh
4392 for k in dir( plugin ):
4393 if k[0] == '_': continue
4394 algo = getattr( plugin, k )
4395 print " algo:", str(algo)
4396 if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
4397 print " meshMethod:" , str(algo.meshMethod)
4398 if not hasattr( Mesh, algo.meshMethod ):
4399 setattr( Mesh, algo.meshMethod, algoCreator() )
4401 getattr( Mesh, algo.meshMethod ).add( algo )