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
95 ## @addtogroup l1_auxiliary
98 # MirrorType enumeration
99 POINT = SMESH_MeshEditor.POINT
100 AXIS = SMESH_MeshEditor.AXIS
101 PLANE = SMESH_MeshEditor.PLANE
103 # Smooth_Method enumeration
104 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
105 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
107 PrecisionConfusion = 1e-07
109 # TopAbs_State enumeration
110 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
112 # Methods of splitting a hexahedron into tetrahedra
113 Hex_5Tet, Hex_6Tet, Hex_24Tet = 1, 2, 3
115 ## Converts an angle from degrees to radians
116 def DegreesToRadians(AngleInDegrees):
118 return AngleInDegrees * pi / 180.0
120 import salome_notebook
121 notebook = salome_notebook.notebook
122 # Salome notebook variable separator
125 ## Return list of variable values from salome notebook.
126 # The last argument, if is callable, is used to modify values got from notebook
127 def ParseParameters(*args):
132 if args and callable( args[-1] ):
133 args, varModifFun = args[:-1], args[-1]
134 for parameter in args:
136 Parameters += str(parameter) + var_separator
138 if isinstance(parameter,str):
139 # check if there is an inexistent variable name
140 if not notebook.isVariable(parameter):
141 raise ValueError, "Variable with name '" + parameter + "' doesn't exist!!!"
142 parameter = notebook.get(parameter)
145 parameter = varModifFun(parameter)
148 Result.append(parameter)
151 Parameters = Parameters[:-1]
152 Result.append( Parameters )
153 Result.append( hasVariables )
156 # Parse parameters converting variables to radians
157 def ParseAngles(*args):
158 return ParseParameters( *( args + (DegreesToRadians, )))
160 # Substitute PointStruct.__init__() to create SMESH.PointStruct using notebook variables.
161 # Parameters are stored in PointStruct.parameters attribute
162 def __initPointStruct(point,*args):
163 point.x, point.y, point.z, point.parameters,hasVars = ParseParameters(*args)
165 SMESH.PointStruct.__init__ = __initPointStruct
167 # Substitute AxisStruct.__init__() to create SMESH.AxisStruct using notebook variables.
168 # Parameters are stored in AxisStruct.parameters attribute
169 def __initAxisStruct(ax,*args):
170 ax.x, ax.y, ax.z, ax.vx, ax.vy, ax.vz, ax.parameters,hasVars = ParseParameters(*args)
172 SMESH.AxisStruct.__init__ = __initAxisStruct
175 def IsEqual(val1, val2, tol=PrecisionConfusion):
176 if abs(val1 - val2) < tol:
186 if isinstance(obj, SALOMEDS._objref_SObject):
189 ior = salome.orb.object_to_string(obj)
192 studies = salome.myStudyManager.GetOpenStudies()
193 for sname in studies:
194 s = salome.myStudyManager.GetStudyByName(sname)
196 sobj = s.FindObjectIOR(ior)
197 if not sobj: continue
198 return sobj.GetName()
199 if hasattr(obj, "GetName"):
200 # unknown CORBA object, having GetName() method
203 # unknown CORBA object, no GetName() method
206 if hasattr(obj, "GetName"):
207 # unknown non-CORBA object, having GetName() method
210 raise RuntimeError, "Null or invalid object"
212 ## Prints error message if a hypothesis was not assigned.
213 def TreatHypoStatus(status, hypName, geomName, isAlgo):
215 hypType = "algorithm"
217 hypType = "hypothesis"
219 if status == HYP_UNKNOWN_FATAL :
220 reason = "for unknown reason"
221 elif status == HYP_INCOMPATIBLE :
222 reason = "this hypothesis mismatches the algorithm"
223 elif status == HYP_NOTCONFORM :
224 reason = "a non-conform mesh would be built"
225 elif status == HYP_ALREADY_EXIST :
226 if isAlgo: return # it does not influence anything
227 reason = hypType + " of the same dimension is already assigned to this shape"
228 elif status == HYP_BAD_DIM :
229 reason = hypType + " mismatches the shape"
230 elif status == HYP_CONCURENT :
231 reason = "there are concurrent hypotheses on sub-shapes"
232 elif status == HYP_BAD_SUBSHAPE :
233 reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
234 elif status == HYP_BAD_GEOMETRY:
235 reason = "geometry mismatches the expectation of the algorithm"
236 elif status == HYP_HIDDEN_ALGO:
237 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
238 elif status == HYP_HIDING_ALGO:
239 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
240 elif status == HYP_NEED_SHAPE:
241 reason = "Algorithm can't work without shape"
244 hypName = '"' + hypName + '"'
245 geomName= '"' + geomName+ '"'
246 if status < HYP_UNKNOWN_FATAL and not geomName =='""':
247 print hypName, "was assigned to", geomName,"but", reason
248 elif not geomName == '""':
249 print hypName, "was not assigned to",geomName,":", reason
251 print hypName, "was not assigned:", reason
254 ## Private method. Add geom (sub-shape of the main shape) into the study if not yet there
255 def AssureGeomPublished(mesh, geom, name=''):
256 if not isinstance( geom, geompyDC.GEOM._objref_GEOM_Object ):
258 if not geom.IsSame( mesh.geom ) and \
259 not geom.GetStudyEntry() and \
260 mesh.smeshpyD.GetCurrentStudy():
262 studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
263 if studyID != mesh.geompyD.myStudyId:
264 mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
266 if not name and geom.GetShapeType() != geompyDC.GEOM.COMPOUND:
267 # for all groups SubShapeName() returns "Compound_-1"
268 name = mesh.geompyD.SubShapeName(geom, mesh.geom)
270 name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
272 mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
275 ## Return the first vertex of a geomertical edge by ignoring orienation
276 def FirstVertexOnCurve(edge):
277 from geompy import SubShapeAll, ShapeType, KindOfShape, PointCoordinates
278 vv = SubShapeAll( edge, ShapeType["VERTEX"])
280 raise TypeError, "Given object has no vertices"
281 if len( vv ) == 1: return vv[0]
282 info = KindOfShape(edge)
283 xyz = info[1:4] # coords of the first vertex
284 xyz1 = PointCoordinates( vv[0] )
285 xyz2 = PointCoordinates( vv[1] )
288 dist1 += abs( xyz[i] - xyz1[i] )
289 dist2 += abs( xyz[i] - xyz2[i] )
295 # end of l1_auxiliary
298 # All methods of this class are accessible directly from the smesh.py package.
299 class smeshDC(SMESH._objref_SMESH_Gen):
301 ## Dump component to the Python script
302 # This method overrides IDL function to allow default values for the parameters.
303 def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
304 return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
306 ## Set mode of DumpPython(), \a historical or \a snapshot.
307 # In the \a historical mode, the Python Dump script includes all commands
308 # performed by SMESH engine. In the \a snapshot mode, commands
309 # relating to objects removed from the Study are excluded from the script
310 # as well as commands not influencing the current state of meshes
311 def SetDumpPythonHistorical(self, isHistorical):
312 if isHistorical: val = "true"
314 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
316 ## Sets the current study and Geometry component
317 # @ingroup l1_auxiliary
318 def init_smesh(self,theStudy,geompyD):
319 self.SetCurrentStudy(theStudy,geompyD)
321 ## Creates an empty Mesh. This mesh can have an underlying geometry.
322 # @param obj the Geometrical object on which the mesh is built. If not defined,
323 # the mesh will have no underlying geometry.
324 # @param name the name for the new mesh.
325 # @return an instance of Mesh class.
326 # @ingroup l2_construct
327 def Mesh(self, obj=0, name=0):
328 if isinstance(obj,str):
330 return Mesh(self,self.geompyD,obj,name)
332 ## Returns a long value from enumeration
333 # Should be used for SMESH.FunctorType enumeration
334 # @ingroup l1_controls
335 def EnumToLong(self,theItem):
338 ## Returns a string representation of the color.
339 # To be used with filters.
340 # @param c color value (SALOMEDS.Color)
341 # @ingroup l1_controls
342 def ColorToString(self,c):
344 if isinstance(c, SALOMEDS.Color):
345 val = "%s;%s;%s" % (c.R, c.G, c.B)
346 elif isinstance(c, str):
349 raise ValueError, "Color value should be of string or SALOMEDS.Color type"
352 ## Gets PointStruct from vertex
353 # @param theVertex a GEOM object(vertex)
354 # @return SMESH.PointStruct
355 # @ingroup l1_auxiliary
356 def GetPointStruct(self,theVertex):
357 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
358 return PointStruct(x,y,z)
360 ## Gets DirStruct from vector
361 # @param theVector a GEOM object(vector)
362 # @return SMESH.DirStruct
363 # @ingroup l1_auxiliary
364 def GetDirStruct(self,theVector):
365 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
366 if(len(vertices) != 2):
367 print "Error: vector object is incorrect."
369 p1 = self.geompyD.PointCoordinates(vertices[0])
370 p2 = self.geompyD.PointCoordinates(vertices[1])
371 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
372 dirst = DirStruct(pnt)
375 ## Makes DirStruct from a triplet
376 # @param x,y,z vector components
377 # @return SMESH.DirStruct
378 # @ingroup l1_auxiliary
379 def MakeDirStruct(self,x,y,z):
380 pnt = PointStruct(x,y,z)
381 return DirStruct(pnt)
383 ## Get AxisStruct from object
384 # @param theObj a GEOM object (line or plane)
385 # @return SMESH.AxisStruct
386 # @ingroup l1_auxiliary
387 def GetAxisStruct(self,theObj):
388 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
390 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
391 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
392 vertex1 = self.geompyD.PointCoordinates(vertex1)
393 vertex2 = self.geompyD.PointCoordinates(vertex2)
394 vertex3 = self.geompyD.PointCoordinates(vertex3)
395 vertex4 = self.geompyD.PointCoordinates(vertex4)
396 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
397 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
398 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] ]
399 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
401 elif len(edges) == 1:
402 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
403 p1 = self.geompyD.PointCoordinates( vertex1 )
404 p2 = self.geompyD.PointCoordinates( vertex2 )
405 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
409 # From SMESH_Gen interface:
410 # ------------------------
412 ## Sets the given name to the object
413 # @param obj the object to rename
414 # @param name a new object name
415 # @ingroup l1_auxiliary
416 def SetName(self, obj, name):
417 if isinstance( obj, Mesh ):
419 elif isinstance( obj, Mesh_Algorithm ):
420 obj = obj.GetAlgorithm()
421 ior = salome.orb.object_to_string(obj)
422 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
424 ## Sets the current mode
425 # @ingroup l1_auxiliary
426 def SetEmbeddedMode( self,theMode ):
427 #self.SetEmbeddedMode(theMode)
428 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
430 ## Gets the current mode
431 # @ingroup l1_auxiliary
432 def IsEmbeddedMode(self):
433 #return self.IsEmbeddedMode()
434 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
436 ## Sets the current study
437 # @ingroup l1_auxiliary
438 def SetCurrentStudy( self, theStudy, geompyD = None ):
439 #self.SetCurrentStudy(theStudy)
442 geompyD = geompy.geom
445 self.SetGeomEngine(geompyD)
446 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
449 notebook = salome_notebook.NoteBook( theStudy )
451 notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
453 ## Gets the current study
454 # @ingroup l1_auxiliary
455 def GetCurrentStudy(self):
456 #return self.GetCurrentStudy()
457 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
459 ## Creates a Mesh object importing data from the given UNV file
460 # @return an instance of Mesh class
462 def CreateMeshesFromUNV( self,theFileName ):
463 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
464 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
467 ## Creates a Mesh object(s) importing data from the given MED file
468 # @return a list of Mesh class instances
470 def CreateMeshesFromMED( self,theFileName ):
471 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
473 for iMesh in range(len(aSmeshMeshes)) :
474 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
475 aMeshes.append(aMesh)
476 return aMeshes, aStatus
478 ## Creates a Mesh object(s) importing data from the given SAUV file
479 # @return a list of Mesh class instances
481 def CreateMeshesFromSAUV( self,theFileName ):
482 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
484 for iMesh in range(len(aSmeshMeshes)) :
485 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
486 aMeshes.append(aMesh)
487 return aMeshes, aStatus
489 ## Creates a Mesh object importing data from the given STL file
490 # @return an instance of Mesh class
492 def CreateMeshesFromSTL( self, theFileName ):
493 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
494 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
497 ## Creates Mesh objects importing data from the given CGNS file
498 # @return an instance of Mesh class
500 def CreateMeshesFromCGNS( self, theFileName ):
501 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
503 for iMesh in range(len(aSmeshMeshes)) :
504 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
505 aMeshes.append(aMesh)
506 return aMeshes, aStatus
508 ## Creates a Mesh object importing data from the given GMF file
509 # @return [ an instance of Mesh class, SMESH::ComputeError ]
511 def CreateMeshesFromGMF( self, theFileName ):
512 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,theFileName)
513 if error.comment: print "*** CreateMeshesFromGMF() errors:\n", error.comment
514 return Mesh(self, self.geompyD, aSmeshMesh), error
516 ## Concatenate the given meshes into one mesh.
517 # @return an instance of Mesh class
518 # @param meshes the meshes to combine into one mesh
519 # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
520 # @param mergeNodesAndElements if true, equal nodes and elements aremerged
521 # @param mergeTolerance tolerance for merging nodes
522 # @param allGroups forces creation of groups of all elements
523 def Concatenate( self, meshes, uniteIdenticalGroups,
524 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False):
525 if not meshes: return None
526 for i,m in enumerate(meshes):
527 if isinstance(m, Mesh):
528 meshes[i] = m.GetMesh()
529 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
530 meshes[0].SetParameters(Parameters)
532 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
533 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
535 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
536 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
537 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
540 ## Create a mesh by copying a part of another mesh.
541 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
542 # to copy nodes or elements not contained in any mesh object,
543 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
544 # @param meshName a name of the new mesh
545 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
546 # @param toKeepIDs to preserve IDs of the copied elements or not
547 # @return an instance of Mesh class
548 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
549 if (isinstance( meshPart, Mesh )):
550 meshPart = meshPart.GetMesh()
551 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
552 return Mesh(self, self.geompyD, mesh)
554 ## From SMESH_Gen interface
555 # @return the list of integer values
556 # @ingroup l1_auxiliary
557 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
558 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
560 ## From SMESH_Gen interface. Creates a pattern
561 # @return an instance of SMESH_Pattern
563 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
564 # @ingroup l2_modif_patterns
565 def GetPattern(self):
566 return SMESH._objref_SMESH_Gen.GetPattern(self)
568 ## Sets number of segments per diagonal of boundary box of geometry by which
569 # default segment length of appropriate 1D hypotheses is defined.
570 # Default value is 10
571 # @ingroup l1_auxiliary
572 def SetBoundaryBoxSegmentation(self, nbSegments):
573 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
575 # Filtering. Auxiliary functions:
576 # ------------------------------
578 ## Creates an empty criterion
579 # @return SMESH.Filter.Criterion
580 # @ingroup l1_controls
581 def GetEmptyCriterion(self):
582 Type = self.EnumToLong(FT_Undefined)
583 Compare = self.EnumToLong(FT_Undefined)
587 UnaryOp = self.EnumToLong(FT_Undefined)
588 BinaryOp = self.EnumToLong(FT_Undefined)
591 Precision = -1 ##@1e-07
592 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
593 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
595 ## Creates a criterion by the given parameters
596 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
597 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
598 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
599 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
600 # @param Threshold the threshold value (range of ids as string, shape, numeric)
601 # @param UnaryOp FT_LogicalNOT or FT_Undefined
602 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
603 # FT_Undefined (must be for the last criterion of all criteria)
604 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
605 # FT_LyingOnGeom, FT_CoplanarFaces criteria
606 # @return SMESH.Filter.Criterion
608 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
609 # @ingroup l1_controls
610 def GetCriterion(self,elementType,
612 Compare = FT_EqualTo,
614 UnaryOp=FT_Undefined,
615 BinaryOp=FT_Undefined,
617 if not CritType in SMESH.FunctorType._items:
618 raise TypeError, "CritType should be of SMESH.FunctorType"
619 aCriterion = self.GetEmptyCriterion()
620 aCriterion.TypeOfElement = elementType
621 aCriterion.Type = self.EnumToLong(CritType)
622 aCriterion.Tolerance = Tolerance
624 aThreshold = Threshold
626 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
627 aCriterion.Compare = self.EnumToLong(Compare)
628 elif Compare == "=" or Compare == "==":
629 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
631 aCriterion.Compare = self.EnumToLong(FT_LessThan)
633 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
634 elif Compare != FT_Undefined:
635 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
638 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
639 FT_BelongToCylinder, FT_LyingOnGeom]:
640 # Checks that Threshold is GEOM object
641 if isinstance(aThreshold, geompyDC.GEOM._objref_GEOM_Object):
642 aCriterion.ThresholdStr = GetName(aThreshold)
643 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
644 if not aCriterion.ThresholdID:
645 raise RuntimeError, "Threshold shape must be published"
647 print "Error: The Threshold should be a shape."
649 if isinstance(UnaryOp,float):
650 aCriterion.Tolerance = UnaryOp
651 UnaryOp = FT_Undefined
653 elif CritType == FT_RangeOfIds:
654 # Checks that Threshold is string
655 if isinstance(aThreshold, str):
656 aCriterion.ThresholdStr = aThreshold
658 print "Error: The Threshold should be a string."
660 elif CritType == FT_CoplanarFaces:
661 # Checks the Threshold
662 if isinstance(aThreshold, int):
663 aCriterion.ThresholdID = str(aThreshold)
664 elif isinstance(aThreshold, str):
667 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
668 aCriterion.ThresholdID = aThreshold
671 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
672 elif CritType == FT_ElemGeomType:
673 # Checks the Threshold
675 aCriterion.Threshold = self.EnumToLong(aThreshold)
676 assert( aThreshold in SMESH.GeometryType._items )
678 if isinstance(aThreshold, int):
679 aCriterion.Threshold = aThreshold
681 print "Error: The Threshold should be an integer or SMESH.GeometryType."
685 elif CritType == FT_GroupColor:
686 # Checks the Threshold
688 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
690 print "Error: The threshold value should be of SALOMEDS.Color type"
693 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
694 FT_LinearOrQuadratic, FT_BadOrientedVolume,
695 FT_BareBorderFace, FT_BareBorderVolume,
696 FT_OverConstrainedFace, FT_OverConstrainedVolume,
697 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
698 # At this point the Threshold is unnecessary
699 if aThreshold == FT_LogicalNOT:
700 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
701 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
702 aCriterion.BinaryOp = aThreshold
706 aThreshold = float(aThreshold)
707 aCriterion.Threshold = aThreshold
709 print "Error: The Threshold should be a number."
712 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
713 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
715 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
716 aCriterion.BinaryOp = self.EnumToLong(Threshold)
718 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
719 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
721 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
722 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
726 ## Creates a filter with the given parameters
727 # @param elementType the type of elements in the group
728 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
729 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
730 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
731 # @param UnaryOp FT_LogicalNOT or FT_Undefined
732 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
733 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
734 # @return SMESH_Filter
736 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
737 # @ingroup l1_controls
738 def GetFilter(self,elementType,
739 CritType=FT_Undefined,
742 UnaryOp=FT_Undefined,
744 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
745 aFilterMgr = self.CreateFilterManager()
746 aFilter = aFilterMgr.CreateFilter()
748 aCriteria.append(aCriterion)
749 aFilter.SetCriteria(aCriteria)
750 aFilterMgr.UnRegister()
753 ## Creates a filter from criteria
754 # @param criteria a list of criteria
755 # @return SMESH_Filter
757 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
758 # @ingroup l1_controls
759 def GetFilterFromCriteria(self,criteria):
760 aFilterMgr = self.CreateFilterManager()
761 aFilter = aFilterMgr.CreateFilter()
762 aFilter.SetCriteria(criteria)
763 aFilterMgr.UnRegister()
766 ## Creates a numerical functor by its type
767 # @param theCriterion FT_...; functor type
768 # @return SMESH_NumericalFunctor
769 # @ingroup l1_controls
770 def GetFunctor(self,theCriterion):
771 aFilterMgr = self.CreateFilterManager()
772 if theCriterion == FT_AspectRatio:
773 return aFilterMgr.CreateAspectRatio()
774 elif theCriterion == FT_AspectRatio3D:
775 return aFilterMgr.CreateAspectRatio3D()
776 elif theCriterion == FT_Warping:
777 return aFilterMgr.CreateWarping()
778 elif theCriterion == FT_MinimumAngle:
779 return aFilterMgr.CreateMinimumAngle()
780 elif theCriterion == FT_Taper:
781 return aFilterMgr.CreateTaper()
782 elif theCriterion == FT_Skew:
783 return aFilterMgr.CreateSkew()
784 elif theCriterion == FT_Area:
785 return aFilterMgr.CreateArea()
786 elif theCriterion == FT_Volume3D:
787 return aFilterMgr.CreateVolume3D()
788 elif theCriterion == FT_MaxElementLength2D:
789 return aFilterMgr.CreateMaxElementLength2D()
790 elif theCriterion == FT_MaxElementLength3D:
791 return aFilterMgr.CreateMaxElementLength3D()
792 elif theCriterion == FT_MultiConnection:
793 return aFilterMgr.CreateMultiConnection()
794 elif theCriterion == FT_MultiConnection2D:
795 return aFilterMgr.CreateMultiConnection2D()
796 elif theCriterion == FT_Length:
797 return aFilterMgr.CreateLength()
798 elif theCriterion == FT_Length2D:
799 return aFilterMgr.CreateLength2D()
801 print "Error: given parameter is not numerical functor type."
803 ## Creates hypothesis
804 # @param theHType mesh hypothesis type (string)
805 # @param theLibName mesh plug-in library name
806 # @return created hypothesis instance
807 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
808 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
810 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
813 # wrap hypothesis methods
814 #print "HYPOTHESIS", theHType
815 for meth_name in dir( hyp.__class__ ):
816 if not meth_name.startswith("Get") and \
817 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
818 method = getattr ( hyp.__class__, meth_name )
820 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
824 ## Gets the mesh statistic
825 # @return dictionary "element type" - "count of elements"
826 # @ingroup l1_meshinfo
827 def GetMeshInfo(self, obj):
828 if isinstance( obj, Mesh ):
831 if hasattr(obj, "GetMeshInfo"):
832 values = obj.GetMeshInfo()
833 for i in range(SMESH.Entity_Last._v):
834 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
838 ## Get minimum distance between two objects
840 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
841 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
843 # @param src1 first source object
844 # @param src2 second source object
845 # @param id1 node/element id from the first source
846 # @param id2 node/element id from the second (or first) source
847 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
848 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
849 # @return minimum distance value
850 # @sa GetMinDistance()
851 # @ingroup l1_measurements
852 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
853 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
857 result = result.value
860 ## Get measure structure specifying minimum distance data between two objects
862 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
863 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
865 # @param src1 first source object
866 # @param src2 second source object
867 # @param id1 node/element id from the first source
868 # @param id2 node/element id from the second (or first) source
869 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
870 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
871 # @return Measure structure or None if input data is invalid
873 # @ingroup l1_measurements
874 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
875 if isinstance(src1, Mesh): src1 = src1.mesh
876 if isinstance(src2, Mesh): src2 = src2.mesh
877 if src2 is None and id2 != 0: src2 = src1
878 if not hasattr(src1, "_narrow"): return None
879 src1 = src1._narrow(SMESH.SMESH_IDSource)
880 if not src1: return None
883 e = m.GetMeshEditor()
885 src1 = e.MakeIDSource([id1], SMESH.FACE)
887 src1 = e.MakeIDSource([id1], SMESH.NODE)
889 if hasattr(src2, "_narrow"):
890 src2 = src2._narrow(SMESH.SMESH_IDSource)
891 if src2 and id2 != 0:
893 e = m.GetMeshEditor()
895 src2 = e.MakeIDSource([id2], SMESH.FACE)
897 src2 = e.MakeIDSource([id2], SMESH.NODE)
900 aMeasurements = self.CreateMeasurements()
901 result = aMeasurements.MinDistance(src1, src2)
902 aMeasurements.UnRegister()
905 ## Get bounding box of the specified object(s)
906 # @param objects single source object or list of source objects
907 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
908 # @sa GetBoundingBox()
909 # @ingroup l1_measurements
910 def BoundingBox(self, objects):
911 result = self.GetBoundingBox(objects)
915 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
918 ## Get measure structure specifying bounding box data of the specified object(s)
919 # @param objects single source object or list of source objects
920 # @return Measure structure
922 # @ingroup l1_measurements
923 def GetBoundingBox(self, objects):
924 if isinstance(objects, tuple):
925 objects = list(objects)
926 if not isinstance(objects, list):
930 if isinstance(o, Mesh):
931 srclist.append(o.mesh)
932 elif hasattr(o, "_narrow"):
933 src = o._narrow(SMESH.SMESH_IDSource)
934 if src: srclist.append(src)
937 aMeasurements = self.CreateMeasurements()
938 result = aMeasurements.BoundingBox(srclist)
939 aMeasurements.UnRegister()
943 #Registering the new proxy for SMESH_Gen
944 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
950 ## This class allows defining and managing a mesh.
951 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
952 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
953 # new nodes and elements and by changing the existing entities), to get information
954 # about a mesh and to export a mesh into different formats.
960 functors = [None] * SMESH.FT_Undefined._v
964 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
965 # sets the GUI name of this mesh to \a name.
966 # @param smeshpyD an instance of smeshDC class
967 # @param geompyD an instance of geompyDC class
968 # @param obj Shape to be meshed or SMESH_Mesh object
969 # @param name Study name of the mesh
970 # @ingroup l2_construct
971 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
972 self.smeshpyD=smeshpyD
978 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
980 # publish geom of mesh (issue 0021122)
981 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
983 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
984 if studyID != geompyD.myStudyId:
985 geompyD.init_geom( smeshpyD.GetCurrentStudy())
990 geo_name = "%s_%s_for_meshing"%(self.geom.GetShapeType(), id(self.geom)%100)
991 geompyD.addToStudy( self.geom, geo_name )
992 self.mesh = self.smeshpyD.CreateMesh(self.geom)
994 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
997 self.mesh = self.smeshpyD.CreateEmptyMesh()
999 self.smeshpyD.SetName(self.mesh, name)
1000 elif obj != 0 and objHasName:
1001 self.smeshpyD.SetName(self.mesh, GetName(obj))
1004 self.geom = self.mesh.GetShapeToMesh()
1006 self.editor = self.mesh.GetMeshEditor()
1008 # set self to algoCreator's
1009 for attrName in dir(self):
1010 attr = getattr( self, attrName )
1011 if isinstance( attr, algoCreator ):
1012 setattr( self, attrName, attr.copy( self ))
1014 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1015 # @param theMesh a SMESH_Mesh object
1016 # @ingroup l2_construct
1017 def SetMesh(self, theMesh):
1019 self.geom = self.mesh.GetShapeToMesh()
1021 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1022 # @return a SMESH_Mesh object
1023 # @ingroup l2_construct
1027 ## Gets the name of the mesh
1028 # @return the name of the mesh as a string
1029 # @ingroup l2_construct
1031 name = GetName(self.GetMesh())
1034 ## Sets a name to the mesh
1035 # @param name a new name of the mesh
1036 # @ingroup l2_construct
1037 def SetName(self, name):
1038 self.smeshpyD.SetName(self.GetMesh(), name)
1040 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1041 # The subMesh object gives access to the IDs of nodes and elements.
1042 # @param geom a geometrical object (shape)
1043 # @param name a name for the submesh
1044 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1045 # @ingroup l2_submeshes
1046 def GetSubMesh(self, geom, name):
1047 AssureGeomPublished( self, geom, name )
1048 submesh = self.mesh.GetSubMesh( geom, name )
1051 ## Returns the shape associated to the mesh
1052 # @return a GEOM_Object
1053 # @ingroup l2_construct
1057 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1058 # @param geom the shape to be meshed (GEOM_Object)
1059 # @ingroup l2_construct
1060 def SetShape(self, geom):
1061 self.mesh = self.smeshpyD.CreateMesh(geom)
1063 ## Loads mesh from the study after opening the study
1067 ## Returns true if the hypotheses are defined well
1068 # @param theSubObject a sub-shape of a mesh shape
1069 # @return True or False
1070 # @ingroup l2_construct
1071 def IsReadyToCompute(self, theSubObject):
1072 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1074 ## Returns errors of hypotheses definition.
1075 # The list of errors is empty if everything is OK.
1076 # @param theSubObject a sub-shape of a mesh shape
1077 # @return a list of errors
1078 # @ingroup l2_construct
1079 def GetAlgoState(self, theSubObject):
1080 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1082 ## Returns a geometrical object on which the given element was built.
1083 # The returned geometrical object, if not nil, is either found in the
1084 # study or published by this method with the given name
1085 # @param theElementID the id of the mesh element
1086 # @param theGeomName the user-defined name of the geometrical object
1087 # @return GEOM::GEOM_Object instance
1088 # @ingroup l2_construct
1089 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1090 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1092 ## Returns the mesh dimension depending on the dimension of the underlying shape
1093 # @return mesh dimension as an integer value [0,3]
1094 # @ingroup l1_auxiliary
1095 def MeshDimension(self):
1096 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1097 if len( shells ) > 0 :
1099 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1101 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1107 ## Evaluates size of prospective mesh on a shape
1108 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1109 # To know predicted number of e.g. edges, inquire it this way
1110 # Evaluate()[ EnumToLong( Entity_Edge )]
1111 def Evaluate(self, geom=0):
1112 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1114 geom = self.mesh.GetShapeToMesh()
1117 return self.smeshpyD.Evaluate(self.mesh, geom)
1120 ## Computes the mesh and returns the status of the computation
1121 # @param geom geomtrical shape on which mesh data should be computed
1122 # @param discardModifs if True and the mesh has been edited since
1123 # a last total re-compute and that may prevent successful partial re-compute,
1124 # then the mesh is cleaned before Compute()
1125 # @return True or False
1126 # @ingroup l2_construct
1127 def Compute(self, geom=0, discardModifs=False):
1128 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1130 geom = self.mesh.GetShapeToMesh()
1135 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1137 ok = self.smeshpyD.Compute(self.mesh, geom)
1138 except SALOME.SALOME_Exception, ex:
1139 print "Mesh computation failed, exception caught:"
1140 print " ", ex.details.text
1143 print "Mesh computation failed, exception caught:"
1144 traceback.print_exc()
1148 # Treat compute errors
1149 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1150 for err in computeErrors:
1152 if self.mesh.HasShapeToMesh():
1154 mainIOR = salome.orb.object_to_string(geom)
1155 for sname in salome.myStudyManager.GetOpenStudies():
1156 s = salome.myStudyManager.GetStudyByName(sname)
1158 mainSO = s.FindObjectIOR(mainIOR)
1159 if not mainSO: continue
1160 if err.subShapeID == 1:
1161 shapeText = ' on "%s"' % mainSO.GetName()
1162 subIt = s.NewChildIterator(mainSO)
1164 subSO = subIt.Value()
1166 obj = subSO.GetObject()
1167 if not obj: continue
1168 go = obj._narrow( geompyDC.GEOM._objref_GEOM_Object )
1170 ids = go.GetSubShapeIndices()
1171 if len(ids) == 1 and ids[0] == err.subShapeID:
1172 shapeText = ' on "%s"' % subSO.GetName()
1175 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1177 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1179 shapeText = " on subshape #%s" % (err.subShapeID)
1181 shapeText = " on subshape #%s" % (err.subShapeID)
1183 stdErrors = ["OK", #COMPERR_OK
1184 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1185 "std::exception", #COMPERR_STD_EXCEPTION
1186 "OCC exception", #COMPERR_OCC_EXCEPTION
1187 "SALOME exception", #COMPERR_SLM_EXCEPTION
1188 "Unknown exception", #COMPERR_EXCEPTION
1189 "Memory allocation problem", #COMPERR_MEMORY_PB
1190 "Algorithm failed", #COMPERR_ALGO_FAILED
1191 "Unexpected geometry", #COMPERR_BAD_SHAPE
1192 "Warning", #COMPERR_WARNING
1193 "Computation cancelled",#COMPERR_CANCELED
1194 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1196 if err.code < len(stdErrors): errText = stdErrors[err.code]
1198 errText = "code %s" % -err.code
1199 if errText: errText += ". "
1200 errText += err.comment
1201 if allReasons != "":allReasons += "\n"
1202 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1206 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1208 if err.isGlobalAlgo:
1216 reason = '%s %sD algorithm is missing' % (glob, dim)
1217 elif err.state == HYP_MISSING:
1218 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1219 % (glob, dim, name, dim))
1220 elif err.state == HYP_NOTCONFORM:
1221 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1222 elif err.state == HYP_BAD_PARAMETER:
1223 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1224 % ( glob, dim, name ))
1225 elif err.state == HYP_BAD_GEOMETRY:
1226 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1227 'geometry' % ( glob, dim, name ))
1229 reason = "For unknown reason."+\
1230 " Revise Mesh.Compute() implementation in smeshDC.py!"
1232 if allReasons != "":allReasons += "\n"
1233 allReasons += "- " + reason
1235 if not ok or allReasons != "":
1236 msg = '"' + GetName(self.mesh) + '"'
1237 if ok: msg += " has been computed with warnings"
1238 else: msg += " has not been computed"
1239 if allReasons != "": msg += ":"
1244 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1245 smeshgui = salome.ImportComponentGUI("SMESH")
1246 smeshgui.Init(self.mesh.GetStudyId())
1247 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1248 salome.sg.updateObjBrowser(1)
1252 ## Return submesh objects list in meshing order
1253 # @return list of list of submesh objects
1254 # @ingroup l2_construct
1255 def GetMeshOrder(self):
1256 return self.mesh.GetMeshOrder()
1258 ## Return submesh objects list in meshing order
1259 # @return list of list of submesh objects
1260 # @ingroup l2_construct
1261 def SetMeshOrder(self, submeshes):
1262 return self.mesh.SetMeshOrder(submeshes)
1264 ## Removes all nodes and elements
1265 # @ingroup l2_construct
1268 if salome.sg.hasDesktop():
1269 smeshgui = salome.ImportComponentGUI("SMESH")
1270 smeshgui.Init(self.mesh.GetStudyId())
1271 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1272 salome.sg.updateObjBrowser(1)
1274 ## Removes all nodes and elements of indicated shape
1275 # @ingroup l2_construct
1276 def ClearSubMesh(self, geomId):
1277 self.mesh.ClearSubMesh(geomId)
1278 if salome.sg.hasDesktop():
1279 smeshgui = salome.ImportComponentGUI("SMESH")
1280 smeshgui.Init(self.mesh.GetStudyId())
1281 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1282 salome.sg.updateObjBrowser(1)
1284 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1285 # @param fineness [0.0,1.0] defines mesh fineness
1286 # @return True or False
1287 # @ingroup l3_algos_basic
1288 def AutomaticTetrahedralization(self, fineness=0):
1289 dim = self.MeshDimension()
1291 self.RemoveGlobalHypotheses()
1292 self.Segment().AutomaticLength(fineness)
1294 self.Triangle().LengthFromEdges()
1297 from NETGENPluginDC import NETGEN
1298 self.Tetrahedron(NETGEN)
1300 return self.Compute()
1302 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1303 # @param fineness [0.0, 1.0] defines mesh fineness
1304 # @return True or False
1305 # @ingroup l3_algos_basic
1306 def AutomaticHexahedralization(self, fineness=0):
1307 dim = self.MeshDimension()
1308 # assign the hypotheses
1309 self.RemoveGlobalHypotheses()
1310 self.Segment().AutomaticLength(fineness)
1317 return self.Compute()
1319 ## Assigns a hypothesis
1320 # @param hyp a hypothesis to assign
1321 # @param geom a subhape of mesh geometry
1322 # @return SMESH.Hypothesis_Status
1323 # @ingroup l2_hypotheses
1324 def AddHypothesis(self, hyp, geom=0):
1325 if isinstance( hyp, Mesh_Algorithm ):
1326 hyp = hyp.GetAlgorithm()
1331 geom = self.mesh.GetShapeToMesh()
1333 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1334 status = self.mesh.AddHypothesis(geom, hyp)
1335 isAlgo = hyp._narrow( SMESH_Algo )
1336 hyp_name = GetName( hyp )
1339 geom_name = GetName( geom )
1340 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1343 ## Return True if an algorithm of hypothesis is assigned to a given shape
1344 # @param hyp a hypothesis to check
1345 # @param geom a subhape of mesh geometry
1346 # @return True of False
1347 # @ingroup l2_hypotheses
1348 def IsUsedHypothesis(self, hyp, geom):
1349 if not hyp or not geom:
1351 if isinstance( hyp, Mesh_Algorithm ):
1352 hyp = hyp.GetAlgorithm()
1354 hyps = self.GetHypothesisList(geom)
1356 if h.GetId() == hyp.GetId():
1360 ## Unassigns a hypothesis
1361 # @param hyp a hypothesis to unassign
1362 # @param geom a sub-shape of mesh geometry
1363 # @return SMESH.Hypothesis_Status
1364 # @ingroup l2_hypotheses
1365 def RemoveHypothesis(self, hyp, geom=0):
1366 if isinstance( hyp, Mesh_Algorithm ):
1367 hyp = hyp.GetAlgorithm()
1372 status = self.mesh.RemoveHypothesis(geom, hyp)
1375 ## Gets the list of hypotheses added on a geometry
1376 # @param geom a sub-shape of mesh geometry
1377 # @return the sequence of SMESH_Hypothesis
1378 # @ingroup l2_hypotheses
1379 def GetHypothesisList(self, geom):
1380 return self.mesh.GetHypothesisList( geom )
1382 ## Removes all global hypotheses
1383 # @ingroup l2_hypotheses
1384 def RemoveGlobalHypotheses(self):
1385 current_hyps = self.mesh.GetHypothesisList( self.geom )
1386 for hyp in current_hyps:
1387 self.mesh.RemoveHypothesis( self.geom, hyp )
1391 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1392 ## allowing to overwrite the file if it exists or add the exported data to its contents
1393 # @param f is the file name
1394 # @param auto_groups boolean parameter for creating/not creating
1395 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1396 # the typical use is auto_groups=false.
1397 # @param version MED format version(MED_V2_1 or MED_V2_2)
1398 # @param overwrite boolean parameter for overwriting/not overwriting the file
1399 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1400 # @ingroup l2_impexp
1401 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1403 if isinstance( meshPart, list ):
1404 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1405 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1407 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1409 ## Exports the mesh in a file in SAUV format
1410 # @param f is the file name
1411 # @param auto_groups boolean parameter for creating/not creating
1412 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1413 # the typical use is auto_groups=false.
1414 # @ingroup l2_impexp
1415 def ExportSAUV(self, f, auto_groups=0):
1416 self.mesh.ExportSAUV(f, auto_groups)
1418 ## Exports the mesh in a file in DAT format
1419 # @param f the file name
1420 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1421 # @ingroup l2_impexp
1422 def ExportDAT(self, f, meshPart=None):
1424 if isinstance( meshPart, list ):
1425 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1426 self.mesh.ExportPartToDAT( meshPart, f )
1428 self.mesh.ExportDAT(f)
1430 ## Exports the mesh in a file in UNV format
1431 # @param f the file name
1432 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1433 # @ingroup l2_impexp
1434 def ExportUNV(self, f, meshPart=None):
1436 if isinstance( meshPart, list ):
1437 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1438 self.mesh.ExportPartToUNV( meshPart, f )
1440 self.mesh.ExportUNV(f)
1442 ## Export the mesh in a file in STL format
1443 # @param f the file name
1444 # @param ascii defines the file encoding
1445 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1446 # @ingroup l2_impexp
1447 def ExportSTL(self, f, ascii=1, meshPart=None):
1449 if isinstance( meshPart, list ):
1450 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1451 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1453 self.mesh.ExportSTL(f, ascii)
1455 ## Exports the mesh in a file in CGNS format
1456 # @param f is the file name
1457 # @param overwrite boolean parameter for overwriting/not overwriting the file
1458 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1459 # @ingroup l2_impexp
1460 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1461 if isinstance( meshPart, list ):
1462 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1463 if isinstance( meshPart, Mesh ):
1464 meshPart = meshPart.mesh
1466 meshPart = self.mesh
1467 self.mesh.ExportCGNS(meshPart, f, overwrite)
1469 ## Exports the mesh in a file in GMF format
1470 # @param f is the file name
1471 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1472 # @ingroup l2_impexp
1473 def ExportGMF(self, f, meshPart=None):
1474 if isinstance( meshPart, list ):
1475 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1476 if isinstance( meshPart, Mesh ):
1477 meshPart = meshPart.mesh
1479 meshPart = self.mesh
1480 self.mesh.ExportGMF(meshPart, f)
1482 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1483 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1484 ## allowing to overwrite the file if it exists or add the exported data to its contents
1485 # @param f the file name
1486 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1487 # @param opt boolean parameter for creating/not creating
1488 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1489 # @param overwrite boolean parameter for overwriting/not overwriting the file
1490 # @ingroup l2_impexp
1491 def ExportToMED(self, f, version, opt=0, overwrite=1):
1492 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1494 # Operations with groups:
1495 # ----------------------
1497 ## Creates an empty mesh group
1498 # @param elementType the type of elements in the group
1499 # @param name the name of the mesh group
1500 # @return SMESH_Group
1501 # @ingroup l2_grps_create
1502 def CreateEmptyGroup(self, elementType, name):
1503 return self.mesh.CreateGroup(elementType, name)
1505 ## Creates a mesh group based on the geometric object \a grp
1506 # and gives a \a name, \n if this parameter is not defined
1507 # the name is the same as the geometric group name \n
1508 # Note: Works like GroupOnGeom().
1509 # @param grp a geometric group, a vertex, an edge, a face or a solid
1510 # @param name the name of the mesh group
1511 # @return SMESH_GroupOnGeom
1512 # @ingroup l2_grps_create
1513 def Group(self, grp, name=""):
1514 return self.GroupOnGeom(grp, name)
1516 ## Creates a mesh group based on the geometrical object \a grp
1517 # and gives a \a name, \n if this parameter is not defined
1518 # the name is the same as the geometrical group name
1519 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1520 # @param name the name of the mesh group
1521 # @param typ the type of elements in the group. If not set, it is
1522 # automatically detected by the type of the geometry
1523 # @return SMESH_GroupOnGeom
1524 # @ingroup l2_grps_create
1525 def GroupOnGeom(self, grp, name="", typ=None):
1526 AssureGeomPublished( self, grp, name )
1528 name = grp.GetName()
1530 typ = self._groupTypeFromShape( grp )
1531 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1533 ## Pivate method to get a type of group on geometry
1534 def _groupTypeFromShape( self, shape ):
1535 tgeo = str(shape.GetShapeType())
1536 if tgeo == "VERTEX":
1538 elif tgeo == "EDGE":
1540 elif tgeo == "FACE" or tgeo == "SHELL":
1542 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1544 elif tgeo == "COMPOUND":
1545 sub = self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHAPE"])
1547 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1548 return self._groupTypeFromShape( sub[0] )
1551 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1554 ## Creates a mesh group with given \a name based on the \a filter which
1555 ## is a special type of group dynamically updating it's contents during
1556 ## mesh modification
1557 # @param typ the type of elements in the group
1558 # @param name the name of the mesh group
1559 # @param filter the filter defining group contents
1560 # @return SMESH_GroupOnFilter
1561 # @ingroup l2_grps_create
1562 def GroupOnFilter(self, typ, name, filter):
1563 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1565 ## Creates a mesh group by the given ids of elements
1566 # @param groupName the name of the mesh group
1567 # @param elementType the type of elements in the group
1568 # @param elemIDs the list of ids
1569 # @return SMESH_Group
1570 # @ingroup l2_grps_create
1571 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1572 group = self.mesh.CreateGroup(elementType, groupName)
1576 ## Creates a mesh group by the given conditions
1577 # @param groupName the name of the mesh group
1578 # @param elementType the type of elements in the group
1579 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1580 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1581 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1582 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1583 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1584 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1585 # @return SMESH_Group
1586 # @ingroup l2_grps_create
1590 CritType=FT_Undefined,
1593 UnaryOp=FT_Undefined,
1595 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1596 group = self.MakeGroupByCriterion(groupName, aCriterion)
1599 ## Creates a mesh group by the given criterion
1600 # @param groupName the name of the mesh group
1601 # @param Criterion the instance of Criterion class
1602 # @return SMESH_Group
1603 # @ingroup l2_grps_create
1604 def MakeGroupByCriterion(self, groupName, Criterion):
1605 aFilterMgr = self.smeshpyD.CreateFilterManager()
1606 aFilter = aFilterMgr.CreateFilter()
1608 aCriteria.append(Criterion)
1609 aFilter.SetCriteria(aCriteria)
1610 group = self.MakeGroupByFilter(groupName, aFilter)
1611 aFilterMgr.UnRegister()
1614 ## Creates a mesh group by the given criteria (list of criteria)
1615 # @param groupName the name of the mesh group
1616 # @param theCriteria the list of criteria
1617 # @return SMESH_Group
1618 # @ingroup l2_grps_create
1619 def MakeGroupByCriteria(self, groupName, theCriteria):
1620 aFilterMgr = self.smeshpyD.CreateFilterManager()
1621 aFilter = aFilterMgr.CreateFilter()
1622 aFilter.SetCriteria(theCriteria)
1623 group = self.MakeGroupByFilter(groupName, aFilter)
1624 aFilterMgr.UnRegister()
1627 ## Creates a mesh group by the given filter
1628 # @param groupName the name of the mesh group
1629 # @param theFilter the instance of Filter class
1630 # @return SMESH_Group
1631 # @ingroup l2_grps_create
1632 def MakeGroupByFilter(self, groupName, theFilter):
1633 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1634 theFilter.SetMesh( self.mesh )
1635 group.AddFrom( theFilter )
1639 # @ingroup l2_grps_delete
1640 def RemoveGroup(self, group):
1641 self.mesh.RemoveGroup(group)
1643 ## Removes a group with its contents
1644 # @ingroup l2_grps_delete
1645 def RemoveGroupWithContents(self, group):
1646 self.mesh.RemoveGroupWithContents(group)
1648 ## Gets the list of groups existing in the mesh
1649 # @return a sequence of SMESH_GroupBase
1650 # @ingroup l2_grps_create
1651 def GetGroups(self):
1652 return self.mesh.GetGroups()
1654 ## Gets the number of groups existing in the mesh
1655 # @return the quantity of groups as an integer value
1656 # @ingroup l2_grps_create
1658 return self.mesh.NbGroups()
1660 ## Gets the list of names of groups existing in the mesh
1661 # @return list of strings
1662 # @ingroup l2_grps_create
1663 def GetGroupNames(self):
1664 groups = self.GetGroups()
1666 for group in groups:
1667 names.append(group.GetName())
1670 ## Produces a union of two groups
1671 # A new group is created. All mesh elements that are
1672 # present in the initial groups are added to the new one
1673 # @return an instance of SMESH_Group
1674 # @ingroup l2_grps_operon
1675 def UnionGroups(self, group1, group2, name):
1676 return self.mesh.UnionGroups(group1, group2, name)
1678 ## Produces a union list of groups
1679 # New group is created. All mesh elements that are present in
1680 # initial groups are added to the new one
1681 # @return an instance of SMESH_Group
1682 # @ingroup l2_grps_operon
1683 def UnionListOfGroups(self, groups, name):
1684 return self.mesh.UnionListOfGroups(groups, name)
1686 ## Prodices an intersection of two groups
1687 # A new group is created. All mesh elements that are common
1688 # for the two initial groups are added to the new one.
1689 # @return an instance of SMESH_Group
1690 # @ingroup l2_grps_operon
1691 def IntersectGroups(self, group1, group2, name):
1692 return self.mesh.IntersectGroups(group1, group2, name)
1694 ## Produces an intersection of groups
1695 # New group is created. All mesh elements that are present in all
1696 # initial groups simultaneously are added to the new one
1697 # @return an instance of SMESH_Group
1698 # @ingroup l2_grps_operon
1699 def IntersectListOfGroups(self, groups, name):
1700 return self.mesh.IntersectListOfGroups(groups, name)
1702 ## Produces a cut of two groups
1703 # A new group is created. All mesh elements that are present in
1704 # the main group but are not present in the tool group are added to the new one
1705 # @return an instance of SMESH_Group
1706 # @ingroup l2_grps_operon
1707 def CutGroups(self, main_group, tool_group, name):
1708 return self.mesh.CutGroups(main_group, tool_group, name)
1710 ## Produces a cut of groups
1711 # A new group is created. All mesh elements that are present in main groups
1712 # but do not present in tool groups are added to the new one
1713 # @return an instance of SMESH_Group
1714 # @ingroup l2_grps_operon
1715 def CutListOfGroups(self, main_groups, tool_groups, name):
1716 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1718 ## Produces a group of elements of specified type using list of existing groups
1719 # A new group is created. System
1720 # 1) extracts all nodes on which groups elements are built
1721 # 2) combines all elements of specified dimension laying on these nodes
1722 # @return an instance of SMESH_Group
1723 # @ingroup l2_grps_operon
1724 def CreateDimGroup(self, groups, elem_type, name):
1725 return self.mesh.CreateDimGroup(groups, elem_type, name)
1728 ## Convert group on geom into standalone group
1729 # @ingroup l2_grps_delete
1730 def ConvertToStandalone(self, group):
1731 return self.mesh.ConvertToStandalone(group)
1733 # Get some info about mesh:
1734 # ------------------------
1736 ## Returns the log of nodes and elements added or removed
1737 # since the previous clear of the log.
1738 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1739 # @return list of log_block structures:
1744 # @ingroup l1_auxiliary
1745 def GetLog(self, clearAfterGet):
1746 return self.mesh.GetLog(clearAfterGet)
1748 ## Clears the log of nodes and elements added or removed since the previous
1749 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1750 # @ingroup l1_auxiliary
1752 self.mesh.ClearLog()
1754 ## Toggles auto color mode on the object.
1755 # @param theAutoColor the flag which toggles auto color mode.
1756 # @ingroup l1_auxiliary
1757 def SetAutoColor(self, theAutoColor):
1758 self.mesh.SetAutoColor(theAutoColor)
1760 ## Gets flag of object auto color mode.
1761 # @return True or False
1762 # @ingroup l1_auxiliary
1763 def GetAutoColor(self):
1764 return self.mesh.GetAutoColor()
1766 ## Gets the internal ID
1767 # @return integer value, which is the internal Id of the mesh
1768 # @ingroup l1_auxiliary
1770 return self.mesh.GetId()
1773 # @return integer value, which is the study Id of the mesh
1774 # @ingroup l1_auxiliary
1775 def GetStudyId(self):
1776 return self.mesh.GetStudyId()
1778 ## Checks the group names for duplications.
1779 # Consider the maximum group name length stored in MED file.
1780 # @return True or False
1781 # @ingroup l1_auxiliary
1782 def HasDuplicatedGroupNamesMED(self):
1783 return self.mesh.HasDuplicatedGroupNamesMED()
1785 ## Obtains the mesh editor tool
1786 # @return an instance of SMESH_MeshEditor
1787 # @ingroup l1_modifying
1788 def GetMeshEditor(self):
1791 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1792 # can be passed as argument to a method accepting mesh, group or sub-mesh
1793 # @return an instance of SMESH_IDSource
1794 # @ingroup l1_auxiliary
1795 def GetIDSource(self, ids, elemType):
1796 return self.editor.MakeIDSource(ids, elemType)
1799 # @return an instance of SALOME_MED::MESH
1800 # @ingroup l1_auxiliary
1801 def GetMEDMesh(self):
1802 return self.mesh.GetMEDMesh()
1805 # Get informations about mesh contents:
1806 # ------------------------------------
1808 ## Gets the mesh stattistic
1809 # @return dictionary type element - count of elements
1810 # @ingroup l1_meshinfo
1811 def GetMeshInfo(self, obj = None):
1812 if not obj: obj = self.mesh
1813 return self.smeshpyD.GetMeshInfo(obj)
1815 ## Returns the number of nodes in the mesh
1816 # @return an integer value
1817 # @ingroup l1_meshinfo
1819 return self.mesh.NbNodes()
1821 ## Returns the number of elements in the mesh
1822 # @return an integer value
1823 # @ingroup l1_meshinfo
1824 def NbElements(self):
1825 return self.mesh.NbElements()
1827 ## Returns the number of 0d elements in the mesh
1828 # @return an integer value
1829 # @ingroup l1_meshinfo
1830 def Nb0DElements(self):
1831 return self.mesh.Nb0DElements()
1833 ## Returns the number of ball discrete elements in the mesh
1834 # @return an integer value
1835 # @ingroup l1_meshinfo
1837 return self.mesh.NbBalls()
1839 ## Returns the number of edges in the mesh
1840 # @return an integer value
1841 # @ingroup l1_meshinfo
1843 return self.mesh.NbEdges()
1845 ## Returns the number of edges with the given order in the mesh
1846 # @param elementOrder the order of elements:
1847 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1848 # @return an integer value
1849 # @ingroup l1_meshinfo
1850 def NbEdgesOfOrder(self, elementOrder):
1851 return self.mesh.NbEdgesOfOrder(elementOrder)
1853 ## Returns the number of faces in the mesh
1854 # @return an integer value
1855 # @ingroup l1_meshinfo
1857 return self.mesh.NbFaces()
1859 ## Returns the number of faces with the given order in the mesh
1860 # @param elementOrder the order of elements:
1861 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1862 # @return an integer value
1863 # @ingroup l1_meshinfo
1864 def NbFacesOfOrder(self, elementOrder):
1865 return self.mesh.NbFacesOfOrder(elementOrder)
1867 ## Returns the number of triangles in the mesh
1868 # @return an integer value
1869 # @ingroup l1_meshinfo
1870 def NbTriangles(self):
1871 return self.mesh.NbTriangles()
1873 ## Returns the number of triangles with the given order in the mesh
1874 # @param elementOrder is the order of elements:
1875 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1876 # @return an integer value
1877 # @ingroup l1_meshinfo
1878 def NbTrianglesOfOrder(self, elementOrder):
1879 return self.mesh.NbTrianglesOfOrder(elementOrder)
1881 ## Returns the number of quadrangles in the mesh
1882 # @return an integer value
1883 # @ingroup l1_meshinfo
1884 def NbQuadrangles(self):
1885 return self.mesh.NbQuadrangles()
1887 ## Returns the number of quadrangles with the given order in the mesh
1888 # @param elementOrder the order of elements:
1889 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1890 # @return an integer value
1891 # @ingroup l1_meshinfo
1892 def NbQuadranglesOfOrder(self, elementOrder):
1893 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1895 ## Returns the number of biquadratic quadrangles in the mesh
1896 # @return an integer value
1897 # @ingroup l1_meshinfo
1898 def NbBiQuadQuadrangles(self):
1899 return self.mesh.NbBiQuadQuadrangles()
1901 ## Returns the number of polygons in the mesh
1902 # @return an integer value
1903 # @ingroup l1_meshinfo
1904 def NbPolygons(self):
1905 return self.mesh.NbPolygons()
1907 ## Returns the number of volumes in the mesh
1908 # @return an integer value
1909 # @ingroup l1_meshinfo
1910 def NbVolumes(self):
1911 return self.mesh.NbVolumes()
1913 ## Returns the number of volumes with the given order in the mesh
1914 # @param elementOrder the order of elements:
1915 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1916 # @return an integer value
1917 # @ingroup l1_meshinfo
1918 def NbVolumesOfOrder(self, elementOrder):
1919 return self.mesh.NbVolumesOfOrder(elementOrder)
1921 ## Returns the number of tetrahedrons in the mesh
1922 # @return an integer value
1923 # @ingroup l1_meshinfo
1925 return self.mesh.NbTetras()
1927 ## Returns the number of tetrahedrons with the given order in the mesh
1928 # @param elementOrder the order of elements:
1929 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1930 # @return an integer value
1931 # @ingroup l1_meshinfo
1932 def NbTetrasOfOrder(self, elementOrder):
1933 return self.mesh.NbTetrasOfOrder(elementOrder)
1935 ## Returns the number of hexahedrons in the mesh
1936 # @return an integer value
1937 # @ingroup l1_meshinfo
1939 return self.mesh.NbHexas()
1941 ## Returns the number of hexahedrons with the given order in the mesh
1942 # @param elementOrder the order of elements:
1943 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1944 # @return an integer value
1945 # @ingroup l1_meshinfo
1946 def NbHexasOfOrder(self, elementOrder):
1947 return self.mesh.NbHexasOfOrder(elementOrder)
1949 ## Returns the number of triquadratic hexahedrons in the mesh
1950 # @return an integer value
1951 # @ingroup l1_meshinfo
1952 def NbTriQuadraticHexas(self):
1953 return self.mesh.NbTriQuadraticHexas()
1955 ## Returns the number of pyramids in the mesh
1956 # @return an integer value
1957 # @ingroup l1_meshinfo
1958 def NbPyramids(self):
1959 return self.mesh.NbPyramids()
1961 ## Returns the number of pyramids with the given order in the mesh
1962 # @param elementOrder the order of elements:
1963 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1964 # @return an integer value
1965 # @ingroup l1_meshinfo
1966 def NbPyramidsOfOrder(self, elementOrder):
1967 return self.mesh.NbPyramidsOfOrder(elementOrder)
1969 ## Returns the number of prisms in the mesh
1970 # @return an integer value
1971 # @ingroup l1_meshinfo
1973 return self.mesh.NbPrisms()
1975 ## Returns the number of prisms with the given order in the mesh
1976 # @param elementOrder the order of elements:
1977 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1978 # @return an integer value
1979 # @ingroup l1_meshinfo
1980 def NbPrismsOfOrder(self, elementOrder):
1981 return self.mesh.NbPrismsOfOrder(elementOrder)
1983 ## Returns the number of hexagonal prisms in the mesh
1984 # @return an integer value
1985 # @ingroup l1_meshinfo
1986 def NbHexagonalPrisms(self):
1987 return self.mesh.NbHexagonalPrisms()
1989 ## Returns the number of polyhedrons in the mesh
1990 # @return an integer value
1991 # @ingroup l1_meshinfo
1992 def NbPolyhedrons(self):
1993 return self.mesh.NbPolyhedrons()
1995 ## Returns the number of submeshes in the mesh
1996 # @return an integer value
1997 # @ingroup l1_meshinfo
1998 def NbSubMesh(self):
1999 return self.mesh.NbSubMesh()
2001 ## Returns the list of mesh elements IDs
2002 # @return the list of integer values
2003 # @ingroup l1_meshinfo
2004 def GetElementsId(self):
2005 return self.mesh.GetElementsId()
2007 ## Returns the list of IDs of mesh elements with the given type
2008 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2009 # @return list of integer values
2010 # @ingroup l1_meshinfo
2011 def GetElementsByType(self, elementType):
2012 return self.mesh.GetElementsByType(elementType)
2014 ## Returns the list of mesh nodes IDs
2015 # @return the list of integer values
2016 # @ingroup l1_meshinfo
2017 def GetNodesId(self):
2018 return self.mesh.GetNodesId()
2020 # Get the information about mesh elements:
2021 # ------------------------------------
2023 ## Returns the type of mesh element
2024 # @return the value from SMESH::ElementType enumeration
2025 # @ingroup l1_meshinfo
2026 def GetElementType(self, id, iselem):
2027 return self.mesh.GetElementType(id, iselem)
2029 ## Returns the geometric type of mesh element
2030 # @return the value from SMESH::EntityType enumeration
2031 # @ingroup l1_meshinfo
2032 def GetElementGeomType(self, id):
2033 return self.mesh.GetElementGeomType(id)
2035 ## Returns the list of submesh elements IDs
2036 # @param Shape a geom object(sub-shape) IOR
2037 # Shape must be the sub-shape of a ShapeToMesh()
2038 # @return the list of integer values
2039 # @ingroup l1_meshinfo
2040 def GetSubMeshElementsId(self, Shape):
2041 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2042 ShapeID = Shape.GetSubShapeIndices()[0]
2045 return self.mesh.GetSubMeshElementsId(ShapeID)
2047 ## Returns the list of submesh nodes IDs
2048 # @param Shape a geom object(sub-shape) IOR
2049 # Shape must be the sub-shape of a ShapeToMesh()
2050 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2051 # @return the list of integer values
2052 # @ingroup l1_meshinfo
2053 def GetSubMeshNodesId(self, Shape, all):
2054 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2055 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2058 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2060 ## Returns type of elements on given shape
2061 # @param Shape a geom object(sub-shape) IOR
2062 # Shape must be a sub-shape of a ShapeToMesh()
2063 # @return element type
2064 # @ingroup l1_meshinfo
2065 def GetSubMeshElementType(self, Shape):
2066 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2067 ShapeID = Shape.GetSubShapeIndices()[0]
2070 return self.mesh.GetSubMeshElementType(ShapeID)
2072 ## Gets the mesh description
2073 # @return string value
2074 # @ingroup l1_meshinfo
2076 return self.mesh.Dump()
2079 # Get the information about nodes and elements of a mesh by its IDs:
2080 # -----------------------------------------------------------
2082 ## Gets XYZ coordinates of a node
2083 # \n If there is no nodes for the given ID - returns an empty list
2084 # @return a list of double precision values
2085 # @ingroup l1_meshinfo
2086 def GetNodeXYZ(self, id):
2087 return self.mesh.GetNodeXYZ(id)
2089 ## Returns list of IDs of inverse elements for the given node
2090 # \n If there is no node for the given ID - returns an empty list
2091 # @return a list of integer values
2092 # @ingroup l1_meshinfo
2093 def GetNodeInverseElements(self, id):
2094 return self.mesh.GetNodeInverseElements(id)
2096 ## @brief Returns the position of a node on the shape
2097 # @return SMESH::NodePosition
2098 # @ingroup l1_meshinfo
2099 def GetNodePosition(self,NodeID):
2100 return self.mesh.GetNodePosition(NodeID)
2102 ## If the given element is a node, returns the ID of shape
2103 # \n If there is no node for the given ID - returns -1
2104 # @return an integer value
2105 # @ingroup l1_meshinfo
2106 def GetShapeID(self, id):
2107 return self.mesh.GetShapeID(id)
2109 ## Returns the ID of the result shape after
2110 # FindShape() from SMESH_MeshEditor for the given element
2111 # \n If there is no element for the given ID - returns -1
2112 # @return an integer value
2113 # @ingroup l1_meshinfo
2114 def GetShapeIDForElem(self,id):
2115 return self.mesh.GetShapeIDForElem(id)
2117 ## Returns the number of nodes for the given element
2118 # \n If there is no element for the given ID - returns -1
2119 # @return an integer value
2120 # @ingroup l1_meshinfo
2121 def GetElemNbNodes(self, id):
2122 return self.mesh.GetElemNbNodes(id)
2124 ## Returns the node ID the given index for the given element
2125 # \n If there is no element for the given ID - returns -1
2126 # \n If there is no node for the given index - returns -2
2127 # @return an integer value
2128 # @ingroup l1_meshinfo
2129 def GetElemNode(self, id, index):
2130 return self.mesh.GetElemNode(id, index)
2132 ## Returns the IDs of nodes of the given element
2133 # @return a list of integer values
2134 # @ingroup l1_meshinfo
2135 def GetElemNodes(self, id):
2136 return self.mesh.GetElemNodes(id)
2138 ## Returns true if the given node is the medium node in the given quadratic element
2139 # @ingroup l1_meshinfo
2140 def IsMediumNode(self, elementID, nodeID):
2141 return self.mesh.IsMediumNode(elementID, nodeID)
2143 ## Returns true if the given node is the medium node in one of quadratic elements
2144 # @ingroup l1_meshinfo
2145 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2146 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2148 ## Returns the number of edges for the given element
2149 # @ingroup l1_meshinfo
2150 def ElemNbEdges(self, id):
2151 return self.mesh.ElemNbEdges(id)
2153 ## Returns the number of faces for the given element
2154 # @ingroup l1_meshinfo
2155 def ElemNbFaces(self, id):
2156 return self.mesh.ElemNbFaces(id)
2158 ## Returns nodes of given face (counted from zero) for given volumic element.
2159 # @ingroup l1_meshinfo
2160 def GetElemFaceNodes(self,elemId, faceIndex):
2161 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2163 ## Returns an element based on all given nodes.
2164 # @ingroup l1_meshinfo
2165 def FindElementByNodes(self,nodes):
2166 return self.mesh.FindElementByNodes(nodes)
2168 ## Returns true if the given element is a polygon
2169 # @ingroup l1_meshinfo
2170 def IsPoly(self, id):
2171 return self.mesh.IsPoly(id)
2173 ## Returns true if the given element is quadratic
2174 # @ingroup l1_meshinfo
2175 def IsQuadratic(self, id):
2176 return self.mesh.IsQuadratic(id)
2178 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2179 # @ingroup l1_meshinfo
2180 def GetBallDiameter(self, id):
2181 return self.mesh.GetBallDiameter(id)
2183 ## Returns XYZ coordinates of the barycenter of the given element
2184 # \n If there is no element for the given ID - returns an empty list
2185 # @return a list of three double values
2186 # @ingroup l1_meshinfo
2187 def BaryCenter(self, id):
2188 return self.mesh.BaryCenter(id)
2190 ## Passes mesh elements through the given filter and return IDs of fitting elements
2191 # @param theFilter SMESH_Filter
2192 # @return a list of ids
2193 # @ingroup l1_controls
2194 def GetIdsFromFilter(self, theFilter):
2195 theFilter.SetMesh( self.mesh )
2196 return theFilter.GetIDs()
2198 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2199 # Returns a list of special structures (borders).
2200 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2201 # @ingroup l1_controls
2202 def GetFreeBorders(self):
2203 aFilterMgr = self.smeshpyD.CreateFilterManager()
2204 aPredicate = aFilterMgr.CreateFreeEdges()
2205 aPredicate.SetMesh(self.mesh)
2206 aBorders = aPredicate.GetBorders()
2207 aFilterMgr.UnRegister()
2211 # Get mesh measurements information:
2212 # ------------------------------------
2214 ## Get minimum distance between two nodes, elements or distance to the origin
2215 # @param id1 first node/element id
2216 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2217 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2218 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2219 # @return minimum distance value
2220 # @sa GetMinDistance()
2221 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2222 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2223 return aMeasure.value
2225 ## Get measure structure specifying minimum distance data between two objects
2226 # @param id1 first node/element id
2227 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2228 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2229 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2230 # @return Measure structure
2232 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2234 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2236 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2239 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2241 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2246 aMeasurements = self.smeshpyD.CreateMeasurements()
2247 aMeasure = aMeasurements.MinDistance(id1, id2)
2248 aMeasurements.UnRegister()
2251 ## Get bounding box of the specified object(s)
2252 # @param objects single source object or list of source objects or list of nodes/elements IDs
2253 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2254 # @c False specifies that @a objects are nodes
2255 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2256 # @sa GetBoundingBox()
2257 def BoundingBox(self, objects=None, isElem=False):
2258 result = self.GetBoundingBox(objects, isElem)
2262 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2265 ## Get measure structure specifying bounding box data of the specified object(s)
2266 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2267 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2268 # @c False specifies that @a objects are nodes
2269 # @return Measure structure
2271 def GetBoundingBox(self, IDs=None, isElem=False):
2274 elif isinstance(IDs, tuple):
2276 if not isinstance(IDs, list):
2278 if len(IDs) > 0 and isinstance(IDs[0], int):
2282 if isinstance(o, Mesh):
2283 srclist.append(o.mesh)
2284 elif hasattr(o, "_narrow"):
2285 src = o._narrow(SMESH.SMESH_IDSource)
2286 if src: srclist.append(src)
2288 elif isinstance(o, list):
2290 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2292 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2295 aMeasurements = self.smeshpyD.CreateMeasurements()
2296 aMeasure = aMeasurements.BoundingBox(srclist)
2297 aMeasurements.UnRegister()
2300 # Mesh edition (SMESH_MeshEditor functionality):
2301 # ---------------------------------------------
2303 ## Removes the elements from the mesh by ids
2304 # @param IDsOfElements is a list of ids of elements to remove
2305 # @return True or False
2306 # @ingroup l2_modif_del
2307 def RemoveElements(self, IDsOfElements):
2308 return self.editor.RemoveElements(IDsOfElements)
2310 ## Removes nodes from mesh by ids
2311 # @param IDsOfNodes is a list of ids of nodes to remove
2312 # @return True or False
2313 # @ingroup l2_modif_del
2314 def RemoveNodes(self, IDsOfNodes):
2315 return self.editor.RemoveNodes(IDsOfNodes)
2317 ## Removes all orphan (free) nodes from mesh
2318 # @return number of the removed nodes
2319 # @ingroup l2_modif_del
2320 def RemoveOrphanNodes(self):
2321 return self.editor.RemoveOrphanNodes()
2323 ## Add a node to the mesh by coordinates
2324 # @return Id of the new node
2325 # @ingroup l2_modif_add
2326 def AddNode(self, x, y, z):
2327 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2328 if hasVars: self.mesh.SetParameters(Parameters)
2329 return self.editor.AddNode( x, y, z)
2331 ## Creates a 0D element on a node with given number.
2332 # @param IDOfNode the ID of node for creation of the element.
2333 # @return the Id of the new 0D element
2334 # @ingroup l2_modif_add
2335 def Add0DElement(self, IDOfNode):
2336 return self.editor.Add0DElement(IDOfNode)
2338 ## Create 0D elements on all nodes of the given elements except those
2339 # nodes on which a 0D element already exists.
2340 # @param theObject an object on whose nodes 0D elements will be created.
2341 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2342 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2343 # @param theGroupName optional name of a group to add 0D elements created
2344 # and/or found on nodes of \a theObject.
2345 # @return an object (a new group or a temporary SMESH_IDSource) holding
2346 # IDs of new and/or found 0D elements. IDs of 0D elements
2347 # can be retrieved from the returned object by calling GetIDs()
2348 # @ingroup l2_modif_add
2349 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2350 if isinstance( theObject, Mesh ):
2351 theObject = theObject.GetMesh()
2352 if isinstance( theObject, list ):
2353 theObject = self.GetIDSource( theObject, SMESH.ALL )
2354 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2356 ## Creates a ball element on a node with given ID.
2357 # @param IDOfNode the ID of node for creation of the element.
2358 # @param diameter the bal diameter.
2359 # @return the Id of the new ball element
2360 # @ingroup l2_modif_add
2361 def AddBall(self, IDOfNode, diameter):
2362 return self.editor.AddBall( IDOfNode, diameter )
2364 ## Creates a linear or quadratic edge (this is determined
2365 # by the number of given nodes).
2366 # @param IDsOfNodes the list of node IDs for creation of the element.
2367 # The order of nodes in this list should correspond to the description
2368 # of MED. \n This description is located by the following link:
2369 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2370 # @return the Id of the new edge
2371 # @ingroup l2_modif_add
2372 def AddEdge(self, IDsOfNodes):
2373 return self.editor.AddEdge(IDsOfNodes)
2375 ## Creates a linear or quadratic face (this is determined
2376 # by the number of given nodes).
2377 # @param IDsOfNodes the list of node IDs for creation of the element.
2378 # The order of nodes in this list should correspond to the description
2379 # of MED. \n This description is located by the following link:
2380 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2381 # @return the Id of the new face
2382 # @ingroup l2_modif_add
2383 def AddFace(self, IDsOfNodes):
2384 return self.editor.AddFace(IDsOfNodes)
2386 ## Adds a polygonal face to the mesh by the list of node IDs
2387 # @param IdsOfNodes the list of node IDs for creation of the element.
2388 # @return the Id of the new face
2389 # @ingroup l2_modif_add
2390 def AddPolygonalFace(self, IdsOfNodes):
2391 return self.editor.AddPolygonalFace(IdsOfNodes)
2393 ## Creates both simple and quadratic volume (this is determined
2394 # by the number of given nodes).
2395 # @param IDsOfNodes the list of node IDs for creation of the element.
2396 # The order of nodes in this list should correspond to the description
2397 # of MED. \n This description is located by the following link:
2398 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2399 # @return the Id of the new volumic element
2400 # @ingroup l2_modif_add
2401 def AddVolume(self, IDsOfNodes):
2402 return self.editor.AddVolume(IDsOfNodes)
2404 ## Creates a volume of many faces, giving nodes for each face.
2405 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2406 # @param Quantities the list of integer values, Quantities[i]
2407 # gives the quantity of nodes in face number i.
2408 # @return the Id of the new volumic element
2409 # @ingroup l2_modif_add
2410 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2411 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2413 ## Creates a volume of many faces, giving the IDs of the existing faces.
2414 # @param IdsOfFaces the list of face IDs for volume creation.
2416 # Note: The created volume will refer only to the nodes
2417 # of the given faces, not to the faces themselves.
2418 # @return the Id of the new volumic element
2419 # @ingroup l2_modif_add
2420 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2421 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2424 ## @brief Binds a node to a vertex
2425 # @param NodeID a node ID
2426 # @param Vertex a vertex or vertex ID
2427 # @return True if succeed else raises an exception
2428 # @ingroup l2_modif_add
2429 def SetNodeOnVertex(self, NodeID, Vertex):
2430 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2431 VertexID = Vertex.GetSubShapeIndices()[0]
2435 self.editor.SetNodeOnVertex(NodeID, VertexID)
2436 except SALOME.SALOME_Exception, inst:
2437 raise ValueError, inst.details.text
2441 ## @brief Stores the node position on an edge
2442 # @param NodeID a node ID
2443 # @param Edge an edge or edge ID
2444 # @param paramOnEdge a parameter on the edge where the node is located
2445 # @return True if succeed else raises an exception
2446 # @ingroup l2_modif_add
2447 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2448 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2449 EdgeID = Edge.GetSubShapeIndices()[0]
2453 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2454 except SALOME.SALOME_Exception, inst:
2455 raise ValueError, inst.details.text
2458 ## @brief Stores node position on a face
2459 # @param NodeID a node ID
2460 # @param Face a face or face ID
2461 # @param u U parameter on the face where the node is located
2462 # @param v V parameter on the face where the node is located
2463 # @return True if succeed else raises an exception
2464 # @ingroup l2_modif_add
2465 def SetNodeOnFace(self, NodeID, Face, u, v):
2466 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2467 FaceID = Face.GetSubShapeIndices()[0]
2471 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2472 except SALOME.SALOME_Exception, inst:
2473 raise ValueError, inst.details.text
2476 ## @brief Binds a node to a solid
2477 # @param NodeID a node ID
2478 # @param Solid a solid or solid ID
2479 # @return True if succeed else raises an exception
2480 # @ingroup l2_modif_add
2481 def SetNodeInVolume(self, NodeID, Solid):
2482 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2483 SolidID = Solid.GetSubShapeIndices()[0]
2487 self.editor.SetNodeInVolume(NodeID, SolidID)
2488 except SALOME.SALOME_Exception, inst:
2489 raise ValueError, inst.details.text
2492 ## @brief Bind an element to a shape
2493 # @param ElementID an element ID
2494 # @param Shape a shape or shape ID
2495 # @return True if succeed else raises an exception
2496 # @ingroup l2_modif_add
2497 def SetMeshElementOnShape(self, ElementID, Shape):
2498 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2499 ShapeID = Shape.GetSubShapeIndices()[0]
2503 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2504 except SALOME.SALOME_Exception, inst:
2505 raise ValueError, inst.details.text
2509 ## Moves the node with the given id
2510 # @param NodeID the id of the node
2511 # @param x a new X coordinate
2512 # @param y a new Y coordinate
2513 # @param z a new Z coordinate
2514 # @return True if succeed else False
2515 # @ingroup l2_modif_movenode
2516 def MoveNode(self, NodeID, x, y, z):
2517 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2518 if hasVars: self.mesh.SetParameters(Parameters)
2519 return self.editor.MoveNode(NodeID, x, y, z)
2521 ## Finds the node closest to a point and moves it to a point location
2522 # @param x the X coordinate of a point
2523 # @param y the Y coordinate of a point
2524 # @param z the Z coordinate of a point
2525 # @param NodeID if specified (>0), the node with this ID is moved,
2526 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2527 # @return the ID of a node
2528 # @ingroup l2_modif_throughp
2529 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2530 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2531 if hasVars: self.mesh.SetParameters(Parameters)
2532 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2534 ## Finds the node closest to a point
2535 # @param x the X coordinate of a point
2536 # @param y the Y coordinate of a point
2537 # @param z the Z coordinate of a point
2538 # @return the ID of a node
2539 # @ingroup l2_modif_throughp
2540 def FindNodeClosestTo(self, x, y, z):
2541 #preview = self.mesh.GetMeshEditPreviewer()
2542 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2543 return self.editor.FindNodeClosestTo(x, y, z)
2545 ## Finds the elements where a point lays IN or ON
2546 # @param x the X coordinate of a point
2547 # @param y the Y coordinate of a point
2548 # @param z the Z coordinate of a point
2549 # @param elementType type of elements to find (SMESH.ALL type
2550 # means elements of any type excluding nodes, discrete and 0D elements)
2551 # @param meshPart a part of mesh (group, sub-mesh) to search within
2552 # @return list of IDs of found elements
2553 # @ingroup l2_modif_throughp
2554 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2556 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2558 return self.editor.FindElementsByPoint(x, y, z, elementType)
2560 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2561 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2562 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2564 def GetPointState(self, x, y, z):
2565 return self.editor.GetPointState(x, y, z)
2567 ## Finds the node closest to a point and moves it to a point location
2568 # @param x the X coordinate of a point
2569 # @param y the Y coordinate of a point
2570 # @param z the Z coordinate of a point
2571 # @return the ID of a moved node
2572 # @ingroup l2_modif_throughp
2573 def MeshToPassThroughAPoint(self, x, y, z):
2574 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2576 ## Replaces two neighbour triangles sharing Node1-Node2 link
2577 # with the triangles built on the same 4 nodes but having other common link.
2578 # @param NodeID1 the ID of the first node
2579 # @param NodeID2 the ID of the second node
2580 # @return false if proper faces were not found
2581 # @ingroup l2_modif_invdiag
2582 def InverseDiag(self, NodeID1, NodeID2):
2583 return self.editor.InverseDiag(NodeID1, NodeID2)
2585 ## Replaces two neighbour triangles sharing Node1-Node2 link
2586 # with a quadrangle built on the same 4 nodes.
2587 # @param NodeID1 the ID of the first node
2588 # @param NodeID2 the ID of the second node
2589 # @return false if proper faces were not found
2590 # @ingroup l2_modif_unitetri
2591 def DeleteDiag(self, NodeID1, NodeID2):
2592 return self.editor.DeleteDiag(NodeID1, NodeID2)
2594 ## Reorients elements by ids
2595 # @param IDsOfElements if undefined reorients all mesh elements
2596 # @return True if succeed else False
2597 # @ingroup l2_modif_changori
2598 def Reorient(self, IDsOfElements=None):
2599 if IDsOfElements == None:
2600 IDsOfElements = self.GetElementsId()
2601 return self.editor.Reorient(IDsOfElements)
2603 ## Reorients all elements of the object
2604 # @param theObject mesh, submesh or group
2605 # @return True if succeed else False
2606 # @ingroup l2_modif_changori
2607 def ReorientObject(self, theObject):
2608 if ( isinstance( theObject, Mesh )):
2609 theObject = theObject.GetMesh()
2610 return self.editor.ReorientObject(theObject)
2612 ## Reorient faces contained in \a the2DObject.
2613 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2614 # @param theDirection is a desired direction of normal of \a theFace.
2615 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2616 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2617 # compared with theDirection. It can be either ID of face or a point
2618 # by which the face will be found. The point can be given as either
2619 # a GEOM vertex or a list of point coordinates.
2620 # @return number of reoriented faces
2621 # @ingroup l2_modif_changori
2622 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2624 if isinstance( the2DObject, Mesh ):
2625 the2DObject = the2DObject.GetMesh()
2626 if isinstance( the2DObject, list ):
2627 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2628 # check theDirection
2629 if isinstance( theDirection, geompyDC.GEOM._objref_GEOM_Object):
2630 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2631 if isinstance( theDirection, list ):
2632 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2633 # prepare theFace and thePoint
2634 theFace = theFaceOrPoint
2635 thePoint = PointStruct(0,0,0)
2636 if isinstance( theFaceOrPoint, geompyDC.GEOM._objref_GEOM_Object):
2637 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2639 if isinstance( theFaceOrPoint, list ):
2640 thePoint = PointStruct( *theFaceOrPoint )
2642 if isinstance( theFaceOrPoint, PointStruct ):
2643 thePoint = theFaceOrPoint
2645 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2647 ## Fuses the neighbouring triangles into quadrangles.
2648 # @param IDsOfElements The triangles to be fused,
2649 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2650 # @param MaxAngle is the maximum angle between element normals at which the fusion
2651 # is still performed; theMaxAngle is mesured in radians.
2652 # Also it could be a name of variable which defines angle in degrees.
2653 # @return TRUE in case of success, FALSE otherwise.
2654 # @ingroup l2_modif_unitetri
2655 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2657 if isinstance(MaxAngle,str):
2659 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2660 self.mesh.SetParameters(Parameters)
2661 if not IDsOfElements:
2662 IDsOfElements = self.GetElementsId()
2664 if ( isinstance( theCriterion, SMESH._objref_NumericalFunctor ) ):
2665 Functor = theCriterion
2667 Functor = self.smeshpyD.GetFunctor(theCriterion)
2668 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2670 ## Fuses the neighbouring triangles of the object into quadrangles
2671 # @param theObject is mesh, submesh or group
2672 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2673 # @param MaxAngle a max angle between element normals at which the fusion
2674 # is still performed; theMaxAngle is mesured in radians.
2675 # @return TRUE in case of success, FALSE otherwise.
2676 # @ingroup l2_modif_unitetri
2677 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2678 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2679 self.mesh.SetParameters(Parameters)
2680 if ( isinstance( theObject, Mesh )):
2681 theObject = theObject.GetMesh()
2682 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2684 ## Splits quadrangles into triangles.
2686 # If @a theCriterion is None, quadrangles will be split by the smallest diagonal.
2688 # @param IDsOfElements the faces to be splitted.
2689 # @param theCriterion FT_...; used to choose a diagonal for splitting.
2690 # @return TRUE in case of success, FALSE otherwise.
2691 # @ingroup l2_modif_cutquadr
2692 def QuadToTri (self, IDsOfElements, theCriterion = None):
2693 if IDsOfElements == []:
2694 IDsOfElements = self.GetElementsId()
2695 if theCriterion is None:
2696 theCriterion = FT_MaxElementLength2D
2697 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2699 ## Splits quadrangles into triangles.
2701 # If @a theCriterion is None, quadrangles will be split by the smallest diagonal.
2703 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
2704 # @param theCriterion FT_...; used to choose a diagonal for splitting.
2705 # @return TRUE in case of success, FALSE otherwise.
2706 # @ingroup l2_modif_cutquadr
2707 def QuadToTriObject (self, theObject, theCriterion = None):
2708 if ( isinstance( theObject, Mesh )):
2709 theObject = theObject.GetMesh()
2710 if theCriterion is None:
2711 theCriterion = FT_MaxElementLength2D
2712 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2714 ## Splits quadrangles into triangles.
2715 # @param IDsOfElements the faces to be splitted
2716 # @param Diag13 is used to choose a diagonal for splitting.
2717 # @return TRUE in case of success, FALSE otherwise.
2718 # @ingroup l2_modif_cutquadr
2719 def SplitQuad (self, IDsOfElements, Diag13):
2720 if IDsOfElements == []:
2721 IDsOfElements = self.GetElementsId()
2722 return self.editor.SplitQuad(IDsOfElements, Diag13)
2724 ## Splits quadrangles into triangles.
2725 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
2726 # @param Diag13 is used to choose a diagonal for splitting.
2727 # @return TRUE in case of success, FALSE otherwise.
2728 # @ingroup l2_modif_cutquadr
2729 def SplitQuadObject (self, theObject, Diag13):
2730 if ( isinstance( theObject, Mesh )):
2731 theObject = theObject.GetMesh()
2732 return self.editor.SplitQuadObject(theObject, Diag13)
2734 ## Finds a better splitting of the given quadrangle.
2735 # @param IDOfQuad the ID of the quadrangle to be splitted.
2736 # @param theCriterion FT_...; a criterion to choose a diagonal for splitting.
2737 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2738 # diagonal is better, 0 if error occurs.
2739 # @ingroup l2_modif_cutquadr
2740 def BestSplit (self, IDOfQuad, theCriterion):
2741 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2743 ## Splits volumic elements into tetrahedrons
2744 # @param elemIDs either list of elements or mesh or group or submesh
2745 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2746 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2747 # @ingroup l2_modif_cutquadr
2748 def SplitVolumesIntoTetra(self, elemIDs, method=Hex_5Tet ):
2749 if isinstance( elemIDs, Mesh ):
2750 elemIDs = elemIDs.GetMesh()
2751 if ( isinstance( elemIDs, list )):
2752 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2753 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2755 ## Splits quadrangle faces near triangular facets of volumes
2757 # @ingroup l1_auxiliary
2758 def SplitQuadsNearTriangularFacets(self):
2759 faces_array = self.GetElementsByType(SMESH.FACE)
2760 for face_id in faces_array:
2761 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2762 quad_nodes = self.mesh.GetElemNodes(face_id)
2763 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2764 isVolumeFound = False
2765 for node1_elem in node1_elems:
2766 if not isVolumeFound:
2767 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2768 nb_nodes = self.GetElemNbNodes(node1_elem)
2769 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2770 volume_elem = node1_elem
2771 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2772 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2773 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2774 isVolumeFound = True
2775 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2776 self.SplitQuad([face_id], False) # diagonal 2-4
2777 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2778 isVolumeFound = True
2779 self.SplitQuad([face_id], True) # diagonal 1-3
2780 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2781 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2782 isVolumeFound = True
2783 self.SplitQuad([face_id], True) # diagonal 1-3
2785 ## @brief Splits hexahedrons into tetrahedrons.
2787 # This operation uses pattern mapping functionality for splitting.
2788 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2789 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2790 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2791 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2792 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2793 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2794 # @return TRUE in case of success, FALSE otherwise.
2795 # @ingroup l1_auxiliary
2796 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2797 # Pattern: 5.---------.6
2802 # (0,0,1) 4.---------.7 * |
2809 # (0,0,0) 0.---------.3
2810 pattern_tetra = "!!! Nb of points: \n 8 \n\
2820 !!! Indices of points of 6 tetras: \n\
2828 pattern = self.smeshpyD.GetPattern()
2829 isDone = pattern.LoadFromFile(pattern_tetra)
2831 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2834 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2835 isDone = pattern.MakeMesh(self.mesh, False, False)
2836 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2838 # split quafrangle faces near triangular facets of volumes
2839 self.SplitQuadsNearTriangularFacets()
2843 ## @brief Split hexahedrons into prisms.
2845 # Uses the pattern mapping functionality for splitting.
2846 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2847 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2848 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2849 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2850 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2851 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2852 # @return TRUE in case of success, FALSE otherwise.
2853 # @ingroup l1_auxiliary
2854 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2855 # Pattern: 5.---------.6
2860 # (0,0,1) 4.---------.7 |
2867 # (0,0,0) 0.---------.3
2868 pattern_prism = "!!! Nb of points: \n 8 \n\
2878 !!! Indices of points of 2 prisms: \n\
2882 pattern = self.smeshpyD.GetPattern()
2883 isDone = pattern.LoadFromFile(pattern_prism)
2885 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2888 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2889 isDone = pattern.MakeMesh(self.mesh, False, False)
2890 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2892 # Splits quafrangle faces near triangular facets of volumes
2893 self.SplitQuadsNearTriangularFacets()
2897 ## Smoothes elements
2898 # @param IDsOfElements the list if ids of elements to smooth
2899 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2900 # Note that nodes built on edges and boundary nodes are always fixed.
2901 # @param MaxNbOfIterations the maximum number of iterations
2902 # @param MaxAspectRatio varies in range [1.0, inf]
2903 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2904 # @return TRUE in case of success, FALSE otherwise.
2905 # @ingroup l2_modif_smooth
2906 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2907 MaxNbOfIterations, MaxAspectRatio, Method):
2908 if IDsOfElements == []:
2909 IDsOfElements = self.GetElementsId()
2910 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2911 self.mesh.SetParameters(Parameters)
2912 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2913 MaxNbOfIterations, MaxAspectRatio, Method)
2915 ## Smoothes elements which belong to the given object
2916 # @param theObject the object to smooth
2917 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2918 # Note that nodes built on edges and boundary nodes are always fixed.
2919 # @param MaxNbOfIterations the maximum number of iterations
2920 # @param MaxAspectRatio varies in range [1.0, inf]
2921 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2922 # @return TRUE in case of success, FALSE otherwise.
2923 # @ingroup l2_modif_smooth
2924 def SmoothObject(self, theObject, IDsOfFixedNodes,
2925 MaxNbOfIterations, MaxAspectRatio, Method):
2926 if ( isinstance( theObject, Mesh )):
2927 theObject = theObject.GetMesh()
2928 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2929 MaxNbOfIterations, MaxAspectRatio, Method)
2931 ## Parametrically smoothes the given elements
2932 # @param IDsOfElements the list if ids of elements to smooth
2933 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2934 # Note that nodes built on edges and boundary nodes are always fixed.
2935 # @param MaxNbOfIterations the maximum number of iterations
2936 # @param MaxAspectRatio varies in range [1.0, inf]
2937 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2938 # @return TRUE in case of success, FALSE otherwise.
2939 # @ingroup l2_modif_smooth
2940 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2941 MaxNbOfIterations, MaxAspectRatio, Method):
2942 if IDsOfElements == []:
2943 IDsOfElements = self.GetElementsId()
2944 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2945 self.mesh.SetParameters(Parameters)
2946 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2947 MaxNbOfIterations, MaxAspectRatio, Method)
2949 ## Parametrically smoothes the elements which belong to the given object
2950 # @param theObject the object to smooth
2951 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2952 # Note that nodes built on edges and boundary nodes are always fixed.
2953 # @param MaxNbOfIterations the maximum number of iterations
2954 # @param MaxAspectRatio varies in range [1.0, inf]
2955 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2956 # @return TRUE in case of success, FALSE otherwise.
2957 # @ingroup l2_modif_smooth
2958 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2959 MaxNbOfIterations, MaxAspectRatio, Method):
2960 if ( isinstance( theObject, Mesh )):
2961 theObject = theObject.GetMesh()
2962 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2963 MaxNbOfIterations, MaxAspectRatio, Method)
2965 ## Converts the mesh to quadratic, deletes old elements, replacing
2966 # them with quadratic with the same id.
2967 # @param theForce3d new node creation method:
2968 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
2969 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
2970 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2971 # @ingroup l2_modif_tofromqu
2972 def ConvertToQuadratic(self, theForce3d, theSubMesh=None):
2974 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
2976 self.editor.ConvertToQuadratic(theForce3d)
2978 ## Converts the mesh from quadratic to ordinary,
2979 # deletes old quadratic elements, \n replacing
2980 # them with ordinary mesh elements with the same id.
2981 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2982 # @ingroup l2_modif_tofromqu
2983 def ConvertFromQuadratic(self, theSubMesh=None):
2985 self.editor.ConvertFromQuadraticObject(theSubMesh)
2987 return self.editor.ConvertFromQuadratic()
2989 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
2990 # @return TRUE if operation has been completed successfully, FALSE otherwise
2991 # @ingroup l2_modif_edit
2992 def Make2DMeshFrom3D(self):
2993 return self.editor. Make2DMeshFrom3D()
2995 ## Creates missing boundary elements
2996 # @param elements - elements whose boundary is to be checked:
2997 # mesh, group, sub-mesh or list of elements
2998 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
2999 # @param dimension - defines type of boundary elements to create:
3000 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3001 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3002 # @param groupName - a name of group to store created boundary elements in,
3003 # "" means not to create the group
3004 # @param meshName - a name of new mesh to store created boundary elements in,
3005 # "" means not to create the new mesh
3006 # @param toCopyElements - if true, the checked elements will be copied into
3007 # the new mesh else only boundary elements will be copied into the new mesh
3008 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3009 # boundary elements will be copied into the new mesh
3010 # @return tuple (mesh, group) where bondary elements were added to
3011 # @ingroup l2_modif_edit
3012 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3013 toCopyElements=False, toCopyExistingBondary=False):
3014 if isinstance( elements, Mesh ):
3015 elements = elements.GetMesh()
3016 if ( isinstance( elements, list )):
3017 elemType = SMESH.ALL
3018 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3019 elements = self.editor.MakeIDSource(elements, elemType)
3020 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3021 toCopyElements,toCopyExistingBondary)
3022 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3026 # @brief Creates missing boundary elements around either the whole mesh or
3027 # groups of 2D elements
3028 # @param dimension - defines type of boundary elements to create
3029 # @param groupName - a name of group to store all boundary elements in,
3030 # "" means not to create the group
3031 # @param meshName - a name of a new mesh, which is a copy of the initial
3032 # mesh + created boundary elements; "" means not to create the new mesh
3033 # @param toCopyAll - if true, the whole initial mesh will be copied into
3034 # the new mesh else only boundary elements will be copied into the new mesh
3035 # @param groups - groups of 2D elements to make boundary around
3036 # @retval tuple( long, mesh, groups )
3037 # long - number of added boundary elements
3038 # mesh - the mesh where elements were added to
3039 # group - the group of boundary elements or None
3041 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3042 toCopyAll=False, groups=[]):
3043 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3045 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3046 return nb, mesh, group
3048 ## Renumber mesh nodes
3049 # @ingroup l2_modif_renumber
3050 def RenumberNodes(self):
3051 self.editor.RenumberNodes()
3053 ## Renumber mesh elements
3054 # @ingroup l2_modif_renumber
3055 def RenumberElements(self):
3056 self.editor.RenumberElements()
3058 ## Generates new elements by rotation of the elements around the axis
3059 # @param IDsOfElements the list of ids of elements to sweep
3060 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3061 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3062 # @param NbOfSteps the number of steps
3063 # @param Tolerance tolerance
3064 # @param MakeGroups forces the generation of new groups from existing ones
3065 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3066 # of all steps, else - size of each step
3067 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3068 # @ingroup l2_modif_extrurev
3069 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3070 MakeGroups=False, TotalAngle=False):
3071 if IDsOfElements == []:
3072 IDsOfElements = self.GetElementsId()
3073 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3074 Axis = self.smeshpyD.GetAxisStruct(Axis)
3075 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3076 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3077 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3078 self.mesh.SetParameters(Parameters)
3079 if TotalAngle and NbOfSteps:
3080 AngleInRadians /= NbOfSteps
3082 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3083 AngleInRadians, NbOfSteps, Tolerance)
3084 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3087 ## Generates new elements by rotation of the elements of object around the axis
3088 # @param theObject object which elements should be sweeped.
3089 # It can be a mesh, a sub mesh or a group.
3090 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3091 # @param AngleInRadians the angle of Rotation
3092 # @param NbOfSteps number of steps
3093 # @param Tolerance tolerance
3094 # @param MakeGroups forces the generation of new groups from existing ones
3095 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3096 # of all steps, else - size of each step
3097 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3098 # @ingroup l2_modif_extrurev
3099 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3100 MakeGroups=False, TotalAngle=False):
3101 if ( isinstance( theObject, Mesh )):
3102 theObject = theObject.GetMesh()
3103 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3104 Axis = self.smeshpyD.GetAxisStruct(Axis)
3105 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3106 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3107 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3108 self.mesh.SetParameters(Parameters)
3109 if TotalAngle and NbOfSteps:
3110 AngleInRadians /= NbOfSteps
3112 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3113 NbOfSteps, Tolerance)
3114 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3117 ## Generates new elements by rotation of the elements of object around the axis
3118 # @param theObject object which elements should be sweeped.
3119 # It can be a mesh, a sub mesh or a group.
3120 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3121 # @param AngleInRadians the angle of Rotation
3122 # @param NbOfSteps number of steps
3123 # @param Tolerance tolerance
3124 # @param MakeGroups forces the generation of new groups from existing ones
3125 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3126 # of all steps, else - size of each step
3127 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3128 # @ingroup l2_modif_extrurev
3129 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3130 MakeGroups=False, TotalAngle=False):
3131 if ( isinstance( theObject, Mesh )):
3132 theObject = theObject.GetMesh()
3133 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3134 Axis = self.smeshpyD.GetAxisStruct(Axis)
3135 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3136 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3137 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3138 self.mesh.SetParameters(Parameters)
3139 if TotalAngle and NbOfSteps:
3140 AngleInRadians /= NbOfSteps
3142 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3143 NbOfSteps, Tolerance)
3144 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3147 ## Generates new elements by rotation of the elements of object around the axis
3148 # @param theObject object which elements should be sweeped.
3149 # It can be a mesh, a sub mesh or a group.
3150 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3151 # @param AngleInRadians the angle of Rotation
3152 # @param NbOfSteps number of steps
3153 # @param Tolerance tolerance
3154 # @param MakeGroups forces the generation of new groups from existing ones
3155 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3156 # of all steps, else - size of each step
3157 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3158 # @ingroup l2_modif_extrurev
3159 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3160 MakeGroups=False, TotalAngle=False):
3161 if ( isinstance( theObject, Mesh )):
3162 theObject = theObject.GetMesh()
3163 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3164 Axis = self.smeshpyD.GetAxisStruct(Axis)
3165 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3166 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3167 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3168 self.mesh.SetParameters(Parameters)
3169 if TotalAngle and NbOfSteps:
3170 AngleInRadians /= NbOfSteps
3172 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3173 NbOfSteps, Tolerance)
3174 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3177 ## Generates new elements by extrusion of the elements with given ids
3178 # @param IDsOfElements the list of elements ids for extrusion
3179 # @param StepVector vector or DirStruct, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3180 # @param NbOfSteps the number of steps
3181 # @param MakeGroups forces the generation of new groups from existing ones
3182 # @param IsNodes is True if elements with given ids are nodes
3183 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3184 # @ingroup l2_modif_extrurev
3185 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3186 if IDsOfElements == []:
3187 IDsOfElements = self.GetElementsId()
3188 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3189 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3190 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3191 Parameters = StepVector.PS.parameters + var_separator + Parameters
3192 self.mesh.SetParameters(Parameters)
3195 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3197 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3199 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3201 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3204 ## Generates new elements by extrusion of the elements with given ids
3205 # @param IDsOfElements is ids of elements
3206 # @param StepVector vector, defining the direction and value of extrusion
3207 # @param NbOfSteps the number of steps
3208 # @param ExtrFlags sets flags for extrusion
3209 # @param SewTolerance uses for comparing locations of nodes if flag
3210 # EXTRUSION_FLAG_SEW is set
3211 # @param MakeGroups forces the generation of new groups from existing ones
3212 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3213 # @ingroup l2_modif_extrurev
3214 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3215 ExtrFlags, SewTolerance, MakeGroups=False):
3216 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3217 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3219 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3220 ExtrFlags, SewTolerance)
3221 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3222 ExtrFlags, SewTolerance)
3225 ## Generates new elements by extrusion of the elements which belong to the object
3226 # @param theObject the object which elements should be processed.
3227 # It can be a mesh, a sub mesh or a group.
3228 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3229 # @param NbOfSteps the number of steps
3230 # @param MakeGroups forces the generation of new groups from existing ones
3231 # @param IsNodes is True if elements which belong to the object are nodes
3232 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3233 # @ingroup l2_modif_extrurev
3234 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3235 if ( isinstance( theObject, Mesh )):
3236 theObject = theObject.GetMesh()
3237 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3238 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3239 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3240 Parameters = StepVector.PS.parameters + var_separator + Parameters
3241 self.mesh.SetParameters(Parameters)
3244 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3246 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3248 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3250 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3253 ## Generates new elements by extrusion of the elements which belong to the object
3254 # @param theObject object which elements should be processed.
3255 # It can be a mesh, a sub mesh or a group.
3256 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3257 # @param NbOfSteps the number of steps
3258 # @param MakeGroups to generate new groups from existing ones
3259 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3260 # @ingroup l2_modif_extrurev
3261 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3262 if ( isinstance( theObject, Mesh )):
3263 theObject = theObject.GetMesh()
3264 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3265 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3266 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3267 Parameters = StepVector.PS.parameters + var_separator + Parameters
3268 self.mesh.SetParameters(Parameters)
3270 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3271 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3274 ## Generates new elements by extrusion of the elements which belong to the object
3275 # @param theObject object which elements should be processed.
3276 # It can be a mesh, a sub mesh or a group.
3277 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3278 # @param NbOfSteps the number of steps
3279 # @param MakeGroups forces the generation of new groups from existing ones
3280 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3281 # @ingroup l2_modif_extrurev
3282 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3283 if ( isinstance( theObject, Mesh )):
3284 theObject = theObject.GetMesh()
3285 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3286 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3287 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3288 Parameters = StepVector.PS.parameters + var_separator + Parameters
3289 self.mesh.SetParameters(Parameters)
3291 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3292 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3297 ## Generates new elements by extrusion of the given elements
3298 # The path of extrusion must be a meshed edge.
3299 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3300 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3301 # @param NodeStart the start node from Path. Defines the direction of extrusion
3302 # @param HasAngles allows the shape to be rotated around the path
3303 # to get the resulting mesh in a helical fashion
3304 # @param Angles list of angles in radians
3305 # @param LinearVariation forces the computation of rotation angles as linear
3306 # variation of the given Angles along path steps
3307 # @param HasRefPoint allows using the reference point
3308 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3309 # The User can specify any point as the Reference Point.
3310 # @param MakeGroups forces the generation of new groups from existing ones
3311 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3312 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3313 # only SMESH::Extrusion_Error otherwise
3314 # @ingroup l2_modif_extrurev
3315 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3316 HasAngles, Angles, LinearVariation,
3317 HasRefPoint, RefPoint, MakeGroups, ElemType):
3318 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3319 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3321 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3322 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3323 self.mesh.SetParameters(Parameters)
3325 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3327 if isinstance(Base, list):
3329 if Base == []: IDsOfElements = self.GetElementsId()
3330 else: IDsOfElements = Base
3331 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3332 HasAngles, Angles, LinearVariation,
3333 HasRefPoint, RefPoint, MakeGroups, ElemType)
3335 if isinstance(Base, Mesh): Base = Base.GetMesh()
3336 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3337 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3338 HasAngles, Angles, LinearVariation,
3339 HasRefPoint, RefPoint, MakeGroups, ElemType)
3341 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3344 ## Generates new elements by extrusion of the given elements
3345 # The path of extrusion must be a meshed edge.
3346 # @param IDsOfElements ids of elements
3347 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3348 # @param PathShape shape(edge) defines the sub-mesh for the path
3349 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3350 # @param HasAngles allows the shape to be rotated around the path
3351 # to get the resulting mesh in a helical fashion
3352 # @param Angles list of angles in radians
3353 # @param HasRefPoint allows using the reference point
3354 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3355 # The User can specify any point as the Reference Point.
3356 # @param MakeGroups forces the generation of new groups from existing ones
3357 # @param LinearVariation forces the computation of rotation angles as linear
3358 # variation of the given Angles along path steps
3359 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3360 # only SMESH::Extrusion_Error otherwise
3361 # @ingroup l2_modif_extrurev
3362 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3363 HasAngles, Angles, HasRefPoint, RefPoint,
3364 MakeGroups=False, LinearVariation=False):
3365 if IDsOfElements == []:
3366 IDsOfElements = self.GetElementsId()
3367 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3368 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3370 if ( isinstance( PathMesh, Mesh )):
3371 PathMesh = PathMesh.GetMesh()
3372 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3373 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3374 self.mesh.SetParameters(Parameters)
3375 if HasAngles and Angles and LinearVariation:
3376 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3379 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3380 PathShape, NodeStart, HasAngles,
3381 Angles, HasRefPoint, RefPoint)
3382 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3383 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3385 ## Generates new elements by extrusion of the elements which belong to the object
3386 # The path of extrusion must be a meshed edge.
3387 # @param theObject the object which elements should be processed.
3388 # It can be a mesh, a sub mesh or a group.
3389 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3390 # @param PathShape shape(edge) defines the sub-mesh for the path
3391 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3392 # @param HasAngles allows the shape to be rotated around the path
3393 # to get the resulting mesh in a helical fashion
3394 # @param Angles list of angles
3395 # @param HasRefPoint allows using the reference point
3396 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3397 # The User can specify any point as the Reference Point.
3398 # @param MakeGroups forces the generation of new groups from existing ones
3399 # @param LinearVariation forces the computation of rotation angles as linear
3400 # variation of the given Angles along path steps
3401 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3402 # only SMESH::Extrusion_Error otherwise
3403 # @ingroup l2_modif_extrurev
3404 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3405 HasAngles, Angles, HasRefPoint, RefPoint,
3406 MakeGroups=False, LinearVariation=False):
3407 if ( isinstance( theObject, Mesh )):
3408 theObject = theObject.GetMesh()
3409 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3410 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3411 if ( isinstance( PathMesh, Mesh )):
3412 PathMesh = PathMesh.GetMesh()
3413 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3414 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3415 self.mesh.SetParameters(Parameters)
3416 if HasAngles and Angles and LinearVariation:
3417 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3420 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3421 PathShape, NodeStart, HasAngles,
3422 Angles, HasRefPoint, RefPoint)
3423 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3424 NodeStart, HasAngles, Angles, HasRefPoint,
3427 ## Generates new elements by extrusion of the elements which belong to the object
3428 # The path of extrusion must be a meshed edge.
3429 # @param theObject the object which elements should be processed.
3430 # It can be a mesh, a sub mesh or a group.
3431 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3432 # @param PathShape shape(edge) defines the sub-mesh for the path
3433 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3434 # @param HasAngles allows the shape to be rotated around the path
3435 # to get the resulting mesh in a helical fashion
3436 # @param Angles list of angles
3437 # @param HasRefPoint allows using the reference point
3438 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3439 # The User can specify any point as the Reference Point.
3440 # @param MakeGroups forces the generation of new groups from existing ones
3441 # @param LinearVariation forces the computation of rotation angles as linear
3442 # variation of the given Angles along path steps
3443 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3444 # only SMESH::Extrusion_Error otherwise
3445 # @ingroup l2_modif_extrurev
3446 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3447 HasAngles, Angles, HasRefPoint, RefPoint,
3448 MakeGroups=False, LinearVariation=False):
3449 if ( isinstance( theObject, Mesh )):
3450 theObject = theObject.GetMesh()
3451 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3452 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3453 if ( isinstance( PathMesh, Mesh )):
3454 PathMesh = PathMesh.GetMesh()
3455 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3456 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3457 self.mesh.SetParameters(Parameters)
3458 if HasAngles and Angles and LinearVariation:
3459 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3462 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3463 PathShape, NodeStart, HasAngles,
3464 Angles, HasRefPoint, RefPoint)
3465 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3466 NodeStart, HasAngles, Angles, HasRefPoint,
3469 ## Generates new elements by extrusion of the elements which belong to the object
3470 # The path of extrusion must be a meshed edge.
3471 # @param theObject the object which elements should be processed.
3472 # It can be a mesh, a sub mesh or a group.
3473 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3474 # @param PathShape shape(edge) defines the sub-mesh for the path
3475 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3476 # @param HasAngles allows the shape to be rotated around the path
3477 # to get the resulting mesh in a helical fashion
3478 # @param Angles list of angles
3479 # @param HasRefPoint allows using the reference point
3480 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3481 # The User can specify any point as the Reference Point.
3482 # @param MakeGroups forces the generation of new groups from existing ones
3483 # @param LinearVariation forces the computation of rotation angles as linear
3484 # variation of the given Angles along path steps
3485 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3486 # only SMESH::Extrusion_Error otherwise
3487 # @ingroup l2_modif_extrurev
3488 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3489 HasAngles, Angles, HasRefPoint, RefPoint,
3490 MakeGroups=False, LinearVariation=False):
3491 if ( isinstance( theObject, Mesh )):
3492 theObject = theObject.GetMesh()
3493 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3494 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3495 if ( isinstance( PathMesh, Mesh )):
3496 PathMesh = PathMesh.GetMesh()
3497 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3498 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3499 self.mesh.SetParameters(Parameters)
3500 if HasAngles and Angles and LinearVariation:
3501 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3504 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3505 PathShape, NodeStart, HasAngles,
3506 Angles, HasRefPoint, RefPoint)
3507 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3508 NodeStart, HasAngles, Angles, HasRefPoint,
3511 ## Creates a symmetrical copy of mesh elements
3512 # @param IDsOfElements list of elements ids
3513 # @param Mirror is AxisStruct or geom object(point, line, plane)
3514 # @param theMirrorType is POINT, AXIS or PLANE
3515 # If the Mirror is a geom object this parameter is unnecessary
3516 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3517 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3518 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3519 # @ingroup l2_modif_trsf
3520 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3521 if IDsOfElements == []:
3522 IDsOfElements = self.GetElementsId()
3523 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3524 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3525 self.mesh.SetParameters(Mirror.parameters)
3526 if Copy and MakeGroups:
3527 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3528 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3531 ## Creates a new mesh by a symmetrical copy of mesh elements
3532 # @param IDsOfElements the list of elements ids
3533 # @param Mirror is AxisStruct or geom object (point, line, plane)
3534 # @param theMirrorType is POINT, AXIS or PLANE
3535 # If the Mirror is a geom object this parameter is unnecessary
3536 # @param MakeGroups to generate new groups from existing ones
3537 # @param NewMeshName a name of the new mesh to create
3538 # @return instance of Mesh class
3539 # @ingroup l2_modif_trsf
3540 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3541 if IDsOfElements == []:
3542 IDsOfElements = self.GetElementsId()
3543 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3544 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3545 self.mesh.SetParameters(Mirror.parameters)
3546 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3547 MakeGroups, NewMeshName)
3548 return Mesh(self.smeshpyD,self.geompyD,mesh)
3550 ## Creates a symmetrical copy of the object
3551 # @param theObject mesh, submesh or group
3552 # @param Mirror AxisStruct or geom object (point, line, plane)
3553 # @param theMirrorType is POINT, AXIS or PLANE
3554 # If the Mirror is a geom object this parameter is unnecessary
3555 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3556 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3557 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3558 # @ingroup l2_modif_trsf
3559 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3560 if ( isinstance( theObject, Mesh )):
3561 theObject = theObject.GetMesh()
3562 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3563 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3564 self.mesh.SetParameters(Mirror.parameters)
3565 if Copy and MakeGroups:
3566 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3567 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3570 ## Creates a new mesh by a symmetrical copy of the object
3571 # @param theObject mesh, submesh or group
3572 # @param Mirror AxisStruct or geom object (point, line, plane)
3573 # @param theMirrorType POINT, AXIS or PLANE
3574 # If the Mirror is a geom object this parameter is unnecessary
3575 # @param MakeGroups forces the generation of new groups from existing ones
3576 # @param NewMeshName the name of the new mesh to create
3577 # @return instance of Mesh class
3578 # @ingroup l2_modif_trsf
3579 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3580 if ( isinstance( theObject, Mesh )):
3581 theObject = theObject.GetMesh()
3582 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3583 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3584 self.mesh.SetParameters(Mirror.parameters)
3585 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3586 MakeGroups, NewMeshName)
3587 return Mesh( self.smeshpyD,self.geompyD,mesh )
3589 ## Translates the elements
3590 # @param IDsOfElements list of elements ids
3591 # @param Vector the direction of translation (DirStruct or vector)
3592 # @param Copy allows copying the translated elements
3593 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3594 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3595 # @ingroup l2_modif_trsf
3596 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3597 if IDsOfElements == []:
3598 IDsOfElements = self.GetElementsId()
3599 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3600 Vector = self.smeshpyD.GetDirStruct(Vector)
3601 self.mesh.SetParameters(Vector.PS.parameters)
3602 if Copy and MakeGroups:
3603 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3604 self.editor.Translate(IDsOfElements, Vector, Copy)
3607 ## Creates a new mesh of translated elements
3608 # @param IDsOfElements list of elements ids
3609 # @param Vector the direction of translation (DirStruct or vector)
3610 # @param MakeGroups forces the generation of new groups from existing ones
3611 # @param NewMeshName the name of the newly created mesh
3612 # @return instance of Mesh class
3613 # @ingroup l2_modif_trsf
3614 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3615 if IDsOfElements == []:
3616 IDsOfElements = self.GetElementsId()
3617 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3618 Vector = self.smeshpyD.GetDirStruct(Vector)
3619 self.mesh.SetParameters(Vector.PS.parameters)
3620 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3621 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3623 ## Translates the object
3624 # @param theObject the object to translate (mesh, submesh, or group)
3625 # @param Vector direction of translation (DirStruct or geom vector)
3626 # @param Copy allows copying the translated elements
3627 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3628 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3629 # @ingroup l2_modif_trsf
3630 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3631 if ( isinstance( theObject, Mesh )):
3632 theObject = theObject.GetMesh()
3633 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3634 Vector = self.smeshpyD.GetDirStruct(Vector)
3635 self.mesh.SetParameters(Vector.PS.parameters)
3636 if Copy and MakeGroups:
3637 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3638 self.editor.TranslateObject(theObject, Vector, Copy)
3641 ## Creates a new mesh from the translated object
3642 # @param theObject the object to translate (mesh, submesh, or group)
3643 # @param Vector the direction of translation (DirStruct or geom vector)
3644 # @param MakeGroups forces the generation of new groups from existing ones
3645 # @param NewMeshName the name of the newly created mesh
3646 # @return instance of Mesh class
3647 # @ingroup l2_modif_trsf
3648 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3649 if (isinstance(theObject, Mesh)):
3650 theObject = theObject.GetMesh()
3651 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3652 Vector = self.smeshpyD.GetDirStruct(Vector)
3653 self.mesh.SetParameters(Vector.PS.parameters)
3654 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3655 return Mesh( self.smeshpyD, self.geompyD, mesh )
3659 ## Scales the object
3660 # @param theObject - the object to translate (mesh, submesh, or group)
3661 # @param thePoint - base point for scale
3662 # @param theScaleFact - list of 1-3 scale factors for axises
3663 # @param Copy - allows copying the translated elements
3664 # @param MakeGroups - forces the generation of new groups from existing
3666 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3667 # empty list otherwise
3668 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3669 if ( isinstance( theObject, Mesh )):
3670 theObject = theObject.GetMesh()
3671 if ( isinstance( theObject, list )):
3672 theObject = self.GetIDSource(theObject, SMESH.ALL)
3674 self.mesh.SetParameters(thePoint.parameters)
3676 if Copy and MakeGroups:
3677 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3678 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3681 ## Creates a new mesh from the translated object
3682 # @param theObject - the object to translate (mesh, submesh, or group)
3683 # @param thePoint - base point for scale
3684 # @param theScaleFact - list of 1-3 scale factors for axises
3685 # @param MakeGroups - forces the generation of new groups from existing ones
3686 # @param NewMeshName - the name of the newly created mesh
3687 # @return instance of Mesh class
3688 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3689 if (isinstance(theObject, Mesh)):
3690 theObject = theObject.GetMesh()
3691 if ( isinstance( theObject, list )):
3692 theObject = self.GetIDSource(theObject,SMESH.ALL)
3694 self.mesh.SetParameters(thePoint.parameters)
3695 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3696 MakeGroups, NewMeshName)
3697 return Mesh( self.smeshpyD, self.geompyD, mesh )
3701 ## Rotates the elements
3702 # @param IDsOfElements list of elements ids
3703 # @param Axis the axis of rotation (AxisStruct or geom line)
3704 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3705 # @param Copy allows copying the rotated elements
3706 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3707 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3708 # @ingroup l2_modif_trsf
3709 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3710 if IDsOfElements == []:
3711 IDsOfElements = self.GetElementsId()
3712 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3713 Axis = self.smeshpyD.GetAxisStruct(Axis)
3714 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3715 Parameters = Axis.parameters + var_separator + Parameters
3716 self.mesh.SetParameters(Parameters)
3717 if Copy and MakeGroups:
3718 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3719 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3722 ## Creates a new mesh of rotated elements
3723 # @param IDsOfElements list of element ids
3724 # @param Axis the axis of rotation (AxisStruct or geom line)
3725 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3726 # @param MakeGroups forces the generation of new groups from existing ones
3727 # @param NewMeshName the name of the newly created mesh
3728 # @return instance of Mesh class
3729 # @ingroup l2_modif_trsf
3730 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3731 if IDsOfElements == []:
3732 IDsOfElements = self.GetElementsId()
3733 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3734 Axis = self.smeshpyD.GetAxisStruct(Axis)
3735 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3736 Parameters = Axis.parameters + var_separator + Parameters
3737 self.mesh.SetParameters(Parameters)
3738 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3739 MakeGroups, NewMeshName)
3740 return Mesh( self.smeshpyD, self.geompyD, mesh )
3742 ## Rotates the object
3743 # @param theObject the object to rotate( mesh, submesh, or group)
3744 # @param Axis the axis of rotation (AxisStruct or geom line)
3745 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3746 # @param Copy allows copying the rotated 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 RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3751 if (isinstance(theObject, Mesh)):
3752 theObject = theObject.GetMesh()
3753 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3754 Axis = self.smeshpyD.GetAxisStruct(Axis)
3755 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3756 Parameters = Axis.parameters + ":" + Parameters
3757 self.mesh.SetParameters(Parameters)
3758 if Copy and MakeGroups:
3759 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3760 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3763 ## Creates a new mesh from the rotated object
3764 # @param theObject the object to rotate (mesh, submesh, or group)
3765 # @param Axis the axis of rotation (AxisStruct or geom line)
3766 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3767 # @param MakeGroups forces the generation of new groups from existing ones
3768 # @param NewMeshName the name of the newly created mesh
3769 # @return instance of Mesh class
3770 # @ingroup l2_modif_trsf
3771 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3772 if (isinstance( theObject, Mesh )):
3773 theObject = theObject.GetMesh()
3774 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3775 Axis = self.smeshpyD.GetAxisStruct(Axis)
3776 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3777 Parameters = Axis.parameters + ":" + Parameters
3778 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3779 MakeGroups, NewMeshName)
3780 self.mesh.SetParameters(Parameters)
3781 return Mesh( self.smeshpyD, self.geompyD, mesh )
3783 ## Finds groups of ajacent nodes within Tolerance.
3784 # @param Tolerance the value of tolerance
3785 # @return the list of groups of nodes
3786 # @ingroup l2_modif_trsf
3787 def FindCoincidentNodes (self, Tolerance):
3788 return self.editor.FindCoincidentNodes(Tolerance)
3790 ## Finds groups of ajacent nodes within Tolerance.
3791 # @param Tolerance the value of tolerance
3792 # @param SubMeshOrGroup SubMesh or Group
3793 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3794 # @return the list of groups of nodes
3795 # @ingroup l2_modif_trsf
3796 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3797 if (isinstance( SubMeshOrGroup, Mesh )):
3798 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3799 if not isinstance( exceptNodes, list):
3800 exceptNodes = [ exceptNodes ]
3801 if exceptNodes and isinstance( exceptNodes[0], int):
3802 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3803 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3806 # @param GroupsOfNodes the list of groups of nodes
3807 # @ingroup l2_modif_trsf
3808 def MergeNodes (self, GroupsOfNodes):
3809 self.editor.MergeNodes(GroupsOfNodes)
3811 ## Finds the elements built on the same nodes.
3812 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3813 # @return a list of groups of equal elements
3814 # @ingroup l2_modif_trsf
3815 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3816 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
3817 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
3818 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3820 ## Merges elements in each given group.
3821 # @param GroupsOfElementsID groups of elements for merging
3822 # @ingroup l2_modif_trsf
3823 def MergeElements(self, GroupsOfElementsID):
3824 self.editor.MergeElements(GroupsOfElementsID)
3826 ## Leaves one element and removes all other elements built on the same nodes.
3827 # @ingroup l2_modif_trsf
3828 def MergeEqualElements(self):
3829 self.editor.MergeEqualElements()
3831 ## Sews free borders
3832 # @return SMESH::Sew_Error
3833 # @ingroup l2_modif_trsf
3834 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3835 FirstNodeID2, SecondNodeID2, LastNodeID2,
3836 CreatePolygons, CreatePolyedrs):
3837 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3838 FirstNodeID2, SecondNodeID2, LastNodeID2,
3839 CreatePolygons, CreatePolyedrs)
3841 ## Sews conform free borders
3842 # @return SMESH::Sew_Error
3843 # @ingroup l2_modif_trsf
3844 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3845 FirstNodeID2, SecondNodeID2):
3846 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3847 FirstNodeID2, SecondNodeID2)
3849 ## Sews border to side
3850 # @return SMESH::Sew_Error
3851 # @ingroup l2_modif_trsf
3852 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3853 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3854 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3855 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3857 ## Sews two sides of a mesh. The nodes belonging to Side1 are
3858 # merged with the nodes of elements of Side2.
3859 # The number of elements in theSide1 and in theSide2 must be
3860 # equal and they should have similar nodal connectivity.
3861 # The nodes to merge should belong to side borders and
3862 # the first node should be linked to the second.
3863 # @return SMESH::Sew_Error
3864 # @ingroup l2_modif_trsf
3865 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3866 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3867 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3868 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3869 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3870 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3872 ## Sets new nodes for the given element.
3873 # @param ide the element id
3874 # @param newIDs nodes ids
3875 # @return If the number of nodes does not correspond to the type of element - returns false
3876 # @ingroup l2_modif_edit
3877 def ChangeElemNodes(self, ide, newIDs):
3878 return self.editor.ChangeElemNodes(ide, newIDs)
3880 ## If during the last operation of MeshEditor some nodes were
3881 # created, this method returns the list of their IDs, \n
3882 # if new nodes were not created - returns empty list
3883 # @return the list of integer values (can be empty)
3884 # @ingroup l1_auxiliary
3885 def GetLastCreatedNodes(self):
3886 return self.editor.GetLastCreatedNodes()
3888 ## If during the last operation of MeshEditor some elements were
3889 # created this method returns the list of their IDs, \n
3890 # if new elements were not created - returns empty list
3891 # @return the list of integer values (can be empty)
3892 # @ingroup l1_auxiliary
3893 def GetLastCreatedElems(self):
3894 return self.editor.GetLastCreatedElems()
3896 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3897 # @param theNodes identifiers of nodes to be doubled
3898 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
3899 # nodes. If list of element identifiers is empty then nodes are doubled but
3900 # they not assigned to elements
3901 # @return TRUE if operation has been completed successfully, FALSE otherwise
3902 # @ingroup l2_modif_edit
3903 def DoubleNodes(self, theNodes, theModifiedElems):
3904 return self.editor.DoubleNodes(theNodes, theModifiedElems)
3906 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3907 # This method provided for convenience works as DoubleNodes() described above.
3908 # @param theNodeId identifiers of node to be doubled
3909 # @param theModifiedElems identifiers of elements to be updated
3910 # @return TRUE if operation has been completed successfully, FALSE otherwise
3911 # @ingroup l2_modif_edit
3912 def DoubleNode(self, theNodeId, theModifiedElems):
3913 return self.editor.DoubleNode(theNodeId, theModifiedElems)
3915 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3916 # This method provided for convenience works as DoubleNodes() described above.
3917 # @param theNodes group of nodes to be doubled
3918 # @param theModifiedElems group of elements to be updated.
3919 # @param theMakeGroup forces the generation of a group containing new nodes.
3920 # @return TRUE or a created group if operation has been completed successfully,
3921 # FALSE or None otherwise
3922 # @ingroup l2_modif_edit
3923 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
3925 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
3926 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
3928 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3929 # This method provided for convenience works as DoubleNodes() described above.
3930 # @param theNodes list of groups of nodes to be doubled
3931 # @param theModifiedElems list of groups of elements to be updated.
3932 # @param theMakeGroup forces the generation of a group containing new nodes.
3933 # @return TRUE if operation has been completed successfully, FALSE otherwise
3934 # @ingroup l2_modif_edit
3935 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
3937 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
3938 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
3940 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3941 # @param theElems - the list of elements (edges or faces) to be replicated
3942 # The nodes for duplication could be found from these elements
3943 # @param theNodesNot - list of nodes to NOT replicate
3944 # @param theAffectedElems - the list of elements (cells and edges) to which the
3945 # replicated nodes should be associated to.
3946 # @return TRUE if operation has been completed successfully, FALSE otherwise
3947 # @ingroup l2_modif_edit
3948 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
3949 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
3951 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3952 # @param theElems - the list of elements (edges or faces) to be replicated
3953 # The nodes for duplication could be found from these elements
3954 # @param theNodesNot - list of nodes to NOT replicate
3955 # @param theShape - shape to detect affected elements (element which geometric center
3956 # located on or inside shape).
3957 # The replicated nodes should be associated to affected elements.
3958 # @return TRUE if operation has been completed successfully, FALSE otherwise
3959 # @ingroup l2_modif_edit
3960 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
3961 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
3963 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3964 # This method provided for convenience works as DoubleNodes() described above.
3965 # @param theElems - group of of elements (edges or faces) to be replicated
3966 # @param theNodesNot - group of nodes not to replicated
3967 # @param theAffectedElems - group of elements to which the replicated nodes
3968 # should be associated to.
3969 # @param theMakeGroup forces the generation of a group containing new elements.
3970 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
3971 # @return TRUE or created groups (one or two) if operation has been completed successfully,
3972 # FALSE or None otherwise
3973 # @ingroup l2_modif_edit
3974 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
3975 theMakeGroup=False, theMakeNodeGroup=False):
3976 if theMakeGroup or theMakeNodeGroup:
3977 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
3979 theMakeGroup, theMakeNodeGroup)
3980 if theMakeGroup and theMakeNodeGroup:
3983 return twoGroups[ int(theMakeNodeGroup) ]
3984 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
3986 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3987 # This method provided for convenience works as DoubleNodes() described above.
3988 # @param theElems - group of of elements (edges or faces) to be replicated
3989 # @param theNodesNot - group of nodes not to replicated
3990 # @param theShape - shape to detect affected elements (element which geometric center
3991 # located on or inside shape).
3992 # The replicated nodes should be associated to affected elements.
3993 # @ingroup l2_modif_edit
3994 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
3995 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
3997 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3998 # This method provided for convenience works as DoubleNodes() described above.
3999 # @param theElems - list of groups of elements (edges or faces) to be replicated
4000 # @param theNodesNot - list of groups of nodes not to replicated
4001 # @param theAffectedElems - group of elements to which the replicated nodes
4002 # should be associated to.
4003 # @param theMakeGroup forces the generation of a group containing new elements.
4004 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4005 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4006 # FALSE or None otherwise
4007 # @ingroup l2_modif_edit
4008 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4009 theMakeGroup=False, theMakeNodeGroup=False):
4010 if theMakeGroup or theMakeNodeGroup:
4011 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4013 theMakeGroup, theMakeNodeGroup)
4014 if theMakeGroup and theMakeNodeGroup:
4017 return twoGroups[ int(theMakeNodeGroup) ]
4018 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4020 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4021 # This method provided for convenience works as DoubleNodes() described above.
4022 # @param theElems - list of groups of elements (edges or faces) to be replicated
4023 # @param theNodesNot - list of groups of nodes not to replicated
4024 # @param theShape - shape to detect affected elements (element which geometric center
4025 # located on or inside shape).
4026 # The replicated nodes should be associated to affected elements.
4027 # @return TRUE if operation has been completed successfully, FALSE otherwise
4028 # @ingroup l2_modif_edit
4029 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4030 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4032 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4033 # This method is the first step of DoubleNodeElemGroupsInRegion.
4034 # @param theElems - list of groups of elements (edges or faces) to be replicated
4035 # @param theNodesNot - list of groups of nodes not to replicated
4036 # @param theShape - shape to detect affected elements (element which geometric center
4037 # located on or inside shape).
4038 # The replicated nodes should be associated to affected elements.
4039 # @return groups of affected elements
4040 # @ingroup l2_modif_edit
4041 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4042 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4044 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4045 # The list of groups must describe a partition of the mesh volumes.
4046 # The nodes of the internal faces at the boundaries of the groups are doubled.
4047 # In option, the internal faces are replaced by flat elements.
4048 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4049 # @param theDomains - list of groups of volumes
4050 # @param createJointElems - if TRUE, create the elements
4051 # @return TRUE if operation has been completed successfully, FALSE otherwise
4052 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4053 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4055 ## Double nodes on some external faces and create flat elements.
4056 # Flat elements are mainly used by some types of mechanic calculations.
4058 # Each group of the list must be constituted of faces.
4059 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4060 # @param theGroupsOfFaces - list of groups of faces
4061 # @return TRUE if operation has been completed successfully, FALSE otherwise
4062 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4063 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4065 ## identify all the elements around a geom shape, get the faces delimiting the hole
4067 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4068 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4070 def _getFunctor(self, funcType ):
4071 fn = self.functors[ funcType._v ]
4073 fn = self.smeshpyD.GetFunctor(funcType)
4074 fn.SetMesh(self.mesh)
4075 self.functors[ funcType._v ] = fn
4078 def _valueFromFunctor(self, funcType, elemId):
4079 fn = self._getFunctor( funcType )
4080 if fn.GetElementType() == self.GetElementType(elemId, True):
4081 val = fn.GetValue(elemId)
4086 ## Get length of 1D element.
4087 # @param elemId mesh element ID
4088 # @return element's length value
4089 # @ingroup l1_measurements
4090 def GetLength(self, elemId):
4091 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4093 ## Get area of 2D element.
4094 # @param elemId mesh element ID
4095 # @return element's area value
4096 # @ingroup l1_measurements
4097 def GetArea(self, elemId):
4098 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4100 ## Get volume of 3D element.
4101 # @param elemId mesh element ID
4102 # @return element's volume value
4103 # @ingroup l1_measurements
4104 def GetVolume(self, elemId):
4105 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4107 ## Get maximum element length.
4108 # @param elemId mesh element ID
4109 # @return element's maximum length value
4110 # @ingroup l1_measurements
4111 def GetMaxElementLength(self, elemId):
4112 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4113 ftype = SMESH.FT_MaxElementLength3D
4115 ftype = SMESH.FT_MaxElementLength2D
4116 return self._valueFromFunctor(ftype, elemId)
4118 ## Get aspect ratio of 2D or 3D element.
4119 # @param elemId mesh element ID
4120 # @return element's aspect ratio value
4121 # @ingroup l1_measurements
4122 def GetAspectRatio(self, elemId):
4123 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4124 ftype = SMESH.FT_AspectRatio3D
4126 ftype = SMESH.FT_AspectRatio
4127 return self._valueFromFunctor(ftype, elemId)
4129 ## Get warping angle of 2D element.
4130 # @param elemId mesh element ID
4131 # @return element's warping angle value
4132 # @ingroup l1_measurements
4133 def GetWarping(self, elemId):
4134 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4136 ## Get minimum angle of 2D element.
4137 # @param elemId mesh element ID
4138 # @return element's minimum angle value
4139 # @ingroup l1_measurements
4140 def GetMinimumAngle(self, elemId):
4141 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4143 ## Get taper of 2D element.
4144 # @param elemId mesh element ID
4145 # @return element's taper value
4146 # @ingroup l1_measurements
4147 def GetTaper(self, elemId):
4148 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4150 ## Get skew of 2D element.
4151 # @param elemId mesh element ID
4152 # @return element's skew value
4153 # @ingroup l1_measurements
4154 def GetSkew(self, elemId):
4155 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4157 pass # end of Mesh class
4159 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4161 class Pattern(SMESH._objref_SMESH_Pattern):
4163 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4164 decrFun = lambda i: i-1
4165 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4166 theMesh.SetParameters(Parameters)
4167 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4169 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4170 decrFun = lambda i: i-1
4171 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4172 theMesh.SetParameters(Parameters)
4173 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4175 # Registering the new proxy for Pattern
4176 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4178 ## Private class used to bind methods creating algorithms to the class Mesh
4183 self.defaultAlgoType = ""
4184 self.algoTypeToClass = {}
4186 # Stores a python class of algorithm
4187 def add(self, algoClass):
4188 if type( algoClass ).__name__ == 'classobj' and \
4189 hasattr( algoClass, "algoType"):
4190 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4191 if not self.defaultAlgoType and \
4192 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4193 self.defaultAlgoType = algoClass.algoType
4194 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4196 # creates a copy of self and assign mesh to the copy
4197 def copy(self, mesh):
4198 other = algoCreator()
4199 other.defaultAlgoType = self.defaultAlgoType
4200 other.algoTypeToClass = self.algoTypeToClass
4204 # creates an instance of algorithm
4205 def __call__(self,algo="",geom=0,*args):
4206 algoType = self.defaultAlgoType
4207 for arg in args + (algo,geom):
4208 if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ):
4210 if isinstance( arg, str ) and arg:
4212 if not algoType and self.algoTypeToClass:
4213 algoType = self.algoTypeToClass.keys()[0]
4214 if self.algoTypeToClass.has_key( algoType ):
4215 #print "Create algo",algoType
4216 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4217 raise RuntimeError, "No class found for algo type %s" % algoType
4220 # Private class used to substitute and store variable parameters of hypotheses.
4222 class hypMethodWrapper:
4223 def __init__(self, hyp, method):
4225 self.method = method
4226 #print "REBIND:", method.__name__
4229 # call a method of hypothesis with calling SetVarParameter() before
4230 def __call__(self,*args):
4232 return self.method( self.hyp, *args ) # hypothesis method with no args
4234 #print "MethWrapper.__call__",self.method.__name__, args
4236 parsed = ParseParameters(*args) # replace variables with their values
4237 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4238 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4239 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4240 # maybe there is a replaced string arg which is not variable
4241 result = self.method( self.hyp, *args )
4242 except ValueError, detail: # raised by ParseParameters()
4244 result = self.method( self.hyp, *args )
4245 except omniORB.CORBA.BAD_PARAM:
4246 raise ValueError, detail # wrong variable name