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.
963 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
964 # sets the GUI name of this mesh to \a name.
965 # @param smeshpyD an instance of smeshDC class
966 # @param geompyD an instance of geompyDC class
967 # @param obj Shape to be meshed or SMESH_Mesh object
968 # @param name Study name of the mesh
969 # @ingroup l2_construct
970 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
971 self.smeshpyD=smeshpyD
977 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
979 # publish geom of mesh (issue 0021122)
980 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
982 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
983 if studyID != geompyD.myStudyId:
984 geompyD.init_geom( smeshpyD.GetCurrentStudy())
989 geo_name = "%s_%s_for_meshing"%(self.geom.GetShapeType(), id(self.geom)%100)
990 geompyD.addToStudy( self.geom, geo_name )
991 self.mesh = self.smeshpyD.CreateMesh(self.geom)
993 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
996 self.mesh = self.smeshpyD.CreateEmptyMesh()
998 self.smeshpyD.SetName(self.mesh, name)
999 elif obj != 0 and objHasName:
1000 self.smeshpyD.SetName(self.mesh, GetName(obj))
1003 self.geom = self.mesh.GetShapeToMesh()
1005 self.editor = self.mesh.GetMeshEditor()
1007 # set self to algoCreator's
1008 for attrName in dir(self):
1009 attr = getattr( self, attrName )
1010 if isinstance( attr, algoCreator ):
1011 setattr( self, attrName, attr.copy( self ))
1013 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1014 # @param theMesh a SMESH_Mesh object
1015 # @ingroup l2_construct
1016 def SetMesh(self, theMesh):
1018 self.geom = self.mesh.GetShapeToMesh()
1020 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1021 # @return a SMESH_Mesh object
1022 # @ingroup l2_construct
1026 ## Gets the name of the mesh
1027 # @return the name of the mesh as a string
1028 # @ingroup l2_construct
1030 name = GetName(self.GetMesh())
1033 ## Sets a name to the mesh
1034 # @param name a new name of the mesh
1035 # @ingroup l2_construct
1036 def SetName(self, name):
1037 self.smeshpyD.SetName(self.GetMesh(), name)
1039 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1040 # The subMesh object gives access to the IDs of nodes and elements.
1041 # @param geom a geometrical object (shape)
1042 # @param name a name for the submesh
1043 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1044 # @ingroup l2_submeshes
1045 def GetSubMesh(self, geom, name):
1046 AssureGeomPublished( self, geom, name )
1047 submesh = self.mesh.GetSubMesh( geom, name )
1050 ## Returns the shape associated to the mesh
1051 # @return a GEOM_Object
1052 # @ingroup l2_construct
1056 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1057 # @param geom the shape to be meshed (GEOM_Object)
1058 # @ingroup l2_construct
1059 def SetShape(self, geom):
1060 self.mesh = self.smeshpyD.CreateMesh(geom)
1062 ## Loads mesh from the study after opening the study
1066 ## Returns true if the hypotheses are defined well
1067 # @param theSubObject a sub-shape of a mesh shape
1068 # @return True or False
1069 # @ingroup l2_construct
1070 def IsReadyToCompute(self, theSubObject):
1071 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1073 ## Returns errors of hypotheses definition.
1074 # The list of errors is empty if everything is OK.
1075 # @param theSubObject a sub-shape of a mesh shape
1076 # @return a list of errors
1077 # @ingroup l2_construct
1078 def GetAlgoState(self, theSubObject):
1079 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1081 ## Returns a geometrical object on which the given element was built.
1082 # The returned geometrical object, if not nil, is either found in the
1083 # study or published by this method with the given name
1084 # @param theElementID the id of the mesh element
1085 # @param theGeomName the user-defined name of the geometrical object
1086 # @return GEOM::GEOM_Object instance
1087 # @ingroup l2_construct
1088 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1089 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1091 ## Returns the mesh dimension depending on the dimension of the underlying shape
1092 # @return mesh dimension as an integer value [0,3]
1093 # @ingroup l1_auxiliary
1094 def MeshDimension(self):
1095 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1096 if len( shells ) > 0 :
1098 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1100 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1106 ## Evaluates size of prospective mesh on a shape
1107 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1108 # To know predicted number of e.g. edges, inquire it this way
1109 # Evaluate()[ EnumToLong( Entity_Edge )]
1110 def Evaluate(self, geom=0):
1111 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1113 geom = self.mesh.GetShapeToMesh()
1116 return self.smeshpyD.Evaluate(self.mesh, geom)
1119 ## Computes the mesh and returns the status of the computation
1120 # @param geom geomtrical shape on which mesh data should be computed
1121 # @param discardModifs if True and the mesh has been edited since
1122 # a last total re-compute and that may prevent successful partial re-compute,
1123 # then the mesh is cleaned before Compute()
1124 # @return True or False
1125 # @ingroup l2_construct
1126 def Compute(self, geom=0, discardModifs=False):
1127 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1129 geom = self.mesh.GetShapeToMesh()
1134 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1136 ok = self.smeshpyD.Compute(self.mesh, geom)
1137 except SALOME.SALOME_Exception, ex:
1138 print "Mesh computation failed, exception caught:"
1139 print " ", ex.details.text
1142 print "Mesh computation failed, exception caught:"
1143 traceback.print_exc()
1147 # Treat compute errors
1148 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1149 for err in computeErrors:
1151 if self.mesh.HasShapeToMesh():
1153 mainIOR = salome.orb.object_to_string(geom)
1154 for sname in salome.myStudyManager.GetOpenStudies():
1155 s = salome.myStudyManager.GetStudyByName(sname)
1157 mainSO = s.FindObjectIOR(mainIOR)
1158 if not mainSO: continue
1159 if err.subShapeID == 1:
1160 shapeText = ' on "%s"' % mainSO.GetName()
1161 subIt = s.NewChildIterator(mainSO)
1163 subSO = subIt.Value()
1165 obj = subSO.GetObject()
1166 if not obj: continue
1167 go = obj._narrow( geompyDC.GEOM._objref_GEOM_Object )
1169 ids = go.GetSubShapeIndices()
1170 if len(ids) == 1 and ids[0] == err.subShapeID:
1171 shapeText = ' on "%s"' % subSO.GetName()
1174 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1176 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1178 shapeText = " on subshape #%s" % (err.subShapeID)
1180 shapeText = " on subshape #%s" % (err.subShapeID)
1182 stdErrors = ["OK", #COMPERR_OK
1183 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1184 "std::exception", #COMPERR_STD_EXCEPTION
1185 "OCC exception", #COMPERR_OCC_EXCEPTION
1186 "SALOME exception", #COMPERR_SLM_EXCEPTION
1187 "Unknown exception", #COMPERR_EXCEPTION
1188 "Memory allocation problem", #COMPERR_MEMORY_PB
1189 "Algorithm failed", #COMPERR_ALGO_FAILED
1190 "Unexpected geometry", #COMPERR_BAD_SHAPE
1191 "Warning", #COMPERR_WARNING
1192 "Computation cancelled",#COMPERR_CANCELED
1193 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1195 if err.code < len(stdErrors): errText = stdErrors[err.code]
1197 errText = "code %s" % -err.code
1198 if errText: errText += ". "
1199 errText += err.comment
1200 if allReasons != "":allReasons += "\n"
1201 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1205 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1207 if err.isGlobalAlgo:
1215 reason = '%s %sD algorithm is missing' % (glob, dim)
1216 elif err.state == HYP_MISSING:
1217 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1218 % (glob, dim, name, dim))
1219 elif err.state == HYP_NOTCONFORM:
1220 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1221 elif err.state == HYP_BAD_PARAMETER:
1222 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1223 % ( glob, dim, name ))
1224 elif err.state == HYP_BAD_GEOMETRY:
1225 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1226 'geometry' % ( glob, dim, name ))
1228 reason = "For unknown reason."+\
1229 " Revise Mesh.Compute() implementation in smeshDC.py!"
1231 if allReasons != "":allReasons += "\n"
1232 allReasons += "- " + reason
1234 if not ok or allReasons != "":
1235 msg = '"' + GetName(self.mesh) + '"'
1236 if ok: msg += " has been computed with warnings"
1237 else: msg += " has not been computed"
1238 if allReasons != "": msg += ":"
1243 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1244 smeshgui = salome.ImportComponentGUI("SMESH")
1245 smeshgui.Init(self.mesh.GetStudyId())
1246 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1247 salome.sg.updateObjBrowser(1)
1251 ## Return submesh objects list in meshing order
1252 # @return list of list of submesh objects
1253 # @ingroup l2_construct
1254 def GetMeshOrder(self):
1255 return self.mesh.GetMeshOrder()
1257 ## Return submesh objects list in meshing order
1258 # @return list of list of submesh objects
1259 # @ingroup l2_construct
1260 def SetMeshOrder(self, submeshes):
1261 return self.mesh.SetMeshOrder(submeshes)
1263 ## Removes all nodes and elements
1264 # @ingroup l2_construct
1267 if salome.sg.hasDesktop():
1268 smeshgui = salome.ImportComponentGUI("SMESH")
1269 smeshgui.Init(self.mesh.GetStudyId())
1270 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1271 salome.sg.updateObjBrowser(1)
1273 ## Removes all nodes and elements of indicated shape
1274 # @ingroup l2_construct
1275 def ClearSubMesh(self, geomId):
1276 self.mesh.ClearSubMesh(geomId)
1277 if salome.sg.hasDesktop():
1278 smeshgui = salome.ImportComponentGUI("SMESH")
1279 smeshgui.Init(self.mesh.GetStudyId())
1280 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1281 salome.sg.updateObjBrowser(1)
1283 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1284 # @param fineness [0.0,1.0] defines mesh fineness
1285 # @return True or False
1286 # @ingroup l3_algos_basic
1287 def AutomaticTetrahedralization(self, fineness=0):
1288 dim = self.MeshDimension()
1290 self.RemoveGlobalHypotheses()
1291 self.Segment().AutomaticLength(fineness)
1293 self.Triangle().LengthFromEdges()
1296 from NETGENPluginDC import NETGEN
1297 self.Tetrahedron(NETGEN)
1299 return self.Compute()
1301 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1302 # @param fineness [0.0, 1.0] defines mesh fineness
1303 # @return True or False
1304 # @ingroup l3_algos_basic
1305 def AutomaticHexahedralization(self, fineness=0):
1306 dim = self.MeshDimension()
1307 # assign the hypotheses
1308 self.RemoveGlobalHypotheses()
1309 self.Segment().AutomaticLength(fineness)
1316 return self.Compute()
1318 ## Assigns a hypothesis
1319 # @param hyp a hypothesis to assign
1320 # @param geom a subhape of mesh geometry
1321 # @return SMESH.Hypothesis_Status
1322 # @ingroup l2_hypotheses
1323 def AddHypothesis(self, hyp, geom=0):
1324 if isinstance( hyp, Mesh_Algorithm ):
1325 hyp = hyp.GetAlgorithm()
1330 geom = self.mesh.GetShapeToMesh()
1332 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1333 status = self.mesh.AddHypothesis(geom, hyp)
1334 isAlgo = hyp._narrow( SMESH_Algo )
1335 hyp_name = GetName( hyp )
1338 geom_name = GetName( geom )
1339 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1342 ## Return True if an algorithm of hypothesis is assigned to a given shape
1343 # @param hyp a hypothesis to check
1344 # @param geom a subhape of mesh geometry
1345 # @return True of False
1346 # @ingroup l2_hypotheses
1347 def IsUsedHypothesis(self, hyp, geom):
1348 if not hyp or not geom:
1350 if isinstance( hyp, Mesh_Algorithm ):
1351 hyp = hyp.GetAlgorithm()
1353 hyps = self.GetHypothesisList(geom)
1355 if h.GetId() == hyp.GetId():
1359 ## Unassigns a hypothesis
1360 # @param hyp a hypothesis to unassign
1361 # @param geom a sub-shape of mesh geometry
1362 # @return SMESH.Hypothesis_Status
1363 # @ingroup l2_hypotheses
1364 def RemoveHypothesis(self, hyp, geom=0):
1365 if isinstance( hyp, Mesh_Algorithm ):
1366 hyp = hyp.GetAlgorithm()
1371 status = self.mesh.RemoveHypothesis(geom, hyp)
1374 ## Gets the list of hypotheses added on a geometry
1375 # @param geom a sub-shape of mesh geometry
1376 # @return the sequence of SMESH_Hypothesis
1377 # @ingroup l2_hypotheses
1378 def GetHypothesisList(self, geom):
1379 return self.mesh.GetHypothesisList( geom )
1381 ## Removes all global hypotheses
1382 # @ingroup l2_hypotheses
1383 def RemoveGlobalHypotheses(self):
1384 current_hyps = self.mesh.GetHypothesisList( self.geom )
1385 for hyp in current_hyps:
1386 self.mesh.RemoveHypothesis( self.geom, hyp )
1390 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1391 ## allowing to overwrite the file if it exists or add the exported data to its contents
1392 # @param f is the file name
1393 # @param auto_groups boolean parameter for creating/not creating
1394 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1395 # the typical use is auto_groups=false.
1396 # @param version MED format version(MED_V2_1 or MED_V2_2)
1397 # @param overwrite boolean parameter for overwriting/not overwriting the file
1398 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1399 # @ingroup l2_impexp
1400 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1402 if isinstance( meshPart, list ):
1403 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1404 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1406 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1408 ## Exports the mesh in a file in SAUV format
1409 # @param f is the file name
1410 # @param auto_groups boolean parameter for creating/not creating
1411 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1412 # the typical use is auto_groups=false.
1413 # @ingroup l2_impexp
1414 def ExportSAUV(self, f, auto_groups=0):
1415 self.mesh.ExportSAUV(f, auto_groups)
1417 ## Exports the mesh in a file in DAT format
1418 # @param f the file name
1419 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1420 # @ingroup l2_impexp
1421 def ExportDAT(self, f, meshPart=None):
1423 if isinstance( meshPart, list ):
1424 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1425 self.mesh.ExportPartToDAT( meshPart, f )
1427 self.mesh.ExportDAT(f)
1429 ## Exports the mesh in a file in UNV format
1430 # @param f the file name
1431 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1432 # @ingroup l2_impexp
1433 def ExportUNV(self, f, meshPart=None):
1435 if isinstance( meshPart, list ):
1436 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1437 self.mesh.ExportPartToUNV( meshPart, f )
1439 self.mesh.ExportUNV(f)
1441 ## Export the mesh in a file in STL format
1442 # @param f the file name
1443 # @param ascii defines the file encoding
1444 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1445 # @ingroup l2_impexp
1446 def ExportSTL(self, f, ascii=1, meshPart=None):
1448 if isinstance( meshPart, list ):
1449 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1450 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1452 self.mesh.ExportSTL(f, ascii)
1454 ## Exports the mesh in a file in CGNS format
1455 # @param f is the file name
1456 # @param overwrite boolean parameter for overwriting/not overwriting the file
1457 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1458 # @ingroup l2_impexp
1459 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1460 if isinstance( meshPart, list ):
1461 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1462 if isinstance( meshPart, Mesh ):
1463 meshPart = meshPart.mesh
1465 meshPart = self.mesh
1466 self.mesh.ExportCGNS(meshPart, f, overwrite)
1468 ## Exports the mesh in a file in GMF format
1469 # @param f is the file name
1470 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1471 # @ingroup l2_impexp
1472 def ExportGMF(self, f, meshPart=None):
1473 if isinstance( meshPart, list ):
1474 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1475 if isinstance( meshPart, Mesh ):
1476 meshPart = meshPart.mesh
1478 meshPart = self.mesh
1479 self.mesh.ExportGMF(meshPart, f)
1481 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1482 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1483 ## allowing to overwrite the file if it exists or add the exported data to its contents
1484 # @param f the file name
1485 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1486 # @param opt boolean parameter for creating/not creating
1487 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1488 # @param overwrite boolean parameter for overwriting/not overwriting the file
1489 # @ingroup l2_impexp
1490 def ExportToMED(self, f, version, opt=0, overwrite=1):
1491 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1493 # Operations with groups:
1494 # ----------------------
1496 ## Creates an empty mesh group
1497 # @param elementType the type of elements in the group
1498 # @param name the name of the mesh group
1499 # @return SMESH_Group
1500 # @ingroup l2_grps_create
1501 def CreateEmptyGroup(self, elementType, name):
1502 return self.mesh.CreateGroup(elementType, name)
1504 ## Creates a mesh group based on the geometric object \a grp
1505 # and gives a \a name, \n if this parameter is not defined
1506 # the name is the same as the geometric group name \n
1507 # Note: Works like GroupOnGeom().
1508 # @param grp a geometric group, a vertex, an edge, a face or a solid
1509 # @param name the name of the mesh group
1510 # @return SMESH_GroupOnGeom
1511 # @ingroup l2_grps_create
1512 def Group(self, grp, name=""):
1513 return self.GroupOnGeom(grp, name)
1515 ## Creates a mesh group based on the geometrical object \a grp
1516 # and gives a \a name, \n if this parameter is not defined
1517 # the name is the same as the geometrical group name
1518 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1519 # @param name the name of the mesh group
1520 # @param typ the type of elements in the group. If not set, it is
1521 # automatically detected by the type of the geometry
1522 # @return SMESH_GroupOnGeom
1523 # @ingroup l2_grps_create
1524 def GroupOnGeom(self, grp, name="", typ=None):
1525 AssureGeomPublished( self, grp, name )
1527 name = grp.GetName()
1529 typ = self._groupTypeFromShape( grp )
1530 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1532 ## Pivate method to get a type of group on geometry
1533 def _groupTypeFromShape( self, shape ):
1534 tgeo = str(shape.GetShapeType())
1535 if tgeo == "VERTEX":
1537 elif tgeo == "EDGE":
1539 elif tgeo == "FACE" or tgeo == "SHELL":
1541 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1543 elif tgeo == "COMPOUND":
1544 sub = self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHAPE"])
1546 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1547 return self._groupTypeFromShape( sub[0] )
1550 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1553 ## Creates a mesh group with given \a name based on the \a filter which
1554 ## is a special type of group dynamically updating it's contents during
1555 ## mesh modification
1556 # @param typ the type of elements in the group
1557 # @param name the name of the mesh group
1558 # @param filter the filter defining group contents
1559 # @return SMESH_GroupOnFilter
1560 # @ingroup l2_grps_create
1561 def GroupOnFilter(self, typ, name, filter):
1562 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1564 ## Creates a mesh group by the given ids of elements
1565 # @param groupName the name of the mesh group
1566 # @param elementType the type of elements in the group
1567 # @param elemIDs the list of ids
1568 # @return SMESH_Group
1569 # @ingroup l2_grps_create
1570 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1571 group = self.mesh.CreateGroup(elementType, groupName)
1575 ## Creates a mesh group by the given conditions
1576 # @param groupName the name of the mesh group
1577 # @param elementType the type of elements in the group
1578 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1579 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1580 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1581 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1582 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1583 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1584 # @return SMESH_Group
1585 # @ingroup l2_grps_create
1589 CritType=FT_Undefined,
1592 UnaryOp=FT_Undefined,
1594 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1595 group = self.MakeGroupByCriterion(groupName, aCriterion)
1598 ## Creates a mesh group by the given criterion
1599 # @param groupName the name of the mesh group
1600 # @param Criterion the instance of Criterion class
1601 # @return SMESH_Group
1602 # @ingroup l2_grps_create
1603 def MakeGroupByCriterion(self, groupName, Criterion):
1604 aFilterMgr = self.smeshpyD.CreateFilterManager()
1605 aFilter = aFilterMgr.CreateFilter()
1607 aCriteria.append(Criterion)
1608 aFilter.SetCriteria(aCriteria)
1609 group = self.MakeGroupByFilter(groupName, aFilter)
1610 aFilterMgr.UnRegister()
1613 ## Creates a mesh group by the given criteria (list of criteria)
1614 # @param groupName the name of the mesh group
1615 # @param theCriteria the list of criteria
1616 # @return SMESH_Group
1617 # @ingroup l2_grps_create
1618 def MakeGroupByCriteria(self, groupName, theCriteria):
1619 aFilterMgr = self.smeshpyD.CreateFilterManager()
1620 aFilter = aFilterMgr.CreateFilter()
1621 aFilter.SetCriteria(theCriteria)
1622 group = self.MakeGroupByFilter(groupName, aFilter)
1623 aFilterMgr.UnRegister()
1626 ## Creates a mesh group by the given filter
1627 # @param groupName the name of the mesh group
1628 # @param theFilter the instance of Filter class
1629 # @return SMESH_Group
1630 # @ingroup l2_grps_create
1631 def MakeGroupByFilter(self, groupName, theFilter):
1632 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1633 theFilter.SetMesh( self.mesh )
1634 group.AddFrom( theFilter )
1638 # @ingroup l2_grps_delete
1639 def RemoveGroup(self, group):
1640 self.mesh.RemoveGroup(group)
1642 ## Removes a group with its contents
1643 # @ingroup l2_grps_delete
1644 def RemoveGroupWithContents(self, group):
1645 self.mesh.RemoveGroupWithContents(group)
1647 ## Gets the list of groups existing in the mesh
1648 # @return a sequence of SMESH_GroupBase
1649 # @ingroup l2_grps_create
1650 def GetGroups(self):
1651 return self.mesh.GetGroups()
1653 ## Gets the number of groups existing in the mesh
1654 # @return the quantity of groups as an integer value
1655 # @ingroup l2_grps_create
1657 return self.mesh.NbGroups()
1659 ## Gets the list of names of groups existing in the mesh
1660 # @return list of strings
1661 # @ingroup l2_grps_create
1662 def GetGroupNames(self):
1663 groups = self.GetGroups()
1665 for group in groups:
1666 names.append(group.GetName())
1669 ## Produces a union of two groups
1670 # A new group is created. All mesh elements that are
1671 # present in the initial groups are added to the new one
1672 # @return an instance of SMESH_Group
1673 # @ingroup l2_grps_operon
1674 def UnionGroups(self, group1, group2, name):
1675 return self.mesh.UnionGroups(group1, group2, name)
1677 ## Produces a union list of groups
1678 # New group is created. All mesh elements that are present in
1679 # initial groups are added to the new one
1680 # @return an instance of SMESH_Group
1681 # @ingroup l2_grps_operon
1682 def UnionListOfGroups(self, groups, name):
1683 return self.mesh.UnionListOfGroups(groups, name)
1685 ## Prodices an intersection of two groups
1686 # A new group is created. All mesh elements that are common
1687 # for the two initial groups are added to the new one.
1688 # @return an instance of SMESH_Group
1689 # @ingroup l2_grps_operon
1690 def IntersectGroups(self, group1, group2, name):
1691 return self.mesh.IntersectGroups(group1, group2, name)
1693 ## Produces an intersection of groups
1694 # New group is created. All mesh elements that are present in all
1695 # initial groups simultaneously are added to the new one
1696 # @return an instance of SMESH_Group
1697 # @ingroup l2_grps_operon
1698 def IntersectListOfGroups(self, groups, name):
1699 return self.mesh.IntersectListOfGroups(groups, name)
1701 ## Produces a cut of two groups
1702 # A new group is created. All mesh elements that are present in
1703 # the main group but are not present in the tool group are added to the new one
1704 # @return an instance of SMESH_Group
1705 # @ingroup l2_grps_operon
1706 def CutGroups(self, main_group, tool_group, name):
1707 return self.mesh.CutGroups(main_group, tool_group, name)
1709 ## Produces a cut of groups
1710 # A new group is created. All mesh elements that are present in main groups
1711 # but do not present in tool groups are added to the new one
1712 # @return an instance of SMESH_Group
1713 # @ingroup l2_grps_operon
1714 def CutListOfGroups(self, main_groups, tool_groups, name):
1715 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1717 ## Produces a group of elements of specified type using list of existing groups
1718 # A new group is created. System
1719 # 1) extracts all nodes on which groups elements are built
1720 # 2) combines all elements of specified dimension laying on these nodes
1721 # @return an instance of SMESH_Group
1722 # @ingroup l2_grps_operon
1723 def CreateDimGroup(self, groups, elem_type, name):
1724 return self.mesh.CreateDimGroup(groups, elem_type, name)
1727 ## Convert group on geom into standalone group
1728 # @ingroup l2_grps_delete
1729 def ConvertToStandalone(self, group):
1730 return self.mesh.ConvertToStandalone(group)
1732 # Get some info about mesh:
1733 # ------------------------
1735 ## Returns the log of nodes and elements added or removed
1736 # since the previous clear of the log.
1737 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1738 # @return list of log_block structures:
1743 # @ingroup l1_auxiliary
1744 def GetLog(self, clearAfterGet):
1745 return self.mesh.GetLog(clearAfterGet)
1747 ## Clears the log of nodes and elements added or removed since the previous
1748 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1749 # @ingroup l1_auxiliary
1751 self.mesh.ClearLog()
1753 ## Toggles auto color mode on the object.
1754 # @param theAutoColor the flag which toggles auto color mode.
1755 # @ingroup l1_auxiliary
1756 def SetAutoColor(self, theAutoColor):
1757 self.mesh.SetAutoColor(theAutoColor)
1759 ## Gets flag of object auto color mode.
1760 # @return True or False
1761 # @ingroup l1_auxiliary
1762 def GetAutoColor(self):
1763 return self.mesh.GetAutoColor()
1765 ## Gets the internal ID
1766 # @return integer value, which is the internal Id of the mesh
1767 # @ingroup l1_auxiliary
1769 return self.mesh.GetId()
1772 # @return integer value, which is the study Id of the mesh
1773 # @ingroup l1_auxiliary
1774 def GetStudyId(self):
1775 return self.mesh.GetStudyId()
1777 ## Checks the group names for duplications.
1778 # Consider the maximum group name length stored in MED file.
1779 # @return True or False
1780 # @ingroup l1_auxiliary
1781 def HasDuplicatedGroupNamesMED(self):
1782 return self.mesh.HasDuplicatedGroupNamesMED()
1784 ## Obtains the mesh editor tool
1785 # @return an instance of SMESH_MeshEditor
1786 # @ingroup l1_modifying
1787 def GetMeshEditor(self):
1790 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1791 # can be passed as argument to a method accepting mesh, group or sub-mesh
1792 # @return an instance of SMESH_IDSource
1793 # @ingroup l1_auxiliary
1794 def GetIDSource(self, ids, elemType):
1795 return self.editor.MakeIDSource(ids, elemType)
1798 # @return an instance of SALOME_MED::MESH
1799 # @ingroup l1_auxiliary
1800 def GetMEDMesh(self):
1801 return self.mesh.GetMEDMesh()
1804 # Get informations about mesh contents:
1805 # ------------------------------------
1807 ## Gets the mesh stattistic
1808 # @return dictionary type element - count of elements
1809 # @ingroup l1_meshinfo
1810 def GetMeshInfo(self, obj = None):
1811 if not obj: obj = self.mesh
1812 return self.smeshpyD.GetMeshInfo(obj)
1814 ## Returns the number of nodes in the mesh
1815 # @return an integer value
1816 # @ingroup l1_meshinfo
1818 return self.mesh.NbNodes()
1820 ## Returns the number of elements in the mesh
1821 # @return an integer value
1822 # @ingroup l1_meshinfo
1823 def NbElements(self):
1824 return self.mesh.NbElements()
1826 ## Returns the number of 0d elements in the mesh
1827 # @return an integer value
1828 # @ingroup l1_meshinfo
1829 def Nb0DElements(self):
1830 return self.mesh.Nb0DElements()
1832 ## Returns the number of ball discrete elements in the mesh
1833 # @return an integer value
1834 # @ingroup l1_meshinfo
1836 return self.mesh.NbBalls()
1838 ## Returns the number of edges in the mesh
1839 # @return an integer value
1840 # @ingroup l1_meshinfo
1842 return self.mesh.NbEdges()
1844 ## Returns the number of edges with the given order in the mesh
1845 # @param elementOrder the order of elements:
1846 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1847 # @return an integer value
1848 # @ingroup l1_meshinfo
1849 def NbEdgesOfOrder(self, elementOrder):
1850 return self.mesh.NbEdgesOfOrder(elementOrder)
1852 ## Returns the number of faces in the mesh
1853 # @return an integer value
1854 # @ingroup l1_meshinfo
1856 return self.mesh.NbFaces()
1858 ## Returns the number of faces with the given order in the mesh
1859 # @param elementOrder the order of elements:
1860 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1861 # @return an integer value
1862 # @ingroup l1_meshinfo
1863 def NbFacesOfOrder(self, elementOrder):
1864 return self.mesh.NbFacesOfOrder(elementOrder)
1866 ## Returns the number of triangles in the mesh
1867 # @return an integer value
1868 # @ingroup l1_meshinfo
1869 def NbTriangles(self):
1870 return self.mesh.NbTriangles()
1872 ## Returns the number of triangles with the given order in the mesh
1873 # @param elementOrder is the order of elements:
1874 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1875 # @return an integer value
1876 # @ingroup l1_meshinfo
1877 def NbTrianglesOfOrder(self, elementOrder):
1878 return self.mesh.NbTrianglesOfOrder(elementOrder)
1880 ## Returns the number of quadrangles in the mesh
1881 # @return an integer value
1882 # @ingroup l1_meshinfo
1883 def NbQuadrangles(self):
1884 return self.mesh.NbQuadrangles()
1886 ## Returns the number of quadrangles with the given order in the mesh
1887 # @param elementOrder the order of elements:
1888 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1889 # @return an integer value
1890 # @ingroup l1_meshinfo
1891 def NbQuadranglesOfOrder(self, elementOrder):
1892 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1894 ## Returns the number of biquadratic quadrangles in the mesh
1895 # @return an integer value
1896 # @ingroup l1_meshinfo
1897 def NbBiQuadQuadrangles(self):
1898 return self.mesh.NbBiQuadQuadrangles()
1900 ## Returns the number of polygons in the mesh
1901 # @return an integer value
1902 # @ingroup l1_meshinfo
1903 def NbPolygons(self):
1904 return self.mesh.NbPolygons()
1906 ## Returns the number of volumes in the mesh
1907 # @return an integer value
1908 # @ingroup l1_meshinfo
1909 def NbVolumes(self):
1910 return self.mesh.NbVolumes()
1912 ## Returns the number of volumes with the given order in the mesh
1913 # @param elementOrder the order of elements:
1914 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1915 # @return an integer value
1916 # @ingroup l1_meshinfo
1917 def NbVolumesOfOrder(self, elementOrder):
1918 return self.mesh.NbVolumesOfOrder(elementOrder)
1920 ## Returns the number of tetrahedrons in the mesh
1921 # @return an integer value
1922 # @ingroup l1_meshinfo
1924 return self.mesh.NbTetras()
1926 ## Returns the number of tetrahedrons with the given order in the mesh
1927 # @param elementOrder the order of elements:
1928 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1929 # @return an integer value
1930 # @ingroup l1_meshinfo
1931 def NbTetrasOfOrder(self, elementOrder):
1932 return self.mesh.NbTetrasOfOrder(elementOrder)
1934 ## Returns the number of hexahedrons in the mesh
1935 # @return an integer value
1936 # @ingroup l1_meshinfo
1938 return self.mesh.NbHexas()
1940 ## Returns the number of hexahedrons with the given order in the mesh
1941 # @param elementOrder the order of elements:
1942 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1943 # @return an integer value
1944 # @ingroup l1_meshinfo
1945 def NbHexasOfOrder(self, elementOrder):
1946 return self.mesh.NbHexasOfOrder(elementOrder)
1948 ## Returns the number of triquadratic hexahedrons in the mesh
1949 # @return an integer value
1950 # @ingroup l1_meshinfo
1951 def NbTriQuadraticHexas(self):
1952 return self.mesh.NbTriQuadraticHexas()
1954 ## Returns the number of pyramids in the mesh
1955 # @return an integer value
1956 # @ingroup l1_meshinfo
1957 def NbPyramids(self):
1958 return self.mesh.NbPyramids()
1960 ## Returns the number of pyramids with the given order in the mesh
1961 # @param elementOrder the order of elements:
1962 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1963 # @return an integer value
1964 # @ingroup l1_meshinfo
1965 def NbPyramidsOfOrder(self, elementOrder):
1966 return self.mesh.NbPyramidsOfOrder(elementOrder)
1968 ## Returns the number of prisms in the mesh
1969 # @return an integer value
1970 # @ingroup l1_meshinfo
1972 return self.mesh.NbPrisms()
1974 ## Returns the number of prisms with the given order in the mesh
1975 # @param elementOrder the order of elements:
1976 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1977 # @return an integer value
1978 # @ingroup l1_meshinfo
1979 def NbPrismsOfOrder(self, elementOrder):
1980 return self.mesh.NbPrismsOfOrder(elementOrder)
1982 ## Returns the number of hexagonal prisms in the mesh
1983 # @return an integer value
1984 # @ingroup l1_meshinfo
1985 def NbHexagonalPrisms(self):
1986 return self.mesh.NbHexagonalPrisms()
1988 ## Returns the number of polyhedrons in the mesh
1989 # @return an integer value
1990 # @ingroup l1_meshinfo
1991 def NbPolyhedrons(self):
1992 return self.mesh.NbPolyhedrons()
1994 ## Returns the number of submeshes in the mesh
1995 # @return an integer value
1996 # @ingroup l1_meshinfo
1997 def NbSubMesh(self):
1998 return self.mesh.NbSubMesh()
2000 ## Returns the list of mesh elements IDs
2001 # @return the list of integer values
2002 # @ingroup l1_meshinfo
2003 def GetElementsId(self):
2004 return self.mesh.GetElementsId()
2006 ## Returns the list of IDs of mesh elements with the given type
2007 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2008 # @return list of integer values
2009 # @ingroup l1_meshinfo
2010 def GetElementsByType(self, elementType):
2011 return self.mesh.GetElementsByType(elementType)
2013 ## Returns the list of mesh nodes IDs
2014 # @return the list of integer values
2015 # @ingroup l1_meshinfo
2016 def GetNodesId(self):
2017 return self.mesh.GetNodesId()
2019 # Get the information about mesh elements:
2020 # ------------------------------------
2022 ## Returns the type of mesh element
2023 # @return the value from SMESH::ElementType enumeration
2024 # @ingroup l1_meshinfo
2025 def GetElementType(self, id, iselem):
2026 return self.mesh.GetElementType(id, iselem)
2028 ## Returns the geometric type of mesh element
2029 # @return the value from SMESH::EntityType enumeration
2030 # @ingroup l1_meshinfo
2031 def GetElementGeomType(self, id):
2032 return self.mesh.GetElementGeomType(id)
2034 ## Returns the list of submesh elements IDs
2035 # @param Shape a geom object(sub-shape) IOR
2036 # Shape must be the sub-shape of a ShapeToMesh()
2037 # @return the list of integer values
2038 # @ingroup l1_meshinfo
2039 def GetSubMeshElementsId(self, Shape):
2040 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2041 ShapeID = Shape.GetSubShapeIndices()[0]
2044 return self.mesh.GetSubMeshElementsId(ShapeID)
2046 ## Returns the list of submesh nodes IDs
2047 # @param Shape a geom object(sub-shape) IOR
2048 # Shape must be the sub-shape of a ShapeToMesh()
2049 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2050 # @return the list of integer values
2051 # @ingroup l1_meshinfo
2052 def GetSubMeshNodesId(self, Shape, all):
2053 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2054 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2057 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2059 ## Returns type of elements on given shape
2060 # @param Shape a geom object(sub-shape) IOR
2061 # Shape must be a sub-shape of a ShapeToMesh()
2062 # @return element type
2063 # @ingroup l1_meshinfo
2064 def GetSubMeshElementType(self, Shape):
2065 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2066 ShapeID = Shape.GetSubShapeIndices()[0]
2069 return self.mesh.GetSubMeshElementType(ShapeID)
2071 ## Gets the mesh description
2072 # @return string value
2073 # @ingroup l1_meshinfo
2075 return self.mesh.Dump()
2078 # Get the information about nodes and elements of a mesh by its IDs:
2079 # -----------------------------------------------------------
2081 ## Gets XYZ coordinates of a node
2082 # \n If there is no nodes for the given ID - returns an empty list
2083 # @return a list of double precision values
2084 # @ingroup l1_meshinfo
2085 def GetNodeXYZ(self, id):
2086 return self.mesh.GetNodeXYZ(id)
2088 ## Returns list of IDs of inverse elements for the given node
2089 # \n If there is no node for the given ID - returns an empty list
2090 # @return a list of integer values
2091 # @ingroup l1_meshinfo
2092 def GetNodeInverseElements(self, id):
2093 return self.mesh.GetNodeInverseElements(id)
2095 ## @brief Returns the position of a node on the shape
2096 # @return SMESH::NodePosition
2097 # @ingroup l1_meshinfo
2098 def GetNodePosition(self,NodeID):
2099 return self.mesh.GetNodePosition(NodeID)
2101 ## If the given element is a node, returns the ID of shape
2102 # \n If there is no node for the given ID - returns -1
2103 # @return an integer value
2104 # @ingroup l1_meshinfo
2105 def GetShapeID(self, id):
2106 return self.mesh.GetShapeID(id)
2108 ## Returns the ID of the result shape after
2109 # FindShape() from SMESH_MeshEditor for the given element
2110 # \n If there is no element for the given ID - returns -1
2111 # @return an integer value
2112 # @ingroup l1_meshinfo
2113 def GetShapeIDForElem(self,id):
2114 return self.mesh.GetShapeIDForElem(id)
2116 ## Returns the number of nodes for the given element
2117 # \n If there is no element for the given ID - returns -1
2118 # @return an integer value
2119 # @ingroup l1_meshinfo
2120 def GetElemNbNodes(self, id):
2121 return self.mesh.GetElemNbNodes(id)
2123 ## Returns the node ID the given index for the given element
2124 # \n If there is no element for the given ID - returns -1
2125 # \n If there is no node for the given index - returns -2
2126 # @return an integer value
2127 # @ingroup l1_meshinfo
2128 def GetElemNode(self, id, index):
2129 return self.mesh.GetElemNode(id, index)
2131 ## Returns the IDs of nodes of the given element
2132 # @return a list of integer values
2133 # @ingroup l1_meshinfo
2134 def GetElemNodes(self, id):
2135 return self.mesh.GetElemNodes(id)
2137 ## Returns true if the given node is the medium node in the given quadratic element
2138 # @ingroup l1_meshinfo
2139 def IsMediumNode(self, elementID, nodeID):
2140 return self.mesh.IsMediumNode(elementID, nodeID)
2142 ## Returns true if the given node is the medium node in one of quadratic elements
2143 # @ingroup l1_meshinfo
2144 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2145 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2147 ## Returns the number of edges for the given element
2148 # @ingroup l1_meshinfo
2149 def ElemNbEdges(self, id):
2150 return self.mesh.ElemNbEdges(id)
2152 ## Returns the number of faces for the given element
2153 # @ingroup l1_meshinfo
2154 def ElemNbFaces(self, id):
2155 return self.mesh.ElemNbFaces(id)
2157 ## Returns nodes of given face (counted from zero) for given volumic element.
2158 # @ingroup l1_meshinfo
2159 def GetElemFaceNodes(self,elemId, faceIndex):
2160 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2162 ## Returns an element based on all given nodes.
2163 # @ingroup l1_meshinfo
2164 def FindElementByNodes(self,nodes):
2165 return self.mesh.FindElementByNodes(nodes)
2167 ## Returns true if the given element is a polygon
2168 # @ingroup l1_meshinfo
2169 def IsPoly(self, id):
2170 return self.mesh.IsPoly(id)
2172 ## Returns true if the given element is quadratic
2173 # @ingroup l1_meshinfo
2174 def IsQuadratic(self, id):
2175 return self.mesh.IsQuadratic(id)
2177 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2178 # @ingroup l1_meshinfo
2179 def GetBallDiameter(self, id):
2180 return self.mesh.GetBallDiameter(id)
2182 ## Returns XYZ coordinates of the barycenter of the given element
2183 # \n If there is no element for the given ID - returns an empty list
2184 # @return a list of three double values
2185 # @ingroup l1_meshinfo
2186 def BaryCenter(self, id):
2187 return self.mesh.BaryCenter(id)
2189 ## Passes mesh elements through the given filter and return IDs of fitting elements
2190 # @param theFilter SMESH_Filter
2191 # @return a list of ids
2192 # @ingroup l1_controls
2193 def GetIdsFromFilter(self, theFilter):
2194 theFilter.SetMesh( self.mesh )
2195 return theFilter.GetIDs()
2197 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2198 # Returns a list of special structures (borders).
2199 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2200 # @ingroup l1_controls
2201 def GetFreeBorders(self):
2202 aFilterMgr = self.smeshpyD.CreateFilterManager()
2203 aPredicate = aFilterMgr.CreateFreeEdges()
2204 aPredicate.SetMesh(self.mesh)
2205 aBorders = aPredicate.GetBorders()
2206 aFilterMgr.UnRegister()
2210 # Get mesh measurements information:
2211 # ------------------------------------
2213 ## Get minimum distance between two nodes, elements or distance to the origin
2214 # @param id1 first node/element id
2215 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2216 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2217 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2218 # @return minimum distance value
2219 # @sa GetMinDistance()
2220 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2221 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2222 return aMeasure.value
2224 ## Get measure structure specifying minimum distance data between two objects
2225 # @param id1 first node/element id
2226 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2227 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2228 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2229 # @return Measure structure
2231 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2233 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2235 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2238 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2240 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2245 aMeasurements = self.smeshpyD.CreateMeasurements()
2246 aMeasure = aMeasurements.MinDistance(id1, id2)
2247 aMeasurements.UnRegister()
2250 ## Get bounding box of the specified object(s)
2251 # @param objects single source object or list of source objects or list of nodes/elements IDs
2252 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2253 # @c False specifies that @a objects are nodes
2254 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2255 # @sa GetBoundingBox()
2256 def BoundingBox(self, objects=None, isElem=False):
2257 result = self.GetBoundingBox(objects, isElem)
2261 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2264 ## Get measure structure specifying bounding box data of the specified object(s)
2265 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2266 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2267 # @c False specifies that @a objects are nodes
2268 # @return Measure structure
2270 def GetBoundingBox(self, IDs=None, isElem=False):
2273 elif isinstance(IDs, tuple):
2275 if not isinstance(IDs, list):
2277 if len(IDs) > 0 and isinstance(IDs[0], int):
2281 if isinstance(o, Mesh):
2282 srclist.append(o.mesh)
2283 elif hasattr(o, "_narrow"):
2284 src = o._narrow(SMESH.SMESH_IDSource)
2285 if src: srclist.append(src)
2287 elif isinstance(o, list):
2289 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2291 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2294 aMeasurements = self.smeshpyD.CreateMeasurements()
2295 aMeasure = aMeasurements.BoundingBox(srclist)
2296 aMeasurements.UnRegister()
2299 # Mesh edition (SMESH_MeshEditor functionality):
2300 # ---------------------------------------------
2302 ## Removes the elements from the mesh by ids
2303 # @param IDsOfElements is a list of ids of elements to remove
2304 # @return True or False
2305 # @ingroup l2_modif_del
2306 def RemoveElements(self, IDsOfElements):
2307 return self.editor.RemoveElements(IDsOfElements)
2309 ## Removes nodes from mesh by ids
2310 # @param IDsOfNodes is a list of ids of nodes to remove
2311 # @return True or False
2312 # @ingroup l2_modif_del
2313 def RemoveNodes(self, IDsOfNodes):
2314 return self.editor.RemoveNodes(IDsOfNodes)
2316 ## Removes all orphan (free) nodes from mesh
2317 # @return number of the removed nodes
2318 # @ingroup l2_modif_del
2319 def RemoveOrphanNodes(self):
2320 return self.editor.RemoveOrphanNodes()
2322 ## Add a node to the mesh by coordinates
2323 # @return Id of the new node
2324 # @ingroup l2_modif_add
2325 def AddNode(self, x, y, z):
2326 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2327 if hasVars: self.mesh.SetParameters(Parameters)
2328 return self.editor.AddNode( x, y, z)
2330 ## Creates a 0D element on a node with given number.
2331 # @param IDOfNode the ID of node for creation of the element.
2332 # @return the Id of the new 0D element
2333 # @ingroup l2_modif_add
2334 def Add0DElement(self, IDOfNode):
2335 return self.editor.Add0DElement(IDOfNode)
2337 ## Creates a ball element on a node with given ID.
2338 # @param IDOfNode the ID of node for creation of the element.
2339 # @param diameter the bal diameter.
2340 # @return the Id of the new ball element
2341 # @ingroup l2_modif_add
2342 def AddBall(self, IDOfNode, diameter):
2343 return self.editor.AddBall( IDOfNode, diameter )
2345 ## Creates a linear or quadratic edge (this is determined
2346 # by the number of given nodes).
2347 # @param IDsOfNodes the list of node IDs for creation of the element.
2348 # The order of nodes in this list should correspond to the description
2349 # of MED. \n This description is located by the following link:
2350 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2351 # @return the Id of the new edge
2352 # @ingroup l2_modif_add
2353 def AddEdge(self, IDsOfNodes):
2354 return self.editor.AddEdge(IDsOfNodes)
2356 ## Creates a linear or quadratic face (this is determined
2357 # by the number of given nodes).
2358 # @param IDsOfNodes the list of node IDs for creation of the element.
2359 # The order of nodes in this list should correspond to the description
2360 # of MED. \n This description is located by the following link:
2361 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2362 # @return the Id of the new face
2363 # @ingroup l2_modif_add
2364 def AddFace(self, IDsOfNodes):
2365 return self.editor.AddFace(IDsOfNodes)
2367 ## Adds a polygonal face to the mesh by the list of node IDs
2368 # @param IdsOfNodes the list of node IDs for creation of the element.
2369 # @return the Id of the new face
2370 # @ingroup l2_modif_add
2371 def AddPolygonalFace(self, IdsOfNodes):
2372 return self.editor.AddPolygonalFace(IdsOfNodes)
2374 ## Creates both simple and quadratic volume (this is determined
2375 # by the number of given nodes).
2376 # @param IDsOfNodes the list of node IDs for creation of the element.
2377 # The order of nodes in this list should correspond to the description
2378 # of MED. \n This description is located by the following link:
2379 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2380 # @return the Id of the new volumic element
2381 # @ingroup l2_modif_add
2382 def AddVolume(self, IDsOfNodes):
2383 return self.editor.AddVolume(IDsOfNodes)
2385 ## Creates a volume of many faces, giving nodes for each face.
2386 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2387 # @param Quantities the list of integer values, Quantities[i]
2388 # gives the quantity of nodes in face number i.
2389 # @return the Id of the new volumic element
2390 # @ingroup l2_modif_add
2391 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2392 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2394 ## Creates a volume of many faces, giving the IDs of the existing faces.
2395 # @param IdsOfFaces the list of face IDs for volume creation.
2397 # Note: The created volume will refer only to the nodes
2398 # of the given faces, not to the faces themselves.
2399 # @return the Id of the new volumic element
2400 # @ingroup l2_modif_add
2401 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2402 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2405 ## @brief Binds a node to a vertex
2406 # @param NodeID a node ID
2407 # @param Vertex a vertex or vertex ID
2408 # @return True if succeed else raises an exception
2409 # @ingroup l2_modif_add
2410 def SetNodeOnVertex(self, NodeID, Vertex):
2411 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2412 VertexID = Vertex.GetSubShapeIndices()[0]
2416 self.editor.SetNodeOnVertex(NodeID, VertexID)
2417 except SALOME.SALOME_Exception, inst:
2418 raise ValueError, inst.details.text
2422 ## @brief Stores the node position on an edge
2423 # @param NodeID a node ID
2424 # @param Edge an edge or edge ID
2425 # @param paramOnEdge a parameter on the edge where the node is located
2426 # @return True if succeed else raises an exception
2427 # @ingroup l2_modif_add
2428 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2429 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2430 EdgeID = Edge.GetSubShapeIndices()[0]
2434 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2435 except SALOME.SALOME_Exception, inst:
2436 raise ValueError, inst.details.text
2439 ## @brief Stores node position on a face
2440 # @param NodeID a node ID
2441 # @param Face a face or face ID
2442 # @param u U parameter on the face where the node is located
2443 # @param v V parameter on the face where the node is located
2444 # @return True if succeed else raises an exception
2445 # @ingroup l2_modif_add
2446 def SetNodeOnFace(self, NodeID, Face, u, v):
2447 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2448 FaceID = Face.GetSubShapeIndices()[0]
2452 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2453 except SALOME.SALOME_Exception, inst:
2454 raise ValueError, inst.details.text
2457 ## @brief Binds a node to a solid
2458 # @param NodeID a node ID
2459 # @param Solid a solid or solid ID
2460 # @return True if succeed else raises an exception
2461 # @ingroup l2_modif_add
2462 def SetNodeInVolume(self, NodeID, Solid):
2463 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2464 SolidID = Solid.GetSubShapeIndices()[0]
2468 self.editor.SetNodeInVolume(NodeID, SolidID)
2469 except SALOME.SALOME_Exception, inst:
2470 raise ValueError, inst.details.text
2473 ## @brief Bind an element to a shape
2474 # @param ElementID an element ID
2475 # @param Shape a shape or shape ID
2476 # @return True if succeed else raises an exception
2477 # @ingroup l2_modif_add
2478 def SetMeshElementOnShape(self, ElementID, Shape):
2479 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2480 ShapeID = Shape.GetSubShapeIndices()[0]
2484 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2485 except SALOME.SALOME_Exception, inst:
2486 raise ValueError, inst.details.text
2490 ## Moves the node with the given id
2491 # @param NodeID the id of the node
2492 # @param x a new X coordinate
2493 # @param y a new Y coordinate
2494 # @param z a new Z coordinate
2495 # @return True if succeed else False
2496 # @ingroup l2_modif_movenode
2497 def MoveNode(self, NodeID, x, y, z):
2498 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2499 if hasVars: self.mesh.SetParameters(Parameters)
2500 return self.editor.MoveNode(NodeID, x, y, z)
2502 ## Finds the node closest to a point and moves it to a point location
2503 # @param x the X coordinate of a point
2504 # @param y the Y coordinate of a point
2505 # @param z the Z coordinate of a point
2506 # @param NodeID if specified (>0), the node with this ID is moved,
2507 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2508 # @return the ID of a node
2509 # @ingroup l2_modif_throughp
2510 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2511 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2512 if hasVars: self.mesh.SetParameters(Parameters)
2513 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2515 ## Finds the node closest to a point
2516 # @param x the X coordinate of a point
2517 # @param y the Y coordinate of a point
2518 # @param z the Z coordinate of a point
2519 # @return the ID of a node
2520 # @ingroup l2_modif_throughp
2521 def FindNodeClosestTo(self, x, y, z):
2522 #preview = self.mesh.GetMeshEditPreviewer()
2523 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2524 return self.editor.FindNodeClosestTo(x, y, z)
2526 ## Finds the elements where a point lays IN or ON
2527 # @param x the X coordinate of a point
2528 # @param y the Y coordinate of a point
2529 # @param z the Z coordinate of a point
2530 # @param elementType type of elements to find (SMESH.ALL type
2531 # means elements of any type excluding nodes, discrete and 0D elements)
2532 # @param meshPart a part of mesh (group, sub-mesh) to search within
2533 # @return list of IDs of found elements
2534 # @ingroup l2_modif_throughp
2535 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2537 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2539 return self.editor.FindElementsByPoint(x, y, z, elementType)
2541 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2542 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2543 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2545 def GetPointState(self, x, y, z):
2546 return self.editor.GetPointState(x, y, z)
2548 ## Finds the node closest to a point and moves it to a point location
2549 # @param x the X coordinate of a point
2550 # @param y the Y coordinate of a point
2551 # @param z the Z coordinate of a point
2552 # @return the ID of a moved node
2553 # @ingroup l2_modif_throughp
2554 def MeshToPassThroughAPoint(self, x, y, z):
2555 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2557 ## Replaces two neighbour triangles sharing Node1-Node2 link
2558 # with the triangles built on the same 4 nodes but having other common link.
2559 # @param NodeID1 the ID of the first node
2560 # @param NodeID2 the ID of the second node
2561 # @return false if proper faces were not found
2562 # @ingroup l2_modif_invdiag
2563 def InverseDiag(self, NodeID1, NodeID2):
2564 return self.editor.InverseDiag(NodeID1, NodeID2)
2566 ## Replaces two neighbour triangles sharing Node1-Node2 link
2567 # with a quadrangle built on the same 4 nodes.
2568 # @param NodeID1 the ID of the first node
2569 # @param NodeID2 the ID of the second node
2570 # @return false if proper faces were not found
2571 # @ingroup l2_modif_unitetri
2572 def DeleteDiag(self, NodeID1, NodeID2):
2573 return self.editor.DeleteDiag(NodeID1, NodeID2)
2575 ## Reorients elements by ids
2576 # @param IDsOfElements if undefined reorients all mesh elements
2577 # @return True if succeed else False
2578 # @ingroup l2_modif_changori
2579 def Reorient(self, IDsOfElements=None):
2580 if IDsOfElements == None:
2581 IDsOfElements = self.GetElementsId()
2582 return self.editor.Reorient(IDsOfElements)
2584 ## Reorients all elements of the object
2585 # @param theObject mesh, submesh or group
2586 # @return True if succeed else False
2587 # @ingroup l2_modif_changori
2588 def ReorientObject(self, theObject):
2589 if ( isinstance( theObject, Mesh )):
2590 theObject = theObject.GetMesh()
2591 return self.editor.ReorientObject(theObject)
2593 ## Reorient faces contained in \a the2DObject.
2594 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2595 # @param theDirection is a desired direction of normal of \a theFace.
2596 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2597 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2598 # compared with theDirection. It can be either ID of face or a point
2599 # by which the face will be found. The point can be given as either
2600 # a GEOM vertex or a list of point coordinates.
2601 # @return number of reoriented faces
2602 # @ingroup l2_modif_changori
2603 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2605 if isinstance( the2DObject, Mesh ):
2606 the2DObject = the2DObject.GetMesh()
2607 if isinstance( the2DObject, list ):
2608 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2609 # check theDirection
2610 if isinstance( theDirection, geompyDC.GEOM._objref_GEOM_Object):
2611 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2612 if isinstance( theDirection, list ):
2613 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2614 # prepare theFace and thePoint
2615 theFace = theFaceOrPoint
2616 thePoint = PointStruct(0,0,0)
2617 if isinstance( theFaceOrPoint, geompyDC.GEOM._objref_GEOM_Object):
2618 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2620 if isinstance( theFaceOrPoint, list ):
2621 thePoint = PointStruct( *theFaceOrPoint )
2623 if isinstance( theFaceOrPoint, PointStruct ):
2624 thePoint = theFaceOrPoint
2626 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2628 ## Fuses the neighbouring triangles into quadrangles.
2629 # @param IDsOfElements The triangles to be fused,
2630 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2631 # @param MaxAngle is the maximum angle between element normals at which the fusion
2632 # is still performed; theMaxAngle is mesured in radians.
2633 # Also it could be a name of variable which defines angle in degrees.
2634 # @return TRUE in case of success, FALSE otherwise.
2635 # @ingroup l2_modif_unitetri
2636 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2638 if isinstance(MaxAngle,str):
2640 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2641 self.mesh.SetParameters(Parameters)
2642 if not IDsOfElements:
2643 IDsOfElements = self.GetElementsId()
2645 if ( isinstance( theCriterion, SMESH._objref_NumericalFunctor ) ):
2646 Functor = theCriterion
2648 Functor = self.smeshpyD.GetFunctor(theCriterion)
2649 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2651 ## Fuses the neighbouring triangles of the object into quadrangles
2652 # @param theObject is mesh, submesh or group
2653 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2654 # @param MaxAngle a max angle between element normals at which the fusion
2655 # is still performed; theMaxAngle is mesured in radians.
2656 # @return TRUE in case of success, FALSE otherwise.
2657 # @ingroup l2_modif_unitetri
2658 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2659 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2660 self.mesh.SetParameters(Parameters)
2661 if ( isinstance( theObject, Mesh )):
2662 theObject = theObject.GetMesh()
2663 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2665 ## Splits quadrangles into triangles.
2666 # @param IDsOfElements the faces to be splitted.
2667 # @param theCriterion FT_...; used to choose a diagonal for splitting.
2668 # @return TRUE in case of success, FALSE otherwise.
2669 # @ingroup l2_modif_cutquadr
2670 def QuadToTri (self, IDsOfElements, theCriterion):
2671 if IDsOfElements == []:
2672 IDsOfElements = self.GetElementsId()
2673 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2675 ## Splits quadrangles into triangles.
2676 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
2677 # @param theCriterion FT_...; used to choose a diagonal for splitting.
2678 # @return TRUE in case of success, FALSE otherwise.
2679 # @ingroup l2_modif_cutquadr
2680 def QuadToTriObject (self, theObject, theCriterion):
2681 if ( isinstance( theObject, Mesh )):
2682 theObject = theObject.GetMesh()
2683 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2685 ## Splits quadrangles into triangles.
2686 # @param IDsOfElements the faces to be splitted
2687 # @param Diag13 is used to choose a diagonal for splitting.
2688 # @return TRUE in case of success, FALSE otherwise.
2689 # @ingroup l2_modif_cutquadr
2690 def SplitQuad (self, IDsOfElements, Diag13):
2691 if IDsOfElements == []:
2692 IDsOfElements = self.GetElementsId()
2693 return self.editor.SplitQuad(IDsOfElements, Diag13)
2695 ## Splits quadrangles into triangles.
2696 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
2697 # @param Diag13 is used to choose a diagonal for splitting.
2698 # @return TRUE in case of success, FALSE otherwise.
2699 # @ingroup l2_modif_cutquadr
2700 def SplitQuadObject (self, theObject, Diag13):
2701 if ( isinstance( theObject, Mesh )):
2702 theObject = theObject.GetMesh()
2703 return self.editor.SplitQuadObject(theObject, Diag13)
2705 ## Finds a better splitting of the given quadrangle.
2706 # @param IDOfQuad the ID of the quadrangle to be splitted.
2707 # @param theCriterion FT_...; a criterion to choose a diagonal for splitting.
2708 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2709 # diagonal is better, 0 if error occurs.
2710 # @ingroup l2_modif_cutquadr
2711 def BestSplit (self, IDOfQuad, theCriterion):
2712 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2714 ## Splits volumic elements into tetrahedrons
2715 # @param elemIDs either list of elements or mesh or group or submesh
2716 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2717 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2718 # @ingroup l2_modif_cutquadr
2719 def SplitVolumesIntoTetra(self, elemIDs, method=Hex_5Tet ):
2720 if isinstance( elemIDs, Mesh ):
2721 elemIDs = elemIDs.GetMesh()
2722 if ( isinstance( elemIDs, list )):
2723 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2724 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2726 ## Splits quadrangle faces near triangular facets of volumes
2728 # @ingroup l1_auxiliary
2729 def SplitQuadsNearTriangularFacets(self):
2730 faces_array = self.GetElementsByType(SMESH.FACE)
2731 for face_id in faces_array:
2732 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2733 quad_nodes = self.mesh.GetElemNodes(face_id)
2734 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2735 isVolumeFound = False
2736 for node1_elem in node1_elems:
2737 if not isVolumeFound:
2738 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2739 nb_nodes = self.GetElemNbNodes(node1_elem)
2740 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2741 volume_elem = node1_elem
2742 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2743 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2744 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2745 isVolumeFound = True
2746 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2747 self.SplitQuad([face_id], False) # diagonal 2-4
2748 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2749 isVolumeFound = True
2750 self.SplitQuad([face_id], True) # diagonal 1-3
2751 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2752 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2753 isVolumeFound = True
2754 self.SplitQuad([face_id], True) # diagonal 1-3
2756 ## @brief Splits hexahedrons into tetrahedrons.
2758 # This operation uses pattern mapping functionality for splitting.
2759 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2760 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2761 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2762 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2763 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2764 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2765 # @return TRUE in case of success, FALSE otherwise.
2766 # @ingroup l1_auxiliary
2767 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2768 # Pattern: 5.---------.6
2773 # (0,0,1) 4.---------.7 * |
2780 # (0,0,0) 0.---------.3
2781 pattern_tetra = "!!! Nb of points: \n 8 \n\
2791 !!! Indices of points of 6 tetras: \n\
2799 pattern = self.smeshpyD.GetPattern()
2800 isDone = pattern.LoadFromFile(pattern_tetra)
2802 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2805 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2806 isDone = pattern.MakeMesh(self.mesh, False, False)
2807 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2809 # split quafrangle faces near triangular facets of volumes
2810 self.SplitQuadsNearTriangularFacets()
2814 ## @brief Split hexahedrons into prisms.
2816 # Uses the pattern mapping functionality for splitting.
2817 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2818 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2819 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2820 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2821 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2822 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2823 # @return TRUE in case of success, FALSE otherwise.
2824 # @ingroup l1_auxiliary
2825 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2826 # Pattern: 5.---------.6
2831 # (0,0,1) 4.---------.7 |
2838 # (0,0,0) 0.---------.3
2839 pattern_prism = "!!! Nb of points: \n 8 \n\
2849 !!! Indices of points of 2 prisms: \n\
2853 pattern = self.smeshpyD.GetPattern()
2854 isDone = pattern.LoadFromFile(pattern_prism)
2856 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2859 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2860 isDone = pattern.MakeMesh(self.mesh, False, False)
2861 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2863 # Splits quafrangle faces near triangular facets of volumes
2864 self.SplitQuadsNearTriangularFacets()
2868 ## Smoothes elements
2869 # @param IDsOfElements the list if ids of elements to smooth
2870 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2871 # Note that nodes built on edges and boundary nodes are always fixed.
2872 # @param MaxNbOfIterations the maximum number of iterations
2873 # @param MaxAspectRatio varies in range [1.0, inf]
2874 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2875 # @return TRUE in case of success, FALSE otherwise.
2876 # @ingroup l2_modif_smooth
2877 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2878 MaxNbOfIterations, MaxAspectRatio, Method):
2879 if IDsOfElements == []:
2880 IDsOfElements = self.GetElementsId()
2881 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2882 self.mesh.SetParameters(Parameters)
2883 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2884 MaxNbOfIterations, MaxAspectRatio, Method)
2886 ## Smoothes elements which belong to the given object
2887 # @param theObject the object to smooth
2888 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2889 # Note that nodes built on edges and boundary nodes are always fixed.
2890 # @param MaxNbOfIterations the maximum number of iterations
2891 # @param MaxAspectRatio varies in range [1.0, inf]
2892 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2893 # @return TRUE in case of success, FALSE otherwise.
2894 # @ingroup l2_modif_smooth
2895 def SmoothObject(self, theObject, IDsOfFixedNodes,
2896 MaxNbOfIterations, MaxAspectRatio, Method):
2897 if ( isinstance( theObject, Mesh )):
2898 theObject = theObject.GetMesh()
2899 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2900 MaxNbOfIterations, MaxAspectRatio, Method)
2902 ## Parametrically smoothes the given elements
2903 # @param IDsOfElements the list if ids of elements to smooth
2904 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2905 # Note that nodes built on edges and boundary nodes are always fixed.
2906 # @param MaxNbOfIterations the maximum number of iterations
2907 # @param MaxAspectRatio varies in range [1.0, inf]
2908 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2909 # @return TRUE in case of success, FALSE otherwise.
2910 # @ingroup l2_modif_smooth
2911 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2912 MaxNbOfIterations, MaxAspectRatio, Method):
2913 if IDsOfElements == []:
2914 IDsOfElements = self.GetElementsId()
2915 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2916 self.mesh.SetParameters(Parameters)
2917 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2918 MaxNbOfIterations, MaxAspectRatio, Method)
2920 ## Parametrically smoothes the elements which belong to the given object
2921 # @param theObject the object to smooth
2922 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2923 # Note that nodes built on edges and boundary nodes are always fixed.
2924 # @param MaxNbOfIterations the maximum number of iterations
2925 # @param MaxAspectRatio varies in range [1.0, inf]
2926 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2927 # @return TRUE in case of success, FALSE otherwise.
2928 # @ingroup l2_modif_smooth
2929 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2930 MaxNbOfIterations, MaxAspectRatio, Method):
2931 if ( isinstance( theObject, Mesh )):
2932 theObject = theObject.GetMesh()
2933 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2934 MaxNbOfIterations, MaxAspectRatio, Method)
2936 ## Converts the mesh to quadratic, deletes old elements, replacing
2937 # them with quadratic with the same id.
2938 # @param theForce3d new node creation method:
2939 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
2940 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
2941 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2942 # @ingroup l2_modif_tofromqu
2943 def ConvertToQuadratic(self, theForce3d, theSubMesh=None):
2945 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
2947 self.editor.ConvertToQuadratic(theForce3d)
2949 ## Converts the mesh from quadratic to ordinary,
2950 # deletes old quadratic elements, \n replacing
2951 # them with ordinary mesh elements with the same id.
2952 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2953 # @ingroup l2_modif_tofromqu
2954 def ConvertFromQuadratic(self, theSubMesh=None):
2956 self.editor.ConvertFromQuadraticObject(theSubMesh)
2958 return self.editor.ConvertFromQuadratic()
2960 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
2961 # @return TRUE if operation has been completed successfully, FALSE otherwise
2962 # @ingroup l2_modif_edit
2963 def Make2DMeshFrom3D(self):
2964 return self.editor. Make2DMeshFrom3D()
2966 ## Creates missing boundary elements
2967 # @param elements - elements whose boundary is to be checked:
2968 # mesh, group, sub-mesh or list of elements
2969 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
2970 # @param dimension - defines type of boundary elements to create:
2971 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
2972 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
2973 # @param groupName - a name of group to store created boundary elements in,
2974 # "" means not to create the group
2975 # @param meshName - a name of new mesh to store created boundary elements in,
2976 # "" means not to create the new mesh
2977 # @param toCopyElements - if true, the checked elements will be copied into
2978 # the new mesh else only boundary elements will be copied into the new mesh
2979 # @param toCopyExistingBondary - if true, not only new but also pre-existing
2980 # boundary elements will be copied into the new mesh
2981 # @return tuple (mesh, group) where bondary elements were added to
2982 # @ingroup l2_modif_edit
2983 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
2984 toCopyElements=False, toCopyExistingBondary=False):
2985 if isinstance( elements, Mesh ):
2986 elements = elements.GetMesh()
2987 if ( isinstance( elements, list )):
2988 elemType = SMESH.ALL
2989 if elements: elemType = self.GetElementType( elements[0], iselem=True)
2990 elements = self.editor.MakeIDSource(elements, elemType)
2991 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
2992 toCopyElements,toCopyExistingBondary)
2993 if mesh: mesh = self.smeshpyD.Mesh(mesh)
2997 # @brief Creates missing boundary elements around either the whole mesh or
2998 # groups of 2D elements
2999 # @param dimension - defines type of boundary elements to create
3000 # @param groupName - a name of group to store all boundary elements in,
3001 # "" means not to create the group
3002 # @param meshName - a name of a new mesh, which is a copy of the initial
3003 # mesh + created boundary elements; "" means not to create the new mesh
3004 # @param toCopyAll - if true, the whole initial mesh will be copied into
3005 # the new mesh else only boundary elements will be copied into the new mesh
3006 # @param groups - groups of 2D elements to make boundary around
3007 # @retval tuple( long, mesh, groups )
3008 # long - number of added boundary elements
3009 # mesh - the mesh where elements were added to
3010 # group - the group of boundary elements or None
3012 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3013 toCopyAll=False, groups=[]):
3014 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3016 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3017 return nb, mesh, group
3019 ## Renumber mesh nodes
3020 # @ingroup l2_modif_renumber
3021 def RenumberNodes(self):
3022 self.editor.RenumberNodes()
3024 ## Renumber mesh elements
3025 # @ingroup l2_modif_renumber
3026 def RenumberElements(self):
3027 self.editor.RenumberElements()
3029 ## Generates new elements by rotation of the elements around the axis
3030 # @param IDsOfElements the list of ids of elements to sweep
3031 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3032 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3033 # @param NbOfSteps the number of steps
3034 # @param Tolerance tolerance
3035 # @param MakeGroups forces the generation of new groups from existing ones
3036 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3037 # of all steps, else - size of each step
3038 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3039 # @ingroup l2_modif_extrurev
3040 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3041 MakeGroups=False, TotalAngle=False):
3042 if IDsOfElements == []:
3043 IDsOfElements = self.GetElementsId()
3044 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3045 Axis = self.smeshpyD.GetAxisStruct(Axis)
3046 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3047 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3048 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3049 self.mesh.SetParameters(Parameters)
3050 if TotalAngle and NbOfSteps:
3051 AngleInRadians /= NbOfSteps
3053 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3054 AngleInRadians, NbOfSteps, Tolerance)
3055 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3058 ## Generates new elements by rotation of the elements of object around the axis
3059 # @param theObject object which elements should be sweeped.
3060 # It can be a mesh, a sub mesh or a group.
3061 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3062 # @param AngleInRadians the angle of Rotation
3063 # @param NbOfSteps number of steps
3064 # @param Tolerance tolerance
3065 # @param MakeGroups forces the generation of new groups from existing ones
3066 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3067 # of all steps, else - size of each step
3068 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3069 # @ingroup l2_modif_extrurev
3070 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3071 MakeGroups=False, TotalAngle=False):
3072 if ( isinstance( theObject, Mesh )):
3073 theObject = theObject.GetMesh()
3074 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3075 Axis = self.smeshpyD.GetAxisStruct(Axis)
3076 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3077 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3078 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3079 self.mesh.SetParameters(Parameters)
3080 if TotalAngle and NbOfSteps:
3081 AngleInRadians /= NbOfSteps
3083 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3084 NbOfSteps, Tolerance)
3085 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3088 ## Generates new elements by rotation of the elements of object around the axis
3089 # @param theObject object which elements should be sweeped.
3090 # It can be a mesh, a sub mesh or a group.
3091 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3092 # @param AngleInRadians the angle of Rotation
3093 # @param NbOfSteps number of steps
3094 # @param Tolerance tolerance
3095 # @param MakeGroups forces the generation of new groups from existing ones
3096 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3097 # of all steps, else - size of each step
3098 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3099 # @ingroup l2_modif_extrurev
3100 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3101 MakeGroups=False, TotalAngle=False):
3102 if ( isinstance( theObject, Mesh )):
3103 theObject = theObject.GetMesh()
3104 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3105 Axis = self.smeshpyD.GetAxisStruct(Axis)
3106 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3107 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3108 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3109 self.mesh.SetParameters(Parameters)
3110 if TotalAngle and NbOfSteps:
3111 AngleInRadians /= NbOfSteps
3113 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3114 NbOfSteps, Tolerance)
3115 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3118 ## Generates new elements by rotation of the elements of object around the axis
3119 # @param theObject object which elements should be sweeped.
3120 # It can be a mesh, a sub mesh or a group.
3121 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3122 # @param AngleInRadians the angle of Rotation
3123 # @param NbOfSteps number of steps
3124 # @param Tolerance tolerance
3125 # @param MakeGroups forces the generation of new groups from existing ones
3126 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3127 # of all steps, else - size of each step
3128 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3129 # @ingroup l2_modif_extrurev
3130 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3131 MakeGroups=False, TotalAngle=False):
3132 if ( isinstance( theObject, Mesh )):
3133 theObject = theObject.GetMesh()
3134 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3135 Axis = self.smeshpyD.GetAxisStruct(Axis)
3136 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3137 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3138 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3139 self.mesh.SetParameters(Parameters)
3140 if TotalAngle and NbOfSteps:
3141 AngleInRadians /= NbOfSteps
3143 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3144 NbOfSteps, Tolerance)
3145 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3148 ## Generates new elements by extrusion of the elements with given ids
3149 # @param IDsOfElements the list of elements ids for extrusion
3150 # @param StepVector vector or DirStruct, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3151 # @param NbOfSteps the number of steps
3152 # @param MakeGroups forces the generation of new groups from existing ones
3153 # @param IsNodes is True if elements with given ids are nodes
3154 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3155 # @ingroup l2_modif_extrurev
3156 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3157 if IDsOfElements == []:
3158 IDsOfElements = self.GetElementsId()
3159 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3160 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3161 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3162 Parameters = StepVector.PS.parameters + var_separator + Parameters
3163 self.mesh.SetParameters(Parameters)
3166 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3168 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3170 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3172 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3175 ## Generates new elements by extrusion of the elements with given ids
3176 # @param IDsOfElements is ids of elements
3177 # @param StepVector vector, defining the direction and value of extrusion
3178 # @param NbOfSteps the number of steps
3179 # @param ExtrFlags sets flags for extrusion
3180 # @param SewTolerance uses for comparing locations of nodes if flag
3181 # EXTRUSION_FLAG_SEW is set
3182 # @param MakeGroups forces the generation of new groups from existing ones
3183 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3184 # @ingroup l2_modif_extrurev
3185 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3186 ExtrFlags, SewTolerance, MakeGroups=False):
3187 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3188 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3190 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3191 ExtrFlags, SewTolerance)
3192 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3193 ExtrFlags, SewTolerance)
3196 ## Generates new elements by extrusion of the elements which belong to the object
3197 # @param theObject the object which elements should be processed.
3198 # It can be a mesh, a sub mesh or a group.
3199 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3200 # @param NbOfSteps the number of steps
3201 # @param MakeGroups forces the generation of new groups from existing ones
3202 # @param IsNodes is True if elements which belong to the object are nodes
3203 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3204 # @ingroup l2_modif_extrurev
3205 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3206 if ( isinstance( theObject, Mesh )):
3207 theObject = theObject.GetMesh()
3208 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3209 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3210 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3211 Parameters = StepVector.PS.parameters + var_separator + Parameters
3212 self.mesh.SetParameters(Parameters)
3215 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3217 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3219 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3221 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3224 ## Generates new elements by extrusion of the elements which belong to the object
3225 # @param theObject object which elements should be processed.
3226 # It can be a mesh, a sub mesh or a group.
3227 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3228 # @param NbOfSteps the number of steps
3229 # @param MakeGroups to generate new groups from existing ones
3230 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3231 # @ingroup l2_modif_extrurev
3232 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3233 if ( isinstance( theObject, Mesh )):
3234 theObject = theObject.GetMesh()
3235 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3236 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3237 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3238 Parameters = StepVector.PS.parameters + var_separator + Parameters
3239 self.mesh.SetParameters(Parameters)
3241 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3242 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3245 ## Generates new elements by extrusion of the elements which belong to the object
3246 # @param theObject object which elements should be processed.
3247 # It can be a mesh, a sub mesh or a group.
3248 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3249 # @param NbOfSteps the number of steps
3250 # @param MakeGroups forces the generation of new groups from existing ones
3251 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3252 # @ingroup l2_modif_extrurev
3253 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3254 if ( isinstance( theObject, Mesh )):
3255 theObject = theObject.GetMesh()
3256 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3257 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3258 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3259 Parameters = StepVector.PS.parameters + var_separator + Parameters
3260 self.mesh.SetParameters(Parameters)
3262 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3263 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3268 ## Generates new elements by extrusion of the given elements
3269 # The path of extrusion must be a meshed edge.
3270 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3271 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3272 # @param NodeStart the start node from Path. Defines the direction of extrusion
3273 # @param HasAngles allows the shape to be rotated around the path
3274 # to get the resulting mesh in a helical fashion
3275 # @param Angles list of angles in radians
3276 # @param LinearVariation forces the computation of rotation angles as linear
3277 # variation of the given Angles along path steps
3278 # @param HasRefPoint allows using the reference point
3279 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3280 # The User can specify any point as the Reference Point.
3281 # @param MakeGroups forces the generation of new groups from existing ones
3282 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3283 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3284 # only SMESH::Extrusion_Error otherwise
3285 # @ingroup l2_modif_extrurev
3286 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3287 HasAngles, Angles, LinearVariation,
3288 HasRefPoint, RefPoint, MakeGroups, ElemType):
3289 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3290 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3292 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3293 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3294 self.mesh.SetParameters(Parameters)
3296 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3298 if isinstance(Base, list):
3300 if Base == []: IDsOfElements = self.GetElementsId()
3301 else: IDsOfElements = Base
3302 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3303 HasAngles, Angles, LinearVariation,
3304 HasRefPoint, RefPoint, MakeGroups, ElemType)
3306 if isinstance(Base, Mesh): Base = Base.GetMesh()
3307 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3308 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3309 HasAngles, Angles, LinearVariation,
3310 HasRefPoint, RefPoint, MakeGroups, ElemType)
3312 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3315 ## Generates new elements by extrusion of the given elements
3316 # The path of extrusion must be a meshed edge.
3317 # @param IDsOfElements ids of elements
3318 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3319 # @param PathShape shape(edge) defines the sub-mesh for the path
3320 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3321 # @param HasAngles allows the shape to be rotated around the path
3322 # to get the resulting mesh in a helical fashion
3323 # @param Angles list of angles in radians
3324 # @param HasRefPoint allows using the reference point
3325 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3326 # The User can specify any point as the Reference Point.
3327 # @param MakeGroups forces the generation of new groups from existing ones
3328 # @param LinearVariation forces the computation of rotation angles as linear
3329 # variation of the given Angles along path steps
3330 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3331 # only SMESH::Extrusion_Error otherwise
3332 # @ingroup l2_modif_extrurev
3333 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3334 HasAngles, Angles, HasRefPoint, RefPoint,
3335 MakeGroups=False, LinearVariation=False):
3336 if IDsOfElements == []:
3337 IDsOfElements = self.GetElementsId()
3338 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3339 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3341 if ( isinstance( PathMesh, Mesh )):
3342 PathMesh = PathMesh.GetMesh()
3343 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3344 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3345 self.mesh.SetParameters(Parameters)
3346 if HasAngles and Angles and LinearVariation:
3347 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3350 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3351 PathShape, NodeStart, HasAngles,
3352 Angles, HasRefPoint, RefPoint)
3353 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3354 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3356 ## Generates new elements by extrusion of the elements which belong to the object
3357 # The path of extrusion must be a meshed edge.
3358 # @param theObject the object which elements should be processed.
3359 # It can be a mesh, a sub mesh or a group.
3360 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3361 # @param PathShape shape(edge) defines the sub-mesh for the path
3362 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3363 # @param HasAngles allows the shape to be rotated around the path
3364 # to get the resulting mesh in a helical fashion
3365 # @param Angles list of angles
3366 # @param HasRefPoint allows using the reference point
3367 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3368 # The User can specify any point as the Reference Point.
3369 # @param MakeGroups forces the generation of new groups from existing ones
3370 # @param LinearVariation forces the computation of rotation angles as linear
3371 # variation of the given Angles along path steps
3372 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3373 # only SMESH::Extrusion_Error otherwise
3374 # @ingroup l2_modif_extrurev
3375 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3376 HasAngles, Angles, HasRefPoint, RefPoint,
3377 MakeGroups=False, LinearVariation=False):
3378 if ( isinstance( theObject, Mesh )):
3379 theObject = theObject.GetMesh()
3380 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3381 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3382 if ( isinstance( PathMesh, Mesh )):
3383 PathMesh = PathMesh.GetMesh()
3384 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3385 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3386 self.mesh.SetParameters(Parameters)
3387 if HasAngles and Angles and LinearVariation:
3388 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3391 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3392 PathShape, NodeStart, HasAngles,
3393 Angles, HasRefPoint, RefPoint)
3394 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3395 NodeStart, HasAngles, Angles, HasRefPoint,
3398 ## Generates new elements by extrusion of the elements which belong to the object
3399 # The path of extrusion must be a meshed edge.
3400 # @param theObject the object which elements should be processed.
3401 # It can be a mesh, a sub mesh or a group.
3402 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3403 # @param PathShape shape(edge) defines the sub-mesh for the path
3404 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3405 # @param HasAngles allows the shape to be rotated around the path
3406 # to get the resulting mesh in a helical fashion
3407 # @param Angles list of angles
3408 # @param HasRefPoint allows using the reference point
3409 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3410 # The User can specify any point as the Reference Point.
3411 # @param MakeGroups forces the generation of new groups from existing ones
3412 # @param LinearVariation forces the computation of rotation angles as linear
3413 # variation of the given Angles along path steps
3414 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3415 # only SMESH::Extrusion_Error otherwise
3416 # @ingroup l2_modif_extrurev
3417 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3418 HasAngles, Angles, HasRefPoint, RefPoint,
3419 MakeGroups=False, LinearVariation=False):
3420 if ( isinstance( theObject, Mesh )):
3421 theObject = theObject.GetMesh()
3422 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3423 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3424 if ( isinstance( PathMesh, Mesh )):
3425 PathMesh = PathMesh.GetMesh()
3426 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3427 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3428 self.mesh.SetParameters(Parameters)
3429 if HasAngles and Angles and LinearVariation:
3430 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3433 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3434 PathShape, NodeStart, HasAngles,
3435 Angles, HasRefPoint, RefPoint)
3436 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3437 NodeStart, HasAngles, Angles, HasRefPoint,
3440 ## Generates new elements by extrusion of the elements which belong to the object
3441 # The path of extrusion must be a meshed edge.
3442 # @param theObject the object which elements should be processed.
3443 # It can be a mesh, a sub mesh or a group.
3444 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3445 # @param PathShape shape(edge) defines the sub-mesh for the path
3446 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3447 # @param HasAngles allows the shape to be rotated around the path
3448 # to get the resulting mesh in a helical fashion
3449 # @param Angles list of angles
3450 # @param HasRefPoint allows using the reference point
3451 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3452 # The User can specify any point as the Reference Point.
3453 # @param MakeGroups forces the generation of new groups from existing ones
3454 # @param LinearVariation forces the computation of rotation angles as linear
3455 # variation of the given Angles along path steps
3456 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3457 # only SMESH::Extrusion_Error otherwise
3458 # @ingroup l2_modif_extrurev
3459 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3460 HasAngles, Angles, HasRefPoint, RefPoint,
3461 MakeGroups=False, LinearVariation=False):
3462 if ( isinstance( theObject, Mesh )):
3463 theObject = theObject.GetMesh()
3464 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3465 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3466 if ( isinstance( PathMesh, Mesh )):
3467 PathMesh = PathMesh.GetMesh()
3468 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3469 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3470 self.mesh.SetParameters(Parameters)
3471 if HasAngles and Angles and LinearVariation:
3472 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3475 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3476 PathShape, NodeStart, HasAngles,
3477 Angles, HasRefPoint, RefPoint)
3478 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3479 NodeStart, HasAngles, Angles, HasRefPoint,
3482 ## Creates a symmetrical copy of mesh elements
3483 # @param IDsOfElements list of elements ids
3484 # @param Mirror is AxisStruct or geom object(point, line, plane)
3485 # @param theMirrorType is POINT, AXIS or PLANE
3486 # If the Mirror is a geom object this parameter is unnecessary
3487 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3488 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3489 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3490 # @ingroup l2_modif_trsf
3491 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3492 if IDsOfElements == []:
3493 IDsOfElements = self.GetElementsId()
3494 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3495 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3496 self.mesh.SetParameters(Mirror.parameters)
3497 if Copy and MakeGroups:
3498 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3499 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3502 ## Creates a new mesh by a symmetrical copy of mesh elements
3503 # @param IDsOfElements the list of elements ids
3504 # @param Mirror is AxisStruct or geom object (point, line, plane)
3505 # @param theMirrorType is POINT, AXIS or PLANE
3506 # If the Mirror is a geom object this parameter is unnecessary
3507 # @param MakeGroups to generate new groups from existing ones
3508 # @param NewMeshName a name of the new mesh to create
3509 # @return instance of Mesh class
3510 # @ingroup l2_modif_trsf
3511 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3512 if IDsOfElements == []:
3513 IDsOfElements = self.GetElementsId()
3514 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3515 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3516 self.mesh.SetParameters(Mirror.parameters)
3517 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3518 MakeGroups, NewMeshName)
3519 return Mesh(self.smeshpyD,self.geompyD,mesh)
3521 ## Creates a symmetrical copy of the object
3522 # @param theObject mesh, submesh or group
3523 # @param Mirror AxisStruct or geom object (point, line, plane)
3524 # @param theMirrorType is POINT, AXIS or PLANE
3525 # If the Mirror is a geom object this parameter is unnecessary
3526 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3527 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3528 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3529 # @ingroup l2_modif_trsf
3530 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3531 if ( isinstance( theObject, Mesh )):
3532 theObject = theObject.GetMesh()
3533 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3534 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3535 self.mesh.SetParameters(Mirror.parameters)
3536 if Copy and MakeGroups:
3537 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3538 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3541 ## Creates a new mesh by a symmetrical copy of the object
3542 # @param theObject mesh, submesh or group
3543 # @param Mirror AxisStruct or geom object (point, line, plane)
3544 # @param theMirrorType POINT, AXIS or PLANE
3545 # If the Mirror is a geom object this parameter is unnecessary
3546 # @param MakeGroups forces the generation of new groups from existing ones
3547 # @param NewMeshName the name of the new mesh to create
3548 # @return instance of Mesh class
3549 # @ingroup l2_modif_trsf
3550 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3551 if ( isinstance( theObject, Mesh )):
3552 theObject = theObject.GetMesh()
3553 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3554 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3555 self.mesh.SetParameters(Mirror.parameters)
3556 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3557 MakeGroups, NewMeshName)
3558 return Mesh( self.smeshpyD,self.geompyD,mesh )
3560 ## Translates the elements
3561 # @param IDsOfElements list of elements ids
3562 # @param Vector the direction of translation (DirStruct or vector)
3563 # @param Copy allows copying the translated elements
3564 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3565 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3566 # @ingroup l2_modif_trsf
3567 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3568 if IDsOfElements == []:
3569 IDsOfElements = self.GetElementsId()
3570 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3571 Vector = self.smeshpyD.GetDirStruct(Vector)
3572 self.mesh.SetParameters(Vector.PS.parameters)
3573 if Copy and MakeGroups:
3574 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3575 self.editor.Translate(IDsOfElements, Vector, Copy)
3578 ## Creates a new mesh of translated elements
3579 # @param IDsOfElements list of elements ids
3580 # @param Vector the direction of translation (DirStruct or vector)
3581 # @param MakeGroups forces the generation of new groups from existing ones
3582 # @param NewMeshName the name of the newly created mesh
3583 # @return instance of Mesh class
3584 # @ingroup l2_modif_trsf
3585 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3586 if IDsOfElements == []:
3587 IDsOfElements = self.GetElementsId()
3588 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3589 Vector = self.smeshpyD.GetDirStruct(Vector)
3590 self.mesh.SetParameters(Vector.PS.parameters)
3591 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3592 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3594 ## Translates the object
3595 # @param theObject the object to translate (mesh, submesh, or group)
3596 # @param Vector direction of translation (DirStruct or geom vector)
3597 # @param Copy allows copying the translated elements
3598 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3599 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3600 # @ingroup l2_modif_trsf
3601 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3602 if ( isinstance( theObject, Mesh )):
3603 theObject = theObject.GetMesh()
3604 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3605 Vector = self.smeshpyD.GetDirStruct(Vector)
3606 self.mesh.SetParameters(Vector.PS.parameters)
3607 if Copy and MakeGroups:
3608 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3609 self.editor.TranslateObject(theObject, Vector, Copy)
3612 ## Creates a new mesh from the translated object
3613 # @param theObject the object to translate (mesh, submesh, or group)
3614 # @param Vector the direction of translation (DirStruct or geom vector)
3615 # @param MakeGroups forces the generation of new groups from existing ones
3616 # @param NewMeshName the name of the newly created mesh
3617 # @return instance of Mesh class
3618 # @ingroup l2_modif_trsf
3619 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3620 if (isinstance(theObject, Mesh)):
3621 theObject = theObject.GetMesh()
3622 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3623 Vector = self.smeshpyD.GetDirStruct(Vector)
3624 self.mesh.SetParameters(Vector.PS.parameters)
3625 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3626 return Mesh( self.smeshpyD, self.geompyD, mesh )
3630 ## Scales the object
3631 # @param theObject - the object to translate (mesh, submesh, or group)
3632 # @param thePoint - base point for scale
3633 # @param theScaleFact - list of 1-3 scale factors for axises
3634 # @param Copy - allows copying the translated elements
3635 # @param MakeGroups - forces the generation of new groups from existing
3637 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3638 # empty list otherwise
3639 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3640 if ( isinstance( theObject, Mesh )):
3641 theObject = theObject.GetMesh()
3642 if ( isinstance( theObject, list )):
3643 theObject = self.GetIDSource(theObject, SMESH.ALL)
3645 self.mesh.SetParameters(thePoint.parameters)
3647 if Copy and MakeGroups:
3648 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3649 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3652 ## Creates a new mesh from the translated object
3653 # @param theObject - the object to translate (mesh, submesh, or group)
3654 # @param thePoint - base point for scale
3655 # @param theScaleFact - list of 1-3 scale factors for axises
3656 # @param MakeGroups - forces the generation of new groups from existing ones
3657 # @param NewMeshName - the name of the newly created mesh
3658 # @return instance of Mesh class
3659 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3660 if (isinstance(theObject, Mesh)):
3661 theObject = theObject.GetMesh()
3662 if ( isinstance( theObject, list )):
3663 theObject = self.GetIDSource(theObject,SMESH.ALL)
3665 self.mesh.SetParameters(thePoint.parameters)
3666 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3667 MakeGroups, NewMeshName)
3668 return Mesh( self.smeshpyD, self.geompyD, mesh )
3672 ## Rotates the elements
3673 # @param IDsOfElements list of elements ids
3674 # @param Axis the axis of rotation (AxisStruct or geom line)
3675 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3676 # @param Copy allows copying the rotated elements
3677 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3678 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3679 # @ingroup l2_modif_trsf
3680 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3681 if IDsOfElements == []:
3682 IDsOfElements = self.GetElementsId()
3683 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3684 Axis = self.smeshpyD.GetAxisStruct(Axis)
3685 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3686 Parameters = Axis.parameters + var_separator + Parameters
3687 self.mesh.SetParameters(Parameters)
3688 if Copy and MakeGroups:
3689 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3690 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3693 ## Creates a new mesh of rotated elements
3694 # @param IDsOfElements list of element ids
3695 # @param Axis the axis of rotation (AxisStruct or geom line)
3696 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3697 # @param MakeGroups forces the generation of new groups from existing ones
3698 # @param NewMeshName the name of the newly created mesh
3699 # @return instance of Mesh class
3700 # @ingroup l2_modif_trsf
3701 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3702 if IDsOfElements == []:
3703 IDsOfElements = self.GetElementsId()
3704 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3705 Axis = self.smeshpyD.GetAxisStruct(Axis)
3706 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3707 Parameters = Axis.parameters + var_separator + Parameters
3708 self.mesh.SetParameters(Parameters)
3709 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3710 MakeGroups, NewMeshName)
3711 return Mesh( self.smeshpyD, self.geompyD, mesh )
3713 ## Rotates the object
3714 # @param theObject the object to rotate( mesh, submesh, or group)
3715 # @param Axis the axis of rotation (AxisStruct or geom line)
3716 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3717 # @param Copy allows copying the rotated elements
3718 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3719 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3720 # @ingroup l2_modif_trsf
3721 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3722 if (isinstance(theObject, Mesh)):
3723 theObject = theObject.GetMesh()
3724 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3725 Axis = self.smeshpyD.GetAxisStruct(Axis)
3726 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3727 Parameters = Axis.parameters + ":" + Parameters
3728 self.mesh.SetParameters(Parameters)
3729 if Copy and MakeGroups:
3730 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3731 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3734 ## Creates a new mesh from the rotated object
3735 # @param theObject the object to rotate (mesh, submesh, or group)
3736 # @param Axis the axis of rotation (AxisStruct or geom line)
3737 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3738 # @param MakeGroups forces the generation of new groups from existing ones
3739 # @param NewMeshName the name of the newly created mesh
3740 # @return instance of Mesh class
3741 # @ingroup l2_modif_trsf
3742 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3743 if (isinstance( theObject, Mesh )):
3744 theObject = theObject.GetMesh()
3745 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3746 Axis = self.smeshpyD.GetAxisStruct(Axis)
3747 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3748 Parameters = Axis.parameters + ":" + Parameters
3749 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3750 MakeGroups, NewMeshName)
3751 self.mesh.SetParameters(Parameters)
3752 return Mesh( self.smeshpyD, self.geompyD, mesh )
3754 ## Finds groups of ajacent nodes within Tolerance.
3755 # @param Tolerance the value of tolerance
3756 # @return the list of groups of nodes
3757 # @ingroup l2_modif_trsf
3758 def FindCoincidentNodes (self, Tolerance):
3759 return self.editor.FindCoincidentNodes(Tolerance)
3761 ## Finds groups of ajacent nodes within Tolerance.
3762 # @param Tolerance the value of tolerance
3763 # @param SubMeshOrGroup SubMesh or Group
3764 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3765 # @return the list of groups of nodes
3766 # @ingroup l2_modif_trsf
3767 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3768 if (isinstance( SubMeshOrGroup, Mesh )):
3769 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3770 if not isinstance( exceptNodes, list):
3771 exceptNodes = [ exceptNodes ]
3772 if exceptNodes and isinstance( exceptNodes[0], int):
3773 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3774 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3777 # @param GroupsOfNodes the list of groups of nodes
3778 # @ingroup l2_modif_trsf
3779 def MergeNodes (self, GroupsOfNodes):
3780 self.editor.MergeNodes(GroupsOfNodes)
3782 ## Finds the elements built on the same nodes.
3783 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3784 # @return a list of groups of equal elements
3785 # @ingroup l2_modif_trsf
3786 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3787 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
3788 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
3789 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3791 ## Merges elements in each given group.
3792 # @param GroupsOfElementsID groups of elements for merging
3793 # @ingroup l2_modif_trsf
3794 def MergeElements(self, GroupsOfElementsID):
3795 self.editor.MergeElements(GroupsOfElementsID)
3797 ## Leaves one element and removes all other elements built on the same nodes.
3798 # @ingroup l2_modif_trsf
3799 def MergeEqualElements(self):
3800 self.editor.MergeEqualElements()
3802 ## Sews free borders
3803 # @return SMESH::Sew_Error
3804 # @ingroup l2_modif_trsf
3805 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3806 FirstNodeID2, SecondNodeID2, LastNodeID2,
3807 CreatePolygons, CreatePolyedrs):
3808 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3809 FirstNodeID2, SecondNodeID2, LastNodeID2,
3810 CreatePolygons, CreatePolyedrs)
3812 ## Sews conform free borders
3813 # @return SMESH::Sew_Error
3814 # @ingroup l2_modif_trsf
3815 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3816 FirstNodeID2, SecondNodeID2):
3817 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3818 FirstNodeID2, SecondNodeID2)
3820 ## Sews border to side
3821 # @return SMESH::Sew_Error
3822 # @ingroup l2_modif_trsf
3823 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3824 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3825 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3826 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3828 ## Sews two sides of a mesh. The nodes belonging to Side1 are
3829 # merged with the nodes of elements of Side2.
3830 # The number of elements in theSide1 and in theSide2 must be
3831 # equal and they should have similar nodal connectivity.
3832 # The nodes to merge should belong to side borders and
3833 # the first node should be linked to the second.
3834 # @return SMESH::Sew_Error
3835 # @ingroup l2_modif_trsf
3836 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3837 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3838 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3839 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3840 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3841 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3843 ## Sets new nodes for the given element.
3844 # @param ide the element id
3845 # @param newIDs nodes ids
3846 # @return If the number of nodes does not correspond to the type of element - returns false
3847 # @ingroup l2_modif_edit
3848 def ChangeElemNodes(self, ide, newIDs):
3849 return self.editor.ChangeElemNodes(ide, newIDs)
3851 ## If during the last operation of MeshEditor some nodes were
3852 # created, this method returns the list of their IDs, \n
3853 # if new nodes were not created - returns empty list
3854 # @return the list of integer values (can be empty)
3855 # @ingroup l1_auxiliary
3856 def GetLastCreatedNodes(self):
3857 return self.editor.GetLastCreatedNodes()
3859 ## If during the last operation of MeshEditor some elements were
3860 # created this method returns the list of their IDs, \n
3861 # if new elements were not created - returns empty list
3862 # @return the list of integer values (can be empty)
3863 # @ingroup l1_auxiliary
3864 def GetLastCreatedElems(self):
3865 return self.editor.GetLastCreatedElems()
3867 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3868 # @param theNodes identifiers of nodes to be doubled
3869 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
3870 # nodes. If list of element identifiers is empty then nodes are doubled but
3871 # they not assigned to elements
3872 # @return TRUE if operation has been completed successfully, FALSE otherwise
3873 # @ingroup l2_modif_edit
3874 def DoubleNodes(self, theNodes, theModifiedElems):
3875 return self.editor.DoubleNodes(theNodes, theModifiedElems)
3877 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3878 # This method provided for convenience works as DoubleNodes() described above.
3879 # @param theNodeId identifiers of node to be doubled
3880 # @param theModifiedElems identifiers of elements to be updated
3881 # @return TRUE if operation has been completed successfully, FALSE otherwise
3882 # @ingroup l2_modif_edit
3883 def DoubleNode(self, theNodeId, theModifiedElems):
3884 return self.editor.DoubleNode(theNodeId, theModifiedElems)
3886 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3887 # This method provided for convenience works as DoubleNodes() described above.
3888 # @param theNodes group of nodes to be doubled
3889 # @param theModifiedElems group of elements to be updated.
3890 # @param theMakeGroup forces the generation of a group containing new nodes.
3891 # @return TRUE or a created group if operation has been completed successfully,
3892 # FALSE or None otherwise
3893 # @ingroup l2_modif_edit
3894 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
3896 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
3897 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
3899 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3900 # This method provided for convenience works as DoubleNodes() described above.
3901 # @param theNodes list of groups of nodes to be doubled
3902 # @param theModifiedElems list of groups of elements to be updated.
3903 # @param theMakeGroup forces the generation of a group containing new nodes.
3904 # @return TRUE if operation has been completed successfully, FALSE otherwise
3905 # @ingroup l2_modif_edit
3906 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
3908 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
3909 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
3911 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3912 # @param theElems - the list of elements (edges or faces) to be replicated
3913 # The nodes for duplication could be found from these elements
3914 # @param theNodesNot - list of nodes to NOT replicate
3915 # @param theAffectedElems - the list of elements (cells and edges) to which the
3916 # replicated nodes should be associated to.
3917 # @return TRUE if operation has been completed successfully, FALSE otherwise
3918 # @ingroup l2_modif_edit
3919 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
3920 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
3922 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3923 # @param theElems - the list of elements (edges or faces) to be replicated
3924 # The nodes for duplication could be found from these elements
3925 # @param theNodesNot - list of nodes to NOT replicate
3926 # @param theShape - shape to detect affected elements (element which geometric center
3927 # located on or inside shape).
3928 # The replicated nodes should be associated to affected elements.
3929 # @return TRUE if operation has been completed successfully, FALSE otherwise
3930 # @ingroup l2_modif_edit
3931 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
3932 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
3934 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3935 # This method provided for convenience works as DoubleNodes() described above.
3936 # @param theElems - group of of elements (edges or faces) to be replicated
3937 # @param theNodesNot - group of nodes not to replicated
3938 # @param theAffectedElems - group of elements to which the replicated nodes
3939 # should be associated to.
3940 # @param theMakeGroup forces the generation of a group containing new elements.
3941 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
3942 # @return TRUE or created groups (one or two) if operation has been completed successfully,
3943 # FALSE or None otherwise
3944 # @ingroup l2_modif_edit
3945 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
3946 theMakeGroup=False, theMakeNodeGroup=False):
3947 if theMakeGroup or theMakeNodeGroup:
3948 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
3950 theMakeGroup, theMakeNodeGroup)
3951 if theMakeGroup and theMakeNodeGroup:
3954 return twoGroups[ int(theMakeNodeGroup) ]
3955 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
3957 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3958 # This method provided for convenience works as DoubleNodes() described above.
3959 # @param theElems - group of of elements (edges or faces) to be replicated
3960 # @param theNodesNot - group of nodes not to replicated
3961 # @param theShape - shape to detect affected elements (element which geometric center
3962 # located on or inside shape).
3963 # The replicated nodes should be associated to affected elements.
3964 # @ingroup l2_modif_edit
3965 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
3966 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
3968 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3969 # This method provided for convenience works as DoubleNodes() described above.
3970 # @param theElems - list of groups of elements (edges or faces) to be replicated
3971 # @param theNodesNot - list of groups of nodes not to replicated
3972 # @param theAffectedElems - group of elements to which the replicated nodes
3973 # should be associated to.
3974 # @param theMakeGroup forces the generation of a group containing new elements.
3975 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
3976 # @return TRUE or created groups (one or two) if operation has been completed successfully,
3977 # FALSE or None otherwise
3978 # @ingroup l2_modif_edit
3979 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
3980 theMakeGroup=False, theMakeNodeGroup=False):
3981 if theMakeGroup or theMakeNodeGroup:
3982 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
3984 theMakeGroup, theMakeNodeGroup)
3985 if theMakeGroup and theMakeNodeGroup:
3988 return twoGroups[ int(theMakeNodeGroup) ]
3989 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
3991 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3992 # This method provided for convenience works as DoubleNodes() described above.
3993 # @param theElems - list of groups of elements (edges or faces) to be replicated
3994 # @param theNodesNot - list of groups of nodes not to replicated
3995 # @param theShape - shape to detect affected elements (element which geometric center
3996 # located on or inside shape).
3997 # The replicated nodes should be associated to affected elements.
3998 # @return TRUE if operation has been completed successfully, FALSE otherwise
3999 # @ingroup l2_modif_edit
4000 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4001 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4003 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4004 # This method is the first step of DoubleNodeElemGroupsInRegion.
4005 # @param theElems - list of groups of elements (edges or faces) to be replicated
4006 # @param theNodesNot - list of groups of nodes not to replicated
4007 # @param theShape - shape to detect affected elements (element which geometric center
4008 # located on or inside shape).
4009 # The replicated nodes should be associated to affected elements.
4010 # @return groups of affected elements
4011 # @ingroup l2_modif_edit
4012 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4013 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4015 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4016 # The list of groups must describe a partition of the mesh volumes.
4017 # The nodes of the internal faces at the boundaries of the groups are doubled.
4018 # In option, the internal faces are replaced by flat elements.
4019 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4020 # @param theDomains - list of groups of volumes
4021 # @param createJointElems - if TRUE, create the elements
4022 # @return TRUE if operation has been completed successfully, FALSE otherwise
4023 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4024 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4026 ## Double nodes on some external faces and create flat elements.
4027 # Flat elements are mainly used by some types of mechanic calculations.
4029 # Each group of the list must be constituted of faces.
4030 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4031 # @param theGroupsOfFaces - list of groups of faces
4032 # @return TRUE if operation has been completed successfully, FALSE otherwise
4033 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4034 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4036 ## identify all the elements around a geom shape, get the faces delimiting the hole
4038 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4039 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4041 def _valueFromFunctor(self, funcType, elemId):
4042 fn = self.smeshpyD.GetFunctor(funcType)
4043 fn.SetMesh(self.mesh)
4044 if fn.GetElementType() == self.GetElementType(elemId, True):
4045 val = fn.GetValue(elemId)
4050 ## Get length of 1D element.
4051 # @param elemId mesh element ID
4052 # @return element's length value
4053 # @ingroup l1_measurements
4054 def GetLength(self, elemId):
4055 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4057 ## Get area of 2D element.
4058 # @param elemId mesh element ID
4059 # @return element's area value
4060 # @ingroup l1_measurements
4061 def GetArea(self, elemId):
4062 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4064 ## Get volume of 3D element.
4065 # @param elemId mesh element ID
4066 # @return element's volume value
4067 # @ingroup l1_measurements
4068 def GetVolume(self, elemId):
4069 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4071 ## Get maximum element length.
4072 # @param elemId mesh element ID
4073 # @return element's maximum length value
4074 # @ingroup l1_measurements
4075 def GetMaxElementLength(self, elemId):
4076 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4077 ftype = SMESH.FT_MaxElementLength3D
4079 ftype = SMESH.FT_MaxElementLength2D
4080 return self._valueFromFunctor(ftype, elemId)
4082 ## Get aspect ratio of 2D or 3D element.
4083 # @param elemId mesh element ID
4084 # @return element's aspect ratio value
4085 # @ingroup l1_measurements
4086 def GetAspectRatio(self, elemId):
4087 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4088 ftype = SMESH.FT_AspectRatio3D
4090 ftype = SMESH.FT_AspectRatio
4091 return self._valueFromFunctor(ftype, elemId)
4093 ## Get warping angle of 2D element.
4094 # @param elemId mesh element ID
4095 # @return element's warping angle value
4096 # @ingroup l1_measurements
4097 def GetWarping(self, elemId):
4098 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4100 ## Get minimum angle of 2D element.
4101 # @param elemId mesh element ID
4102 # @return element's minimum angle value
4103 # @ingroup l1_measurements
4104 def GetMinimumAngle(self, elemId):
4105 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4107 ## Get taper of 2D element.
4108 # @param elemId mesh element ID
4109 # @return element's taper value
4110 # @ingroup l1_measurements
4111 def GetTaper(self, elemId):
4112 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4114 ## Get skew of 2D element.
4115 # @param elemId mesh element ID
4116 # @return element's skew value
4117 # @ingroup l1_measurements
4118 def GetSkew(self, elemId):
4119 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4121 pass # end of Mesh class
4123 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4125 class Pattern(SMESH._objref_SMESH_Pattern):
4127 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4128 decrFun = lambda i: i-1
4129 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4130 theMesh.SetParameters(Parameters)
4131 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4133 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4134 decrFun = lambda i: i-1
4135 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4136 theMesh.SetParameters(Parameters)
4137 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4139 # Registering the new proxy for Pattern
4140 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4142 ## Private class used to bind methods creating algorithms to the class Mesh
4147 self.defaultAlgoType = ""
4148 self.algoTypeToClass = {}
4150 # Stores a python class of algorithm
4151 def add(self, algoClass):
4152 if type( algoClass ).__name__ == 'classobj' and \
4153 hasattr( algoClass, "algoType"):
4154 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4155 if not self.defaultAlgoType and \
4156 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4157 self.defaultAlgoType = algoClass.algoType
4158 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4160 # creates a copy of self and assign mesh to the copy
4161 def copy(self, mesh):
4162 other = algoCreator()
4163 other.defaultAlgoType = self.defaultAlgoType
4164 other.algoTypeToClass = self.algoTypeToClass
4168 # creates an instance of algorithm
4169 def __call__(self,algo="",geom=0,*args):
4170 algoType = self.defaultAlgoType
4171 for arg in args + (algo,geom):
4172 if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ):
4174 if isinstance( arg, str ) and arg:
4176 if not algoType and self.algoTypeToClass:
4177 algoType = self.algoTypeToClass.keys()[0]
4178 if self.algoTypeToClass.has_key( algoType ):
4179 #print "Create algo",algoType
4180 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4181 raise RuntimeError, "No class found for algo type %s" % algoType
4184 # Private class used to substitute and store variable parameters of hypotheses.
4186 class hypMethodWrapper:
4187 def __init__(self, hyp, method):
4189 self.method = method
4190 #print "REBIND:", method.__name__
4193 # call a method of hypothesis with calling SetVarParameter() before
4194 def __call__(self,*args):
4196 return self.method( self.hyp, *args ) # hypothesis method with no args
4198 #print "MethWrapper.__call__",self.method.__name__, args
4200 parsed = ParseParameters(*args) # replace variables with their values
4201 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4202 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4203 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4204 # maybe there is a replaced string arg which is not variable
4205 result = self.method( self.hyp, *args )
4206 except ValueError, detail: # raised by ParseParameters()
4208 result = self.method( self.hyp, *args )
4209 except omniORB.CORBA.BAD_PARAM:
4210 raise ValueError, detail # wrong variable name