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