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