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.GetStudyEntry() and \
259 mesh.smeshpyD.GetCurrentStudy():
261 studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
262 if studyID != mesh.geompyD.myStudyId:
263 mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
265 if not name and geom.GetShapeType() != geompyDC.GEOM.COMPOUND:
266 # for all groups SubShapeName() returns "Compound_-1"
267 name = mesh.geompyD.SubShapeName(geom, mesh.geom)
269 name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
271 mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
274 ## Return the first vertex of a geomertical edge by ignoring orienation
275 def FirstVertexOnCurve(edge):
276 from geompy import SubShapeAll, ShapeType, KindOfShape, PointCoordinates
277 vv = SubShapeAll( edge, ShapeType["VERTEX"])
279 raise TypeError, "Given object has no vertices"
280 if len( vv ) == 1: return vv[0]
281 info = KindOfShape(edge)
282 xyz = info[1:4] # coords of the first vertex
283 xyz1 = PointCoordinates( vv[0] )
284 xyz2 = PointCoordinates( vv[1] )
287 dist1 += abs( xyz[i] - xyz1[i] )
288 dist2 += abs( xyz[i] - xyz2[i] )
294 # end of l1_auxiliary
297 # All methods of this class are accessible directly from the smesh.py package.
298 class smeshDC(SMESH._objref_SMESH_Gen):
300 ## Dump component to the Python script
301 # This method overrides IDL function to allow default values for the parameters.
302 def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
303 return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
305 ## Set mode of DumpPython(), \a historical or \a snapshot.
306 # In the \a historical mode, the Python Dump script includes all commands
307 # performed by SMESH engine. In the \a snapshot mode, commands
308 # relating to objects removed from the Study are excluded from the script
309 # as well as commands not influencing the current state of meshes
310 def SetDumpPythonHistorical(self, isHistorical):
311 if isHistorical: val = "true"
313 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
315 ## Sets the current study and Geometry component
316 # @ingroup l1_auxiliary
317 def init_smesh(self,theStudy,geompyD):
318 self.SetCurrentStudy(theStudy,geompyD)
320 ## Creates an empty Mesh. This mesh can have an underlying geometry.
321 # @param obj the Geometrical object on which the mesh is built. If not defined,
322 # the mesh will have no underlying geometry.
323 # @param name the name for the new mesh.
324 # @return an instance of Mesh class.
325 # @ingroup l2_construct
326 def Mesh(self, obj=0, name=0):
327 if isinstance(obj,str):
329 return Mesh(self,self.geompyD,obj,name)
331 ## Returns a long value from enumeration
332 # @ingroup l1_controls
333 def EnumToLong(self,theItem):
336 ## Returns a string representation of the color.
337 # To be used with filters.
338 # @param c color value (SALOMEDS.Color)
339 # @ingroup l1_controls
340 def ColorToString(self,c):
342 if isinstance(c, SALOMEDS.Color):
343 val = "%s;%s;%s" % (c.R, c.G, c.B)
344 elif isinstance(c, str):
347 raise ValueError, "Color value should be of string or SALOMEDS.Color type"
350 ## Gets PointStruct from vertex
351 # @param theVertex a GEOM object(vertex)
352 # @return SMESH.PointStruct
353 # @ingroup l1_auxiliary
354 def GetPointStruct(self,theVertex):
355 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
356 return PointStruct(x,y,z)
358 ## Gets DirStruct from vector
359 # @param theVector a GEOM object(vector)
360 # @return SMESH.DirStruct
361 # @ingroup l1_auxiliary
362 def GetDirStruct(self,theVector):
363 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
364 if(len(vertices) != 2):
365 print "Error: vector object is incorrect."
367 p1 = self.geompyD.PointCoordinates(vertices[0])
368 p2 = self.geompyD.PointCoordinates(vertices[1])
369 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
370 dirst = DirStruct(pnt)
373 ## Makes DirStruct from a triplet
374 # @param x,y,z vector components
375 # @return SMESH.DirStruct
376 # @ingroup l1_auxiliary
377 def MakeDirStruct(self,x,y,z):
378 pnt = PointStruct(x,y,z)
379 return DirStruct(pnt)
381 ## Get AxisStruct from object
382 # @param theObj a GEOM object (line or plane)
383 # @return SMESH.AxisStruct
384 # @ingroup l1_auxiliary
385 def GetAxisStruct(self,theObj):
386 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
388 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
389 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
390 vertex1 = self.geompyD.PointCoordinates(vertex1)
391 vertex2 = self.geompyD.PointCoordinates(vertex2)
392 vertex3 = self.geompyD.PointCoordinates(vertex3)
393 vertex4 = self.geompyD.PointCoordinates(vertex4)
394 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
395 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
396 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] ]
397 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
399 elif len(edges) == 1:
400 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
401 p1 = self.geompyD.PointCoordinates( vertex1 )
402 p2 = self.geompyD.PointCoordinates( vertex2 )
403 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
407 # From SMESH_Gen interface:
408 # ------------------------
410 ## Sets the given name to the object
411 # @param obj the object to rename
412 # @param name a new object name
413 # @ingroup l1_auxiliary
414 def SetName(self, obj, name):
415 if isinstance( obj, Mesh ):
417 elif isinstance( obj, Mesh_Algorithm ):
418 obj = obj.GetAlgorithm()
419 ior = salome.orb.object_to_string(obj)
420 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
422 ## Sets the current mode
423 # @ingroup l1_auxiliary
424 def SetEmbeddedMode( self,theMode ):
425 #self.SetEmbeddedMode(theMode)
426 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
428 ## Gets the current mode
429 # @ingroup l1_auxiliary
430 def IsEmbeddedMode(self):
431 #return self.IsEmbeddedMode()
432 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
434 ## Sets the current study
435 # @ingroup l1_auxiliary
436 def SetCurrentStudy( self, theStudy, geompyD = None ):
437 #self.SetCurrentStudy(theStudy)
440 geompyD = geompy.geom
443 self.SetGeomEngine(geompyD)
444 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
447 notebook = salome_notebook.NoteBook( theStudy )
449 notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
451 ## Gets the current study
452 # @ingroup l1_auxiliary
453 def GetCurrentStudy(self):
454 #return self.GetCurrentStudy()
455 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
457 ## Creates a Mesh object importing data from the given UNV file
458 # @return an instance of Mesh class
460 def CreateMeshesFromUNV( self,theFileName ):
461 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
462 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
465 ## Creates a Mesh object(s) importing data from the given MED file
466 # @return a list of Mesh class instances
468 def CreateMeshesFromMED( self,theFileName ):
469 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
471 for iMesh in range(len(aSmeshMeshes)) :
472 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
473 aMeshes.append(aMesh)
474 return aMeshes, aStatus
476 ## Creates a Mesh object(s) importing data from the given SAUV file
477 # @return a list of Mesh class instances
479 def CreateMeshesFromSAUV( self,theFileName ):
480 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
482 for iMesh in range(len(aSmeshMeshes)) :
483 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
484 aMeshes.append(aMesh)
485 return aMeshes, aStatus
487 ## Creates a Mesh object importing data from the given STL file
488 # @return an instance of Mesh class
490 def CreateMeshesFromSTL( self, theFileName ):
491 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
492 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
495 ## Creates Mesh objects importing data from the given CGNS file
496 # @return an instance of Mesh class
498 def CreateMeshesFromCGNS( self, theFileName ):
499 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
501 for iMesh in range(len(aSmeshMeshes)) :
502 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
503 aMeshes.append(aMesh)
504 return aMeshes, aStatus
506 ## Creates a Mesh object importing data from the given GMF file
507 # @return [ an instance of Mesh class, SMESH::ComputeError ]
509 def CreateMeshesFromGMF( self, theFileName ):
510 aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
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 # @param name name of a new mesh
524 def Concatenate( self, meshes, uniteIdenticalGroups,
525 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
527 if not meshes: return None
528 for i,m in enumerate(meshes):
529 if isinstance(m, Mesh):
530 meshes[i] = m.GetMesh()
531 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
532 meshes[0].SetParameters(Parameters)
534 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
535 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
537 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
538 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
539 aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
542 ## Create a mesh by copying a part of another mesh.
543 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
544 # to copy nodes or elements not contained in any mesh object,
545 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
546 # @param meshName a name of the new mesh
547 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
548 # @param toKeepIDs to preserve IDs of the copied elements or not
549 # @return an instance of Mesh class
550 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
551 if (isinstance( meshPart, Mesh )):
552 meshPart = meshPart.GetMesh()
553 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
554 return Mesh(self, self.geompyD, mesh)
556 ## From SMESH_Gen interface
557 # @return the list of integer values
558 # @ingroup l1_auxiliary
559 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
560 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
562 ## From SMESH_Gen interface. Creates a pattern
563 # @return an instance of SMESH_Pattern
565 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
566 # @ingroup l2_modif_patterns
567 def GetPattern(self):
568 return SMESH._objref_SMESH_Gen.GetPattern(self)
570 ## Sets number of segments per diagonal of boundary box of geometry by which
571 # default segment length of appropriate 1D hypotheses is defined.
572 # Default value is 10
573 # @ingroup l1_auxiliary
574 def SetBoundaryBoxSegmentation(self, nbSegments):
575 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
577 # Filtering. Auxiliary functions:
578 # ------------------------------
580 ## Creates an empty criterion
581 # @return SMESH.Filter.Criterion
582 # @ingroup l1_controls
583 def GetEmptyCriterion(self):
584 Type = self.EnumToLong(FT_Undefined)
585 Compare = self.EnumToLong(FT_Undefined)
589 UnaryOp = self.EnumToLong(FT_Undefined)
590 BinaryOp = self.EnumToLong(FT_Undefined)
593 Precision = -1 ##@1e-07
594 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
595 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
597 ## Creates a criterion by the given parameters
598 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
599 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
600 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
601 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
602 # @param Threshold the threshold value (range of ids as string, shape, numeric)
603 # @param UnaryOp FT_LogicalNOT or FT_Undefined
604 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
605 # FT_Undefined (must be for the last criterion of all criteria)
606 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
607 # FT_LyingOnGeom, FT_CoplanarFaces criteria
608 # @return SMESH.Filter.Criterion
610 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
611 # @ingroup l1_controls
612 def GetCriterion(self,elementType,
614 Compare = FT_EqualTo,
616 UnaryOp=FT_Undefined,
617 BinaryOp=FT_Undefined,
619 if not CritType in SMESH.FunctorType._items:
620 raise TypeError, "CritType should be of SMESH.FunctorType"
621 aCriterion = self.GetEmptyCriterion()
622 aCriterion.TypeOfElement = elementType
623 aCriterion.Type = self.EnumToLong(CritType)
624 aCriterion.Tolerance = Tolerance
626 aThreshold = Threshold
628 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
629 aCriterion.Compare = self.EnumToLong(Compare)
630 elif Compare == "=" or Compare == "==":
631 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
633 aCriterion.Compare = self.EnumToLong(FT_LessThan)
635 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
636 elif Compare != FT_Undefined:
637 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
640 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
641 FT_BelongToCylinder, FT_LyingOnGeom]:
642 # Checks that Threshold is GEOM object
643 if isinstance(aThreshold, geompyDC.GEOM._objref_GEOM_Object):
644 aCriterion.ThresholdStr = GetName(aThreshold)
645 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
646 if not aCriterion.ThresholdID:
647 name = aCriterion.ThresholdStr
649 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
650 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
651 #raise RuntimeError, "Threshold shape must be published"
653 print "Error: The Threshold should be a shape."
655 if isinstance(UnaryOp,float):
656 aCriterion.Tolerance = UnaryOp
657 UnaryOp = FT_Undefined
659 elif CritType == FT_RangeOfIds:
660 # Checks that Threshold is string
661 if isinstance(aThreshold, str):
662 aCriterion.ThresholdStr = aThreshold
664 print "Error: The Threshold should be a string."
666 elif CritType == FT_CoplanarFaces:
667 # Checks the Threshold
668 if isinstance(aThreshold, int):
669 aCriterion.ThresholdID = str(aThreshold)
670 elif isinstance(aThreshold, str):
673 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
674 aCriterion.ThresholdID = aThreshold
677 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
678 elif CritType == FT_ElemGeomType:
679 # Checks the Threshold
681 aCriterion.Threshold = self.EnumToLong(aThreshold)
682 assert( aThreshold in SMESH.GeometryType._items )
684 if isinstance(aThreshold, int):
685 aCriterion.Threshold = aThreshold
687 print "Error: The Threshold should be an integer or SMESH.GeometryType."
691 elif CritType == FT_GroupColor:
692 # Checks the Threshold
694 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
696 print "Error: The threshold value should be of SALOMEDS.Color type"
699 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
700 FT_LinearOrQuadratic, FT_BadOrientedVolume,
701 FT_BareBorderFace, FT_BareBorderVolume,
702 FT_OverConstrainedFace, FT_OverConstrainedVolume,
703 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
704 # At this point the Threshold is unnecessary
705 if aThreshold == FT_LogicalNOT:
706 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
707 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
708 aCriterion.BinaryOp = aThreshold
712 aThreshold = float(aThreshold)
713 aCriterion.Threshold = aThreshold
715 print "Error: The Threshold should be a number."
718 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
719 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
721 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
722 aCriterion.BinaryOp = self.EnumToLong(Threshold)
724 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
725 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
727 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
728 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
732 ## Creates a filter with the given parameters
733 # @param elementType the type of elements in the group
734 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
735 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
736 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
737 # @param UnaryOp FT_LogicalNOT or FT_Undefined
738 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
739 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
740 # @return SMESH_Filter
742 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
743 # @ingroup l1_controls
744 def GetFilter(self,elementType,
745 CritType=FT_Undefined,
748 UnaryOp=FT_Undefined,
750 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
751 aFilterMgr = self.CreateFilterManager()
752 aFilter = aFilterMgr.CreateFilter()
754 aCriteria.append(aCriterion)
755 aFilter.SetCriteria(aCriteria)
756 aFilterMgr.UnRegister()
759 ## Creates a filter from criteria
760 # @param criteria a list of criteria
761 # @return SMESH_Filter
763 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
764 # @ingroup l1_controls
765 def GetFilterFromCriteria(self,criteria):
766 aFilterMgr = self.CreateFilterManager()
767 aFilter = aFilterMgr.CreateFilter()
768 aFilter.SetCriteria(criteria)
769 aFilterMgr.UnRegister()
772 ## Creates a numerical functor by its type
773 # @param theCriterion FT_...; functor type
774 # @return SMESH_NumericalFunctor
775 # @ingroup l1_controls
776 def GetFunctor(self,theCriterion):
777 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
779 aFilterMgr = self.CreateFilterManager()
781 if theCriterion == FT_AspectRatio:
782 functor = aFilterMgr.CreateAspectRatio()
783 elif theCriterion == FT_AspectRatio3D:
784 functor = aFilterMgr.CreateAspectRatio3D()
785 elif theCriterion == FT_Warping:
786 functor = aFilterMgr.CreateWarping()
787 elif theCriterion == FT_MinimumAngle:
788 functor = aFilterMgr.CreateMinimumAngle()
789 elif theCriterion == FT_Taper:
790 functor = aFilterMgr.CreateTaper()
791 elif theCriterion == FT_Skew:
792 functor = aFilterMgr.CreateSkew()
793 elif theCriterion == FT_Area:
794 functor = aFilterMgr.CreateArea()
795 elif theCriterion == FT_Volume3D:
796 functor = aFilterMgr.CreateVolume3D()
797 elif theCriterion == FT_MaxElementLength2D:
798 functor = aFilterMgr.CreateMaxElementLength2D()
799 elif theCriterion == FT_MaxElementLength3D:
800 functor = aFilterMgr.CreateMaxElementLength3D()
801 elif theCriterion == FT_MultiConnection:
802 functor = aFilterMgr.CreateMultiConnection()
803 elif theCriterion == FT_MultiConnection2D:
804 functor = aFilterMgr.CreateMultiConnection2D()
805 elif theCriterion == FT_Length:
806 functor = aFilterMgr.CreateLength()
807 elif theCriterion == FT_Length2D:
808 functor = aFilterMgr.CreateLength2D()
810 print "Error: given parameter is not numerical functor type."
811 aFilterMgr.UnRegister()
814 ## Creates hypothesis
815 # @param theHType mesh hypothesis type (string)
816 # @param theLibName mesh plug-in library name
817 # @return created hypothesis instance
818 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
819 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
821 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
824 # wrap hypothesis methods
825 #print "HYPOTHESIS", theHType
826 for meth_name in dir( hyp.__class__ ):
827 if not meth_name.startswith("Get") and \
828 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
829 method = getattr ( hyp.__class__, meth_name )
831 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
835 ## Gets the mesh statistic
836 # @return dictionary "element type" - "count of elements"
837 # @ingroup l1_meshinfo
838 def GetMeshInfo(self, obj):
839 if isinstance( obj, Mesh ):
842 if hasattr(obj, "GetMeshInfo"):
843 values = obj.GetMeshInfo()
844 for i in range(SMESH.Entity_Last._v):
845 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
849 ## Get minimum distance between two objects
851 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
852 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
854 # @param src1 first source object
855 # @param src2 second source object
856 # @param id1 node/element id from the first source
857 # @param id2 node/element id from the second (or first) source
858 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
859 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
860 # @return minimum distance value
861 # @sa GetMinDistance()
862 # @ingroup l1_measurements
863 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
864 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
868 result = result.value
871 ## Get measure structure specifying minimum distance data between two objects
873 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
874 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
876 # @param src1 first source object
877 # @param src2 second source object
878 # @param id1 node/element id from the first source
879 # @param id2 node/element id from the second (or first) source
880 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
881 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
882 # @return Measure structure or None if input data is invalid
884 # @ingroup l1_measurements
885 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
886 if isinstance(src1, Mesh): src1 = src1.mesh
887 if isinstance(src2, Mesh): src2 = src2.mesh
888 if src2 is None and id2 != 0: src2 = src1
889 if not hasattr(src1, "_narrow"): return None
890 src1 = src1._narrow(SMESH.SMESH_IDSource)
891 if not src1: return None
894 e = m.GetMeshEditor()
896 src1 = e.MakeIDSource([id1], SMESH.FACE)
898 src1 = e.MakeIDSource([id1], SMESH.NODE)
900 if hasattr(src2, "_narrow"):
901 src2 = src2._narrow(SMESH.SMESH_IDSource)
902 if src2 and id2 != 0:
904 e = m.GetMeshEditor()
906 src2 = e.MakeIDSource([id2], SMESH.FACE)
908 src2 = e.MakeIDSource([id2], SMESH.NODE)
911 aMeasurements = self.CreateMeasurements()
912 result = aMeasurements.MinDistance(src1, src2)
913 aMeasurements.UnRegister()
916 ## Get bounding box of the specified object(s)
917 # @param objects single source object or list of source objects
918 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
919 # @sa GetBoundingBox()
920 # @ingroup l1_measurements
921 def BoundingBox(self, objects):
922 result = self.GetBoundingBox(objects)
926 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
929 ## Get measure structure specifying bounding box data of the specified object(s)
930 # @param objects single source object or list of source objects
931 # @return Measure structure
933 # @ingroup l1_measurements
934 def GetBoundingBox(self, objects):
935 if isinstance(objects, tuple):
936 objects = list(objects)
937 if not isinstance(objects, list):
941 if isinstance(o, Mesh):
942 srclist.append(o.mesh)
943 elif hasattr(o, "_narrow"):
944 src = o._narrow(SMESH.SMESH_IDSource)
945 if src: srclist.append(src)
948 aMeasurements = self.CreateMeasurements()
949 result = aMeasurements.BoundingBox(srclist)
950 aMeasurements.UnRegister()
954 #Registering the new proxy for SMESH_Gen
955 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
961 ## This class allows defining and managing a mesh.
962 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
963 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
964 # new nodes and elements and by changing the existing entities), to get information
965 # about a mesh and to export a mesh into different formats.
974 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
975 # sets the GUI name of this mesh to \a name.
976 # @param smeshpyD an instance of smeshDC class
977 # @param geompyD an instance of geompyDC class
978 # @param obj Shape to be meshed or SMESH_Mesh object
979 # @param name Study name of the mesh
980 # @ingroup l2_construct
981 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
982 self.smeshpyD=smeshpyD
988 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
990 # publish geom of mesh (issue 0021122)
991 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
993 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
994 if studyID != geompyD.myStudyId:
995 geompyD.init_geom( smeshpyD.GetCurrentStudy())
1000 geo_name = "%s_%s_for_meshing"%(self.geom.GetShapeType(), id(self.geom)%100)
1001 geompyD.addToStudy( self.geom, geo_name )
1002 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1004 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1007 self.mesh = self.smeshpyD.CreateEmptyMesh()
1009 self.smeshpyD.SetName(self.mesh, name)
1010 elif obj != 0 and objHasName:
1011 self.smeshpyD.SetName(self.mesh, GetName(obj))
1014 self.geom = self.mesh.GetShapeToMesh()
1016 self.editor = self.mesh.GetMeshEditor()
1017 self.functors = [None] * SMESH.FT_Undefined._v
1019 # set self to algoCreator's
1020 for attrName in dir(self):
1021 attr = getattr( self, attrName )
1022 if isinstance( attr, algoCreator ):
1023 setattr( self, attrName, attr.copy( self ))
1025 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1026 # @param theMesh a SMESH_Mesh object
1027 # @ingroup l2_construct
1028 def SetMesh(self, theMesh):
1029 if self.mesh: self.mesh.UnRegister()
1032 self.mesh.Register()
1033 self.geom = self.mesh.GetShapeToMesh()
1035 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1036 # @return a SMESH_Mesh object
1037 # @ingroup l2_construct
1041 ## Gets the name of the mesh
1042 # @return the name of the mesh as a string
1043 # @ingroup l2_construct
1045 name = GetName(self.GetMesh())
1048 ## Sets a name to the mesh
1049 # @param name a new name of the mesh
1050 # @ingroup l2_construct
1051 def SetName(self, name):
1052 self.smeshpyD.SetName(self.GetMesh(), name)
1054 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1055 # The subMesh object gives access to the IDs of nodes and elements.
1056 # @param geom a geometrical object (shape)
1057 # @param name a name for the submesh
1058 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1059 # @ingroup l2_submeshes
1060 def GetSubMesh(self, geom, name):
1061 AssureGeomPublished( self, geom, name )
1062 submesh = self.mesh.GetSubMesh( geom, name )
1065 ## Returns the shape associated to the mesh
1066 # @return a GEOM_Object
1067 # @ingroup l2_construct
1071 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1072 # @param geom the shape to be meshed (GEOM_Object)
1073 # @ingroup l2_construct
1074 def SetShape(self, geom):
1075 self.mesh = self.smeshpyD.CreateMesh(geom)
1077 ## Loads mesh from the study after opening the study
1081 ## Returns true if the hypotheses are defined well
1082 # @param theSubObject a sub-shape of a mesh shape
1083 # @return True or False
1084 # @ingroup l2_construct
1085 def IsReadyToCompute(self, theSubObject):
1086 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1088 ## Returns errors of hypotheses definition.
1089 # The list of errors is empty if everything is OK.
1090 # @param theSubObject a sub-shape of a mesh shape
1091 # @return a list of errors
1092 # @ingroup l2_construct
1093 def GetAlgoState(self, theSubObject):
1094 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1096 ## Returns a geometrical object on which the given element was built.
1097 # The returned geometrical object, if not nil, is either found in the
1098 # study or published by this method with the given name
1099 # @param theElementID the id of the mesh element
1100 # @param theGeomName the user-defined name of the geometrical object
1101 # @return GEOM::GEOM_Object instance
1102 # @ingroup l2_construct
1103 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1104 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1106 ## Returns the mesh dimension depending on the dimension of the underlying shape
1107 # @return mesh dimension as an integer value [0,3]
1108 # @ingroup l1_auxiliary
1109 def MeshDimension(self):
1110 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1111 if len( shells ) > 0 :
1113 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1115 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1121 ## Evaluates size of prospective mesh on a shape
1122 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1123 # To know predicted number of e.g. edges, inquire it this way
1124 # Evaluate()[ EnumToLong( Entity_Edge )]
1125 def Evaluate(self, geom=0):
1126 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1128 geom = self.mesh.GetShapeToMesh()
1131 return self.smeshpyD.Evaluate(self.mesh, geom)
1134 ## Computes the mesh and returns the status of the computation
1135 # @param geom geomtrical shape on which mesh data should be computed
1136 # @param discardModifs if True and the mesh has been edited since
1137 # a last total re-compute and that may prevent successful partial re-compute,
1138 # then the mesh is cleaned before Compute()
1139 # @return True or False
1140 # @ingroup l2_construct
1141 def Compute(self, geom=0, discardModifs=False):
1142 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1144 geom = self.mesh.GetShapeToMesh()
1149 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1151 ok = self.smeshpyD.Compute(self.mesh, geom)
1152 except SALOME.SALOME_Exception, ex:
1153 print "Mesh computation failed, exception caught:"
1154 print " ", ex.details.text
1157 print "Mesh computation failed, exception caught:"
1158 traceback.print_exc()
1162 # Treat compute errors
1163 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1164 for err in computeErrors:
1166 if self.mesh.HasShapeToMesh():
1168 mainIOR = salome.orb.object_to_string(geom)
1169 for sname in salome.myStudyManager.GetOpenStudies():
1170 s = salome.myStudyManager.GetStudyByName(sname)
1172 mainSO = s.FindObjectIOR(mainIOR)
1173 if not mainSO: continue
1174 if err.subShapeID == 1:
1175 shapeText = ' on "%s"' % mainSO.GetName()
1176 subIt = s.NewChildIterator(mainSO)
1178 subSO = subIt.Value()
1180 obj = subSO.GetObject()
1181 if not obj: continue
1182 go = obj._narrow( geompyDC.GEOM._objref_GEOM_Object )
1184 ids = go.GetSubShapeIndices()
1185 if len(ids) == 1 and ids[0] == err.subShapeID:
1186 shapeText = ' on "%s"' % subSO.GetName()
1189 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1191 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1193 shapeText = " on subshape #%s" % (err.subShapeID)
1195 shapeText = " on subshape #%s" % (err.subShapeID)
1197 stdErrors = ["OK", #COMPERR_OK
1198 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1199 "std::exception", #COMPERR_STD_EXCEPTION
1200 "OCC exception", #COMPERR_OCC_EXCEPTION
1201 "..", #COMPERR_SLM_EXCEPTION
1202 "Unknown exception", #COMPERR_EXCEPTION
1203 "Memory allocation problem", #COMPERR_MEMORY_PB
1204 "Algorithm failed", #COMPERR_ALGO_FAILED
1205 "Unexpected geometry", #COMPERR_BAD_SHAPE
1206 "Warning", #COMPERR_WARNING
1207 "Computation cancelled",#COMPERR_CANCELED
1208 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1210 if err.code < len(stdErrors): errText = stdErrors[err.code]
1212 errText = "code %s" % -err.code
1213 if errText: errText += ". "
1214 errText += err.comment
1215 if allReasons != "":allReasons += "\n"
1216 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1220 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1222 if err.isGlobalAlgo:
1230 reason = '%s %sD algorithm is missing' % (glob, dim)
1231 elif err.state == HYP_MISSING:
1232 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1233 % (glob, dim, name, dim))
1234 elif err.state == HYP_NOTCONFORM:
1235 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1236 elif err.state == HYP_BAD_PARAMETER:
1237 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1238 % ( glob, dim, name ))
1239 elif err.state == HYP_BAD_GEOMETRY:
1240 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1241 'geometry' % ( glob, dim, name ))
1242 elif err.state == HYP_HIDDEN_ALGO:
1243 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1244 'algorithm of upper dimension generating %sD mesh'
1245 % ( glob, dim, name, glob, dim ))
1247 reason = ("For unknown reason. "
1248 "Developer, revise Mesh.Compute() implementation in smeshDC.py!")
1250 if allReasons != "":allReasons += "\n"
1251 allReasons += "- " + reason
1253 if not ok or allReasons != "":
1254 msg = '"' + GetName(self.mesh) + '"'
1255 if ok: msg += " has been computed with warnings"
1256 else: msg += " has not been computed"
1257 if allReasons != "": msg += ":"
1262 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1263 smeshgui = salome.ImportComponentGUI("SMESH")
1264 smeshgui.Init(self.mesh.GetStudyId())
1265 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1266 salome.sg.updateObjBrowser(1)
1270 ## Return submesh objects list in meshing order
1271 # @return list of list of submesh objects
1272 # @ingroup l2_construct
1273 def GetMeshOrder(self):
1274 return self.mesh.GetMeshOrder()
1276 ## Return submesh objects list in meshing order
1277 # @return list of list of submesh objects
1278 # @ingroup l2_construct
1279 def SetMeshOrder(self, submeshes):
1280 return self.mesh.SetMeshOrder(submeshes)
1282 ## Removes all nodes and elements
1283 # @ingroup l2_construct
1286 if ( salome.sg.hasDesktop() and
1287 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1288 smeshgui = salome.ImportComponentGUI("SMESH")
1289 smeshgui.Init(self.mesh.GetStudyId())
1290 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1291 salome.sg.updateObjBrowser(1)
1293 ## Removes all nodes and elements of indicated shape
1294 # @ingroup l2_construct
1295 def ClearSubMesh(self, geomId):
1296 self.mesh.ClearSubMesh(geomId)
1297 if salome.sg.hasDesktop():
1298 smeshgui = salome.ImportComponentGUI("SMESH")
1299 smeshgui.Init(self.mesh.GetStudyId())
1300 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1301 salome.sg.updateObjBrowser(1)
1303 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1304 # @param fineness [0.0,1.0] defines mesh fineness
1305 # @return True or False
1306 # @ingroup l3_algos_basic
1307 def AutomaticTetrahedralization(self, fineness=0):
1308 dim = self.MeshDimension()
1310 self.RemoveGlobalHypotheses()
1311 self.Segment().AutomaticLength(fineness)
1313 self.Triangle().LengthFromEdges()
1316 from NETGENPluginDC import NETGEN
1317 self.Tetrahedron(NETGEN)
1319 return self.Compute()
1321 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1322 # @param fineness [0.0, 1.0] defines mesh fineness
1323 # @return True or False
1324 # @ingroup l3_algos_basic
1325 def AutomaticHexahedralization(self, fineness=0):
1326 dim = self.MeshDimension()
1327 # assign the hypotheses
1328 self.RemoveGlobalHypotheses()
1329 self.Segment().AutomaticLength(fineness)
1336 return self.Compute()
1338 ## Assigns a hypothesis
1339 # @param hyp a hypothesis to assign
1340 # @param geom a subhape of mesh geometry
1341 # @return SMESH.Hypothesis_Status
1342 # @ingroup l2_hypotheses
1343 def AddHypothesis(self, hyp, geom=0):
1344 if isinstance( hyp, Mesh_Algorithm ):
1345 hyp = hyp.GetAlgorithm()
1350 geom = self.mesh.GetShapeToMesh()
1352 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1353 status = self.mesh.AddHypothesis(geom, hyp)
1354 isAlgo = hyp._narrow( SMESH_Algo )
1355 hyp_name = GetName( hyp )
1358 geom_name = GetName( geom )
1359 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1362 ## Return True if an algorithm of hypothesis is assigned to a given shape
1363 # @param hyp a hypothesis to check
1364 # @param geom a subhape of mesh geometry
1365 # @return True of False
1366 # @ingroup l2_hypotheses
1367 def IsUsedHypothesis(self, hyp, geom):
1368 if not hyp or not geom:
1370 if isinstance( hyp, Mesh_Algorithm ):
1371 hyp = hyp.GetAlgorithm()
1373 hyps = self.GetHypothesisList(geom)
1375 if h.GetId() == hyp.GetId():
1379 ## Unassigns a hypothesis
1380 # @param hyp a hypothesis to unassign
1381 # @param geom a sub-shape of mesh geometry
1382 # @return SMESH.Hypothesis_Status
1383 # @ingroup l2_hypotheses
1384 def RemoveHypothesis(self, hyp, geom=0):
1385 if isinstance( hyp, Mesh_Algorithm ):
1386 hyp = hyp.GetAlgorithm()
1391 status = self.mesh.RemoveHypothesis(geom, hyp)
1394 ## Gets the list of hypotheses added on a geometry
1395 # @param geom a sub-shape of mesh geometry
1396 # @return the sequence of SMESH_Hypothesis
1397 # @ingroup l2_hypotheses
1398 def GetHypothesisList(self, geom):
1399 return self.mesh.GetHypothesisList( geom )
1401 ## Removes all global hypotheses
1402 # @ingroup l2_hypotheses
1403 def RemoveGlobalHypotheses(self):
1404 current_hyps = self.mesh.GetHypothesisList( self.geom )
1405 for hyp in current_hyps:
1406 self.mesh.RemoveHypothesis( self.geom, hyp )
1410 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1411 ## allowing to overwrite the file if it exists or add the exported data to its contents
1412 # @param f is the file name
1413 # @param auto_groups boolean parameter for creating/not creating
1414 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1415 # the typical use is auto_groups=false.
1416 # @param version MED format version(MED_V2_1 or MED_V2_2)
1417 # @param overwrite boolean parameter for overwriting/not overwriting the file
1418 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1419 # @ingroup l2_impexp
1420 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1422 if isinstance( meshPart, list ):
1423 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1424 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1426 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1428 ## Exports the mesh in a file in SAUV format
1429 # @param f is the file name
1430 # @param auto_groups boolean parameter for creating/not creating
1431 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1432 # the typical use is auto_groups=false.
1433 # @ingroup l2_impexp
1434 def ExportSAUV(self, f, auto_groups=0):
1435 self.mesh.ExportSAUV(f, auto_groups)
1437 ## Exports the mesh in a file in DAT format
1438 # @param f the file name
1439 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1440 # @ingroup l2_impexp
1441 def ExportDAT(self, f, meshPart=None):
1443 if isinstance( meshPart, list ):
1444 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1445 self.mesh.ExportPartToDAT( meshPart, f )
1447 self.mesh.ExportDAT(f)
1449 ## Exports the mesh in a file in UNV format
1450 # @param f the file name
1451 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1452 # @ingroup l2_impexp
1453 def ExportUNV(self, f, meshPart=None):
1455 if isinstance( meshPart, list ):
1456 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1457 self.mesh.ExportPartToUNV( meshPart, f )
1459 self.mesh.ExportUNV(f)
1461 ## Export the mesh in a file in STL format
1462 # @param f the file name
1463 # @param ascii defines the file encoding
1464 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1465 # @ingroup l2_impexp
1466 def ExportSTL(self, f, ascii=1, meshPart=None):
1468 if isinstance( meshPart, list ):
1469 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1470 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1472 self.mesh.ExportSTL(f, ascii)
1474 ## Exports the mesh in a file in CGNS format
1475 # @param f is the file name
1476 # @param overwrite boolean parameter for overwriting/not overwriting the file
1477 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1478 # @ingroup l2_impexp
1479 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1480 if isinstance( meshPart, list ):
1481 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1482 if isinstance( meshPart, Mesh ):
1483 meshPart = meshPart.mesh
1485 meshPart = self.mesh
1486 self.mesh.ExportCGNS(meshPart, f, overwrite)
1488 ## Exports the mesh in a file in GMF format
1489 # @param f is the file name
1490 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1491 # @ingroup l2_impexp
1492 def ExportGMF(self, f, meshPart=None):
1493 if isinstance( meshPart, list ):
1494 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1495 if isinstance( meshPart, Mesh ):
1496 meshPart = meshPart.mesh
1498 meshPart = self.mesh
1499 self.mesh.ExportGMF(meshPart, f, True)
1501 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1502 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1503 ## allowing to overwrite the file if it exists or add the exported data to its contents
1504 # @param f the file name
1505 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1506 # @param opt boolean parameter for creating/not creating
1507 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1508 # @param overwrite boolean parameter for overwriting/not overwriting the file
1509 # @ingroup l2_impexp
1510 def ExportToMED(self, f, version, opt=0, overwrite=1):
1511 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1513 # Operations with groups:
1514 # ----------------------
1516 ## Creates an empty mesh group
1517 # @param elementType the type of elements in the group
1518 # @param name the name of the mesh group
1519 # @return SMESH_Group
1520 # @ingroup l2_grps_create
1521 def CreateEmptyGroup(self, elementType, name):
1522 return self.mesh.CreateGroup(elementType, name)
1524 ## Creates a mesh group based on the geometric object \a grp
1525 # and gives a \a name, \n if this parameter is not defined
1526 # the name is the same as the geometric group name \n
1527 # Note: Works like GroupOnGeom().
1528 # @param grp a geometric group, a vertex, an edge, a face or a solid
1529 # @param name the name of the mesh group
1530 # @return SMESH_GroupOnGeom
1531 # @ingroup l2_grps_create
1532 def Group(self, grp, name=""):
1533 return self.GroupOnGeom(grp, name)
1535 ## Creates a mesh group based on the geometrical object \a grp
1536 # and gives a \a name, \n if this parameter is not defined
1537 # the name is the same as the geometrical group name
1538 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1539 # @param name the name of the mesh group
1540 # @param typ the type of elements in the group. If not set, it is
1541 # automatically detected by the type of the geometry
1542 # @return SMESH_GroupOnGeom
1543 # @ingroup l2_grps_create
1544 def GroupOnGeom(self, grp, name="", typ=None):
1545 AssureGeomPublished( self, grp, name )
1547 name = grp.GetName()
1549 typ = self._groupTypeFromShape( grp )
1550 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1552 ## Pivate method to get a type of group on geometry
1553 def _groupTypeFromShape( self, shape ):
1554 tgeo = str(shape.GetShapeType())
1555 if tgeo == "VERTEX":
1557 elif tgeo == "EDGE":
1559 elif tgeo == "FACE" or tgeo == "SHELL":
1561 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1563 elif tgeo == "COMPOUND":
1564 sub = self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHAPE"])
1566 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1567 return self._groupTypeFromShape( sub[0] )
1570 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1573 ## Creates a mesh group with given \a name based on the \a filter which
1574 ## is a special type of group dynamically updating it's contents during
1575 ## mesh modification
1576 # @param typ the type of elements in the group
1577 # @param name the name of the mesh group
1578 # @param filter the filter defining group contents
1579 # @return SMESH_GroupOnFilter
1580 # @ingroup l2_grps_create
1581 def GroupOnFilter(self, typ, name, filter):
1582 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1584 ## Creates a mesh group by the given ids of elements
1585 # @param groupName the name of the mesh group
1586 # @param elementType the type of elements in the group
1587 # @param elemIDs the list of ids
1588 # @return SMESH_Group
1589 # @ingroup l2_grps_create
1590 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1591 group = self.mesh.CreateGroup(elementType, groupName)
1595 ## Creates a mesh group by the given conditions
1596 # @param groupName the name of the mesh group
1597 # @param elementType the type of elements in the group
1598 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1599 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1600 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1601 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1602 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1603 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1604 # @return SMESH_Group
1605 # @ingroup l2_grps_create
1609 CritType=FT_Undefined,
1612 UnaryOp=FT_Undefined,
1614 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1615 group = self.MakeGroupByCriterion(groupName, aCriterion)
1618 ## Creates a mesh group by the given criterion
1619 # @param groupName the name of the mesh group
1620 # @param Criterion the instance of Criterion class
1621 # @return SMESH_Group
1622 # @ingroup l2_grps_create
1623 def MakeGroupByCriterion(self, groupName, Criterion):
1624 aFilterMgr = self.smeshpyD.CreateFilterManager()
1625 aFilter = aFilterMgr.CreateFilter()
1627 aCriteria.append(Criterion)
1628 aFilter.SetCriteria(aCriteria)
1629 group = self.MakeGroupByFilter(groupName, aFilter)
1630 aFilterMgr.UnRegister()
1633 ## Creates a mesh group by the given criteria (list of criteria)
1634 # @param groupName the name of the mesh group
1635 # @param theCriteria the list of criteria
1636 # @return SMESH_Group
1637 # @ingroup l2_grps_create
1638 def MakeGroupByCriteria(self, groupName, theCriteria):
1639 aFilterMgr = self.smeshpyD.CreateFilterManager()
1640 aFilter = aFilterMgr.CreateFilter()
1641 aFilter.SetCriteria(theCriteria)
1642 group = self.MakeGroupByFilter(groupName, aFilter)
1643 aFilterMgr.UnRegister()
1646 ## Creates a mesh group by the given filter
1647 # @param groupName the name of the mesh group
1648 # @param theFilter the instance of Filter class
1649 # @return SMESH_Group
1650 # @ingroup l2_grps_create
1651 def MakeGroupByFilter(self, groupName, theFilter):
1652 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1653 theFilter.SetMesh( self.mesh )
1654 group.AddFrom( theFilter )
1658 # @ingroup l2_grps_delete
1659 def RemoveGroup(self, group):
1660 self.mesh.RemoveGroup(group)
1662 ## Removes a group with its contents
1663 # @ingroup l2_grps_delete
1664 def RemoveGroupWithContents(self, group):
1665 self.mesh.RemoveGroupWithContents(group)
1667 ## Gets the list of groups existing in the mesh
1668 # @return a sequence of SMESH_GroupBase
1669 # @ingroup l2_grps_create
1670 def GetGroups(self):
1671 return self.mesh.GetGroups()
1673 ## Gets the number of groups existing in the mesh
1674 # @return the quantity of groups as an integer value
1675 # @ingroup l2_grps_create
1677 return self.mesh.NbGroups()
1679 ## Gets the list of names of groups existing in the mesh
1680 # @return list of strings
1681 # @ingroup l2_grps_create
1682 def GetGroupNames(self):
1683 groups = self.GetGroups()
1685 for group in groups:
1686 names.append(group.GetName())
1689 ## Produces a union of two groups
1690 # A new group is created. All mesh elements that are
1691 # present in the initial groups are added to the new one
1692 # @return an instance of SMESH_Group
1693 # @ingroup l2_grps_operon
1694 def UnionGroups(self, group1, group2, name):
1695 return self.mesh.UnionGroups(group1, group2, name)
1697 ## Produces a union list of groups
1698 # New group is created. All mesh elements that are present in
1699 # initial groups are added to the new one
1700 # @return an instance of SMESH_Group
1701 # @ingroup l2_grps_operon
1702 def UnionListOfGroups(self, groups, name):
1703 return self.mesh.UnionListOfGroups(groups, name)
1705 ## Prodices an intersection of two groups
1706 # A new group is created. All mesh elements that are common
1707 # for the two initial groups are added to the new one.
1708 # @return an instance of SMESH_Group
1709 # @ingroup l2_grps_operon
1710 def IntersectGroups(self, group1, group2, name):
1711 return self.mesh.IntersectGroups(group1, group2, name)
1713 ## Produces an intersection of groups
1714 # New group is created. All mesh elements that are present in all
1715 # initial groups simultaneously are added to the new one
1716 # @return an instance of SMESH_Group
1717 # @ingroup l2_grps_operon
1718 def IntersectListOfGroups(self, groups, name):
1719 return self.mesh.IntersectListOfGroups(groups, name)
1721 ## Produces a cut of two groups
1722 # A new group is created. All mesh elements that are present in
1723 # the main group but are not present in the tool group are added to the new one
1724 # @return an instance of SMESH_Group
1725 # @ingroup l2_grps_operon
1726 def CutGroups(self, main_group, tool_group, name):
1727 return self.mesh.CutGroups(main_group, tool_group, name)
1729 ## Produces a cut of groups
1730 # A new group is created. All mesh elements that are present in main groups
1731 # but do not present in tool groups are added to the new one
1732 # @return an instance of SMESH_Group
1733 # @ingroup l2_grps_operon
1734 def CutListOfGroups(self, main_groups, tool_groups, name):
1735 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1737 ## Produces a group of elements of specified type using list of existing groups
1738 # A new group is created. System
1739 # 1) extracts all nodes on which groups elements are built
1740 # 2) combines all elements of specified dimension laying on these nodes
1741 # @return an instance of SMESH_Group
1742 # @ingroup l2_grps_operon
1743 def CreateDimGroup(self, groups, elem_type, name):
1744 return self.mesh.CreateDimGroup(groups, elem_type, name)
1747 ## Convert group on geom into standalone group
1748 # @ingroup l2_grps_delete
1749 def ConvertToStandalone(self, group):
1750 return self.mesh.ConvertToStandalone(group)
1752 # Get some info about mesh:
1753 # ------------------------
1755 ## Returns the log of nodes and elements added or removed
1756 # since the previous clear of the log.
1757 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1758 # @return list of log_block structures:
1763 # @ingroup l1_auxiliary
1764 def GetLog(self, clearAfterGet):
1765 return self.mesh.GetLog(clearAfterGet)
1767 ## Clears the log of nodes and elements added or removed since the previous
1768 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1769 # @ingroup l1_auxiliary
1771 self.mesh.ClearLog()
1773 ## Toggles auto color mode on the object.
1774 # @param theAutoColor the flag which toggles auto color mode.
1775 # @ingroup l1_auxiliary
1776 def SetAutoColor(self, theAutoColor):
1777 self.mesh.SetAutoColor(theAutoColor)
1779 ## Gets flag of object auto color mode.
1780 # @return True or False
1781 # @ingroup l1_auxiliary
1782 def GetAutoColor(self):
1783 return self.mesh.GetAutoColor()
1785 ## Gets the internal ID
1786 # @return integer value, which is the internal Id of the mesh
1787 # @ingroup l1_auxiliary
1789 return self.mesh.GetId()
1792 # @return integer value, which is the study Id of the mesh
1793 # @ingroup l1_auxiliary
1794 def GetStudyId(self):
1795 return self.mesh.GetStudyId()
1797 ## Checks the group names for duplications.
1798 # Consider the maximum group name length stored in MED file.
1799 # @return True or False
1800 # @ingroup l1_auxiliary
1801 def HasDuplicatedGroupNamesMED(self):
1802 return self.mesh.HasDuplicatedGroupNamesMED()
1804 ## Obtains the mesh editor tool
1805 # @return an instance of SMESH_MeshEditor
1806 # @ingroup l1_modifying
1807 def GetMeshEditor(self):
1810 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1811 # can be passed as argument to a method accepting mesh, group or sub-mesh
1812 # @return an instance of SMESH_IDSource
1813 # @ingroup l1_auxiliary
1814 def GetIDSource(self, ids, elemType):
1815 return self.editor.MakeIDSource(ids, elemType)
1818 # @return an instance of SALOME_MED::MESH
1819 # @ingroup l1_auxiliary
1820 def GetMEDMesh(self):
1821 return self.mesh.GetMEDMesh()
1824 # Get informations about mesh contents:
1825 # ------------------------------------
1827 ## Gets the mesh stattistic
1828 # @return dictionary type element - count of elements
1829 # @ingroup l1_meshinfo
1830 def GetMeshInfo(self, obj = None):
1831 if not obj: obj = self.mesh
1832 return self.smeshpyD.GetMeshInfo(obj)
1834 ## Returns the number of nodes in the mesh
1835 # @return an integer value
1836 # @ingroup l1_meshinfo
1838 return self.mesh.NbNodes()
1840 ## Returns the number of elements in the mesh
1841 # @return an integer value
1842 # @ingroup l1_meshinfo
1843 def NbElements(self):
1844 return self.mesh.NbElements()
1846 ## Returns the number of 0d elements in the mesh
1847 # @return an integer value
1848 # @ingroup l1_meshinfo
1849 def Nb0DElements(self):
1850 return self.mesh.Nb0DElements()
1852 ## Returns the number of ball discrete elements in the mesh
1853 # @return an integer value
1854 # @ingroup l1_meshinfo
1856 return self.mesh.NbBalls()
1858 ## Returns the number of edges in the mesh
1859 # @return an integer value
1860 # @ingroup l1_meshinfo
1862 return self.mesh.NbEdges()
1864 ## Returns the number of edges with the given order in the mesh
1865 # @param elementOrder the order of elements:
1866 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1867 # @return an integer value
1868 # @ingroup l1_meshinfo
1869 def NbEdgesOfOrder(self, elementOrder):
1870 return self.mesh.NbEdgesOfOrder(elementOrder)
1872 ## Returns the number of faces in the mesh
1873 # @return an integer value
1874 # @ingroup l1_meshinfo
1876 return self.mesh.NbFaces()
1878 ## Returns the number of faces with the given order in the mesh
1879 # @param elementOrder the order of elements:
1880 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1881 # @return an integer value
1882 # @ingroup l1_meshinfo
1883 def NbFacesOfOrder(self, elementOrder):
1884 return self.mesh.NbFacesOfOrder(elementOrder)
1886 ## Returns the number of triangles in the mesh
1887 # @return an integer value
1888 # @ingroup l1_meshinfo
1889 def NbTriangles(self):
1890 return self.mesh.NbTriangles()
1892 ## Returns the number of triangles with the given order in the mesh
1893 # @param elementOrder is the order of elements:
1894 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1895 # @return an integer value
1896 # @ingroup l1_meshinfo
1897 def NbTrianglesOfOrder(self, elementOrder):
1898 return self.mesh.NbTrianglesOfOrder(elementOrder)
1900 ## Returns the number of quadrangles in the mesh
1901 # @return an integer value
1902 # @ingroup l1_meshinfo
1903 def NbQuadrangles(self):
1904 return self.mesh.NbQuadrangles()
1906 ## Returns the number of quadrangles with the given order in the mesh
1907 # @param elementOrder the order of elements:
1908 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1909 # @return an integer value
1910 # @ingroup l1_meshinfo
1911 def NbQuadranglesOfOrder(self, elementOrder):
1912 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1914 ## Returns the number of biquadratic quadrangles in the mesh
1915 # @return an integer value
1916 # @ingroup l1_meshinfo
1917 def NbBiQuadQuadrangles(self):
1918 return self.mesh.NbBiQuadQuadrangles()
1920 ## Returns the number of polygons in the mesh
1921 # @return an integer value
1922 # @ingroup l1_meshinfo
1923 def NbPolygons(self):
1924 return self.mesh.NbPolygons()
1926 ## Returns the number of volumes in the mesh
1927 # @return an integer value
1928 # @ingroup l1_meshinfo
1929 def NbVolumes(self):
1930 return self.mesh.NbVolumes()
1932 ## Returns the number of volumes with the given order in the mesh
1933 # @param elementOrder the order of elements:
1934 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1935 # @return an integer value
1936 # @ingroup l1_meshinfo
1937 def NbVolumesOfOrder(self, elementOrder):
1938 return self.mesh.NbVolumesOfOrder(elementOrder)
1940 ## Returns the number of tetrahedrons in the mesh
1941 # @return an integer value
1942 # @ingroup l1_meshinfo
1944 return self.mesh.NbTetras()
1946 ## Returns the number of tetrahedrons with the given order in the mesh
1947 # @param elementOrder the order of elements:
1948 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1949 # @return an integer value
1950 # @ingroup l1_meshinfo
1951 def NbTetrasOfOrder(self, elementOrder):
1952 return self.mesh.NbTetrasOfOrder(elementOrder)
1954 ## Returns the number of hexahedrons in the mesh
1955 # @return an integer value
1956 # @ingroup l1_meshinfo
1958 return self.mesh.NbHexas()
1960 ## Returns the number of hexahedrons 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 NbHexasOfOrder(self, elementOrder):
1966 return self.mesh.NbHexasOfOrder(elementOrder)
1968 ## Returns the number of triquadratic hexahedrons in the mesh
1969 # @return an integer value
1970 # @ingroup l1_meshinfo
1971 def NbTriQuadraticHexas(self):
1972 return self.mesh.NbTriQuadraticHexas()
1974 ## Returns the number of pyramids in the mesh
1975 # @return an integer value
1976 # @ingroup l1_meshinfo
1977 def NbPyramids(self):
1978 return self.mesh.NbPyramids()
1980 ## Returns the number of pyramids with the given order in the mesh
1981 # @param elementOrder the order of elements:
1982 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1983 # @return an integer value
1984 # @ingroup l1_meshinfo
1985 def NbPyramidsOfOrder(self, elementOrder):
1986 return self.mesh.NbPyramidsOfOrder(elementOrder)
1988 ## Returns the number of prisms in the mesh
1989 # @return an integer value
1990 # @ingroup l1_meshinfo
1992 return self.mesh.NbPrisms()
1994 ## Returns the number of prisms with the given order in the mesh
1995 # @param elementOrder the order of elements:
1996 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1997 # @return an integer value
1998 # @ingroup l1_meshinfo
1999 def NbPrismsOfOrder(self, elementOrder):
2000 return self.mesh.NbPrismsOfOrder(elementOrder)
2002 ## Returns the number of hexagonal prisms in the mesh
2003 # @return an integer value
2004 # @ingroup l1_meshinfo
2005 def NbHexagonalPrisms(self):
2006 return self.mesh.NbHexagonalPrisms()
2008 ## Returns the number of polyhedrons in the mesh
2009 # @return an integer value
2010 # @ingroup l1_meshinfo
2011 def NbPolyhedrons(self):
2012 return self.mesh.NbPolyhedrons()
2014 ## Returns the number of submeshes in the mesh
2015 # @return an integer value
2016 # @ingroup l1_meshinfo
2017 def NbSubMesh(self):
2018 return self.mesh.NbSubMesh()
2020 ## Returns the list of mesh elements IDs
2021 # @return the list of integer values
2022 # @ingroup l1_meshinfo
2023 def GetElementsId(self):
2024 return self.mesh.GetElementsId()
2026 ## Returns the list of IDs of mesh elements with the given type
2027 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2028 # @return list of integer values
2029 # @ingroup l1_meshinfo
2030 def GetElementsByType(self, elementType):
2031 return self.mesh.GetElementsByType(elementType)
2033 ## Returns the list of mesh nodes IDs
2034 # @return the list of integer values
2035 # @ingroup l1_meshinfo
2036 def GetNodesId(self):
2037 return self.mesh.GetNodesId()
2039 # Get the information about mesh elements:
2040 # ------------------------------------
2042 ## Returns the type of mesh element
2043 # @return the value from SMESH::ElementType enumeration
2044 # @ingroup l1_meshinfo
2045 def GetElementType(self, id, iselem):
2046 return self.mesh.GetElementType(id, iselem)
2048 ## Returns the geometric type of mesh element
2049 # @return the value from SMESH::EntityType enumeration
2050 # @ingroup l1_meshinfo
2051 def GetElementGeomType(self, id):
2052 return self.mesh.GetElementGeomType(id)
2054 ## Returns the list of submesh elements IDs
2055 # @param Shape a geom object(sub-shape) IOR
2056 # Shape must be the sub-shape of a ShapeToMesh()
2057 # @return the list of integer values
2058 # @ingroup l1_meshinfo
2059 def GetSubMeshElementsId(self, Shape):
2060 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2061 ShapeID = Shape.GetSubShapeIndices()[0]
2064 return self.mesh.GetSubMeshElementsId(ShapeID)
2066 ## Returns the list of submesh nodes IDs
2067 # @param Shape a geom object(sub-shape) IOR
2068 # Shape must be the sub-shape of a ShapeToMesh()
2069 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2070 # @return the list of integer values
2071 # @ingroup l1_meshinfo
2072 def GetSubMeshNodesId(self, Shape, all):
2073 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2074 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2077 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2079 ## Returns type of elements on given shape
2080 # @param Shape a geom object(sub-shape) IOR
2081 # Shape must be a sub-shape of a ShapeToMesh()
2082 # @return element type
2083 # @ingroup l1_meshinfo
2084 def GetSubMeshElementType(self, Shape):
2085 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2086 ShapeID = Shape.GetSubShapeIndices()[0]
2089 return self.mesh.GetSubMeshElementType(ShapeID)
2091 ## Gets the mesh description
2092 # @return string value
2093 # @ingroup l1_meshinfo
2095 return self.mesh.Dump()
2098 # Get the information about nodes and elements of a mesh by its IDs:
2099 # -----------------------------------------------------------
2101 ## Gets XYZ coordinates of a node
2102 # \n If there is no nodes for the given ID - returns an empty list
2103 # @return a list of double precision values
2104 # @ingroup l1_meshinfo
2105 def GetNodeXYZ(self, id):
2106 return self.mesh.GetNodeXYZ(id)
2108 ## Returns list of IDs of inverse elements for the given node
2109 # \n If there is no node for the given ID - returns an empty list
2110 # @return a list of integer values
2111 # @ingroup l1_meshinfo
2112 def GetNodeInverseElements(self, id):
2113 return self.mesh.GetNodeInverseElements(id)
2115 ## @brief Returns the position of a node on the shape
2116 # @return SMESH::NodePosition
2117 # @ingroup l1_meshinfo
2118 def GetNodePosition(self,NodeID):
2119 return self.mesh.GetNodePosition(NodeID)
2121 ## If the given element is a node, returns the ID of shape
2122 # \n If there is no node for the given ID - returns -1
2123 # @return an integer value
2124 # @ingroup l1_meshinfo
2125 def GetShapeID(self, id):
2126 return self.mesh.GetShapeID(id)
2128 ## Returns the ID of the result shape after
2129 # FindShape() from SMESH_MeshEditor for the given element
2130 # \n If there is no element for the given ID - returns -1
2131 # @return an integer value
2132 # @ingroup l1_meshinfo
2133 def GetShapeIDForElem(self,id):
2134 return self.mesh.GetShapeIDForElem(id)
2136 ## Returns the number of nodes for the given element
2137 # \n If there is no element for the given ID - returns -1
2138 # @return an integer value
2139 # @ingroup l1_meshinfo
2140 def GetElemNbNodes(self, id):
2141 return self.mesh.GetElemNbNodes(id)
2143 ## Returns the node ID the given index for the given element
2144 # \n If there is no element for the given ID - returns -1
2145 # \n If there is no node for the given index - returns -2
2146 # @return an integer value
2147 # @ingroup l1_meshinfo
2148 def GetElemNode(self, id, index):
2149 return self.mesh.GetElemNode(id, index)
2151 ## Returns the IDs of nodes of the given element
2152 # @return a list of integer values
2153 # @ingroup l1_meshinfo
2154 def GetElemNodes(self, id):
2155 return self.mesh.GetElemNodes(id)
2157 ## Returns true if the given node is the medium node in the given quadratic element
2158 # @ingroup l1_meshinfo
2159 def IsMediumNode(self, elementID, nodeID):
2160 return self.mesh.IsMediumNode(elementID, nodeID)
2162 ## Returns true if the given node is the medium node in one of quadratic elements
2163 # @ingroup l1_meshinfo
2164 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2165 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2167 ## Returns the number of edges for the given element
2168 # @ingroup l1_meshinfo
2169 def ElemNbEdges(self, id):
2170 return self.mesh.ElemNbEdges(id)
2172 ## Returns the number of faces for the given element
2173 # @ingroup l1_meshinfo
2174 def ElemNbFaces(self, id):
2175 return self.mesh.ElemNbFaces(id)
2177 ## Returns nodes of given face (counted from zero) for given volumic element.
2178 # @ingroup l1_meshinfo
2179 def GetElemFaceNodes(self,elemId, faceIndex):
2180 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2182 ## Returns an element based on all given nodes.
2183 # @ingroup l1_meshinfo
2184 def FindElementByNodes(self,nodes):
2185 return self.mesh.FindElementByNodes(nodes)
2187 ## Returns true if the given element is a polygon
2188 # @ingroup l1_meshinfo
2189 def IsPoly(self, id):
2190 return self.mesh.IsPoly(id)
2192 ## Returns true if the given element is quadratic
2193 # @ingroup l1_meshinfo
2194 def IsQuadratic(self, id):
2195 return self.mesh.IsQuadratic(id)
2197 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2198 # @ingroup l1_meshinfo
2199 def GetBallDiameter(self, id):
2200 return self.mesh.GetBallDiameter(id)
2202 ## Returns XYZ coordinates of the barycenter of the given element
2203 # \n If there is no element for the given ID - returns an empty list
2204 # @return a list of three double values
2205 # @ingroup l1_meshinfo
2206 def BaryCenter(self, id):
2207 return self.mesh.BaryCenter(id)
2209 ## Passes mesh elements through the given filter and return IDs of fitting elements
2210 # @param theFilter SMESH_Filter
2211 # @return a list of ids
2212 # @ingroup l1_controls
2213 def GetIdsFromFilter(self, theFilter):
2214 theFilter.SetMesh( self.mesh )
2215 return theFilter.GetIDs()
2217 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2218 # Returns a list of special structures (borders).
2219 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2220 # @ingroup l1_controls
2221 def GetFreeBorders(self):
2222 aFilterMgr = self.smeshpyD.CreateFilterManager()
2223 aPredicate = aFilterMgr.CreateFreeEdges()
2224 aPredicate.SetMesh(self.mesh)
2225 aBorders = aPredicate.GetBorders()
2226 aFilterMgr.UnRegister()
2230 # Get mesh measurements information:
2231 # ------------------------------------
2233 ## Get minimum distance between two nodes, elements or distance to the origin
2234 # @param id1 first node/element id
2235 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2236 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2237 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2238 # @return minimum distance value
2239 # @sa GetMinDistance()
2240 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2241 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2242 return aMeasure.value
2244 ## Get measure structure specifying minimum distance data between two objects
2245 # @param id1 first node/element id
2246 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2247 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2248 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2249 # @return Measure structure
2251 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2253 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2255 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2258 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2260 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2265 aMeasurements = self.smeshpyD.CreateMeasurements()
2266 aMeasure = aMeasurements.MinDistance(id1, id2)
2267 aMeasurements.UnRegister()
2270 ## Get bounding box of the specified object(s)
2271 # @param objects single source object or list of source objects or list of nodes/elements IDs
2272 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2273 # @c False specifies that @a objects are nodes
2274 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2275 # @sa GetBoundingBox()
2276 def BoundingBox(self, objects=None, isElem=False):
2277 result = self.GetBoundingBox(objects, isElem)
2281 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2284 ## Get measure structure specifying bounding box data of the specified object(s)
2285 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2286 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2287 # @c False specifies that @a objects are nodes
2288 # @return Measure structure
2290 def GetBoundingBox(self, IDs=None, isElem=False):
2293 elif isinstance(IDs, tuple):
2295 if not isinstance(IDs, list):
2297 if len(IDs) > 0 and isinstance(IDs[0], int):
2301 if isinstance(o, Mesh):
2302 srclist.append(o.mesh)
2303 elif hasattr(o, "_narrow"):
2304 src = o._narrow(SMESH.SMESH_IDSource)
2305 if src: srclist.append(src)
2307 elif isinstance(o, list):
2309 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2311 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2314 aMeasurements = self.smeshpyD.CreateMeasurements()
2315 aMeasure = aMeasurements.BoundingBox(srclist)
2316 aMeasurements.UnRegister()
2319 # Mesh edition (SMESH_MeshEditor functionality):
2320 # ---------------------------------------------
2322 ## Removes the elements from the mesh by ids
2323 # @param IDsOfElements is a list of ids of elements to remove
2324 # @return True or False
2325 # @ingroup l2_modif_del
2326 def RemoveElements(self, IDsOfElements):
2327 return self.editor.RemoveElements(IDsOfElements)
2329 ## Removes nodes from mesh by ids
2330 # @param IDsOfNodes is a list of ids of nodes to remove
2331 # @return True or False
2332 # @ingroup l2_modif_del
2333 def RemoveNodes(self, IDsOfNodes):
2334 return self.editor.RemoveNodes(IDsOfNodes)
2336 ## Removes all orphan (free) nodes from mesh
2337 # @return number of the removed nodes
2338 # @ingroup l2_modif_del
2339 def RemoveOrphanNodes(self):
2340 return self.editor.RemoveOrphanNodes()
2342 ## Add a node to the mesh by coordinates
2343 # @return Id of the new node
2344 # @ingroup l2_modif_add
2345 def AddNode(self, x, y, z):
2346 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2347 if hasVars: self.mesh.SetParameters(Parameters)
2348 return self.editor.AddNode( x, y, z)
2350 ## Creates a 0D element on a node with given number.
2351 # @param IDOfNode the ID of node for creation of the element.
2352 # @return the Id of the new 0D element
2353 # @ingroup l2_modif_add
2354 def Add0DElement(self, IDOfNode):
2355 return self.editor.Add0DElement(IDOfNode)
2357 ## Create 0D elements on all nodes of the given elements except those
2358 # nodes on which a 0D element already exists.
2359 # @param theObject an object on whose nodes 0D elements will be created.
2360 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2361 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2362 # @param theGroupName optional name of a group to add 0D elements created
2363 # and/or found on nodes of \a theObject.
2364 # @return an object (a new group or a temporary SMESH_IDSource) holding
2365 # IDs of new and/or found 0D elements. IDs of 0D elements
2366 # can be retrieved from the returned object by calling GetIDs()
2367 # @ingroup l2_modif_add
2368 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2369 if isinstance( theObject, Mesh ):
2370 theObject = theObject.GetMesh()
2371 if isinstance( theObject, list ):
2372 theObject = self.GetIDSource( theObject, SMESH.ALL )
2373 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2375 ## Creates a ball element on a node with given ID.
2376 # @param IDOfNode the ID of node for creation of the element.
2377 # @param diameter the bal diameter.
2378 # @return the Id of the new ball element
2379 # @ingroup l2_modif_add
2380 def AddBall(self, IDOfNode, diameter):
2381 return self.editor.AddBall( IDOfNode, diameter )
2383 ## Creates a linear or quadratic edge (this is determined
2384 # by the number of given nodes).
2385 # @param IDsOfNodes the list of node IDs for creation of the element.
2386 # The order of nodes in this list should correspond to the description
2387 # of MED. \n This description is located by the following link:
2388 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2389 # @return the Id of the new edge
2390 # @ingroup l2_modif_add
2391 def AddEdge(self, IDsOfNodes):
2392 return self.editor.AddEdge(IDsOfNodes)
2394 ## Creates a linear or quadratic face (this is determined
2395 # by the number of given nodes).
2396 # @param IDsOfNodes the list of node IDs for creation of the element.
2397 # The order of nodes in this list should correspond to the description
2398 # of MED. \n This description is located by the following link:
2399 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2400 # @return the Id of the new face
2401 # @ingroup l2_modif_add
2402 def AddFace(self, IDsOfNodes):
2403 return self.editor.AddFace(IDsOfNodes)
2405 ## Adds a polygonal face to the mesh by the list of node IDs
2406 # @param IdsOfNodes the list of node IDs for creation of the element.
2407 # @return the Id of the new face
2408 # @ingroup l2_modif_add
2409 def AddPolygonalFace(self, IdsOfNodes):
2410 return self.editor.AddPolygonalFace(IdsOfNodes)
2412 ## Creates both simple and quadratic volume (this is determined
2413 # by the number of given nodes).
2414 # @param IDsOfNodes the list of node IDs for creation of the element.
2415 # The order of nodes in this list should correspond to the description
2416 # of MED. \n This description is located by the following link:
2417 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2418 # @return the Id of the new volumic element
2419 # @ingroup l2_modif_add
2420 def AddVolume(self, IDsOfNodes):
2421 return self.editor.AddVolume(IDsOfNodes)
2423 ## Creates a volume of many faces, giving nodes for each face.
2424 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2425 # @param Quantities the list of integer values, Quantities[i]
2426 # gives the quantity of nodes in face number i.
2427 # @return the Id of the new volumic element
2428 # @ingroup l2_modif_add
2429 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2430 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2432 ## Creates a volume of many faces, giving the IDs of the existing faces.
2433 # @param IdsOfFaces the list of face IDs for volume creation.
2435 # Note: The created volume will refer only to the nodes
2436 # of the given faces, not to the faces themselves.
2437 # @return the Id of the new volumic element
2438 # @ingroup l2_modif_add
2439 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2440 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2443 ## @brief Binds a node to a vertex
2444 # @param NodeID a node ID
2445 # @param Vertex a vertex or vertex ID
2446 # @return True if succeed else raises an exception
2447 # @ingroup l2_modif_add
2448 def SetNodeOnVertex(self, NodeID, Vertex):
2449 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2450 VertexID = Vertex.GetSubShapeIndices()[0]
2454 self.editor.SetNodeOnVertex(NodeID, VertexID)
2455 except SALOME.SALOME_Exception, inst:
2456 raise ValueError, inst.details.text
2460 ## @brief Stores the node position on an edge
2461 # @param NodeID a node ID
2462 # @param Edge an edge or edge ID
2463 # @param paramOnEdge a parameter on the edge where the node is located
2464 # @return True if succeed else raises an exception
2465 # @ingroup l2_modif_add
2466 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2467 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2468 EdgeID = Edge.GetSubShapeIndices()[0]
2472 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2473 except SALOME.SALOME_Exception, inst:
2474 raise ValueError, inst.details.text
2477 ## @brief Stores node position on a face
2478 # @param NodeID a node ID
2479 # @param Face a face or face ID
2480 # @param u U parameter on the face where the node is located
2481 # @param v V parameter on the face where the node is located
2482 # @return True if succeed else raises an exception
2483 # @ingroup l2_modif_add
2484 def SetNodeOnFace(self, NodeID, Face, u, v):
2485 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2486 FaceID = Face.GetSubShapeIndices()[0]
2490 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2491 except SALOME.SALOME_Exception, inst:
2492 raise ValueError, inst.details.text
2495 ## @brief Binds a node to a solid
2496 # @param NodeID a node ID
2497 # @param Solid a solid or solid ID
2498 # @return True if succeed else raises an exception
2499 # @ingroup l2_modif_add
2500 def SetNodeInVolume(self, NodeID, Solid):
2501 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2502 SolidID = Solid.GetSubShapeIndices()[0]
2506 self.editor.SetNodeInVolume(NodeID, SolidID)
2507 except SALOME.SALOME_Exception, inst:
2508 raise ValueError, inst.details.text
2511 ## @brief Bind an element to a shape
2512 # @param ElementID an element ID
2513 # @param Shape a shape or shape ID
2514 # @return True if succeed else raises an exception
2515 # @ingroup l2_modif_add
2516 def SetMeshElementOnShape(self, ElementID, Shape):
2517 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2518 ShapeID = Shape.GetSubShapeIndices()[0]
2522 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2523 except SALOME.SALOME_Exception, inst:
2524 raise ValueError, inst.details.text
2528 ## Moves the node with the given id
2529 # @param NodeID the id of the node
2530 # @param x a new X coordinate
2531 # @param y a new Y coordinate
2532 # @param z a new Z coordinate
2533 # @return True if succeed else False
2534 # @ingroup l2_modif_movenode
2535 def MoveNode(self, NodeID, x, y, z):
2536 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2537 if hasVars: self.mesh.SetParameters(Parameters)
2538 return self.editor.MoveNode(NodeID, x, y, z)
2540 ## Finds the node closest to a point and moves it to a point location
2541 # @param x the X coordinate of a point
2542 # @param y the Y coordinate of a point
2543 # @param z the Z coordinate of a point
2544 # @param NodeID if specified (>0), the node with this ID is moved,
2545 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2546 # @return the ID of a node
2547 # @ingroup l2_modif_throughp
2548 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2549 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2550 if hasVars: self.mesh.SetParameters(Parameters)
2551 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2553 ## Finds the node closest to a point
2554 # @param x the X coordinate of a point
2555 # @param y the Y coordinate of a point
2556 # @param z the Z coordinate of a point
2557 # @return the ID of a node
2558 # @ingroup l2_modif_throughp
2559 def FindNodeClosestTo(self, x, y, z):
2560 #preview = self.mesh.GetMeshEditPreviewer()
2561 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2562 return self.editor.FindNodeClosestTo(x, y, z)
2564 ## Finds the elements where a point lays IN or ON
2565 # @param x the X coordinate of a point
2566 # @param y the Y coordinate of a point
2567 # @param z the Z coordinate of a point
2568 # @param elementType type of elements to find (SMESH.ALL type
2569 # means elements of any type excluding nodes, discrete and 0D elements)
2570 # @param meshPart a part of mesh (group, sub-mesh) to search within
2571 # @return list of IDs of found elements
2572 # @ingroup l2_modif_throughp
2573 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2575 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2577 return self.editor.FindElementsByPoint(x, y, z, elementType)
2579 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2580 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2581 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2583 def GetPointState(self, x, y, z):
2584 return self.editor.GetPointState(x, y, z)
2586 ## Finds the node closest to a point and moves it to a point location
2587 # @param x the X coordinate of a point
2588 # @param y the Y coordinate of a point
2589 # @param z the Z coordinate of a point
2590 # @return the ID of a moved node
2591 # @ingroup l2_modif_throughp
2592 def MeshToPassThroughAPoint(self, x, y, z):
2593 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2595 ## Replaces two neighbour triangles sharing Node1-Node2 link
2596 # with the triangles built on the same 4 nodes but having other common link.
2597 # @param NodeID1 the ID of the first node
2598 # @param NodeID2 the ID of the second node
2599 # @return false if proper faces were not found
2600 # @ingroup l2_modif_invdiag
2601 def InverseDiag(self, NodeID1, NodeID2):
2602 return self.editor.InverseDiag(NodeID1, NodeID2)
2604 ## Replaces two neighbour triangles sharing Node1-Node2 link
2605 # with a quadrangle built on the same 4 nodes.
2606 # @param NodeID1 the ID of the first node
2607 # @param NodeID2 the ID of the second node
2608 # @return false if proper faces were not found
2609 # @ingroup l2_modif_unitetri
2610 def DeleteDiag(self, NodeID1, NodeID2):
2611 return self.editor.DeleteDiag(NodeID1, NodeID2)
2613 ## Reorients elements by ids
2614 # @param IDsOfElements if undefined reorients all mesh elements
2615 # @return True if succeed else False
2616 # @ingroup l2_modif_changori
2617 def Reorient(self, IDsOfElements=None):
2618 if IDsOfElements == None:
2619 IDsOfElements = self.GetElementsId()
2620 return self.editor.Reorient(IDsOfElements)
2622 ## Reorients all elements of the object
2623 # @param theObject mesh, submesh or group
2624 # @return True if succeed else False
2625 # @ingroup l2_modif_changori
2626 def ReorientObject(self, theObject):
2627 if ( isinstance( theObject, Mesh )):
2628 theObject = theObject.GetMesh()
2629 return self.editor.ReorientObject(theObject)
2631 ## Reorient faces contained in \a the2DObject.
2632 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2633 # @param theDirection is a desired direction of normal of \a theFace.
2634 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2635 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2636 # compared with theDirection. It can be either ID of face or a point
2637 # by which the face will be found. The point can be given as either
2638 # a GEOM vertex or a list of point coordinates.
2639 # @return number of reoriented faces
2640 # @ingroup l2_modif_changori
2641 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2643 if isinstance( the2DObject, Mesh ):
2644 the2DObject = the2DObject.GetMesh()
2645 if isinstance( the2DObject, list ):
2646 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2647 # check theDirection
2648 if isinstance( theDirection, geompyDC.GEOM._objref_GEOM_Object):
2649 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2650 if isinstance( theDirection, list ):
2651 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2652 # prepare theFace and thePoint
2653 theFace = theFaceOrPoint
2654 thePoint = PointStruct(0,0,0)
2655 if isinstance( theFaceOrPoint, geompyDC.GEOM._objref_GEOM_Object):
2656 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2658 if isinstance( theFaceOrPoint, list ):
2659 thePoint = PointStruct( *theFaceOrPoint )
2661 if isinstance( theFaceOrPoint, PointStruct ):
2662 thePoint = theFaceOrPoint
2664 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2666 ## Fuses the neighbouring triangles into quadrangles.
2667 # @param IDsOfElements The triangles to be fused,
2668 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2669 # choose a neighbour to fuse with.
2670 # @param MaxAngle is the maximum angle between element normals at which the fusion
2671 # is still performed; theMaxAngle is mesured in radians.
2672 # Also it could be a name of variable which defines angle in degrees.
2673 # @return TRUE in case of success, FALSE otherwise.
2674 # @ingroup l2_modif_unitetri
2675 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2676 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2677 self.mesh.SetParameters(Parameters)
2678 if not IDsOfElements:
2679 IDsOfElements = self.GetElementsId()
2680 Functor = self.smeshpyD.GetFunctor(theCriterion)
2681 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2683 ## Fuses the neighbouring triangles of the object into quadrangles
2684 # @param theObject is mesh, submesh or group
2685 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2686 # choose a neighbour to fuse with.
2687 # @param MaxAngle a max angle between element normals at which the fusion
2688 # is still performed; theMaxAngle is mesured in radians.
2689 # @return TRUE in case of success, FALSE otherwise.
2690 # @ingroup l2_modif_unitetri
2691 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2692 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2693 self.mesh.SetParameters(Parameters)
2694 if isinstance( theObject, Mesh ):
2695 theObject = theObject.GetMesh()
2696 Functor = self.smeshpyD.GetFunctor(theCriterion)
2697 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2699 ## Splits quadrangles into triangles.
2701 # @param IDsOfElements the faces to be splitted.
2702 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2703 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2704 # value, then quadrangles will be split by the smallest diagonal.
2705 # @return TRUE in case of success, FALSE otherwise.
2706 # @ingroup l2_modif_cutquadr
2707 def QuadToTri (self, IDsOfElements, theCriterion = None):
2708 if IDsOfElements == []:
2709 IDsOfElements = self.GetElementsId()
2710 if theCriterion is None:
2711 theCriterion = FT_MaxElementLength2D
2712 Functor = self.smeshpyD.GetFunctor(theCriterion)
2713 return self.editor.QuadToTri(IDsOfElements, Functor)
2715 ## Splits quadrangles into triangles.
2716 # @param theObject the object from which the list of elements is taken,
2717 # this is mesh, submesh or group
2718 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2719 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2720 # value, then quadrangles will be split by the smallest diagonal.
2721 # @return TRUE in case of success, FALSE otherwise.
2722 # @ingroup l2_modif_cutquadr
2723 def QuadToTriObject (self, theObject, theCriterion = None):
2724 if ( isinstance( theObject, Mesh )):
2725 theObject = theObject.GetMesh()
2726 if theCriterion is None:
2727 theCriterion = FT_MaxElementLength2D
2728 Functor = self.smeshpyD.GetFunctor(theCriterion)
2729 return self.editor.QuadToTriObject(theObject, Functor)
2731 ## Splits quadrangles into triangles.
2732 # @param IDsOfElements the faces to be splitted
2733 # @param Diag13 is used to choose a diagonal for splitting.
2734 # @return TRUE in case of success, FALSE otherwise.
2735 # @ingroup l2_modif_cutquadr
2736 def SplitQuad (self, IDsOfElements, Diag13):
2737 if IDsOfElements == []:
2738 IDsOfElements = self.GetElementsId()
2739 return self.editor.SplitQuad(IDsOfElements, Diag13)
2741 ## Splits quadrangles into triangles.
2742 # @param theObject the object from which the list of elements is taken,
2743 # this is mesh, submesh or group
2744 # @param Diag13 is used to choose a diagonal for splitting.
2745 # @return TRUE in case of success, FALSE otherwise.
2746 # @ingroup l2_modif_cutquadr
2747 def SplitQuadObject (self, theObject, Diag13):
2748 if ( isinstance( theObject, Mesh )):
2749 theObject = theObject.GetMesh()
2750 return self.editor.SplitQuadObject(theObject, Diag13)
2752 ## Finds a better splitting of the given quadrangle.
2753 # @param IDOfQuad the ID of the quadrangle to be splitted.
2754 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2755 # choose a diagonal for splitting.
2756 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2757 # diagonal is better, 0 if error occurs.
2758 # @ingroup l2_modif_cutquadr
2759 def BestSplit (self, IDOfQuad, theCriterion):
2760 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2762 ## Splits volumic elements into tetrahedrons
2763 # @param elemIDs either list of elements or mesh or group or submesh
2764 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2765 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2766 # @ingroup l2_modif_cutquadr
2767 def SplitVolumesIntoTetra(self, elemIDs, method=Hex_5Tet ):
2768 if isinstance( elemIDs, Mesh ):
2769 elemIDs = elemIDs.GetMesh()
2770 if ( isinstance( elemIDs, list )):
2771 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2772 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2774 ## Splits quadrangle faces near triangular facets of volumes
2776 # @ingroup l1_auxiliary
2777 def SplitQuadsNearTriangularFacets(self):
2778 faces_array = self.GetElementsByType(SMESH.FACE)
2779 for face_id in faces_array:
2780 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2781 quad_nodes = self.mesh.GetElemNodes(face_id)
2782 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2783 isVolumeFound = False
2784 for node1_elem in node1_elems:
2785 if not isVolumeFound:
2786 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2787 nb_nodes = self.GetElemNbNodes(node1_elem)
2788 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2789 volume_elem = node1_elem
2790 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2791 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2792 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2793 isVolumeFound = True
2794 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2795 self.SplitQuad([face_id], False) # diagonal 2-4
2796 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2797 isVolumeFound = True
2798 self.SplitQuad([face_id], True) # diagonal 1-3
2799 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2800 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2801 isVolumeFound = True
2802 self.SplitQuad([face_id], True) # diagonal 1-3
2804 ## @brief Splits hexahedrons into tetrahedrons.
2806 # This operation uses pattern mapping functionality for splitting.
2807 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2808 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2809 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2810 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2811 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2812 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2813 # @return TRUE in case of success, FALSE otherwise.
2814 # @ingroup l1_auxiliary
2815 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2816 # Pattern: 5.---------.6
2821 # (0,0,1) 4.---------.7 * |
2828 # (0,0,0) 0.---------.3
2829 pattern_tetra = "!!! Nb of points: \n 8 \n\
2839 !!! Indices of points of 6 tetras: \n\
2847 pattern = self.smeshpyD.GetPattern()
2848 isDone = pattern.LoadFromFile(pattern_tetra)
2850 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2853 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2854 isDone = pattern.MakeMesh(self.mesh, False, False)
2855 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2857 # split quafrangle faces near triangular facets of volumes
2858 self.SplitQuadsNearTriangularFacets()
2862 ## @brief Split hexahedrons into prisms.
2864 # Uses the pattern mapping functionality for splitting.
2865 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2866 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2867 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2868 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2869 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2870 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2871 # @return TRUE in case of success, FALSE otherwise.
2872 # @ingroup l1_auxiliary
2873 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2874 # Pattern: 5.---------.6
2879 # (0,0,1) 4.---------.7 |
2886 # (0,0,0) 0.---------.3
2887 pattern_prism = "!!! Nb of points: \n 8 \n\
2897 !!! Indices of points of 2 prisms: \n\
2901 pattern = self.smeshpyD.GetPattern()
2902 isDone = pattern.LoadFromFile(pattern_prism)
2904 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2907 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2908 isDone = pattern.MakeMesh(self.mesh, False, False)
2909 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2911 # Splits quafrangle faces near triangular facets of volumes
2912 self.SplitQuadsNearTriangularFacets()
2916 ## Smoothes elements
2917 # @param IDsOfElements the list if ids of elements to smooth
2918 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2919 # Note that nodes built on edges and boundary nodes are always fixed.
2920 # @param MaxNbOfIterations the maximum number of iterations
2921 # @param MaxAspectRatio varies in range [1.0, inf]
2922 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2923 # @return TRUE in case of success, FALSE otherwise.
2924 # @ingroup l2_modif_smooth
2925 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2926 MaxNbOfIterations, MaxAspectRatio, Method):
2927 if IDsOfElements == []:
2928 IDsOfElements = self.GetElementsId()
2929 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2930 self.mesh.SetParameters(Parameters)
2931 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2932 MaxNbOfIterations, MaxAspectRatio, Method)
2934 ## Smoothes elements which belong to the given object
2935 # @param theObject the object to smooth
2936 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2937 # Note that nodes built on edges and boundary nodes are always fixed.
2938 # @param MaxNbOfIterations the maximum number of iterations
2939 # @param MaxAspectRatio varies in range [1.0, inf]
2940 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2941 # @return TRUE in case of success, FALSE otherwise.
2942 # @ingroup l2_modif_smooth
2943 def SmoothObject(self, theObject, IDsOfFixedNodes,
2944 MaxNbOfIterations, MaxAspectRatio, Method):
2945 if ( isinstance( theObject, Mesh )):
2946 theObject = theObject.GetMesh()
2947 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2948 MaxNbOfIterations, MaxAspectRatio, Method)
2950 ## Parametrically smoothes the given elements
2951 # @param IDsOfElements the list if ids of elements to smooth
2952 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2953 # Note that nodes built on edges and boundary nodes are always fixed.
2954 # @param MaxNbOfIterations the maximum number of iterations
2955 # @param MaxAspectRatio varies in range [1.0, inf]
2956 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2957 # @return TRUE in case of success, FALSE otherwise.
2958 # @ingroup l2_modif_smooth
2959 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2960 MaxNbOfIterations, MaxAspectRatio, Method):
2961 if IDsOfElements == []:
2962 IDsOfElements = self.GetElementsId()
2963 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2964 self.mesh.SetParameters(Parameters)
2965 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2966 MaxNbOfIterations, MaxAspectRatio, Method)
2968 ## Parametrically smoothes the elements which belong to the given object
2969 # @param theObject the object to smooth
2970 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2971 # Note that nodes built on edges and boundary nodes are always fixed.
2972 # @param MaxNbOfIterations the maximum number of iterations
2973 # @param MaxAspectRatio varies in range [1.0, inf]
2974 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2975 # @return TRUE in case of success, FALSE otherwise.
2976 # @ingroup l2_modif_smooth
2977 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2978 MaxNbOfIterations, MaxAspectRatio, Method):
2979 if ( isinstance( theObject, Mesh )):
2980 theObject = theObject.GetMesh()
2981 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2982 MaxNbOfIterations, MaxAspectRatio, Method)
2984 ## Converts the mesh to quadratic, deletes old elements, replacing
2985 # them with quadratic with the same id.
2986 # @param theForce3d new node creation method:
2987 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
2988 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
2989 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2990 # @ingroup l2_modif_tofromqu
2991 def ConvertToQuadratic(self, theForce3d, theSubMesh=None):
2993 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
2995 self.editor.ConvertToQuadratic(theForce3d)
2997 ## Converts the mesh from quadratic to ordinary,
2998 # deletes old quadratic elements, \n replacing
2999 # them with ordinary mesh elements with the same id.
3000 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3001 # @ingroup l2_modif_tofromqu
3002 def ConvertFromQuadratic(self, theSubMesh=None):
3004 self.editor.ConvertFromQuadraticObject(theSubMesh)
3006 return self.editor.ConvertFromQuadratic()
3008 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3009 # @return TRUE if operation has been completed successfully, FALSE otherwise
3010 # @ingroup l2_modif_edit
3011 def Make2DMeshFrom3D(self):
3012 return self.editor. Make2DMeshFrom3D()
3014 ## Creates missing boundary elements
3015 # @param elements - elements whose boundary is to be checked:
3016 # mesh, group, sub-mesh or list of elements
3017 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3018 # @param dimension - defines type of boundary elements to create:
3019 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3020 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3021 # @param groupName - a name of group to store created boundary elements in,
3022 # "" means not to create the group
3023 # @param meshName - a name of new mesh to store created boundary elements in,
3024 # "" means not to create the new mesh
3025 # @param toCopyElements - if true, the checked elements will be copied into
3026 # the new mesh else only boundary elements will be copied into the new mesh
3027 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3028 # boundary elements will be copied into the new mesh
3029 # @return tuple (mesh, group) where bondary elements were added to
3030 # @ingroup l2_modif_edit
3031 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3032 toCopyElements=False, toCopyExistingBondary=False):
3033 if isinstance( elements, Mesh ):
3034 elements = elements.GetMesh()
3035 if ( isinstance( elements, list )):
3036 elemType = SMESH.ALL
3037 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3038 elements = self.editor.MakeIDSource(elements, elemType)
3039 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3040 toCopyElements,toCopyExistingBondary)
3041 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3045 # @brief Creates missing boundary elements around either the whole mesh or
3046 # groups of 2D elements
3047 # @param dimension - defines type of boundary elements to create
3048 # @param groupName - a name of group to store all boundary elements in,
3049 # "" means not to create the group
3050 # @param meshName - a name of a new mesh, which is a copy of the initial
3051 # mesh + created boundary elements; "" means not to create the new mesh
3052 # @param toCopyAll - if true, the whole initial mesh will be copied into
3053 # the new mesh else only boundary elements will be copied into the new mesh
3054 # @param groups - groups of 2D elements to make boundary around
3055 # @retval tuple( long, mesh, groups )
3056 # long - number of added boundary elements
3057 # mesh - the mesh where elements were added to
3058 # group - the group of boundary elements or None
3060 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3061 toCopyAll=False, groups=[]):
3062 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3064 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3065 return nb, mesh, group
3067 ## Renumber mesh nodes
3068 # @ingroup l2_modif_renumber
3069 def RenumberNodes(self):
3070 self.editor.RenumberNodes()
3072 ## Renumber mesh elements
3073 # @ingroup l2_modif_renumber
3074 def RenumberElements(self):
3075 self.editor.RenumberElements()
3077 ## Generates new elements by rotation of the elements around the axis
3078 # @param IDsOfElements the list of ids of elements to sweep
3079 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3080 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3081 # @param NbOfSteps the 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 RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3089 MakeGroups=False, TotalAngle=False):
3090 if IDsOfElements == []:
3091 IDsOfElements = self.GetElementsId()
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.RotationSweepMakeGroups(IDsOfElements, Axis,
3102 AngleInRadians, NbOfSteps, Tolerance)
3103 self.editor.RotationSweep(IDsOfElements, 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 RotationSweepObject(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.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3132 NbOfSteps, Tolerance)
3133 self.editor.RotationSweepObject(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 RotationSweepObject1D(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.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3162 NbOfSteps, Tolerance)
3163 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3166 ## Generates new elements by rotation of the elements of object around the axis
3167 # @param theObject object which elements should be sweeped.
3168 # It can be a mesh, a sub mesh or a group.
3169 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3170 # @param AngleInRadians the angle of Rotation
3171 # @param NbOfSteps number of steps
3172 # @param Tolerance tolerance
3173 # @param MakeGroups forces the generation of new groups from existing ones
3174 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3175 # of all steps, else - size of each step
3176 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3177 # @ingroup l2_modif_extrurev
3178 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3179 MakeGroups=False, TotalAngle=False):
3180 if ( isinstance( theObject, Mesh )):
3181 theObject = theObject.GetMesh()
3182 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3183 Axis = self.smeshpyD.GetAxisStruct(Axis)
3184 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3185 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3186 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3187 self.mesh.SetParameters(Parameters)
3188 if TotalAngle and NbOfSteps:
3189 AngleInRadians /= NbOfSteps
3191 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3192 NbOfSteps, Tolerance)
3193 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3196 ## Generates new elements by extrusion of the elements with given ids
3197 # @param IDsOfElements the list of elements ids for extrusion
3198 # @param StepVector vector or DirStruct or 3 vector components, defining
3199 # the direction and value of extrusion for one step (the total extrusion
3200 # length will be NbOfSteps * ||StepVector||)
3201 # @param NbOfSteps the number of steps
3202 # @param MakeGroups forces the generation of new groups from existing ones
3203 # @param IsNodes is True if elements with given ids are nodes
3204 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3205 # @ingroup l2_modif_extrurev
3206 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3207 if IDsOfElements == []:
3208 IDsOfElements = self.GetElementsId()
3209 if isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object):
3210 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3211 if isinstance( StepVector, list ):
3212 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3213 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3214 Parameters = StepVector.PS.parameters + var_separator + Parameters
3215 self.mesh.SetParameters(Parameters)
3218 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3220 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3222 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3224 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3227 ## Generates new elements by extrusion of the elements with given ids
3228 # @param IDsOfElements is ids of elements
3229 # @param StepVector vector or DirStruct or 3 vector components, defining
3230 # the direction and value of extrusion for one step (the total extrusion
3231 # length will be NbOfSteps * ||StepVector||)
3232 # @param NbOfSteps the number of steps
3233 # @param ExtrFlags sets flags for extrusion
3234 # @param SewTolerance uses for comparing locations of nodes if flag
3235 # EXTRUSION_FLAG_SEW is set
3236 # @param MakeGroups forces the generation of new groups from existing ones
3237 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3238 # @ingroup l2_modif_extrurev
3239 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3240 ExtrFlags, SewTolerance, MakeGroups=False):
3241 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3242 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3243 if isinstance( StepVector, list ):
3244 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3246 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3247 ExtrFlags, SewTolerance)
3248 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3249 ExtrFlags, SewTolerance)
3252 ## Generates new elements by extrusion of the elements which belong to the object
3253 # @param theObject the object which elements should be processed.
3254 # It can be a mesh, a sub mesh or a group.
3255 # @param StepVector vector or DirStruct or 3 vector components, defining
3256 # the direction and value of extrusion for one step (the total extrusion
3257 # length will be NbOfSteps * ||StepVector||)
3258 # @param MakeGroups forces the generation of new groups from existing ones
3259 # @param IsNodes is True if elements which belong to the object are nodes
3260 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3261 # @ingroup l2_modif_extrurev
3262 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3263 if ( isinstance( theObject, Mesh )):
3264 theObject = theObject.GetMesh()
3265 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3266 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3267 if isinstance( StepVector, list ):
3268 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3269 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3270 Parameters = StepVector.PS.parameters + var_separator + Parameters
3271 self.mesh.SetParameters(Parameters)
3274 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3276 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3278 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3280 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3283 ## Generates new elements by extrusion of the elements which belong to the object
3284 # @param theObject object which elements should be processed.
3285 # It can be a mesh, a sub mesh or a group.
3286 # @param StepVector vector or DirStruct or 3 vector components, defining
3287 # the direction and value of extrusion for one step (the total extrusion
3288 # length will be NbOfSteps * ||StepVector||)
3289 # @param NbOfSteps the number of steps
3290 # @param MakeGroups to generate new groups from existing ones
3291 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3292 # @ingroup l2_modif_extrurev
3293 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3294 if ( isinstance( theObject, Mesh )):
3295 theObject = theObject.GetMesh()
3296 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3297 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3298 if isinstance( StepVector, list ):
3299 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3300 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3301 Parameters = StepVector.PS.parameters + var_separator + Parameters
3302 self.mesh.SetParameters(Parameters)
3304 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3305 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3308 ## Generates new elements by extrusion of the elements which belong to the object
3309 # @param theObject object which elements should be processed.
3310 # It can be a mesh, a sub mesh or a group.
3311 # @param StepVector vector or DirStruct or 3 vector components, defining
3312 # the direction and value of extrusion for one step (the total extrusion
3313 # length will be NbOfSteps * ||StepVector||)
3314 # @param NbOfSteps the number of steps
3315 # @param MakeGroups forces the generation of new groups from existing ones
3316 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3317 # @ingroup l2_modif_extrurev
3318 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3319 if ( isinstance( theObject, Mesh )):
3320 theObject = theObject.GetMesh()
3321 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3322 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3323 if isinstance( StepVector, list ):
3324 StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3325 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3326 Parameters = StepVector.PS.parameters + var_separator + Parameters
3327 self.mesh.SetParameters(Parameters)
3329 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3330 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3335 ## Generates new elements by extrusion of the given elements
3336 # The path of extrusion must be a meshed edge.
3337 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3338 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3339 # @param NodeStart the start node from Path. Defines the direction of extrusion
3340 # @param HasAngles allows the shape to be rotated around the path
3341 # to get the resulting mesh in a helical fashion
3342 # @param Angles list of angles in radians
3343 # @param LinearVariation forces the computation of rotation angles as linear
3344 # variation of the given Angles along path steps
3345 # @param HasRefPoint allows using the reference point
3346 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3347 # The User can specify any point as the Reference Point.
3348 # @param MakeGroups forces the generation of new groups from existing ones
3349 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3350 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3351 # only SMESH::Extrusion_Error otherwise
3352 # @ingroup l2_modif_extrurev
3353 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3354 HasAngles, Angles, LinearVariation,
3355 HasRefPoint, RefPoint, MakeGroups, ElemType):
3356 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3357 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3359 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3360 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3361 self.mesh.SetParameters(Parameters)
3363 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3365 if isinstance(Base, list):
3367 if Base == []: IDsOfElements = self.GetElementsId()
3368 else: IDsOfElements = Base
3369 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3370 HasAngles, Angles, LinearVariation,
3371 HasRefPoint, RefPoint, MakeGroups, ElemType)
3373 if isinstance(Base, Mesh): Base = Base.GetMesh()
3374 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3375 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3376 HasAngles, Angles, LinearVariation,
3377 HasRefPoint, RefPoint, MakeGroups, ElemType)
3379 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3382 ## Generates new elements by extrusion of the given elements
3383 # The path of extrusion must be a meshed edge.
3384 # @param IDsOfElements ids of elements
3385 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3386 # @param PathShape shape(edge) defines the sub-mesh for the path
3387 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3388 # @param HasAngles allows the shape to be rotated around the path
3389 # to get the resulting mesh in a helical fashion
3390 # @param Angles list of angles in radians
3391 # @param HasRefPoint allows using the reference point
3392 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3393 # The User can specify any point as the Reference Point.
3394 # @param MakeGroups forces the generation of new groups from existing ones
3395 # @param LinearVariation forces the computation of rotation angles as linear
3396 # variation of the given Angles along path steps
3397 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3398 # only SMESH::Extrusion_Error otherwise
3399 # @ingroup l2_modif_extrurev
3400 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3401 HasAngles, Angles, HasRefPoint, RefPoint,
3402 MakeGroups=False, LinearVariation=False):
3403 if IDsOfElements == []:
3404 IDsOfElements = self.GetElementsId()
3405 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3406 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3408 if ( isinstance( PathMesh, Mesh )):
3409 PathMesh = PathMesh.GetMesh()
3410 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3411 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3412 self.mesh.SetParameters(Parameters)
3413 if HasAngles and Angles and LinearVariation:
3414 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3417 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3418 PathShape, NodeStart, HasAngles,
3419 Angles, HasRefPoint, RefPoint)
3420 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3421 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3423 ## Generates new elements by extrusion of the elements which belong to the object
3424 # The path of extrusion must be a meshed edge.
3425 # @param theObject the object which elements should be processed.
3426 # It can be a mesh, a sub mesh or a group.
3427 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3428 # @param PathShape shape(edge) defines the sub-mesh for the path
3429 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3430 # @param HasAngles allows the shape to be rotated around the path
3431 # to get the resulting mesh in a helical fashion
3432 # @param Angles list of angles
3433 # @param HasRefPoint allows using the reference point
3434 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3435 # The User can specify any point as the Reference Point.
3436 # @param MakeGroups forces the generation of new groups from existing ones
3437 # @param LinearVariation forces the computation of rotation angles as linear
3438 # variation of the given Angles along path steps
3439 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3440 # only SMESH::Extrusion_Error otherwise
3441 # @ingroup l2_modif_extrurev
3442 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3443 HasAngles, Angles, HasRefPoint, RefPoint,
3444 MakeGroups=False, LinearVariation=False):
3445 if ( isinstance( theObject, Mesh )):
3446 theObject = theObject.GetMesh()
3447 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3448 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3449 if ( isinstance( PathMesh, Mesh )):
3450 PathMesh = PathMesh.GetMesh()
3451 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3452 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3453 self.mesh.SetParameters(Parameters)
3454 if HasAngles and Angles and LinearVariation:
3455 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3458 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3459 PathShape, NodeStart, HasAngles,
3460 Angles, HasRefPoint, RefPoint)
3461 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3462 NodeStart, HasAngles, Angles, HasRefPoint,
3465 ## Generates new elements by extrusion of the elements which belong to the object
3466 # The path of extrusion must be a meshed edge.
3467 # @param theObject the object which elements should be processed.
3468 # It can be a mesh, a sub mesh or a group.
3469 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3470 # @param PathShape shape(edge) defines the sub-mesh for the path
3471 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3472 # @param HasAngles allows the shape to be rotated around the path
3473 # to get the resulting mesh in a helical fashion
3474 # @param Angles list of angles
3475 # @param HasRefPoint allows using the reference point
3476 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3477 # The User can specify any point as the Reference Point.
3478 # @param MakeGroups forces the generation of new groups from existing ones
3479 # @param LinearVariation forces the computation of rotation angles as linear
3480 # variation of the given Angles along path steps
3481 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3482 # only SMESH::Extrusion_Error otherwise
3483 # @ingroup l2_modif_extrurev
3484 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3485 HasAngles, Angles, HasRefPoint, RefPoint,
3486 MakeGroups=False, LinearVariation=False):
3487 if ( isinstance( theObject, Mesh )):
3488 theObject = theObject.GetMesh()
3489 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3490 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3491 if ( isinstance( PathMesh, Mesh )):
3492 PathMesh = PathMesh.GetMesh()
3493 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3494 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3495 self.mesh.SetParameters(Parameters)
3496 if HasAngles and Angles and LinearVariation:
3497 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3500 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3501 PathShape, NodeStart, HasAngles,
3502 Angles, HasRefPoint, RefPoint)
3503 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3504 NodeStart, HasAngles, Angles, HasRefPoint,
3507 ## Generates new elements by extrusion of the elements which belong to the object
3508 # The path of extrusion must be a meshed edge.
3509 # @param theObject the object which elements should be processed.
3510 # It can be a mesh, a sub mesh or a group.
3511 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3512 # @param PathShape shape(edge) defines the sub-mesh for the path
3513 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3514 # @param HasAngles allows the shape to be rotated around the path
3515 # to get the resulting mesh in a helical fashion
3516 # @param Angles list of angles
3517 # @param HasRefPoint allows using the reference point
3518 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3519 # The User can specify any point as the Reference Point.
3520 # @param MakeGroups forces the generation of new groups from existing ones
3521 # @param LinearVariation forces the computation of rotation angles as linear
3522 # variation of the given Angles along path steps
3523 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3524 # only SMESH::Extrusion_Error otherwise
3525 # @ingroup l2_modif_extrurev
3526 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3527 HasAngles, Angles, HasRefPoint, RefPoint,
3528 MakeGroups=False, LinearVariation=False):
3529 if ( isinstance( theObject, Mesh )):
3530 theObject = theObject.GetMesh()
3531 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3532 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3533 if ( isinstance( PathMesh, Mesh )):
3534 PathMesh = PathMesh.GetMesh()
3535 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3536 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3537 self.mesh.SetParameters(Parameters)
3538 if HasAngles and Angles and LinearVariation:
3539 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3542 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3543 PathShape, NodeStart, HasAngles,
3544 Angles, HasRefPoint, RefPoint)
3545 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3546 NodeStart, HasAngles, Angles, HasRefPoint,
3549 ## Creates a symmetrical copy of mesh elements
3550 # @param IDsOfElements list of elements ids
3551 # @param Mirror is AxisStruct or geom object(point, line, plane)
3552 # @param theMirrorType is POINT, AXIS or PLANE
3553 # If the Mirror is a geom object this parameter is unnecessary
3554 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3555 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3556 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3557 # @ingroup l2_modif_trsf
3558 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3559 if IDsOfElements == []:
3560 IDsOfElements = self.GetElementsId()
3561 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3562 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3563 self.mesh.SetParameters(Mirror.parameters)
3564 if Copy and MakeGroups:
3565 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3566 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3569 ## Creates a new mesh by a symmetrical copy of mesh elements
3570 # @param IDsOfElements the list of elements ids
3571 # @param Mirror is AxisStruct or geom object (point, line, plane)
3572 # @param theMirrorType is POINT, AXIS or PLANE
3573 # If the Mirror is a geom object this parameter is unnecessary
3574 # @param MakeGroups to generate new groups from existing ones
3575 # @param NewMeshName a name of the new mesh to create
3576 # @return instance of Mesh class
3577 # @ingroup l2_modif_trsf
3578 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3579 if IDsOfElements == []:
3580 IDsOfElements = self.GetElementsId()
3581 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3582 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3583 self.mesh.SetParameters(Mirror.parameters)
3584 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3585 MakeGroups, NewMeshName)
3586 return Mesh(self.smeshpyD,self.geompyD,mesh)
3588 ## Creates a symmetrical copy of the object
3589 # @param theObject mesh, submesh or group
3590 # @param Mirror AxisStruct or geom object (point, line, plane)
3591 # @param theMirrorType is POINT, AXIS or PLANE
3592 # If the Mirror is a geom object this parameter is unnecessary
3593 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3594 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3595 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3596 # @ingroup l2_modif_trsf
3597 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3598 if ( isinstance( theObject, Mesh )):
3599 theObject = theObject.GetMesh()
3600 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3601 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3602 self.mesh.SetParameters(Mirror.parameters)
3603 if Copy and MakeGroups:
3604 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3605 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3608 ## Creates a new mesh by a symmetrical copy of the object
3609 # @param theObject mesh, submesh or group
3610 # @param Mirror AxisStruct or geom object (point, line, plane)
3611 # @param theMirrorType POINT, AXIS or PLANE
3612 # If the Mirror is a geom object this parameter is unnecessary
3613 # @param MakeGroups forces the generation of new groups from existing ones
3614 # @param NewMeshName the name of the new mesh to create
3615 # @return instance of Mesh class
3616 # @ingroup l2_modif_trsf
3617 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3618 if ( isinstance( theObject, Mesh )):
3619 theObject = theObject.GetMesh()
3620 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3621 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3622 self.mesh.SetParameters(Mirror.parameters)
3623 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3624 MakeGroups, NewMeshName)
3625 return Mesh( self.smeshpyD,self.geompyD,mesh )
3627 ## Translates the elements
3628 # @param IDsOfElements list of elements ids
3629 # @param Vector the direction of translation (DirStruct or vector)
3630 # @param Copy allows copying the translated elements
3631 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3632 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3633 # @ingroup l2_modif_trsf
3634 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3635 if IDsOfElements == []:
3636 IDsOfElements = self.GetElementsId()
3637 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3638 Vector = self.smeshpyD.GetDirStruct(Vector)
3639 self.mesh.SetParameters(Vector.PS.parameters)
3640 if Copy and MakeGroups:
3641 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3642 self.editor.Translate(IDsOfElements, Vector, Copy)
3645 ## Creates a new mesh of translated elements
3646 # @param IDsOfElements list of elements ids
3647 # @param Vector the direction of translation (DirStruct or vector)
3648 # @param MakeGroups forces the generation of new groups from existing ones
3649 # @param NewMeshName the name of the newly created mesh
3650 # @return instance of Mesh class
3651 # @ingroup l2_modif_trsf
3652 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3653 if IDsOfElements == []:
3654 IDsOfElements = self.GetElementsId()
3655 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3656 Vector = self.smeshpyD.GetDirStruct(Vector)
3657 self.mesh.SetParameters(Vector.PS.parameters)
3658 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3659 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3661 ## Translates the object
3662 # @param theObject the object to translate (mesh, submesh, or group)
3663 # @param Vector direction of translation (DirStruct or geom vector)
3664 # @param Copy allows copying the translated elements
3665 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3666 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3667 # @ingroup l2_modif_trsf
3668 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3669 if ( isinstance( theObject, Mesh )):
3670 theObject = theObject.GetMesh()
3671 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3672 Vector = self.smeshpyD.GetDirStruct(Vector)
3673 self.mesh.SetParameters(Vector.PS.parameters)
3674 if Copy and MakeGroups:
3675 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3676 self.editor.TranslateObject(theObject, Vector, Copy)
3679 ## Creates a new mesh from the translated object
3680 # @param theObject the object to translate (mesh, submesh, or group)
3681 # @param Vector the direction of translation (DirStruct or geom vector)
3682 # @param MakeGroups forces the generation of new groups from existing ones
3683 # @param NewMeshName the name of the newly created mesh
3684 # @return instance of Mesh class
3685 # @ingroup l2_modif_trsf
3686 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3687 if (isinstance(theObject, Mesh)):
3688 theObject = theObject.GetMesh()
3689 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3690 Vector = self.smeshpyD.GetDirStruct(Vector)
3691 self.mesh.SetParameters(Vector.PS.parameters)
3692 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3693 return Mesh( self.smeshpyD, self.geompyD, mesh )
3697 ## Scales the object
3698 # @param theObject - the object to translate (mesh, submesh, or group)
3699 # @param thePoint - base point for scale
3700 # @param theScaleFact - list of 1-3 scale factors for axises
3701 # @param Copy - allows copying the translated elements
3702 # @param MakeGroups - forces the generation of new groups from existing
3704 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3705 # empty list otherwise
3706 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3707 if ( isinstance( theObject, Mesh )):
3708 theObject = theObject.GetMesh()
3709 if ( isinstance( theObject, list )):
3710 theObject = self.GetIDSource(theObject, SMESH.ALL)
3711 if ( isinstance( theScaleFact, float )):
3712 theScaleFact = [theScaleFact]
3713 if ( isinstance( theScaleFact, int )):
3714 theScaleFact = [ float(theScaleFact)]
3716 self.mesh.SetParameters(thePoint.parameters)
3718 if Copy and MakeGroups:
3719 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3720 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3723 ## Creates a new mesh from the translated object
3724 # @param theObject - the object to translate (mesh, submesh, or group)
3725 # @param thePoint - base point for scale
3726 # @param theScaleFact - list of 1-3 scale factors for axises
3727 # @param MakeGroups - forces the generation of new groups from existing ones
3728 # @param NewMeshName - the name of the newly created mesh
3729 # @return instance of Mesh class
3730 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3731 if (isinstance(theObject, Mesh)):
3732 theObject = theObject.GetMesh()
3733 if ( isinstance( theObject, list )):
3734 theObject = self.GetIDSource(theObject,SMESH.ALL)
3735 if ( isinstance( theScaleFact, float )):
3736 theScaleFact = [theScaleFact]
3737 if ( isinstance( theScaleFact, int )):
3738 theScaleFact = [ float(theScaleFact)]
3740 self.mesh.SetParameters(thePoint.parameters)
3741 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3742 MakeGroups, NewMeshName)
3743 return Mesh( self.smeshpyD, self.geompyD, mesh )
3747 ## Rotates the elements
3748 # @param IDsOfElements list of elements ids
3749 # @param Axis the axis of rotation (AxisStruct or geom line)
3750 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3751 # @param Copy allows copying the rotated elements
3752 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3753 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3754 # @ingroup l2_modif_trsf
3755 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3756 if IDsOfElements == []:
3757 IDsOfElements = self.GetElementsId()
3758 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3759 Axis = self.smeshpyD.GetAxisStruct(Axis)
3760 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3761 Parameters = Axis.parameters + var_separator + Parameters
3762 self.mesh.SetParameters(Parameters)
3763 if Copy and MakeGroups:
3764 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3765 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3768 ## Creates a new mesh of rotated elements
3769 # @param IDsOfElements list of element ids
3770 # @param Axis the axis of rotation (AxisStruct or geom line)
3771 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3772 # @param MakeGroups forces the generation of new groups from existing ones
3773 # @param NewMeshName the name of the newly created mesh
3774 # @return instance of Mesh class
3775 # @ingroup l2_modif_trsf
3776 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3777 if IDsOfElements == []:
3778 IDsOfElements = self.GetElementsId()
3779 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3780 Axis = self.smeshpyD.GetAxisStruct(Axis)
3781 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3782 Parameters = Axis.parameters + var_separator + Parameters
3783 self.mesh.SetParameters(Parameters)
3784 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3785 MakeGroups, NewMeshName)
3786 return Mesh( self.smeshpyD, self.geompyD, mesh )
3788 ## Rotates the object
3789 # @param theObject the object to rotate( mesh, submesh, or group)
3790 # @param Axis the axis of rotation (AxisStruct or geom line)
3791 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3792 # @param Copy allows copying the rotated elements
3793 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3794 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3795 # @ingroup l2_modif_trsf
3796 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3797 if (isinstance(theObject, Mesh)):
3798 theObject = theObject.GetMesh()
3799 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3800 Axis = self.smeshpyD.GetAxisStruct(Axis)
3801 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3802 Parameters = Axis.parameters + ":" + Parameters
3803 self.mesh.SetParameters(Parameters)
3804 if Copy and MakeGroups:
3805 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3806 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3809 ## Creates a new mesh from the rotated object
3810 # @param theObject the object to rotate (mesh, submesh, or group)
3811 # @param Axis the axis of rotation (AxisStruct or geom line)
3812 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3813 # @param MakeGroups forces the generation of new groups from existing ones
3814 # @param NewMeshName the name of the newly created mesh
3815 # @return instance of Mesh class
3816 # @ingroup l2_modif_trsf
3817 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3818 if (isinstance( theObject, Mesh )):
3819 theObject = theObject.GetMesh()
3820 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3821 Axis = self.smeshpyD.GetAxisStruct(Axis)
3822 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3823 Parameters = Axis.parameters + ":" + Parameters
3824 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3825 MakeGroups, NewMeshName)
3826 self.mesh.SetParameters(Parameters)
3827 return Mesh( self.smeshpyD, self.geompyD, mesh )
3829 ## Finds groups of ajacent nodes within Tolerance.
3830 # @param Tolerance the value of tolerance
3831 # @return the list of groups of nodes
3832 # @ingroup l2_modif_trsf
3833 def FindCoincidentNodes (self, Tolerance):
3834 return self.editor.FindCoincidentNodes(Tolerance)
3836 ## Finds groups of ajacent nodes within Tolerance.
3837 # @param Tolerance the value of tolerance
3838 # @param SubMeshOrGroup SubMesh or Group
3839 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3840 # @return the list of groups of nodes
3841 # @ingroup l2_modif_trsf
3842 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3843 if (isinstance( SubMeshOrGroup, Mesh )):
3844 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3845 if not isinstance( exceptNodes, list):
3846 exceptNodes = [ exceptNodes ]
3847 if exceptNodes and isinstance( exceptNodes[0], int):
3848 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3849 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3852 # @param GroupsOfNodes the list of groups of nodes
3853 # @ingroup l2_modif_trsf
3854 def MergeNodes (self, GroupsOfNodes):
3855 self.editor.MergeNodes(GroupsOfNodes)
3857 ## Finds the elements built on the same nodes.
3858 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3859 # @return a list of groups of equal elements
3860 # @ingroup l2_modif_trsf
3861 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3862 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
3863 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
3864 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3866 ## Merges elements in each given group.
3867 # @param GroupsOfElementsID groups of elements for merging
3868 # @ingroup l2_modif_trsf
3869 def MergeElements(self, GroupsOfElementsID):
3870 self.editor.MergeElements(GroupsOfElementsID)
3872 ## Leaves one element and removes all other elements built on the same nodes.
3873 # @ingroup l2_modif_trsf
3874 def MergeEqualElements(self):
3875 self.editor.MergeEqualElements()
3877 ## Sews free borders
3878 # @return SMESH::Sew_Error
3879 # @ingroup l2_modif_trsf
3880 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3881 FirstNodeID2, SecondNodeID2, LastNodeID2,
3882 CreatePolygons, CreatePolyedrs):
3883 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3884 FirstNodeID2, SecondNodeID2, LastNodeID2,
3885 CreatePolygons, CreatePolyedrs)
3887 ## Sews conform free borders
3888 # @return SMESH::Sew_Error
3889 # @ingroup l2_modif_trsf
3890 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3891 FirstNodeID2, SecondNodeID2):
3892 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3893 FirstNodeID2, SecondNodeID2)
3895 ## Sews border to side
3896 # @return SMESH::Sew_Error
3897 # @ingroup l2_modif_trsf
3898 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3899 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3900 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3901 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3903 ## Sews two sides of a mesh. The nodes belonging to Side1 are
3904 # merged with the nodes of elements of Side2.
3905 # The number of elements in theSide1 and in theSide2 must be
3906 # equal and they should have similar nodal connectivity.
3907 # The nodes to merge should belong to side borders and
3908 # the first node should be linked to the second.
3909 # @return SMESH::Sew_Error
3910 # @ingroup l2_modif_trsf
3911 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3912 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3913 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3914 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3915 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3916 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3918 ## Sets new nodes for the given element.
3919 # @param ide the element id
3920 # @param newIDs nodes ids
3921 # @return If the number of nodes does not correspond to the type of element - returns false
3922 # @ingroup l2_modif_edit
3923 def ChangeElemNodes(self, ide, newIDs):
3924 return self.editor.ChangeElemNodes(ide, newIDs)
3926 ## If during the last operation of MeshEditor some nodes were
3927 # created, this method returns the list of their IDs, \n
3928 # if new nodes were not created - returns empty list
3929 # @return the list of integer values (can be empty)
3930 # @ingroup l1_auxiliary
3931 def GetLastCreatedNodes(self):
3932 return self.editor.GetLastCreatedNodes()
3934 ## If during the last operation of MeshEditor some elements were
3935 # created this method returns the list of their IDs, \n
3936 # if new elements were not created - returns empty list
3937 # @return the list of integer values (can be empty)
3938 # @ingroup l1_auxiliary
3939 def GetLastCreatedElems(self):
3940 return self.editor.GetLastCreatedElems()
3942 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3943 # @param theNodes identifiers of nodes to be doubled
3944 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
3945 # nodes. If list of element identifiers is empty then nodes are doubled but
3946 # they not assigned to elements
3947 # @return TRUE if operation has been completed successfully, FALSE otherwise
3948 # @ingroup l2_modif_edit
3949 def DoubleNodes(self, theNodes, theModifiedElems):
3950 return self.editor.DoubleNodes(theNodes, theModifiedElems)
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 theNodeId identifiers of node to be doubled
3955 # @param theModifiedElems identifiers of elements to be updated
3956 # @return TRUE if operation has been completed successfully, FALSE otherwise
3957 # @ingroup l2_modif_edit
3958 def DoubleNode(self, theNodeId, theModifiedElems):
3959 return self.editor.DoubleNode(theNodeId, theModifiedElems)
3961 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3962 # This method provided for convenience works as DoubleNodes() described above.
3963 # @param theNodes group of nodes to be doubled
3964 # @param theModifiedElems group of elements to be updated.
3965 # @param theMakeGroup forces the generation of a group containing new nodes.
3966 # @return TRUE or a created group if operation has been completed successfully,
3967 # FALSE or None otherwise
3968 # @ingroup l2_modif_edit
3969 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
3971 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
3972 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
3974 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3975 # This method provided for convenience works as DoubleNodes() described above.
3976 # @param theNodes list of groups of nodes to be doubled
3977 # @param theModifiedElems list of groups of elements to be updated.
3978 # @param theMakeGroup forces the generation of a group containing new nodes.
3979 # @return TRUE if operation has been completed successfully, FALSE otherwise
3980 # @ingroup l2_modif_edit
3981 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
3983 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
3984 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
3986 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3987 # @param theElems - the list of elements (edges or faces) to be replicated
3988 # The nodes for duplication could be found from these elements
3989 # @param theNodesNot - list of nodes to NOT replicate
3990 # @param theAffectedElems - the list of elements (cells and edges) to which the
3991 # replicated nodes should be associated to.
3992 # @return TRUE if operation has been completed successfully, FALSE otherwise
3993 # @ingroup l2_modif_edit
3994 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
3995 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
3997 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3998 # @param theElems - the list of elements (edges or faces) to be replicated
3999 # The nodes for duplication could be found from these elements
4000 # @param theNodesNot - list of nodes to NOT replicate
4001 # @param theShape - shape to detect affected elements (element which geometric center
4002 # located on or inside shape).
4003 # The replicated nodes should be associated to affected elements.
4004 # @return TRUE if operation has been completed successfully, FALSE otherwise
4005 # @ingroup l2_modif_edit
4006 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4007 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
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 - group of of elements (edges or faces) to be replicated
4012 # @param theNodesNot - group of nodes not to replicated
4013 # @param theAffectedElems - group of elements to which the replicated nodes
4014 # should be associated to.
4015 # @param theMakeGroup forces the generation of a group containing new elements.
4016 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4017 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4018 # FALSE or None otherwise
4019 # @ingroup l2_modif_edit
4020 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4021 theMakeGroup=False, theMakeNodeGroup=False):
4022 if theMakeGroup or theMakeNodeGroup:
4023 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4025 theMakeGroup, theMakeNodeGroup)
4026 if theMakeGroup and theMakeNodeGroup:
4029 return twoGroups[ int(theMakeNodeGroup) ]
4030 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4032 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4033 # This method provided for convenience works as DoubleNodes() described above.
4034 # @param theElems - group of of elements (edges or faces) to be replicated
4035 # @param theNodesNot - group of nodes not to replicated
4036 # @param theShape - shape to detect affected elements (element which geometric center
4037 # located on or inside shape).
4038 # The replicated nodes should be associated to affected elements.
4039 # @ingroup l2_modif_edit
4040 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4041 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4043 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4044 # This method provided for convenience works as DoubleNodes() described above.
4045 # @param theElems - list of groups of elements (edges or faces) to be replicated
4046 # @param theNodesNot - list of groups of nodes not to replicated
4047 # @param theAffectedElems - group of elements to which the replicated nodes
4048 # should be associated to.
4049 # @param theMakeGroup forces the generation of a group containing new elements.
4050 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4051 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4052 # FALSE or None otherwise
4053 # @ingroup l2_modif_edit
4054 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4055 theMakeGroup=False, theMakeNodeGroup=False):
4056 if theMakeGroup or theMakeNodeGroup:
4057 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4059 theMakeGroup, theMakeNodeGroup)
4060 if theMakeGroup and theMakeNodeGroup:
4063 return twoGroups[ int(theMakeNodeGroup) ]
4064 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4066 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4067 # This method provided for convenience works as DoubleNodes() described above.
4068 # @param theElems - list of groups of elements (edges or faces) to be replicated
4069 # @param theNodesNot - list of groups of nodes not to replicated
4070 # @param theShape - shape to detect affected elements (element which geometric center
4071 # located on or inside shape).
4072 # The replicated nodes should be associated to affected elements.
4073 # @return TRUE if operation has been completed successfully, FALSE otherwise
4074 # @ingroup l2_modif_edit
4075 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4076 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4078 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4079 # This method is the first step of DoubleNodeElemGroupsInRegion.
4080 # @param theElems - list of groups of elements (edges or faces) to be replicated
4081 # @param theNodesNot - list of groups of nodes not to replicated
4082 # @param theShape - shape to detect affected elements (element which geometric center
4083 # located on or inside shape).
4084 # The replicated nodes should be associated to affected elements.
4085 # @return groups of affected elements
4086 # @ingroup l2_modif_edit
4087 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4088 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4090 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4091 # The list of groups must describe a partition of the mesh volumes.
4092 # The nodes of the internal faces at the boundaries of the groups are doubled.
4093 # In option, the internal faces are replaced by flat elements.
4094 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4095 # @param theDomains - list of groups of volumes
4096 # @param createJointElems - if TRUE, create the elements
4097 # @return TRUE if operation has been completed successfully, FALSE otherwise
4098 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4099 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4101 ## Double nodes on some external faces and create flat elements.
4102 # Flat elements are mainly used by some types of mechanic calculations.
4104 # Each group of the list must be constituted of faces.
4105 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4106 # @param theGroupsOfFaces - list of groups of faces
4107 # @return TRUE if operation has been completed successfully, FALSE otherwise
4108 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4109 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4111 ## identify all the elements around a geom shape, get the faces delimiting the hole
4113 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4114 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4116 def _getFunctor(self, funcType ):
4117 fn = self.functors[ funcType._v ]
4119 fn = self.smeshpyD.GetFunctor(funcType)
4120 fn.SetMesh(self.mesh)
4121 self.functors[ funcType._v ] = fn
4124 def _valueFromFunctor(self, funcType, elemId):
4125 fn = self._getFunctor( funcType )
4126 if fn.GetElementType() == self.GetElementType(elemId, True):
4127 val = fn.GetValue(elemId)
4132 ## Get length of 1D element.
4133 # @param elemId mesh element ID
4134 # @return element's length value
4135 # @ingroup l1_measurements
4136 def GetLength(self, elemId):
4137 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4139 ## Get area of 2D element.
4140 # @param elemId mesh element ID
4141 # @return element's area value
4142 # @ingroup l1_measurements
4143 def GetArea(self, elemId):
4144 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4146 ## Get volume of 3D element.
4147 # @param elemId mesh element ID
4148 # @return element's volume value
4149 # @ingroup l1_measurements
4150 def GetVolume(self, elemId):
4151 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4153 ## Get maximum element length.
4154 # @param elemId mesh element ID
4155 # @return element's maximum length value
4156 # @ingroup l1_measurements
4157 def GetMaxElementLength(self, elemId):
4158 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4159 ftype = SMESH.FT_MaxElementLength3D
4161 ftype = SMESH.FT_MaxElementLength2D
4162 return self._valueFromFunctor(ftype, elemId)
4164 ## Get aspect ratio of 2D or 3D element.
4165 # @param elemId mesh element ID
4166 # @return element's aspect ratio value
4167 # @ingroup l1_measurements
4168 def GetAspectRatio(self, elemId):
4169 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4170 ftype = SMESH.FT_AspectRatio3D
4172 ftype = SMESH.FT_AspectRatio
4173 return self._valueFromFunctor(ftype, elemId)
4175 ## Get warping angle of 2D element.
4176 # @param elemId mesh element ID
4177 # @return element's warping angle value
4178 # @ingroup l1_measurements
4179 def GetWarping(self, elemId):
4180 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4182 ## Get minimum angle of 2D element.
4183 # @param elemId mesh element ID
4184 # @return element's minimum angle value
4185 # @ingroup l1_measurements
4186 def GetMinimumAngle(self, elemId):
4187 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4189 ## Get taper of 2D element.
4190 # @param elemId mesh element ID
4191 # @return element's taper value
4192 # @ingroup l1_measurements
4193 def GetTaper(self, elemId):
4194 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4196 ## Get skew of 2D element.
4197 # @param elemId mesh element ID
4198 # @return element's skew value
4199 # @ingroup l1_measurements
4200 def GetSkew(self, elemId):
4201 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4203 pass # end of Mesh class
4205 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4207 class Pattern(SMESH._objref_SMESH_Pattern):
4209 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4210 decrFun = lambda i: i-1
4211 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4212 theMesh.SetParameters(Parameters)
4213 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4215 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4216 decrFun = lambda i: i-1
4217 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4218 theMesh.SetParameters(Parameters)
4219 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4221 # Registering the new proxy for Pattern
4222 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4224 ## Private class used to bind methods creating algorithms to the class Mesh
4229 self.defaultAlgoType = ""
4230 self.algoTypeToClass = {}
4232 # Stores a python class of algorithm
4233 def add(self, algoClass):
4234 if type( algoClass ).__name__ == 'classobj' and \
4235 hasattr( algoClass, "algoType"):
4236 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4237 if not self.defaultAlgoType and \
4238 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4239 self.defaultAlgoType = algoClass.algoType
4240 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4242 # creates a copy of self and assign mesh to the copy
4243 def copy(self, mesh):
4244 other = algoCreator()
4245 other.defaultAlgoType = self.defaultAlgoType
4246 other.algoTypeToClass = self.algoTypeToClass
4250 # creates an instance of algorithm
4251 def __call__(self,algo="",geom=0,*args):
4252 algoType = self.defaultAlgoType
4253 for arg in args + (algo,geom):
4254 if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ):
4256 if isinstance( arg, str ) and arg:
4258 if not algoType and self.algoTypeToClass:
4259 algoType = self.algoTypeToClass.keys()[0]
4260 if self.algoTypeToClass.has_key( algoType ):
4261 #print "Create algo",algoType
4262 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4263 raise RuntimeError, "No class found for algo type %s" % algoType
4266 # Private class used to substitute and store variable parameters of hypotheses.
4268 class hypMethodWrapper:
4269 def __init__(self, hyp, method):
4271 self.method = method
4272 #print "REBIND:", method.__name__
4275 # call a method of hypothesis with calling SetVarParameter() before
4276 def __call__(self,*args):
4278 return self.method( self.hyp, *args ) # hypothesis method with no args
4280 #print "MethWrapper.__call__",self.method.__name__, args
4282 parsed = ParseParameters(*args) # replace variables with their values
4283 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4284 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4285 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4286 # maybe there is a replaced string arg which is not variable
4287 result = self.method( self.hyp, *args )
4288 except ValueError, detail: # raised by ParseParameters()
4290 result = self.method( self.hyp, *args )
4291 except omniORB.CORBA.BAD_PARAM:
4292 raise ValueError, detail # wrong variable name