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 def Concatenate( self, meshes, uniteIdenticalGroups,
524 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False):
525 if not meshes: return None
526 for i,m in enumerate(meshes):
527 if isinstance(m, Mesh):
528 meshes[i] = m.GetMesh()
529 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
530 meshes[0].SetParameters(Parameters)
532 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
533 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
535 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
536 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
537 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
540 ## Create a mesh by copying a part of another mesh.
541 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
542 # to copy nodes or elements not contained in any mesh object,
543 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
544 # @param meshName a name of the new mesh
545 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
546 # @param toKeepIDs to preserve IDs of the copied elements or not
547 # @return an instance of Mesh class
548 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
549 if (isinstance( meshPart, Mesh )):
550 meshPart = meshPart.GetMesh()
551 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
552 return Mesh(self, self.geompyD, mesh)
554 ## From SMESH_Gen interface
555 # @return the list of integer values
556 # @ingroup l1_auxiliary
557 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
558 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
560 ## From SMESH_Gen interface. Creates a pattern
561 # @return an instance of SMESH_Pattern
563 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
564 # @ingroup l2_modif_patterns
565 def GetPattern(self):
566 return SMESH._objref_SMESH_Gen.GetPattern(self)
568 ## Sets number of segments per diagonal of boundary box of geometry by which
569 # default segment length of appropriate 1D hypotheses is defined.
570 # Default value is 10
571 # @ingroup l1_auxiliary
572 def SetBoundaryBoxSegmentation(self, nbSegments):
573 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
575 # Filtering. Auxiliary functions:
576 # ------------------------------
578 ## Creates an empty criterion
579 # @return SMESH.Filter.Criterion
580 # @ingroup l1_controls
581 def GetEmptyCriterion(self):
582 Type = self.EnumToLong(FT_Undefined)
583 Compare = self.EnumToLong(FT_Undefined)
587 UnaryOp = self.EnumToLong(FT_Undefined)
588 BinaryOp = self.EnumToLong(FT_Undefined)
591 Precision = -1 ##@1e-07
592 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
593 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
595 ## Creates a criterion by the given parameters
596 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
597 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
598 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
599 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
600 # @param Threshold the threshold value (range of ids as string, shape, numeric)
601 # @param UnaryOp FT_LogicalNOT or FT_Undefined
602 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
603 # FT_Undefined (must be for the last criterion of all criteria)
604 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
605 # FT_LyingOnGeom, FT_CoplanarFaces criteria
606 # @return SMESH.Filter.Criterion
608 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
609 # @ingroup l1_controls
610 def GetCriterion(self,elementType,
612 Compare = FT_EqualTo,
614 UnaryOp=FT_Undefined,
615 BinaryOp=FT_Undefined,
617 if not CritType in SMESH.FunctorType._items:
618 raise TypeError, "CritType should be of SMESH.FunctorType"
619 aCriterion = self.GetEmptyCriterion()
620 aCriterion.TypeOfElement = elementType
621 aCriterion.Type = self.EnumToLong(CritType)
622 aCriterion.Tolerance = Tolerance
624 aThreshold = Threshold
626 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
627 aCriterion.Compare = self.EnumToLong(Compare)
628 elif Compare == "=" or Compare == "==":
629 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
631 aCriterion.Compare = self.EnumToLong(FT_LessThan)
633 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
634 elif Compare != FT_Undefined:
635 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
638 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
639 FT_BelongToCylinder, FT_LyingOnGeom]:
640 # Checks that Threshold is GEOM object
641 if isinstance(aThreshold, geompyDC.GEOM._objref_GEOM_Object):
642 aCriterion.ThresholdStr = GetName(aThreshold)
643 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
644 if not aCriterion.ThresholdID:
645 name = aCriterion.ThresholdStr
647 name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
648 aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
649 #raise RuntimeError, "Threshold shape must be published"
651 print "Error: The Threshold should be a shape."
653 if isinstance(UnaryOp,float):
654 aCriterion.Tolerance = UnaryOp
655 UnaryOp = FT_Undefined
657 elif CritType == FT_RangeOfIds:
658 # Checks that Threshold is string
659 if isinstance(aThreshold, str):
660 aCriterion.ThresholdStr = aThreshold
662 print "Error: The Threshold should be a string."
664 elif CritType == FT_CoplanarFaces:
665 # Checks the Threshold
666 if isinstance(aThreshold, int):
667 aCriterion.ThresholdID = str(aThreshold)
668 elif isinstance(aThreshold, str):
671 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
672 aCriterion.ThresholdID = aThreshold
675 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
676 elif CritType == FT_ElemGeomType:
677 # Checks the Threshold
679 aCriterion.Threshold = self.EnumToLong(aThreshold)
680 assert( aThreshold in SMESH.GeometryType._items )
682 if isinstance(aThreshold, int):
683 aCriterion.Threshold = aThreshold
685 print "Error: The Threshold should be an integer or SMESH.GeometryType."
689 elif CritType == FT_GroupColor:
690 # Checks the Threshold
692 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
694 print "Error: The threshold value should be of SALOMEDS.Color type"
697 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
698 FT_LinearOrQuadratic, FT_BadOrientedVolume,
699 FT_BareBorderFace, FT_BareBorderVolume,
700 FT_OverConstrainedFace, FT_OverConstrainedVolume,
701 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
702 # At this point the Threshold is unnecessary
703 if aThreshold == FT_LogicalNOT:
704 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
705 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
706 aCriterion.BinaryOp = aThreshold
710 aThreshold = float(aThreshold)
711 aCriterion.Threshold = aThreshold
713 print "Error: The Threshold should be a number."
716 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
717 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
719 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
720 aCriterion.BinaryOp = self.EnumToLong(Threshold)
722 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
723 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
725 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
726 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
730 ## Creates a filter with the given parameters
731 # @param elementType the type of elements in the group
732 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
733 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
734 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
735 # @param UnaryOp FT_LogicalNOT or FT_Undefined
736 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
737 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
738 # @return SMESH_Filter
740 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
741 # @ingroup l1_controls
742 def GetFilter(self,elementType,
743 CritType=FT_Undefined,
746 UnaryOp=FT_Undefined,
748 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
749 aFilterMgr = self.CreateFilterManager()
750 aFilter = aFilterMgr.CreateFilter()
752 aCriteria.append(aCriterion)
753 aFilter.SetCriteria(aCriteria)
754 aFilterMgr.UnRegister()
757 ## Creates a filter from criteria
758 # @param criteria a list of criteria
759 # @return SMESH_Filter
761 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
762 # @ingroup l1_controls
763 def GetFilterFromCriteria(self,criteria):
764 aFilterMgr = self.CreateFilterManager()
765 aFilter = aFilterMgr.CreateFilter()
766 aFilter.SetCriteria(criteria)
767 aFilterMgr.UnRegister()
770 ## Creates a numerical functor by its type
771 # @param theCriterion FT_...; functor type
772 # @return SMESH_NumericalFunctor
773 # @ingroup l1_controls
774 def GetFunctor(self,theCriterion):
775 if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
777 aFilterMgr = self.CreateFilterManager()
779 if theCriterion == FT_AspectRatio:
780 functor = aFilterMgr.CreateAspectRatio()
781 elif theCriterion == FT_AspectRatio3D:
782 functor = aFilterMgr.CreateAspectRatio3D()
783 elif theCriterion == FT_Warping:
784 functor = aFilterMgr.CreateWarping()
785 elif theCriterion == FT_MinimumAngle:
786 functor = aFilterMgr.CreateMinimumAngle()
787 elif theCriterion == FT_Taper:
788 functor = aFilterMgr.CreateTaper()
789 elif theCriterion == FT_Skew:
790 functor = aFilterMgr.CreateSkew()
791 elif theCriterion == FT_Area:
792 functor = aFilterMgr.CreateArea()
793 elif theCriterion == FT_Volume3D:
794 functor = aFilterMgr.CreateVolume3D()
795 elif theCriterion == FT_MaxElementLength2D:
796 functor = aFilterMgr.CreateMaxElementLength2D()
797 elif theCriterion == FT_MaxElementLength3D:
798 functor = aFilterMgr.CreateMaxElementLength3D()
799 elif theCriterion == FT_MultiConnection:
800 functor = aFilterMgr.CreateMultiConnection()
801 elif theCriterion == FT_MultiConnection2D:
802 functor = aFilterMgr.CreateMultiConnection2D()
803 elif theCriterion == FT_Length:
804 functor = aFilterMgr.CreateLength()
805 elif theCriterion == FT_Length2D:
806 functor = aFilterMgr.CreateLength2D()
808 print "Error: given parameter is not numerical functor type."
809 aFilterMgr.UnRegister()
812 ## Creates hypothesis
813 # @param theHType mesh hypothesis type (string)
814 # @param theLibName mesh plug-in library name
815 # @return created hypothesis instance
816 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
817 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
819 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
822 # wrap hypothesis methods
823 #print "HYPOTHESIS", theHType
824 for meth_name in dir( hyp.__class__ ):
825 if not meth_name.startswith("Get") and \
826 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
827 method = getattr ( hyp.__class__, meth_name )
829 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
833 ## Gets the mesh statistic
834 # @return dictionary "element type" - "count of elements"
835 # @ingroup l1_meshinfo
836 def GetMeshInfo(self, obj):
837 if isinstance( obj, Mesh ):
840 if hasattr(obj, "GetMeshInfo"):
841 values = obj.GetMeshInfo()
842 for i in range(SMESH.Entity_Last._v):
843 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
847 ## Get minimum distance between two objects
849 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
850 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
852 # @param src1 first source object
853 # @param src2 second source object
854 # @param id1 node/element id from the first source
855 # @param id2 node/element id from the second (or first) source
856 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
857 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
858 # @return minimum distance value
859 # @sa GetMinDistance()
860 # @ingroup l1_measurements
861 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
862 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
866 result = result.value
869 ## Get measure structure specifying minimum distance data between two objects
871 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
872 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
874 # @param src1 first source object
875 # @param src2 second source object
876 # @param id1 node/element id from the first source
877 # @param id2 node/element id from the second (or first) source
878 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
879 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
880 # @return Measure structure or None if input data is invalid
882 # @ingroup l1_measurements
883 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
884 if isinstance(src1, Mesh): src1 = src1.mesh
885 if isinstance(src2, Mesh): src2 = src2.mesh
886 if src2 is None and id2 != 0: src2 = src1
887 if not hasattr(src1, "_narrow"): return None
888 src1 = src1._narrow(SMESH.SMESH_IDSource)
889 if not src1: return None
892 e = m.GetMeshEditor()
894 src1 = e.MakeIDSource([id1], SMESH.FACE)
896 src1 = e.MakeIDSource([id1], SMESH.NODE)
898 if hasattr(src2, "_narrow"):
899 src2 = src2._narrow(SMESH.SMESH_IDSource)
900 if src2 and id2 != 0:
902 e = m.GetMeshEditor()
904 src2 = e.MakeIDSource([id2], SMESH.FACE)
906 src2 = e.MakeIDSource([id2], SMESH.NODE)
909 aMeasurements = self.CreateMeasurements()
910 result = aMeasurements.MinDistance(src1, src2)
911 aMeasurements.UnRegister()
914 ## Get bounding box of the specified object(s)
915 # @param objects single source object or list of source objects
916 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
917 # @sa GetBoundingBox()
918 # @ingroup l1_measurements
919 def BoundingBox(self, objects):
920 result = self.GetBoundingBox(objects)
924 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
927 ## Get measure structure specifying bounding box data of the specified object(s)
928 # @param objects single source object or list of source objects
929 # @return Measure structure
931 # @ingroup l1_measurements
932 def GetBoundingBox(self, objects):
933 if isinstance(objects, tuple):
934 objects = list(objects)
935 if not isinstance(objects, list):
939 if isinstance(o, Mesh):
940 srclist.append(o.mesh)
941 elif hasattr(o, "_narrow"):
942 src = o._narrow(SMESH.SMESH_IDSource)
943 if src: srclist.append(src)
946 aMeasurements = self.CreateMeasurements()
947 result = aMeasurements.BoundingBox(srclist)
948 aMeasurements.UnRegister()
952 #Registering the new proxy for SMESH_Gen
953 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
959 ## This class allows defining and managing a mesh.
960 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
961 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
962 # new nodes and elements and by changing the existing entities), to get information
963 # about a mesh and to export a mesh into different formats.
972 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
973 # sets the GUI name of this mesh to \a name.
974 # @param smeshpyD an instance of smeshDC class
975 # @param geompyD an instance of geompyDC class
976 # @param obj Shape to be meshed or SMESH_Mesh object
977 # @param name Study name of the mesh
978 # @ingroup l2_construct
979 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
980 self.smeshpyD=smeshpyD
986 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
988 # publish geom of mesh (issue 0021122)
989 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
991 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
992 if studyID != geompyD.myStudyId:
993 geompyD.init_geom( smeshpyD.GetCurrentStudy())
998 geo_name = "%s_%s_for_meshing"%(self.geom.GetShapeType(), id(self.geom)%100)
999 geompyD.addToStudy( self.geom, geo_name )
1000 self.mesh = self.smeshpyD.CreateMesh(self.geom)
1002 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1005 self.mesh = self.smeshpyD.CreateEmptyMesh()
1007 self.smeshpyD.SetName(self.mesh, name)
1008 elif obj != 0 and objHasName:
1009 self.smeshpyD.SetName(self.mesh, GetName(obj))
1012 self.geom = self.mesh.GetShapeToMesh()
1014 self.editor = self.mesh.GetMeshEditor()
1015 self.functors = [None] * SMESH.FT_Undefined._v
1017 # set self to algoCreator's
1018 for attrName in dir(self):
1019 attr = getattr( self, attrName )
1020 if isinstance( attr, algoCreator ):
1021 setattr( self, attrName, attr.copy( self ))
1023 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1024 # @param theMesh a SMESH_Mesh object
1025 # @ingroup l2_construct
1026 def SetMesh(self, theMesh):
1027 if self.mesh: self.mesh.UnRegister()
1030 self.mesh.Register()
1031 self.geom = self.mesh.GetShapeToMesh()
1033 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1034 # @return a SMESH_Mesh object
1035 # @ingroup l2_construct
1039 ## Gets the name of the mesh
1040 # @return the name of the mesh as a string
1041 # @ingroup l2_construct
1043 name = GetName(self.GetMesh())
1046 ## Sets a name to the mesh
1047 # @param name a new name of the mesh
1048 # @ingroup l2_construct
1049 def SetName(self, name):
1050 self.smeshpyD.SetName(self.GetMesh(), name)
1052 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1053 # The subMesh object gives access to the IDs of nodes and elements.
1054 # @param geom a geometrical object (shape)
1055 # @param name a name for the submesh
1056 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1057 # @ingroup l2_submeshes
1058 def GetSubMesh(self, geom, name):
1059 AssureGeomPublished( self, geom, name )
1060 submesh = self.mesh.GetSubMesh( geom, name )
1063 ## Returns the shape associated to the mesh
1064 # @return a GEOM_Object
1065 # @ingroup l2_construct
1069 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1070 # @param geom the shape to be meshed (GEOM_Object)
1071 # @ingroup l2_construct
1072 def SetShape(self, geom):
1073 self.mesh = self.smeshpyD.CreateMesh(geom)
1075 ## Loads mesh from the study after opening the study
1079 ## Returns true if the hypotheses are defined well
1080 # @param theSubObject a sub-shape of a mesh shape
1081 # @return True or False
1082 # @ingroup l2_construct
1083 def IsReadyToCompute(self, theSubObject):
1084 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1086 ## Returns errors of hypotheses definition.
1087 # The list of errors is empty if everything is OK.
1088 # @param theSubObject a sub-shape of a mesh shape
1089 # @return a list of errors
1090 # @ingroup l2_construct
1091 def GetAlgoState(self, theSubObject):
1092 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1094 ## Returns a geometrical object on which the given element was built.
1095 # The returned geometrical object, if not nil, is either found in the
1096 # study or published by this method with the given name
1097 # @param theElementID the id of the mesh element
1098 # @param theGeomName the user-defined name of the geometrical object
1099 # @return GEOM::GEOM_Object instance
1100 # @ingroup l2_construct
1101 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1102 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1104 ## Returns the mesh dimension depending on the dimension of the underlying shape
1105 # @return mesh dimension as an integer value [0,3]
1106 # @ingroup l1_auxiliary
1107 def MeshDimension(self):
1108 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1109 if len( shells ) > 0 :
1111 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1113 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1119 ## Evaluates size of prospective mesh on a shape
1120 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1121 # To know predicted number of e.g. edges, inquire it this way
1122 # Evaluate()[ EnumToLong( Entity_Edge )]
1123 def Evaluate(self, geom=0):
1124 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1126 geom = self.mesh.GetShapeToMesh()
1129 return self.smeshpyD.Evaluate(self.mesh, geom)
1132 ## Computes the mesh and returns the status of the computation
1133 # @param geom geomtrical shape on which mesh data should be computed
1134 # @param discardModifs if True and the mesh has been edited since
1135 # a last total re-compute and that may prevent successful partial re-compute,
1136 # then the mesh is cleaned before Compute()
1137 # @return True or False
1138 # @ingroup l2_construct
1139 def Compute(self, geom=0, discardModifs=False):
1140 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1142 geom = self.mesh.GetShapeToMesh()
1147 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1149 ok = self.smeshpyD.Compute(self.mesh, geom)
1150 except SALOME.SALOME_Exception, ex:
1151 print "Mesh computation failed, exception caught:"
1152 print " ", ex.details.text
1155 print "Mesh computation failed, exception caught:"
1156 traceback.print_exc()
1160 # Treat compute errors
1161 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1162 for err in computeErrors:
1164 if self.mesh.HasShapeToMesh():
1166 mainIOR = salome.orb.object_to_string(geom)
1167 for sname in salome.myStudyManager.GetOpenStudies():
1168 s = salome.myStudyManager.GetStudyByName(sname)
1170 mainSO = s.FindObjectIOR(mainIOR)
1171 if not mainSO: continue
1172 if err.subShapeID == 1:
1173 shapeText = ' on "%s"' % mainSO.GetName()
1174 subIt = s.NewChildIterator(mainSO)
1176 subSO = subIt.Value()
1178 obj = subSO.GetObject()
1179 if not obj: continue
1180 go = obj._narrow( geompyDC.GEOM._objref_GEOM_Object )
1182 ids = go.GetSubShapeIndices()
1183 if len(ids) == 1 and ids[0] == err.subShapeID:
1184 shapeText = ' on "%s"' % subSO.GetName()
1187 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1189 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1191 shapeText = " on subshape #%s" % (err.subShapeID)
1193 shapeText = " on subshape #%s" % (err.subShapeID)
1195 stdErrors = ["OK", #COMPERR_OK
1196 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1197 "std::exception", #COMPERR_STD_EXCEPTION
1198 "OCC exception", #COMPERR_OCC_EXCEPTION
1199 "SALOME exception", #COMPERR_SLM_EXCEPTION
1200 "Unknown exception", #COMPERR_EXCEPTION
1201 "Memory allocation problem", #COMPERR_MEMORY_PB
1202 "Algorithm failed", #COMPERR_ALGO_FAILED
1203 "Unexpected geometry", #COMPERR_BAD_SHAPE
1204 "Warning", #COMPERR_WARNING
1205 "Computation cancelled",#COMPERR_CANCELED
1206 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1208 if err.code < len(stdErrors): errText = stdErrors[err.code]
1210 errText = "code %s" % -err.code
1211 if errText: errText += ". "
1212 errText += err.comment
1213 if allReasons != "":allReasons += "\n"
1214 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1218 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1220 if err.isGlobalAlgo:
1228 reason = '%s %sD algorithm is missing' % (glob, dim)
1229 elif err.state == HYP_MISSING:
1230 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1231 % (glob, dim, name, dim))
1232 elif err.state == HYP_NOTCONFORM:
1233 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1234 elif err.state == HYP_BAD_PARAMETER:
1235 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1236 % ( glob, dim, name ))
1237 elif err.state == HYP_BAD_GEOMETRY:
1238 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1239 'geometry' % ( glob, dim, name ))
1240 elif err.state == HYP_HIDDEN_ALGO:
1241 reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1242 'algorithm of upper dimension generating %sD mesh'
1243 % ( glob, dim, name, glob, dim ))
1245 reason = ("For unknown reason. "
1246 "Developer, revise Mesh.Compute() implementation in smeshDC.py!")
1248 if allReasons != "":allReasons += "\n"
1249 allReasons += "- " + reason
1251 if not ok or allReasons != "":
1252 msg = '"' + GetName(self.mesh) + '"'
1253 if ok: msg += " has been computed with warnings"
1254 else: msg += " has not been computed"
1255 if allReasons != "": msg += ":"
1260 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1261 smeshgui = salome.ImportComponentGUI("SMESH")
1262 smeshgui.Init(self.mesh.GetStudyId())
1263 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1264 salome.sg.updateObjBrowser(1)
1268 ## Return submesh objects list in meshing order
1269 # @return list of list of submesh objects
1270 # @ingroup l2_construct
1271 def GetMeshOrder(self):
1272 return self.mesh.GetMeshOrder()
1274 ## Return submesh objects list in meshing order
1275 # @return list of list of submesh objects
1276 # @ingroup l2_construct
1277 def SetMeshOrder(self, submeshes):
1278 return self.mesh.SetMeshOrder(submeshes)
1280 ## Removes all nodes and elements
1281 # @ingroup l2_construct
1284 if ( salome.sg.hasDesktop() and
1285 salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() )):
1286 smeshgui = salome.ImportComponentGUI("SMESH")
1287 smeshgui.Init(self.mesh.GetStudyId())
1288 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1289 salome.sg.updateObjBrowser(1)
1291 ## Removes all nodes and elements of indicated shape
1292 # @ingroup l2_construct
1293 def ClearSubMesh(self, geomId):
1294 self.mesh.ClearSubMesh(geomId)
1295 if salome.sg.hasDesktop():
1296 smeshgui = salome.ImportComponentGUI("SMESH")
1297 smeshgui.Init(self.mesh.GetStudyId())
1298 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1299 salome.sg.updateObjBrowser(1)
1301 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1302 # @param fineness [0.0,1.0] defines mesh fineness
1303 # @return True or False
1304 # @ingroup l3_algos_basic
1305 def AutomaticTetrahedralization(self, fineness=0):
1306 dim = self.MeshDimension()
1308 self.RemoveGlobalHypotheses()
1309 self.Segment().AutomaticLength(fineness)
1311 self.Triangle().LengthFromEdges()
1314 from NETGENPluginDC import NETGEN
1315 self.Tetrahedron(NETGEN)
1317 return self.Compute()
1319 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1320 # @param fineness [0.0, 1.0] defines mesh fineness
1321 # @return True or False
1322 # @ingroup l3_algos_basic
1323 def AutomaticHexahedralization(self, fineness=0):
1324 dim = self.MeshDimension()
1325 # assign the hypotheses
1326 self.RemoveGlobalHypotheses()
1327 self.Segment().AutomaticLength(fineness)
1334 return self.Compute()
1336 ## Assigns a hypothesis
1337 # @param hyp a hypothesis to assign
1338 # @param geom a subhape of mesh geometry
1339 # @return SMESH.Hypothesis_Status
1340 # @ingroup l2_hypotheses
1341 def AddHypothesis(self, hyp, geom=0):
1342 if isinstance( hyp, Mesh_Algorithm ):
1343 hyp = hyp.GetAlgorithm()
1348 geom = self.mesh.GetShapeToMesh()
1350 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1351 status = self.mesh.AddHypothesis(geom, hyp)
1352 isAlgo = hyp._narrow( SMESH_Algo )
1353 hyp_name = GetName( hyp )
1356 geom_name = GetName( geom )
1357 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1360 ## Return True if an algorithm of hypothesis is assigned to a given shape
1361 # @param hyp a hypothesis to check
1362 # @param geom a subhape of mesh geometry
1363 # @return True of False
1364 # @ingroup l2_hypotheses
1365 def IsUsedHypothesis(self, hyp, geom):
1366 if not hyp or not geom:
1368 if isinstance( hyp, Mesh_Algorithm ):
1369 hyp = hyp.GetAlgorithm()
1371 hyps = self.GetHypothesisList(geom)
1373 if h.GetId() == hyp.GetId():
1377 ## Unassigns a hypothesis
1378 # @param hyp a hypothesis to unassign
1379 # @param geom a sub-shape of mesh geometry
1380 # @return SMESH.Hypothesis_Status
1381 # @ingroup l2_hypotheses
1382 def RemoveHypothesis(self, hyp, geom=0):
1383 if isinstance( hyp, Mesh_Algorithm ):
1384 hyp = hyp.GetAlgorithm()
1389 status = self.mesh.RemoveHypothesis(geom, hyp)
1392 ## Gets the list of hypotheses added on a geometry
1393 # @param geom a sub-shape of mesh geometry
1394 # @return the sequence of SMESH_Hypothesis
1395 # @ingroup l2_hypotheses
1396 def GetHypothesisList(self, geom):
1397 return self.mesh.GetHypothesisList( geom )
1399 ## Removes all global hypotheses
1400 # @ingroup l2_hypotheses
1401 def RemoveGlobalHypotheses(self):
1402 current_hyps = self.mesh.GetHypothesisList( self.geom )
1403 for hyp in current_hyps:
1404 self.mesh.RemoveHypothesis( self.geom, hyp )
1408 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1409 ## allowing to overwrite the file if it exists or add the exported data to its contents
1410 # @param f is the file name
1411 # @param auto_groups boolean parameter for creating/not creating
1412 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1413 # the typical use is auto_groups=false.
1414 # @param version MED format version(MED_V2_1 or MED_V2_2)
1415 # @param overwrite boolean parameter for overwriting/not overwriting the file
1416 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1417 # @ingroup l2_impexp
1418 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1420 if isinstance( meshPart, list ):
1421 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1422 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1424 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1426 ## Exports the mesh in a file in SAUV format
1427 # @param f is the file name
1428 # @param auto_groups boolean parameter for creating/not creating
1429 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1430 # the typical use is auto_groups=false.
1431 # @ingroup l2_impexp
1432 def ExportSAUV(self, f, auto_groups=0):
1433 self.mesh.ExportSAUV(f, auto_groups)
1435 ## Exports the mesh in a file in DAT format
1436 # @param f the file name
1437 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1438 # @ingroup l2_impexp
1439 def ExportDAT(self, f, meshPart=None):
1441 if isinstance( meshPart, list ):
1442 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1443 self.mesh.ExportPartToDAT( meshPart, f )
1445 self.mesh.ExportDAT(f)
1447 ## Exports the mesh in a file in UNV format
1448 # @param f the file name
1449 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1450 # @ingroup l2_impexp
1451 def ExportUNV(self, f, meshPart=None):
1453 if isinstance( meshPart, list ):
1454 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1455 self.mesh.ExportPartToUNV( meshPart, f )
1457 self.mesh.ExportUNV(f)
1459 ## Export the mesh in a file in STL format
1460 # @param f the file name
1461 # @param ascii defines the file encoding
1462 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1463 # @ingroup l2_impexp
1464 def ExportSTL(self, f, ascii=1, meshPart=None):
1466 if isinstance( meshPart, list ):
1467 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1468 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1470 self.mesh.ExportSTL(f, ascii)
1472 ## Exports the mesh in a file in CGNS format
1473 # @param f is the file name
1474 # @param overwrite boolean parameter for overwriting/not overwriting the file
1475 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1476 # @ingroup l2_impexp
1477 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1478 if isinstance( meshPart, list ):
1479 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1480 if isinstance( meshPart, Mesh ):
1481 meshPart = meshPart.mesh
1483 meshPart = self.mesh
1484 self.mesh.ExportCGNS(meshPart, f, overwrite)
1486 ## Exports the mesh in a file in GMF format
1487 # @param f is the file name
1488 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1489 # @ingroup l2_impexp
1490 def ExportGMF(self, f, meshPart=None):
1491 if isinstance( meshPart, list ):
1492 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1493 if isinstance( meshPart, Mesh ):
1494 meshPart = meshPart.mesh
1496 meshPart = self.mesh
1497 self.mesh.ExportGMF(meshPart, f, True)
1499 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1500 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1501 ## allowing to overwrite the file if it exists or add the exported data to its contents
1502 # @param f the file name
1503 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1504 # @param opt boolean parameter for creating/not creating
1505 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1506 # @param overwrite boolean parameter for overwriting/not overwriting the file
1507 # @ingroup l2_impexp
1508 def ExportToMED(self, f, version, opt=0, overwrite=1):
1509 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1511 # Operations with groups:
1512 # ----------------------
1514 ## Creates an empty mesh group
1515 # @param elementType the type of elements in the group
1516 # @param name the name of the mesh group
1517 # @return SMESH_Group
1518 # @ingroup l2_grps_create
1519 def CreateEmptyGroup(self, elementType, name):
1520 return self.mesh.CreateGroup(elementType, name)
1522 ## Creates a mesh group based on the geometric object \a grp
1523 # and gives a \a name, \n if this parameter is not defined
1524 # the name is the same as the geometric group name \n
1525 # Note: Works like GroupOnGeom().
1526 # @param grp a geometric group, a vertex, an edge, a face or a solid
1527 # @param name the name of the mesh group
1528 # @return SMESH_GroupOnGeom
1529 # @ingroup l2_grps_create
1530 def Group(self, grp, name=""):
1531 return self.GroupOnGeom(grp, name)
1533 ## Creates a mesh group based on the geometrical object \a grp
1534 # and gives a \a name, \n if this parameter is not defined
1535 # the name is the same as the geometrical group name
1536 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1537 # @param name the name of the mesh group
1538 # @param typ the type of elements in the group. If not set, it is
1539 # automatically detected by the type of the geometry
1540 # @return SMESH_GroupOnGeom
1541 # @ingroup l2_grps_create
1542 def GroupOnGeom(self, grp, name="", typ=None):
1543 AssureGeomPublished( self, grp, name )
1545 name = grp.GetName()
1547 typ = self._groupTypeFromShape( grp )
1548 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1550 ## Pivate method to get a type of group on geometry
1551 def _groupTypeFromShape( self, shape ):
1552 tgeo = str(shape.GetShapeType())
1553 if tgeo == "VERTEX":
1555 elif tgeo == "EDGE":
1557 elif tgeo == "FACE" or tgeo == "SHELL":
1559 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1561 elif tgeo == "COMPOUND":
1562 sub = self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHAPE"])
1564 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1565 return self._groupTypeFromShape( sub[0] )
1568 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1571 ## Creates a mesh group with given \a name based on the \a filter which
1572 ## is a special type of group dynamically updating it's contents during
1573 ## mesh modification
1574 # @param typ the type of elements in the group
1575 # @param name the name of the mesh group
1576 # @param filter the filter defining group contents
1577 # @return SMESH_GroupOnFilter
1578 # @ingroup l2_grps_create
1579 def GroupOnFilter(self, typ, name, filter):
1580 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1582 ## Creates a mesh group by the given ids of elements
1583 # @param groupName the name of the mesh group
1584 # @param elementType the type of elements in the group
1585 # @param elemIDs the list of ids
1586 # @return SMESH_Group
1587 # @ingroup l2_grps_create
1588 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1589 group = self.mesh.CreateGroup(elementType, groupName)
1593 ## Creates a mesh group by the given conditions
1594 # @param groupName the name of the mesh group
1595 # @param elementType the type of elements in the group
1596 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1597 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1598 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1599 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1600 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1601 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1602 # @return SMESH_Group
1603 # @ingroup l2_grps_create
1607 CritType=FT_Undefined,
1610 UnaryOp=FT_Undefined,
1612 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1613 group = self.MakeGroupByCriterion(groupName, aCriterion)
1616 ## Creates a mesh group by the given criterion
1617 # @param groupName the name of the mesh group
1618 # @param Criterion the instance of Criterion class
1619 # @return SMESH_Group
1620 # @ingroup l2_grps_create
1621 def MakeGroupByCriterion(self, groupName, Criterion):
1622 aFilterMgr = self.smeshpyD.CreateFilterManager()
1623 aFilter = aFilterMgr.CreateFilter()
1625 aCriteria.append(Criterion)
1626 aFilter.SetCriteria(aCriteria)
1627 group = self.MakeGroupByFilter(groupName, aFilter)
1628 aFilterMgr.UnRegister()
1631 ## Creates a mesh group by the given criteria (list of criteria)
1632 # @param groupName the name of the mesh group
1633 # @param theCriteria the list of criteria
1634 # @return SMESH_Group
1635 # @ingroup l2_grps_create
1636 def MakeGroupByCriteria(self, groupName, theCriteria):
1637 aFilterMgr = self.smeshpyD.CreateFilterManager()
1638 aFilter = aFilterMgr.CreateFilter()
1639 aFilter.SetCriteria(theCriteria)
1640 group = self.MakeGroupByFilter(groupName, aFilter)
1641 aFilterMgr.UnRegister()
1644 ## Creates a mesh group by the given filter
1645 # @param groupName the name of the mesh group
1646 # @param theFilter the instance of Filter class
1647 # @return SMESH_Group
1648 # @ingroup l2_grps_create
1649 def MakeGroupByFilter(self, groupName, theFilter):
1650 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1651 theFilter.SetMesh( self.mesh )
1652 group.AddFrom( theFilter )
1656 # @ingroup l2_grps_delete
1657 def RemoveGroup(self, group):
1658 self.mesh.RemoveGroup(group)
1660 ## Removes a group with its contents
1661 # @ingroup l2_grps_delete
1662 def RemoveGroupWithContents(self, group):
1663 self.mesh.RemoveGroupWithContents(group)
1665 ## Gets the list of groups existing in the mesh
1666 # @return a sequence of SMESH_GroupBase
1667 # @ingroup l2_grps_create
1668 def GetGroups(self):
1669 return self.mesh.GetGroups()
1671 ## Gets the number of groups existing in the mesh
1672 # @return the quantity of groups as an integer value
1673 # @ingroup l2_grps_create
1675 return self.mesh.NbGroups()
1677 ## Gets the list of names of groups existing in the mesh
1678 # @return list of strings
1679 # @ingroup l2_grps_create
1680 def GetGroupNames(self):
1681 groups = self.GetGroups()
1683 for group in groups:
1684 names.append(group.GetName())
1687 ## Produces a union of two groups
1688 # A new group is created. All mesh elements that are
1689 # present in the initial groups are added to the new one
1690 # @return an instance of SMESH_Group
1691 # @ingroup l2_grps_operon
1692 def UnionGroups(self, group1, group2, name):
1693 return self.mesh.UnionGroups(group1, group2, name)
1695 ## Produces a union list of groups
1696 # New group is created. All mesh elements that are present in
1697 # initial groups are added to the new one
1698 # @return an instance of SMESH_Group
1699 # @ingroup l2_grps_operon
1700 def UnionListOfGroups(self, groups, name):
1701 return self.mesh.UnionListOfGroups(groups, name)
1703 ## Prodices an intersection of two groups
1704 # A new group is created. All mesh elements that are common
1705 # for the two initial groups are added to the new one.
1706 # @return an instance of SMESH_Group
1707 # @ingroup l2_grps_operon
1708 def IntersectGroups(self, group1, group2, name):
1709 return self.mesh.IntersectGroups(group1, group2, name)
1711 ## Produces an intersection of groups
1712 # New group is created. All mesh elements that are present in all
1713 # initial groups simultaneously are added to the new one
1714 # @return an instance of SMESH_Group
1715 # @ingroup l2_grps_operon
1716 def IntersectListOfGroups(self, groups, name):
1717 return self.mesh.IntersectListOfGroups(groups, name)
1719 ## Produces a cut of two groups
1720 # A new group is created. All mesh elements that are present in
1721 # the main group but are not present in the tool group are added to the new one
1722 # @return an instance of SMESH_Group
1723 # @ingroup l2_grps_operon
1724 def CutGroups(self, main_group, tool_group, name):
1725 return self.mesh.CutGroups(main_group, tool_group, name)
1727 ## Produces a cut of groups
1728 # A new group is created. All mesh elements that are present in main groups
1729 # but do not present in tool groups are added to the new one
1730 # @return an instance of SMESH_Group
1731 # @ingroup l2_grps_operon
1732 def CutListOfGroups(self, main_groups, tool_groups, name):
1733 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1735 ## Produces a group of elements of specified type using list of existing groups
1736 # A new group is created. System
1737 # 1) extracts all nodes on which groups elements are built
1738 # 2) combines all elements of specified dimension laying on these nodes
1739 # @return an instance of SMESH_Group
1740 # @ingroup l2_grps_operon
1741 def CreateDimGroup(self, groups, elem_type, name):
1742 return self.mesh.CreateDimGroup(groups, elem_type, name)
1745 ## Convert group on geom into standalone group
1746 # @ingroup l2_grps_delete
1747 def ConvertToStandalone(self, group):
1748 return self.mesh.ConvertToStandalone(group)
1750 # Get some info about mesh:
1751 # ------------------------
1753 ## Returns the log of nodes and elements added or removed
1754 # since the previous clear of the log.
1755 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1756 # @return list of log_block structures:
1761 # @ingroup l1_auxiliary
1762 def GetLog(self, clearAfterGet):
1763 return self.mesh.GetLog(clearAfterGet)
1765 ## Clears the log of nodes and elements added or removed since the previous
1766 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1767 # @ingroup l1_auxiliary
1769 self.mesh.ClearLog()
1771 ## Toggles auto color mode on the object.
1772 # @param theAutoColor the flag which toggles auto color mode.
1773 # @ingroup l1_auxiliary
1774 def SetAutoColor(self, theAutoColor):
1775 self.mesh.SetAutoColor(theAutoColor)
1777 ## Gets flag of object auto color mode.
1778 # @return True or False
1779 # @ingroup l1_auxiliary
1780 def GetAutoColor(self):
1781 return self.mesh.GetAutoColor()
1783 ## Gets the internal ID
1784 # @return integer value, which is the internal Id of the mesh
1785 # @ingroup l1_auxiliary
1787 return self.mesh.GetId()
1790 # @return integer value, which is the study Id of the mesh
1791 # @ingroup l1_auxiliary
1792 def GetStudyId(self):
1793 return self.mesh.GetStudyId()
1795 ## Checks the group names for duplications.
1796 # Consider the maximum group name length stored in MED file.
1797 # @return True or False
1798 # @ingroup l1_auxiliary
1799 def HasDuplicatedGroupNamesMED(self):
1800 return self.mesh.HasDuplicatedGroupNamesMED()
1802 ## Obtains the mesh editor tool
1803 # @return an instance of SMESH_MeshEditor
1804 # @ingroup l1_modifying
1805 def GetMeshEditor(self):
1808 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1809 # can be passed as argument to a method accepting mesh, group or sub-mesh
1810 # @return an instance of SMESH_IDSource
1811 # @ingroup l1_auxiliary
1812 def GetIDSource(self, ids, elemType):
1813 return self.editor.MakeIDSource(ids, elemType)
1816 # @return an instance of SALOME_MED::MESH
1817 # @ingroup l1_auxiliary
1818 def GetMEDMesh(self):
1819 return self.mesh.GetMEDMesh()
1822 # Get informations about mesh contents:
1823 # ------------------------------------
1825 ## Gets the mesh stattistic
1826 # @return dictionary type element - count of elements
1827 # @ingroup l1_meshinfo
1828 def GetMeshInfo(self, obj = None):
1829 if not obj: obj = self.mesh
1830 return self.smeshpyD.GetMeshInfo(obj)
1832 ## Returns the number of nodes in the mesh
1833 # @return an integer value
1834 # @ingroup l1_meshinfo
1836 return self.mesh.NbNodes()
1838 ## Returns the number of elements in the mesh
1839 # @return an integer value
1840 # @ingroup l1_meshinfo
1841 def NbElements(self):
1842 return self.mesh.NbElements()
1844 ## Returns the number of 0d elements in the mesh
1845 # @return an integer value
1846 # @ingroup l1_meshinfo
1847 def Nb0DElements(self):
1848 return self.mesh.Nb0DElements()
1850 ## Returns the number of ball discrete elements in the mesh
1851 # @return an integer value
1852 # @ingroup l1_meshinfo
1854 return self.mesh.NbBalls()
1856 ## Returns the number of edges in the mesh
1857 # @return an integer value
1858 # @ingroup l1_meshinfo
1860 return self.mesh.NbEdges()
1862 ## Returns the number of edges with the given order in the mesh
1863 # @param elementOrder the order of elements:
1864 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1865 # @return an integer value
1866 # @ingroup l1_meshinfo
1867 def NbEdgesOfOrder(self, elementOrder):
1868 return self.mesh.NbEdgesOfOrder(elementOrder)
1870 ## Returns the number of faces in the mesh
1871 # @return an integer value
1872 # @ingroup l1_meshinfo
1874 return self.mesh.NbFaces()
1876 ## Returns the number of faces with the given order in the mesh
1877 # @param elementOrder the order of elements:
1878 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1879 # @return an integer value
1880 # @ingroup l1_meshinfo
1881 def NbFacesOfOrder(self, elementOrder):
1882 return self.mesh.NbFacesOfOrder(elementOrder)
1884 ## Returns the number of triangles in the mesh
1885 # @return an integer value
1886 # @ingroup l1_meshinfo
1887 def NbTriangles(self):
1888 return self.mesh.NbTriangles()
1890 ## Returns the number of triangles with the given order in the mesh
1891 # @param elementOrder is the order of elements:
1892 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1893 # @return an integer value
1894 # @ingroup l1_meshinfo
1895 def NbTrianglesOfOrder(self, elementOrder):
1896 return self.mesh.NbTrianglesOfOrder(elementOrder)
1898 ## Returns the number of quadrangles in the mesh
1899 # @return an integer value
1900 # @ingroup l1_meshinfo
1901 def NbQuadrangles(self):
1902 return self.mesh.NbQuadrangles()
1904 ## Returns the number of quadrangles with the given order in the mesh
1905 # @param elementOrder the order of elements:
1906 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1907 # @return an integer value
1908 # @ingroup l1_meshinfo
1909 def NbQuadranglesOfOrder(self, elementOrder):
1910 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1912 ## Returns the number of biquadratic quadrangles in the mesh
1913 # @return an integer value
1914 # @ingroup l1_meshinfo
1915 def NbBiQuadQuadrangles(self):
1916 return self.mesh.NbBiQuadQuadrangles()
1918 ## Returns the number of polygons in the mesh
1919 # @return an integer value
1920 # @ingroup l1_meshinfo
1921 def NbPolygons(self):
1922 return self.mesh.NbPolygons()
1924 ## Returns the number of volumes in the mesh
1925 # @return an integer value
1926 # @ingroup l1_meshinfo
1927 def NbVolumes(self):
1928 return self.mesh.NbVolumes()
1930 ## Returns the number of volumes with the given order in the mesh
1931 # @param elementOrder the order of elements:
1932 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1933 # @return an integer value
1934 # @ingroup l1_meshinfo
1935 def NbVolumesOfOrder(self, elementOrder):
1936 return self.mesh.NbVolumesOfOrder(elementOrder)
1938 ## Returns the number of tetrahedrons in the mesh
1939 # @return an integer value
1940 # @ingroup l1_meshinfo
1942 return self.mesh.NbTetras()
1944 ## Returns the number of tetrahedrons with the given order in the mesh
1945 # @param elementOrder the order of elements:
1946 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1947 # @return an integer value
1948 # @ingroup l1_meshinfo
1949 def NbTetrasOfOrder(self, elementOrder):
1950 return self.mesh.NbTetrasOfOrder(elementOrder)
1952 ## Returns the number of hexahedrons in the mesh
1953 # @return an integer value
1954 # @ingroup l1_meshinfo
1956 return self.mesh.NbHexas()
1958 ## Returns the number of hexahedrons with the given order in the mesh
1959 # @param elementOrder the order of elements:
1960 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1961 # @return an integer value
1962 # @ingroup l1_meshinfo
1963 def NbHexasOfOrder(self, elementOrder):
1964 return self.mesh.NbHexasOfOrder(elementOrder)
1966 ## Returns the number of triquadratic hexahedrons in the mesh
1967 # @return an integer value
1968 # @ingroup l1_meshinfo
1969 def NbTriQuadraticHexas(self):
1970 return self.mesh.NbTriQuadraticHexas()
1972 ## Returns the number of pyramids in the mesh
1973 # @return an integer value
1974 # @ingroup l1_meshinfo
1975 def NbPyramids(self):
1976 return self.mesh.NbPyramids()
1978 ## Returns the number of pyramids with the given order in the mesh
1979 # @param elementOrder the order of elements:
1980 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1981 # @return an integer value
1982 # @ingroup l1_meshinfo
1983 def NbPyramidsOfOrder(self, elementOrder):
1984 return self.mesh.NbPyramidsOfOrder(elementOrder)
1986 ## Returns the number of prisms in the mesh
1987 # @return an integer value
1988 # @ingroup l1_meshinfo
1990 return self.mesh.NbPrisms()
1992 ## Returns the number of prisms with the given order in the mesh
1993 # @param elementOrder the order of elements:
1994 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1995 # @return an integer value
1996 # @ingroup l1_meshinfo
1997 def NbPrismsOfOrder(self, elementOrder):
1998 return self.mesh.NbPrismsOfOrder(elementOrder)
2000 ## Returns the number of hexagonal prisms in the mesh
2001 # @return an integer value
2002 # @ingroup l1_meshinfo
2003 def NbHexagonalPrisms(self):
2004 return self.mesh.NbHexagonalPrisms()
2006 ## Returns the number of polyhedrons in the mesh
2007 # @return an integer value
2008 # @ingroup l1_meshinfo
2009 def NbPolyhedrons(self):
2010 return self.mesh.NbPolyhedrons()
2012 ## Returns the number of submeshes in the mesh
2013 # @return an integer value
2014 # @ingroup l1_meshinfo
2015 def NbSubMesh(self):
2016 return self.mesh.NbSubMesh()
2018 ## Returns the list of mesh elements IDs
2019 # @return the list of integer values
2020 # @ingroup l1_meshinfo
2021 def GetElementsId(self):
2022 return self.mesh.GetElementsId()
2024 ## Returns the list of IDs of mesh elements with the given type
2025 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2026 # @return list of integer values
2027 # @ingroup l1_meshinfo
2028 def GetElementsByType(self, elementType):
2029 return self.mesh.GetElementsByType(elementType)
2031 ## Returns the list of mesh nodes IDs
2032 # @return the list of integer values
2033 # @ingroup l1_meshinfo
2034 def GetNodesId(self):
2035 return self.mesh.GetNodesId()
2037 # Get the information about mesh elements:
2038 # ------------------------------------
2040 ## Returns the type of mesh element
2041 # @return the value from SMESH::ElementType enumeration
2042 # @ingroup l1_meshinfo
2043 def GetElementType(self, id, iselem):
2044 return self.mesh.GetElementType(id, iselem)
2046 ## Returns the geometric type of mesh element
2047 # @return the value from SMESH::EntityType enumeration
2048 # @ingroup l1_meshinfo
2049 def GetElementGeomType(self, id):
2050 return self.mesh.GetElementGeomType(id)
2052 ## Returns the list of submesh elements IDs
2053 # @param Shape a geom object(sub-shape) IOR
2054 # Shape must be the sub-shape of a ShapeToMesh()
2055 # @return the list of integer values
2056 # @ingroup l1_meshinfo
2057 def GetSubMeshElementsId(self, Shape):
2058 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2059 ShapeID = Shape.GetSubShapeIndices()[0]
2062 return self.mesh.GetSubMeshElementsId(ShapeID)
2064 ## Returns the list of submesh nodes IDs
2065 # @param Shape a geom object(sub-shape) IOR
2066 # Shape must be the sub-shape of a ShapeToMesh()
2067 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2068 # @return the list of integer values
2069 # @ingroup l1_meshinfo
2070 def GetSubMeshNodesId(self, Shape, all):
2071 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2072 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2075 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2077 ## Returns type of elements on given shape
2078 # @param Shape a geom object(sub-shape) IOR
2079 # Shape must be a sub-shape of a ShapeToMesh()
2080 # @return element type
2081 # @ingroup l1_meshinfo
2082 def GetSubMeshElementType(self, Shape):
2083 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2084 ShapeID = Shape.GetSubShapeIndices()[0]
2087 return self.mesh.GetSubMeshElementType(ShapeID)
2089 ## Gets the mesh description
2090 # @return string value
2091 # @ingroup l1_meshinfo
2093 return self.mesh.Dump()
2096 # Get the information about nodes and elements of a mesh by its IDs:
2097 # -----------------------------------------------------------
2099 ## Gets XYZ coordinates of a node
2100 # \n If there is no nodes for the given ID - returns an empty list
2101 # @return a list of double precision values
2102 # @ingroup l1_meshinfo
2103 def GetNodeXYZ(self, id):
2104 return self.mesh.GetNodeXYZ(id)
2106 ## Returns list of IDs of inverse elements for the given node
2107 # \n If there is no node for the given ID - returns an empty list
2108 # @return a list of integer values
2109 # @ingroup l1_meshinfo
2110 def GetNodeInverseElements(self, id):
2111 return self.mesh.GetNodeInverseElements(id)
2113 ## @brief Returns the position of a node on the shape
2114 # @return SMESH::NodePosition
2115 # @ingroup l1_meshinfo
2116 def GetNodePosition(self,NodeID):
2117 return self.mesh.GetNodePosition(NodeID)
2119 ## If the given element is a node, returns the ID of shape
2120 # \n If there is no node for the given ID - returns -1
2121 # @return an integer value
2122 # @ingroup l1_meshinfo
2123 def GetShapeID(self, id):
2124 return self.mesh.GetShapeID(id)
2126 ## Returns the ID of the result shape after
2127 # FindShape() from SMESH_MeshEditor for the given element
2128 # \n If there is no element for the given ID - returns -1
2129 # @return an integer value
2130 # @ingroup l1_meshinfo
2131 def GetShapeIDForElem(self,id):
2132 return self.mesh.GetShapeIDForElem(id)
2134 ## Returns the number of nodes for the given element
2135 # \n If there is no element for the given ID - returns -1
2136 # @return an integer value
2137 # @ingroup l1_meshinfo
2138 def GetElemNbNodes(self, id):
2139 return self.mesh.GetElemNbNodes(id)
2141 ## Returns the node ID the given index for the given element
2142 # \n If there is no element for the given ID - returns -1
2143 # \n If there is no node for the given index - returns -2
2144 # @return an integer value
2145 # @ingroup l1_meshinfo
2146 def GetElemNode(self, id, index):
2147 return self.mesh.GetElemNode(id, index)
2149 ## Returns the IDs of nodes of the given element
2150 # @return a list of integer values
2151 # @ingroup l1_meshinfo
2152 def GetElemNodes(self, id):
2153 return self.mesh.GetElemNodes(id)
2155 ## Returns true if the given node is the medium node in the given quadratic element
2156 # @ingroup l1_meshinfo
2157 def IsMediumNode(self, elementID, nodeID):
2158 return self.mesh.IsMediumNode(elementID, nodeID)
2160 ## Returns true if the given node is the medium node in one of quadratic elements
2161 # @ingroup l1_meshinfo
2162 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2163 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2165 ## Returns the number of edges for the given element
2166 # @ingroup l1_meshinfo
2167 def ElemNbEdges(self, id):
2168 return self.mesh.ElemNbEdges(id)
2170 ## Returns the number of faces for the given element
2171 # @ingroup l1_meshinfo
2172 def ElemNbFaces(self, id):
2173 return self.mesh.ElemNbFaces(id)
2175 ## Returns nodes of given face (counted from zero) for given volumic element.
2176 # @ingroup l1_meshinfo
2177 def GetElemFaceNodes(self,elemId, faceIndex):
2178 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2180 ## Returns an element based on all given nodes.
2181 # @ingroup l1_meshinfo
2182 def FindElementByNodes(self,nodes):
2183 return self.mesh.FindElementByNodes(nodes)
2185 ## Returns true if the given element is a polygon
2186 # @ingroup l1_meshinfo
2187 def IsPoly(self, id):
2188 return self.mesh.IsPoly(id)
2190 ## Returns true if the given element is quadratic
2191 # @ingroup l1_meshinfo
2192 def IsQuadratic(self, id):
2193 return self.mesh.IsQuadratic(id)
2195 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2196 # @ingroup l1_meshinfo
2197 def GetBallDiameter(self, id):
2198 return self.mesh.GetBallDiameter(id)
2200 ## Returns XYZ coordinates of the barycenter of the given element
2201 # \n If there is no element for the given ID - returns an empty list
2202 # @return a list of three double values
2203 # @ingroup l1_meshinfo
2204 def BaryCenter(self, id):
2205 return self.mesh.BaryCenter(id)
2207 ## Passes mesh elements through the given filter and return IDs of fitting elements
2208 # @param theFilter SMESH_Filter
2209 # @return a list of ids
2210 # @ingroup l1_controls
2211 def GetIdsFromFilter(self, theFilter):
2212 theFilter.SetMesh( self.mesh )
2213 return theFilter.GetIDs()
2215 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2216 # Returns a list of special structures (borders).
2217 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2218 # @ingroup l1_controls
2219 def GetFreeBorders(self):
2220 aFilterMgr = self.smeshpyD.CreateFilterManager()
2221 aPredicate = aFilterMgr.CreateFreeEdges()
2222 aPredicate.SetMesh(self.mesh)
2223 aBorders = aPredicate.GetBorders()
2224 aFilterMgr.UnRegister()
2228 # Get mesh measurements information:
2229 # ------------------------------------
2231 ## Get minimum distance between two nodes, elements or distance to the origin
2232 # @param id1 first node/element id
2233 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2234 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2235 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2236 # @return minimum distance value
2237 # @sa GetMinDistance()
2238 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2239 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2240 return aMeasure.value
2242 ## Get measure structure specifying minimum distance data between two objects
2243 # @param id1 first node/element id
2244 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2245 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2246 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2247 # @return Measure structure
2249 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2251 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2253 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2256 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2258 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2263 aMeasurements = self.smeshpyD.CreateMeasurements()
2264 aMeasure = aMeasurements.MinDistance(id1, id2)
2265 aMeasurements.UnRegister()
2268 ## Get bounding box of the specified object(s)
2269 # @param objects single source object or list of source objects or list of nodes/elements IDs
2270 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2271 # @c False specifies that @a objects are nodes
2272 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2273 # @sa GetBoundingBox()
2274 def BoundingBox(self, objects=None, isElem=False):
2275 result = self.GetBoundingBox(objects, isElem)
2279 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2282 ## Get measure structure specifying bounding box data of the specified object(s)
2283 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2284 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2285 # @c False specifies that @a objects are nodes
2286 # @return Measure structure
2288 def GetBoundingBox(self, IDs=None, isElem=False):
2291 elif isinstance(IDs, tuple):
2293 if not isinstance(IDs, list):
2295 if len(IDs) > 0 and isinstance(IDs[0], int):
2299 if isinstance(o, Mesh):
2300 srclist.append(o.mesh)
2301 elif hasattr(o, "_narrow"):
2302 src = o._narrow(SMESH.SMESH_IDSource)
2303 if src: srclist.append(src)
2305 elif isinstance(o, list):
2307 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2309 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2312 aMeasurements = self.smeshpyD.CreateMeasurements()
2313 aMeasure = aMeasurements.BoundingBox(srclist)
2314 aMeasurements.UnRegister()
2317 # Mesh edition (SMESH_MeshEditor functionality):
2318 # ---------------------------------------------
2320 ## Removes the elements from the mesh by ids
2321 # @param IDsOfElements is a list of ids of elements to remove
2322 # @return True or False
2323 # @ingroup l2_modif_del
2324 def RemoveElements(self, IDsOfElements):
2325 return self.editor.RemoveElements(IDsOfElements)
2327 ## Removes nodes from mesh by ids
2328 # @param IDsOfNodes is a list of ids of nodes to remove
2329 # @return True or False
2330 # @ingroup l2_modif_del
2331 def RemoveNodes(self, IDsOfNodes):
2332 return self.editor.RemoveNodes(IDsOfNodes)
2334 ## Removes all orphan (free) nodes from mesh
2335 # @return number of the removed nodes
2336 # @ingroup l2_modif_del
2337 def RemoveOrphanNodes(self):
2338 return self.editor.RemoveOrphanNodes()
2340 ## Add a node to the mesh by coordinates
2341 # @return Id of the new node
2342 # @ingroup l2_modif_add
2343 def AddNode(self, x, y, z):
2344 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2345 if hasVars: self.mesh.SetParameters(Parameters)
2346 return self.editor.AddNode( x, y, z)
2348 ## Creates a 0D element on a node with given number.
2349 # @param IDOfNode the ID of node for creation of the element.
2350 # @return the Id of the new 0D element
2351 # @ingroup l2_modif_add
2352 def Add0DElement(self, IDOfNode):
2353 return self.editor.Add0DElement(IDOfNode)
2355 ## Create 0D elements on all nodes of the given elements except those
2356 # nodes on which a 0D element already exists.
2357 # @param theObject an object on whose nodes 0D elements will be created.
2358 # It can be mesh, sub-mesh, group, list of element IDs or a holder
2359 # of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2360 # @param theGroupName optional name of a group to add 0D elements created
2361 # and/or found on nodes of \a theObject.
2362 # @return an object (a new group or a temporary SMESH_IDSource) holding
2363 # IDs of new and/or found 0D elements. IDs of 0D elements
2364 # can be retrieved from the returned object by calling GetIDs()
2365 # @ingroup l2_modif_add
2366 def Add0DElementsToAllNodes(self, theObject, theGroupName=""):
2367 if isinstance( theObject, Mesh ):
2368 theObject = theObject.GetMesh()
2369 if isinstance( theObject, list ):
2370 theObject = self.GetIDSource( theObject, SMESH.ALL )
2371 return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName )
2373 ## Creates a ball element on a node with given ID.
2374 # @param IDOfNode the ID of node for creation of the element.
2375 # @param diameter the bal diameter.
2376 # @return the Id of the new ball element
2377 # @ingroup l2_modif_add
2378 def AddBall(self, IDOfNode, diameter):
2379 return self.editor.AddBall( IDOfNode, diameter )
2381 ## Creates a linear or quadratic edge (this is determined
2382 # by the number of given nodes).
2383 # @param IDsOfNodes the list of node IDs for creation of the element.
2384 # The order of nodes in this list should correspond to the description
2385 # of MED. \n This description is located by the following link:
2386 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2387 # @return the Id of the new edge
2388 # @ingroup l2_modif_add
2389 def AddEdge(self, IDsOfNodes):
2390 return self.editor.AddEdge(IDsOfNodes)
2392 ## Creates a linear or quadratic face (this is determined
2393 # by the number of given nodes).
2394 # @param IDsOfNodes the list of node IDs for creation of the element.
2395 # The order of nodes in this list should correspond to the description
2396 # of MED. \n This description is located by the following link:
2397 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2398 # @return the Id of the new face
2399 # @ingroup l2_modif_add
2400 def AddFace(self, IDsOfNodes):
2401 return self.editor.AddFace(IDsOfNodes)
2403 ## Adds a polygonal face to the mesh by the list of node IDs
2404 # @param IdsOfNodes the list of node IDs for creation of the element.
2405 # @return the Id of the new face
2406 # @ingroup l2_modif_add
2407 def AddPolygonalFace(self, IdsOfNodes):
2408 return self.editor.AddPolygonalFace(IdsOfNodes)
2410 ## Creates both simple and quadratic volume (this is determined
2411 # by the number of given nodes).
2412 # @param IDsOfNodes the list of node IDs for creation of the element.
2413 # The order of nodes in this list should correspond to the description
2414 # of MED. \n This description is located by the following link:
2415 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2416 # @return the Id of the new volumic element
2417 # @ingroup l2_modif_add
2418 def AddVolume(self, IDsOfNodes):
2419 return self.editor.AddVolume(IDsOfNodes)
2421 ## Creates a volume of many faces, giving nodes for each face.
2422 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2423 # @param Quantities the list of integer values, Quantities[i]
2424 # gives the quantity of nodes in face number i.
2425 # @return the Id of the new volumic element
2426 # @ingroup l2_modif_add
2427 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2428 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2430 ## Creates a volume of many faces, giving the IDs of the existing faces.
2431 # @param IdsOfFaces the list of face IDs for volume creation.
2433 # Note: The created volume will refer only to the nodes
2434 # of the given faces, not to the faces themselves.
2435 # @return the Id of the new volumic element
2436 # @ingroup l2_modif_add
2437 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2438 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2441 ## @brief Binds a node to a vertex
2442 # @param NodeID a node ID
2443 # @param Vertex a vertex or vertex ID
2444 # @return True if succeed else raises an exception
2445 # @ingroup l2_modif_add
2446 def SetNodeOnVertex(self, NodeID, Vertex):
2447 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2448 VertexID = Vertex.GetSubShapeIndices()[0]
2452 self.editor.SetNodeOnVertex(NodeID, VertexID)
2453 except SALOME.SALOME_Exception, inst:
2454 raise ValueError, inst.details.text
2458 ## @brief Stores the node position on an edge
2459 # @param NodeID a node ID
2460 # @param Edge an edge or edge ID
2461 # @param paramOnEdge a parameter on the edge where the node is located
2462 # @return True if succeed else raises an exception
2463 # @ingroup l2_modif_add
2464 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2465 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2466 EdgeID = Edge.GetSubShapeIndices()[0]
2470 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2471 except SALOME.SALOME_Exception, inst:
2472 raise ValueError, inst.details.text
2475 ## @brief Stores node position on a face
2476 # @param NodeID a node ID
2477 # @param Face a face or face ID
2478 # @param u U parameter on the face where the node is located
2479 # @param v V parameter on the face where the node is located
2480 # @return True if succeed else raises an exception
2481 # @ingroup l2_modif_add
2482 def SetNodeOnFace(self, NodeID, Face, u, v):
2483 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2484 FaceID = Face.GetSubShapeIndices()[0]
2488 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2489 except SALOME.SALOME_Exception, inst:
2490 raise ValueError, inst.details.text
2493 ## @brief Binds a node to a solid
2494 # @param NodeID a node ID
2495 # @param Solid a solid or solid ID
2496 # @return True if succeed else raises an exception
2497 # @ingroup l2_modif_add
2498 def SetNodeInVolume(self, NodeID, Solid):
2499 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2500 SolidID = Solid.GetSubShapeIndices()[0]
2504 self.editor.SetNodeInVolume(NodeID, SolidID)
2505 except SALOME.SALOME_Exception, inst:
2506 raise ValueError, inst.details.text
2509 ## @brief Bind an element to a shape
2510 # @param ElementID an element ID
2511 # @param Shape a shape or shape ID
2512 # @return True if succeed else raises an exception
2513 # @ingroup l2_modif_add
2514 def SetMeshElementOnShape(self, ElementID, Shape):
2515 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2516 ShapeID = Shape.GetSubShapeIndices()[0]
2520 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2521 except SALOME.SALOME_Exception, inst:
2522 raise ValueError, inst.details.text
2526 ## Moves the node with the given id
2527 # @param NodeID the id of the node
2528 # @param x a new X coordinate
2529 # @param y a new Y coordinate
2530 # @param z a new Z coordinate
2531 # @return True if succeed else False
2532 # @ingroup l2_modif_movenode
2533 def MoveNode(self, NodeID, x, y, z):
2534 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2535 if hasVars: self.mesh.SetParameters(Parameters)
2536 return self.editor.MoveNode(NodeID, x, y, z)
2538 ## Finds the node closest to a point and moves it to a point location
2539 # @param x the X coordinate of a point
2540 # @param y the Y coordinate of a point
2541 # @param z the Z coordinate of a point
2542 # @param NodeID if specified (>0), the node with this ID is moved,
2543 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2544 # @return the ID of a node
2545 # @ingroup l2_modif_throughp
2546 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2547 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2548 if hasVars: self.mesh.SetParameters(Parameters)
2549 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2551 ## Finds the node closest to a point
2552 # @param x the X coordinate of a point
2553 # @param y the Y coordinate of a point
2554 # @param z the Z coordinate of a point
2555 # @return the ID of a node
2556 # @ingroup l2_modif_throughp
2557 def FindNodeClosestTo(self, x, y, z):
2558 #preview = self.mesh.GetMeshEditPreviewer()
2559 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2560 return self.editor.FindNodeClosestTo(x, y, z)
2562 ## Finds the elements where a point lays IN or ON
2563 # @param x the X coordinate of a point
2564 # @param y the Y coordinate of a point
2565 # @param z the Z coordinate of a point
2566 # @param elementType type of elements to find (SMESH.ALL type
2567 # means elements of any type excluding nodes, discrete and 0D elements)
2568 # @param meshPart a part of mesh (group, sub-mesh) to search within
2569 # @return list of IDs of found elements
2570 # @ingroup l2_modif_throughp
2571 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2573 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2575 return self.editor.FindElementsByPoint(x, y, z, elementType)
2577 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2578 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2579 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2581 def GetPointState(self, x, y, z):
2582 return self.editor.GetPointState(x, y, z)
2584 ## Finds the node closest to a point and moves it to a point location
2585 # @param x the X coordinate of a point
2586 # @param y the Y coordinate of a point
2587 # @param z the Z coordinate of a point
2588 # @return the ID of a moved node
2589 # @ingroup l2_modif_throughp
2590 def MeshToPassThroughAPoint(self, x, y, z):
2591 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2593 ## Replaces two neighbour triangles sharing Node1-Node2 link
2594 # with the triangles built on the same 4 nodes but having other common link.
2595 # @param NodeID1 the ID of the first node
2596 # @param NodeID2 the ID of the second node
2597 # @return false if proper faces were not found
2598 # @ingroup l2_modif_invdiag
2599 def InverseDiag(self, NodeID1, NodeID2):
2600 return self.editor.InverseDiag(NodeID1, NodeID2)
2602 ## Replaces two neighbour triangles sharing Node1-Node2 link
2603 # with a quadrangle built on the same 4 nodes.
2604 # @param NodeID1 the ID of the first node
2605 # @param NodeID2 the ID of the second node
2606 # @return false if proper faces were not found
2607 # @ingroup l2_modif_unitetri
2608 def DeleteDiag(self, NodeID1, NodeID2):
2609 return self.editor.DeleteDiag(NodeID1, NodeID2)
2611 ## Reorients elements by ids
2612 # @param IDsOfElements if undefined reorients all mesh elements
2613 # @return True if succeed else False
2614 # @ingroup l2_modif_changori
2615 def Reorient(self, IDsOfElements=None):
2616 if IDsOfElements == None:
2617 IDsOfElements = self.GetElementsId()
2618 return self.editor.Reorient(IDsOfElements)
2620 ## Reorients all elements of the object
2621 # @param theObject mesh, submesh or group
2622 # @return True if succeed else False
2623 # @ingroup l2_modif_changori
2624 def ReorientObject(self, theObject):
2625 if ( isinstance( theObject, Mesh )):
2626 theObject = theObject.GetMesh()
2627 return self.editor.ReorientObject(theObject)
2629 ## Reorient faces contained in \a the2DObject.
2630 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2631 # @param theDirection is a desired direction of normal of \a theFace.
2632 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2633 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2634 # compared with theDirection. It can be either ID of face or a point
2635 # by which the face will be found. The point can be given as either
2636 # a GEOM vertex or a list of point coordinates.
2637 # @return number of reoriented faces
2638 # @ingroup l2_modif_changori
2639 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2641 if isinstance( the2DObject, Mesh ):
2642 the2DObject = the2DObject.GetMesh()
2643 if isinstance( the2DObject, list ):
2644 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2645 # check theDirection
2646 if isinstance( theDirection, geompyDC.GEOM._objref_GEOM_Object):
2647 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2648 if isinstance( theDirection, list ):
2649 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2650 # prepare theFace and thePoint
2651 theFace = theFaceOrPoint
2652 thePoint = PointStruct(0,0,0)
2653 if isinstance( theFaceOrPoint, geompyDC.GEOM._objref_GEOM_Object):
2654 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2656 if isinstance( theFaceOrPoint, list ):
2657 thePoint = PointStruct( *theFaceOrPoint )
2659 if isinstance( theFaceOrPoint, PointStruct ):
2660 thePoint = theFaceOrPoint
2662 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2664 ## Fuses the neighbouring triangles into quadrangles.
2665 # @param IDsOfElements The triangles to be fused,
2666 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2667 # choose a neighbour to fuse with.
2668 # @param MaxAngle is the maximum angle between element normals at which the fusion
2669 # is still performed; theMaxAngle is mesured in radians.
2670 # Also it could be a name of variable which defines angle in degrees.
2671 # @return TRUE in case of success, FALSE otherwise.
2672 # @ingroup l2_modif_unitetri
2673 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2674 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2675 self.mesh.SetParameters(Parameters)
2676 if not IDsOfElements:
2677 IDsOfElements = self.GetElementsId()
2678 Functor = self.smeshpyD.GetFunctor(theCriterion)
2679 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2681 ## Fuses the neighbouring triangles of the object into quadrangles
2682 # @param theObject is mesh, submesh or group
2683 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2684 # choose a neighbour to fuse with.
2685 # @param MaxAngle a max angle between element normals at which the fusion
2686 # is still performed; theMaxAngle is mesured in radians.
2687 # @return TRUE in case of success, FALSE otherwise.
2688 # @ingroup l2_modif_unitetri
2689 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2690 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2691 self.mesh.SetParameters(Parameters)
2692 if isinstance( theObject, Mesh ):
2693 theObject = theObject.GetMesh()
2694 Functor = self.smeshpyD.GetFunctor(theCriterion)
2695 return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
2697 ## Splits quadrangles into triangles.
2699 # @param IDsOfElements the faces to be splitted.
2700 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2701 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2702 # value, then quadrangles will be split by the smallest diagonal.
2703 # @return TRUE in case of success, FALSE otherwise.
2704 # @ingroup l2_modif_cutquadr
2705 def QuadToTri (self, IDsOfElements, theCriterion = None):
2706 if IDsOfElements == []:
2707 IDsOfElements = self.GetElementsId()
2708 if theCriterion is None:
2709 theCriterion = FT_MaxElementLength2D
2710 Functor = self.smeshpyD.GetFunctor(theCriterion)
2711 return self.editor.QuadToTri(IDsOfElements, Functor)
2713 ## Splits quadrangles into triangles.
2714 # @param theObject the object from which the list of elements is taken,
2715 # this is mesh, submesh or group
2716 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2717 # choose a diagonal for splitting. If @a theCriterion is None, which is a default
2718 # value, then quadrangles will be split by the smallest diagonal.
2719 # @return TRUE in case of success, FALSE otherwise.
2720 # @ingroup l2_modif_cutquadr
2721 def QuadToTriObject (self, theObject, theCriterion = None):
2722 if ( isinstance( theObject, Mesh )):
2723 theObject = theObject.GetMesh()
2724 if theCriterion is None:
2725 theCriterion = FT_MaxElementLength2D
2726 Functor = self.smeshpyD.GetFunctor(theCriterion)
2727 return self.editor.QuadToTriObject(theObject, Functor)
2729 ## Splits quadrangles into triangles.
2730 # @param IDsOfElements the faces to be splitted
2731 # @param Diag13 is used to choose a diagonal for splitting.
2732 # @return TRUE in case of success, FALSE otherwise.
2733 # @ingroup l2_modif_cutquadr
2734 def SplitQuad (self, IDsOfElements, Diag13):
2735 if IDsOfElements == []:
2736 IDsOfElements = self.GetElementsId()
2737 return self.editor.SplitQuad(IDsOfElements, Diag13)
2739 ## Splits quadrangles into triangles.
2740 # @param theObject the object from which the list of elements is taken,
2741 # this is mesh, submesh or group
2742 # @param Diag13 is used to choose a diagonal for splitting.
2743 # @return TRUE in case of success, FALSE otherwise.
2744 # @ingroup l2_modif_cutquadr
2745 def SplitQuadObject (self, theObject, Diag13):
2746 if ( isinstance( theObject, Mesh )):
2747 theObject = theObject.GetMesh()
2748 return self.editor.SplitQuadObject(theObject, Diag13)
2750 ## Finds a better splitting of the given quadrangle.
2751 # @param IDOfQuad the ID of the quadrangle to be splitted.
2752 # @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
2753 # choose a diagonal for splitting.
2754 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2755 # diagonal is better, 0 if error occurs.
2756 # @ingroup l2_modif_cutquadr
2757 def BestSplit (self, IDOfQuad, theCriterion):
2758 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2760 ## Splits volumic elements into tetrahedrons
2761 # @param elemIDs either list of elements or mesh or group or submesh
2762 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2763 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2764 # @ingroup l2_modif_cutquadr
2765 def SplitVolumesIntoTetra(self, elemIDs, method=Hex_5Tet ):
2766 if isinstance( elemIDs, Mesh ):
2767 elemIDs = elemIDs.GetMesh()
2768 if ( isinstance( elemIDs, list )):
2769 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2770 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2772 ## Splits quadrangle faces near triangular facets of volumes
2774 # @ingroup l1_auxiliary
2775 def SplitQuadsNearTriangularFacets(self):
2776 faces_array = self.GetElementsByType(SMESH.FACE)
2777 for face_id in faces_array:
2778 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2779 quad_nodes = self.mesh.GetElemNodes(face_id)
2780 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2781 isVolumeFound = False
2782 for node1_elem in node1_elems:
2783 if not isVolumeFound:
2784 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2785 nb_nodes = self.GetElemNbNodes(node1_elem)
2786 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2787 volume_elem = node1_elem
2788 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2789 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2790 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2791 isVolumeFound = True
2792 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2793 self.SplitQuad([face_id], False) # diagonal 2-4
2794 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2795 isVolumeFound = True
2796 self.SplitQuad([face_id], True) # diagonal 1-3
2797 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2798 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2799 isVolumeFound = True
2800 self.SplitQuad([face_id], True) # diagonal 1-3
2802 ## @brief Splits hexahedrons into tetrahedrons.
2804 # This operation uses pattern mapping functionality for splitting.
2805 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2806 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2807 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2808 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2809 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2810 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2811 # @return TRUE in case of success, FALSE otherwise.
2812 # @ingroup l1_auxiliary
2813 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2814 # Pattern: 5.---------.6
2819 # (0,0,1) 4.---------.7 * |
2826 # (0,0,0) 0.---------.3
2827 pattern_tetra = "!!! Nb of points: \n 8 \n\
2837 !!! Indices of points of 6 tetras: \n\
2845 pattern = self.smeshpyD.GetPattern()
2846 isDone = pattern.LoadFromFile(pattern_tetra)
2848 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2851 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2852 isDone = pattern.MakeMesh(self.mesh, False, False)
2853 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2855 # split quafrangle faces near triangular facets of volumes
2856 self.SplitQuadsNearTriangularFacets()
2860 ## @brief Split hexahedrons into prisms.
2862 # Uses the pattern mapping functionality for splitting.
2863 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2864 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2865 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2866 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2867 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2868 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2869 # @return TRUE in case of success, FALSE otherwise.
2870 # @ingroup l1_auxiliary
2871 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2872 # Pattern: 5.---------.6
2877 # (0,0,1) 4.---------.7 |
2884 # (0,0,0) 0.---------.3
2885 pattern_prism = "!!! Nb of points: \n 8 \n\
2895 !!! Indices of points of 2 prisms: \n\
2899 pattern = self.smeshpyD.GetPattern()
2900 isDone = pattern.LoadFromFile(pattern_prism)
2902 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2905 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2906 isDone = pattern.MakeMesh(self.mesh, False, False)
2907 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2909 # Splits quafrangle faces near triangular facets of volumes
2910 self.SplitQuadsNearTriangularFacets()
2914 ## Smoothes elements
2915 # @param IDsOfElements the list if ids of elements to smooth
2916 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2917 # Note that nodes built on edges and boundary nodes are always fixed.
2918 # @param MaxNbOfIterations the maximum number of iterations
2919 # @param MaxAspectRatio varies in range [1.0, inf]
2920 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2921 # @return TRUE in case of success, FALSE otherwise.
2922 # @ingroup l2_modif_smooth
2923 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2924 MaxNbOfIterations, MaxAspectRatio, Method):
2925 if IDsOfElements == []:
2926 IDsOfElements = self.GetElementsId()
2927 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2928 self.mesh.SetParameters(Parameters)
2929 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2930 MaxNbOfIterations, MaxAspectRatio, Method)
2932 ## Smoothes elements which belong to the given object
2933 # @param theObject the object to smooth
2934 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2935 # Note that nodes built on edges and boundary nodes are always fixed.
2936 # @param MaxNbOfIterations the maximum number of iterations
2937 # @param MaxAspectRatio varies in range [1.0, inf]
2938 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2939 # @return TRUE in case of success, FALSE otherwise.
2940 # @ingroup l2_modif_smooth
2941 def SmoothObject(self, theObject, IDsOfFixedNodes,
2942 MaxNbOfIterations, MaxAspectRatio, Method):
2943 if ( isinstance( theObject, Mesh )):
2944 theObject = theObject.GetMesh()
2945 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2946 MaxNbOfIterations, MaxAspectRatio, Method)
2948 ## Parametrically smoothes the given elements
2949 # @param IDsOfElements the list if ids of elements to smooth
2950 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2951 # Note that nodes built on edges and boundary nodes are always fixed.
2952 # @param MaxNbOfIterations the maximum number of iterations
2953 # @param MaxAspectRatio varies in range [1.0, inf]
2954 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2955 # @return TRUE in case of success, FALSE otherwise.
2956 # @ingroup l2_modif_smooth
2957 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2958 MaxNbOfIterations, MaxAspectRatio, Method):
2959 if IDsOfElements == []:
2960 IDsOfElements = self.GetElementsId()
2961 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2962 self.mesh.SetParameters(Parameters)
2963 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2964 MaxNbOfIterations, MaxAspectRatio, Method)
2966 ## Parametrically smoothes the elements which belong to the given object
2967 # @param theObject the object to smooth
2968 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2969 # Note that nodes built on edges and boundary nodes are always fixed.
2970 # @param MaxNbOfIterations the maximum number of iterations
2971 # @param MaxAspectRatio varies in range [1.0, inf]
2972 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2973 # @return TRUE in case of success, FALSE otherwise.
2974 # @ingroup l2_modif_smooth
2975 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2976 MaxNbOfIterations, MaxAspectRatio, Method):
2977 if ( isinstance( theObject, Mesh )):
2978 theObject = theObject.GetMesh()
2979 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2980 MaxNbOfIterations, MaxAspectRatio, Method)
2982 ## Converts the mesh to quadratic, deletes old elements, replacing
2983 # them with quadratic with the same id.
2984 # @param theForce3d new node creation method:
2985 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
2986 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
2987 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2988 # @ingroup l2_modif_tofromqu
2989 def ConvertToQuadratic(self, theForce3d, theSubMesh=None):
2991 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
2993 self.editor.ConvertToQuadratic(theForce3d)
2995 ## Converts the mesh from quadratic to ordinary,
2996 # deletes old quadratic elements, \n replacing
2997 # them with ordinary mesh elements with the same id.
2998 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2999 # @ingroup l2_modif_tofromqu
3000 def ConvertFromQuadratic(self, theSubMesh=None):
3002 self.editor.ConvertFromQuadraticObject(theSubMesh)
3004 return self.editor.ConvertFromQuadratic()
3006 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3007 # @return TRUE if operation has been completed successfully, FALSE otherwise
3008 # @ingroup l2_modif_edit
3009 def Make2DMeshFrom3D(self):
3010 return self.editor. Make2DMeshFrom3D()
3012 ## Creates missing boundary elements
3013 # @param elements - elements whose boundary is to be checked:
3014 # mesh, group, sub-mesh or list of elements
3015 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3016 # @param dimension - defines type of boundary elements to create:
3017 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
3018 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3019 # @param groupName - a name of group to store created boundary elements in,
3020 # "" means not to create the group
3021 # @param meshName - a name of new mesh to store created boundary elements in,
3022 # "" means not to create the new mesh
3023 # @param toCopyElements - if true, the checked elements will be copied into
3024 # the new mesh else only boundary elements will be copied into the new mesh
3025 # @param toCopyExistingBondary - if true, not only new but also pre-existing
3026 # boundary elements will be copied into the new mesh
3027 # @return tuple (mesh, group) where bondary elements were added to
3028 # @ingroup l2_modif_edit
3029 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3030 toCopyElements=False, toCopyExistingBondary=False):
3031 if isinstance( elements, Mesh ):
3032 elements = elements.GetMesh()
3033 if ( isinstance( elements, list )):
3034 elemType = SMESH.ALL
3035 if elements: elemType = self.GetElementType( elements[0], iselem=True)
3036 elements = self.editor.MakeIDSource(elements, elemType)
3037 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3038 toCopyElements,toCopyExistingBondary)
3039 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3043 # @brief Creates missing boundary elements around either the whole mesh or
3044 # groups of 2D elements
3045 # @param dimension - defines type of boundary elements to create
3046 # @param groupName - a name of group to store all boundary elements in,
3047 # "" means not to create the group
3048 # @param meshName - a name of a new mesh, which is a copy of the initial
3049 # mesh + created boundary elements; "" means not to create the new mesh
3050 # @param toCopyAll - if true, the whole initial mesh will be copied into
3051 # the new mesh else only boundary elements will be copied into the new mesh
3052 # @param groups - groups of 2D elements to make boundary around
3053 # @retval tuple( long, mesh, groups )
3054 # long - number of added boundary elements
3055 # mesh - the mesh where elements were added to
3056 # group - the group of boundary elements or None
3058 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3059 toCopyAll=False, groups=[]):
3060 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3062 if mesh: mesh = self.smeshpyD.Mesh(mesh)
3063 return nb, mesh, group
3065 ## Renumber mesh nodes
3066 # @ingroup l2_modif_renumber
3067 def RenumberNodes(self):
3068 self.editor.RenumberNodes()
3070 ## Renumber mesh elements
3071 # @ingroup l2_modif_renumber
3072 def RenumberElements(self):
3073 self.editor.RenumberElements()
3075 ## Generates new elements by rotation of the elements around the axis
3076 # @param IDsOfElements the list of ids of elements to sweep
3077 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3078 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3079 # @param NbOfSteps the number of steps
3080 # @param Tolerance tolerance
3081 # @param MakeGroups forces the generation of new groups from existing ones
3082 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3083 # of all steps, else - size of each step
3084 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3085 # @ingroup l2_modif_extrurev
3086 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3087 MakeGroups=False, TotalAngle=False):
3088 if IDsOfElements == []:
3089 IDsOfElements = self.GetElementsId()
3090 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3091 Axis = self.smeshpyD.GetAxisStruct(Axis)
3092 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3093 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3094 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3095 self.mesh.SetParameters(Parameters)
3096 if TotalAngle and NbOfSteps:
3097 AngleInRadians /= NbOfSteps
3099 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3100 AngleInRadians, NbOfSteps, Tolerance)
3101 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3104 ## Generates new elements by rotation of the elements of object around the axis
3105 # @param theObject object which elements should be sweeped.
3106 # It can be a mesh, a sub mesh or a group.
3107 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3108 # @param AngleInRadians the angle of Rotation
3109 # @param NbOfSteps number of steps
3110 # @param Tolerance tolerance
3111 # @param MakeGroups forces the generation of new groups from existing ones
3112 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3113 # of all steps, else - size of each step
3114 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3115 # @ingroup l2_modif_extrurev
3116 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3117 MakeGroups=False, TotalAngle=False):
3118 if ( isinstance( theObject, Mesh )):
3119 theObject = theObject.GetMesh()
3120 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3121 Axis = self.smeshpyD.GetAxisStruct(Axis)
3122 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3123 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3124 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3125 self.mesh.SetParameters(Parameters)
3126 if TotalAngle and NbOfSteps:
3127 AngleInRadians /= NbOfSteps
3129 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3130 NbOfSteps, Tolerance)
3131 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3134 ## Generates new elements by rotation of the elements of object around the axis
3135 # @param theObject object which elements should be sweeped.
3136 # It can be a mesh, a sub mesh or a group.
3137 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3138 # @param AngleInRadians the angle of Rotation
3139 # @param NbOfSteps number of steps
3140 # @param Tolerance tolerance
3141 # @param MakeGroups forces the generation of new groups from existing ones
3142 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3143 # of all steps, else - size of each step
3144 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3145 # @ingroup l2_modif_extrurev
3146 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3147 MakeGroups=False, TotalAngle=False):
3148 if ( isinstance( theObject, Mesh )):
3149 theObject = theObject.GetMesh()
3150 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3151 Axis = self.smeshpyD.GetAxisStruct(Axis)
3152 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3153 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3154 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3155 self.mesh.SetParameters(Parameters)
3156 if TotalAngle and NbOfSteps:
3157 AngleInRadians /= NbOfSteps
3159 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3160 NbOfSteps, Tolerance)
3161 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3164 ## Generates new elements by rotation of the elements of object around the axis
3165 # @param theObject object which elements should be sweeped.
3166 # It can be a mesh, a sub mesh or a group.
3167 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3168 # @param AngleInRadians the angle of Rotation
3169 # @param NbOfSteps number of steps
3170 # @param Tolerance tolerance
3171 # @param MakeGroups forces the generation of new groups from existing ones
3172 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3173 # of all steps, else - size of each step
3174 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3175 # @ingroup l2_modif_extrurev
3176 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3177 MakeGroups=False, TotalAngle=False):
3178 if ( isinstance( theObject, Mesh )):
3179 theObject = theObject.GetMesh()
3180 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3181 Axis = self.smeshpyD.GetAxisStruct(Axis)
3182 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3183 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3184 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3185 self.mesh.SetParameters(Parameters)
3186 if TotalAngle and NbOfSteps:
3187 AngleInRadians /= NbOfSteps
3189 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3190 NbOfSteps, Tolerance)
3191 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3194 ## Generates new elements by extrusion of the elements with given ids
3195 # @param IDsOfElements the list of elements ids for extrusion
3196 # @param StepVector vector or DirStruct, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3197 # @param NbOfSteps the number of steps
3198 # @param MakeGroups forces the generation of new groups from existing ones
3199 # @param IsNodes is True if elements with given ids are nodes
3200 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3201 # @ingroup l2_modif_extrurev
3202 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3203 if IDsOfElements == []:
3204 IDsOfElements = self.GetElementsId()
3205 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3206 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3207 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3208 Parameters = StepVector.PS.parameters + var_separator + Parameters
3209 self.mesh.SetParameters(Parameters)
3212 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3214 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3216 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3218 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3221 ## Generates new elements by extrusion of the elements with given ids
3222 # @param IDsOfElements is ids of elements
3223 # @param StepVector vector, defining the direction and value of extrusion
3224 # @param NbOfSteps the number of steps
3225 # @param ExtrFlags sets flags for extrusion
3226 # @param SewTolerance uses for comparing locations of nodes if flag
3227 # EXTRUSION_FLAG_SEW is set
3228 # @param MakeGroups forces the generation of new groups from existing ones
3229 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3230 # @ingroup l2_modif_extrurev
3231 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3232 ExtrFlags, SewTolerance, MakeGroups=False):
3233 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3234 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3236 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3237 ExtrFlags, SewTolerance)
3238 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3239 ExtrFlags, SewTolerance)
3242 ## Generates new elements by extrusion of the elements which belong to the object
3243 # @param theObject the object which elements should be processed.
3244 # It can be a mesh, a sub mesh or a group.
3245 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3246 # @param NbOfSteps the number of steps
3247 # @param MakeGroups forces the generation of new groups from existing ones
3248 # @param IsNodes is True if elements which belong to the object are nodes
3249 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3250 # @ingroup l2_modif_extrurev
3251 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3252 if ( isinstance( theObject, Mesh )):
3253 theObject = theObject.GetMesh()
3254 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3255 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3256 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3257 Parameters = StepVector.PS.parameters + var_separator + Parameters
3258 self.mesh.SetParameters(Parameters)
3261 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3263 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3265 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3267 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3270 ## Generates new elements by extrusion of the elements which belong to the object
3271 # @param theObject object which elements should be processed.
3272 # It can be a mesh, a sub mesh or a group.
3273 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3274 # @param NbOfSteps the number of steps
3275 # @param MakeGroups to generate new groups from existing ones
3276 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3277 # @ingroup l2_modif_extrurev
3278 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3279 if ( isinstance( theObject, Mesh )):
3280 theObject = theObject.GetMesh()
3281 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3282 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3283 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3284 Parameters = StepVector.PS.parameters + var_separator + Parameters
3285 self.mesh.SetParameters(Parameters)
3287 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3288 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3291 ## Generates new elements by extrusion of the elements which belong to the object
3292 # @param theObject object which elements should be processed.
3293 # It can be a mesh, a sub mesh or a group.
3294 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3295 # @param NbOfSteps the number of steps
3296 # @param MakeGroups forces the generation of new groups from existing ones
3297 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3298 # @ingroup l2_modif_extrurev
3299 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3300 if ( isinstance( theObject, Mesh )):
3301 theObject = theObject.GetMesh()
3302 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3303 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3304 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3305 Parameters = StepVector.PS.parameters + var_separator + Parameters
3306 self.mesh.SetParameters(Parameters)
3308 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3309 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3314 ## Generates new elements by extrusion of the given elements
3315 # The path of extrusion must be a meshed edge.
3316 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3317 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3318 # @param NodeStart the start node from Path. Defines the direction of extrusion
3319 # @param HasAngles allows the shape to be rotated around the path
3320 # to get the resulting mesh in a helical fashion
3321 # @param Angles list of angles in radians
3322 # @param LinearVariation forces the computation of rotation angles as linear
3323 # variation of the given Angles along path steps
3324 # @param HasRefPoint allows using the reference point
3325 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3326 # The User can specify any point as the Reference Point.
3327 # @param MakeGroups forces the generation of new groups from existing ones
3328 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3329 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3330 # only SMESH::Extrusion_Error otherwise
3331 # @ingroup l2_modif_extrurev
3332 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3333 HasAngles, Angles, LinearVariation,
3334 HasRefPoint, RefPoint, MakeGroups, ElemType):
3335 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3336 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3338 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3339 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3340 self.mesh.SetParameters(Parameters)
3342 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3344 if isinstance(Base, list):
3346 if Base == []: IDsOfElements = self.GetElementsId()
3347 else: IDsOfElements = Base
3348 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3349 HasAngles, Angles, LinearVariation,
3350 HasRefPoint, RefPoint, MakeGroups, ElemType)
3352 if isinstance(Base, Mesh): Base = Base.GetMesh()
3353 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3354 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3355 HasAngles, Angles, LinearVariation,
3356 HasRefPoint, RefPoint, MakeGroups, ElemType)
3358 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3361 ## Generates new elements by extrusion of the given elements
3362 # The path of extrusion must be a meshed edge.
3363 # @param IDsOfElements ids of elements
3364 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3365 # @param PathShape shape(edge) defines the sub-mesh for the path
3366 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3367 # @param HasAngles allows the shape to be rotated around the path
3368 # to get the resulting mesh in a helical fashion
3369 # @param Angles list of angles in radians
3370 # @param HasRefPoint allows using the reference point
3371 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3372 # The User can specify any point as the Reference Point.
3373 # @param MakeGroups forces the generation of new groups from existing ones
3374 # @param LinearVariation forces the computation of rotation angles as linear
3375 # variation of the given Angles along path steps
3376 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3377 # only SMESH::Extrusion_Error otherwise
3378 # @ingroup l2_modif_extrurev
3379 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3380 HasAngles, Angles, HasRefPoint, RefPoint,
3381 MakeGroups=False, LinearVariation=False):
3382 if IDsOfElements == []:
3383 IDsOfElements = self.GetElementsId()
3384 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3385 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3387 if ( isinstance( PathMesh, Mesh )):
3388 PathMesh = PathMesh.GetMesh()
3389 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3390 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3391 self.mesh.SetParameters(Parameters)
3392 if HasAngles and Angles and LinearVariation:
3393 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3396 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3397 PathShape, NodeStart, HasAngles,
3398 Angles, HasRefPoint, RefPoint)
3399 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3400 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3402 ## Generates new elements by extrusion of the elements which belong to the object
3403 # The path of extrusion must be a meshed edge.
3404 # @param theObject the object which elements should be processed.
3405 # It can be a mesh, a sub mesh or a group.
3406 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3407 # @param PathShape shape(edge) defines the sub-mesh for the path
3408 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3409 # @param HasAngles allows the shape to be rotated around the path
3410 # to get the resulting mesh in a helical fashion
3411 # @param Angles list of angles
3412 # @param HasRefPoint allows using the reference point
3413 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3414 # The User can specify any point as the Reference Point.
3415 # @param MakeGroups forces the generation of new groups from existing ones
3416 # @param LinearVariation forces the computation of rotation angles as linear
3417 # variation of the given Angles along path steps
3418 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3419 # only SMESH::Extrusion_Error otherwise
3420 # @ingroup l2_modif_extrurev
3421 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3422 HasAngles, Angles, HasRefPoint, RefPoint,
3423 MakeGroups=False, LinearVariation=False):
3424 if ( isinstance( theObject, Mesh )):
3425 theObject = theObject.GetMesh()
3426 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3427 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3428 if ( isinstance( PathMesh, Mesh )):
3429 PathMesh = PathMesh.GetMesh()
3430 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3431 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3432 self.mesh.SetParameters(Parameters)
3433 if HasAngles and Angles and LinearVariation:
3434 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3437 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3438 PathShape, NodeStart, HasAngles,
3439 Angles, HasRefPoint, RefPoint)
3440 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3441 NodeStart, HasAngles, Angles, HasRefPoint,
3444 ## Generates new elements by extrusion of the elements which belong to the object
3445 # The path of extrusion must be a meshed edge.
3446 # @param theObject the object which elements should be processed.
3447 # It can be a mesh, a sub mesh or a group.
3448 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3449 # @param PathShape shape(edge) defines the sub-mesh for the path
3450 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3451 # @param HasAngles allows the shape to be rotated around the path
3452 # to get the resulting mesh in a helical fashion
3453 # @param Angles list of angles
3454 # @param HasRefPoint allows using the reference point
3455 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3456 # The User can specify any point as the Reference Point.
3457 # @param MakeGroups forces the generation of new groups from existing ones
3458 # @param LinearVariation forces the computation of rotation angles as linear
3459 # variation of the given Angles along path steps
3460 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3461 # only SMESH::Extrusion_Error otherwise
3462 # @ingroup l2_modif_extrurev
3463 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3464 HasAngles, Angles, HasRefPoint, RefPoint,
3465 MakeGroups=False, LinearVariation=False):
3466 if ( isinstance( theObject, Mesh )):
3467 theObject = theObject.GetMesh()
3468 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3469 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3470 if ( isinstance( PathMesh, Mesh )):
3471 PathMesh = PathMesh.GetMesh()
3472 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3473 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3474 self.mesh.SetParameters(Parameters)
3475 if HasAngles and Angles and LinearVariation:
3476 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3479 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3480 PathShape, NodeStart, HasAngles,
3481 Angles, HasRefPoint, RefPoint)
3482 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3483 NodeStart, HasAngles, Angles, HasRefPoint,
3486 ## Generates new elements by extrusion of the elements which belong to the object
3487 # The path of extrusion must be a meshed edge.
3488 # @param theObject the object which elements should be processed.
3489 # It can be a mesh, a sub mesh or a group.
3490 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3491 # @param PathShape shape(edge) defines the sub-mesh for the path
3492 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3493 # @param HasAngles allows the shape to be rotated around the path
3494 # to get the resulting mesh in a helical fashion
3495 # @param Angles list of angles
3496 # @param HasRefPoint allows using the reference point
3497 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3498 # The User can specify any point as the Reference Point.
3499 # @param MakeGroups forces the generation of new groups from existing ones
3500 # @param LinearVariation forces the computation of rotation angles as linear
3501 # variation of the given Angles along path steps
3502 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3503 # only SMESH::Extrusion_Error otherwise
3504 # @ingroup l2_modif_extrurev
3505 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3506 HasAngles, Angles, HasRefPoint, RefPoint,
3507 MakeGroups=False, LinearVariation=False):
3508 if ( isinstance( theObject, Mesh )):
3509 theObject = theObject.GetMesh()
3510 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3511 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3512 if ( isinstance( PathMesh, Mesh )):
3513 PathMesh = PathMesh.GetMesh()
3514 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3515 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3516 self.mesh.SetParameters(Parameters)
3517 if HasAngles and Angles and LinearVariation:
3518 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3521 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3522 PathShape, NodeStart, HasAngles,
3523 Angles, HasRefPoint, RefPoint)
3524 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3525 NodeStart, HasAngles, Angles, HasRefPoint,
3528 ## Creates a symmetrical copy of mesh elements
3529 # @param IDsOfElements list of elements ids
3530 # @param Mirror is AxisStruct or geom object(point, line, plane)
3531 # @param theMirrorType is POINT, AXIS or PLANE
3532 # If the Mirror is a geom object this parameter is unnecessary
3533 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3534 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3535 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3536 # @ingroup l2_modif_trsf
3537 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3538 if IDsOfElements == []:
3539 IDsOfElements = self.GetElementsId()
3540 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3541 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3542 self.mesh.SetParameters(Mirror.parameters)
3543 if Copy and MakeGroups:
3544 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3545 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3548 ## Creates a new mesh by a symmetrical copy of mesh elements
3549 # @param IDsOfElements the list of elements ids
3550 # @param Mirror is AxisStruct or geom object (point, line, plane)
3551 # @param theMirrorType is POINT, AXIS or PLANE
3552 # If the Mirror is a geom object this parameter is unnecessary
3553 # @param MakeGroups to generate new groups from existing ones
3554 # @param NewMeshName a name of the new mesh to create
3555 # @return instance of Mesh class
3556 # @ingroup l2_modif_trsf
3557 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3558 if IDsOfElements == []:
3559 IDsOfElements = self.GetElementsId()
3560 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3561 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3562 self.mesh.SetParameters(Mirror.parameters)
3563 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3564 MakeGroups, NewMeshName)
3565 return Mesh(self.smeshpyD,self.geompyD,mesh)
3567 ## Creates a symmetrical copy of the object
3568 # @param theObject mesh, submesh or group
3569 # @param Mirror AxisStruct or geom object (point, line, plane)
3570 # @param theMirrorType is POINT, AXIS or PLANE
3571 # If the Mirror is a geom object this parameter is unnecessary
3572 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3573 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3574 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3575 # @ingroup l2_modif_trsf
3576 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3577 if ( isinstance( theObject, Mesh )):
3578 theObject = theObject.GetMesh()
3579 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3580 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3581 self.mesh.SetParameters(Mirror.parameters)
3582 if Copy and MakeGroups:
3583 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3584 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3587 ## Creates a new mesh by a symmetrical copy of the object
3588 # @param theObject mesh, submesh or group
3589 # @param Mirror AxisStruct or geom object (point, line, plane)
3590 # @param theMirrorType POINT, AXIS or PLANE
3591 # If the Mirror is a geom object this parameter is unnecessary
3592 # @param MakeGroups forces the generation of new groups from existing ones
3593 # @param NewMeshName the name of the new mesh to create
3594 # @return instance of Mesh class
3595 # @ingroup l2_modif_trsf
3596 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3597 if ( isinstance( theObject, Mesh )):
3598 theObject = theObject.GetMesh()
3599 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3600 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3601 self.mesh.SetParameters(Mirror.parameters)
3602 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3603 MakeGroups, NewMeshName)
3604 return Mesh( self.smeshpyD,self.geompyD,mesh )
3606 ## Translates the elements
3607 # @param IDsOfElements list of elements ids
3608 # @param Vector the direction of translation (DirStruct or vector)
3609 # @param Copy allows copying the translated elements
3610 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3611 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3612 # @ingroup l2_modif_trsf
3613 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3614 if IDsOfElements == []:
3615 IDsOfElements = self.GetElementsId()
3616 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3617 Vector = self.smeshpyD.GetDirStruct(Vector)
3618 self.mesh.SetParameters(Vector.PS.parameters)
3619 if Copy and MakeGroups:
3620 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3621 self.editor.Translate(IDsOfElements, Vector, Copy)
3624 ## Creates a new mesh of translated elements
3625 # @param IDsOfElements list of elements ids
3626 # @param Vector the direction of translation (DirStruct or vector)
3627 # @param MakeGroups forces the generation of new groups from existing ones
3628 # @param NewMeshName the name of the newly created mesh
3629 # @return instance of Mesh class
3630 # @ingroup l2_modif_trsf
3631 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3632 if IDsOfElements == []:
3633 IDsOfElements = self.GetElementsId()
3634 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3635 Vector = self.smeshpyD.GetDirStruct(Vector)
3636 self.mesh.SetParameters(Vector.PS.parameters)
3637 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3638 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3640 ## Translates the object
3641 # @param theObject the object to translate (mesh, submesh, or group)
3642 # @param Vector direction of translation (DirStruct or geom vector)
3643 # @param Copy allows copying the translated elements
3644 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3645 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3646 # @ingroup l2_modif_trsf
3647 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3648 if ( isinstance( theObject, Mesh )):
3649 theObject = theObject.GetMesh()
3650 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3651 Vector = self.smeshpyD.GetDirStruct(Vector)
3652 self.mesh.SetParameters(Vector.PS.parameters)
3653 if Copy and MakeGroups:
3654 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3655 self.editor.TranslateObject(theObject, Vector, Copy)
3658 ## Creates a new mesh from the translated object
3659 # @param theObject the object to translate (mesh, submesh, or group)
3660 # @param Vector the direction of translation (DirStruct or geom vector)
3661 # @param MakeGroups forces the generation of new groups from existing ones
3662 # @param NewMeshName the name of the newly created mesh
3663 # @return instance of Mesh class
3664 # @ingroup l2_modif_trsf
3665 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3666 if (isinstance(theObject, Mesh)):
3667 theObject = theObject.GetMesh()
3668 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3669 Vector = self.smeshpyD.GetDirStruct(Vector)
3670 self.mesh.SetParameters(Vector.PS.parameters)
3671 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3672 return Mesh( self.smeshpyD, self.geompyD, mesh )
3676 ## Scales the object
3677 # @param theObject - the object to translate (mesh, submesh, or group)
3678 # @param thePoint - base point for scale
3679 # @param theScaleFact - list of 1-3 scale factors for axises
3680 # @param Copy - allows copying the translated elements
3681 # @param MakeGroups - forces the generation of new groups from existing
3683 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3684 # empty list otherwise
3685 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3686 if ( isinstance( theObject, Mesh )):
3687 theObject = theObject.GetMesh()
3688 if ( isinstance( theObject, list )):
3689 theObject = self.GetIDSource(theObject, SMESH.ALL)
3690 if ( isinstance( theScaleFact, float )):
3691 theScaleFact = [theScaleFact]
3692 if ( isinstance( theScaleFact, int )):
3693 theScaleFact = [ float(theScaleFact)]
3695 self.mesh.SetParameters(thePoint.parameters)
3697 if Copy and MakeGroups:
3698 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3699 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3702 ## Creates a new mesh from the translated object
3703 # @param theObject - the object to translate (mesh, submesh, or group)
3704 # @param thePoint - base point for scale
3705 # @param theScaleFact - list of 1-3 scale factors for axises
3706 # @param MakeGroups - forces the generation of new groups from existing ones
3707 # @param NewMeshName - the name of the newly created mesh
3708 # @return instance of Mesh class
3709 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3710 if (isinstance(theObject, Mesh)):
3711 theObject = theObject.GetMesh()
3712 if ( isinstance( theObject, list )):
3713 theObject = self.GetIDSource(theObject,SMESH.ALL)
3714 if ( isinstance( theScaleFact, float )):
3715 theScaleFact = [theScaleFact]
3716 if ( isinstance( theScaleFact, int )):
3717 theScaleFact = [ float(theScaleFact)]
3719 self.mesh.SetParameters(thePoint.parameters)
3720 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3721 MakeGroups, NewMeshName)
3722 return Mesh( self.smeshpyD, self.geompyD, mesh )
3726 ## Rotates the elements
3727 # @param IDsOfElements list of elements ids
3728 # @param Axis the axis of rotation (AxisStruct or geom line)
3729 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3730 # @param Copy allows copying the rotated elements
3731 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3732 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3733 # @ingroup l2_modif_trsf
3734 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3735 if IDsOfElements == []:
3736 IDsOfElements = self.GetElementsId()
3737 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3738 Axis = self.smeshpyD.GetAxisStruct(Axis)
3739 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3740 Parameters = Axis.parameters + var_separator + Parameters
3741 self.mesh.SetParameters(Parameters)
3742 if Copy and MakeGroups:
3743 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3744 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3747 ## Creates a new mesh of rotated elements
3748 # @param IDsOfElements list of element 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 MakeGroups forces the generation of new groups from existing ones
3752 # @param NewMeshName the name of the newly created mesh
3753 # @return instance of Mesh class
3754 # @ingroup l2_modif_trsf
3755 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
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 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3764 MakeGroups, NewMeshName)
3765 return Mesh( self.smeshpyD, self.geompyD, mesh )
3767 ## Rotates the object
3768 # @param theObject the object to rotate( mesh, submesh, or group)
3769 # @param Axis the axis of rotation (AxisStruct or geom line)
3770 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3771 # @param Copy allows copying the rotated elements
3772 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3773 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3774 # @ingroup l2_modif_trsf
3775 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3776 if (isinstance(theObject, Mesh)):
3777 theObject = theObject.GetMesh()
3778 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3779 Axis = self.smeshpyD.GetAxisStruct(Axis)
3780 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3781 Parameters = Axis.parameters + ":" + Parameters
3782 self.mesh.SetParameters(Parameters)
3783 if Copy and MakeGroups:
3784 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3785 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3788 ## Creates a new mesh from the rotated 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 MakeGroups forces the generation of new groups from existing ones
3793 # @param NewMeshName the name of the newly created mesh
3794 # @return instance of Mesh class
3795 # @ingroup l2_modif_trsf
3796 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
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 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3804 MakeGroups, NewMeshName)
3805 self.mesh.SetParameters(Parameters)
3806 return Mesh( self.smeshpyD, self.geompyD, mesh )
3808 ## Finds groups of ajacent nodes within Tolerance.
3809 # @param Tolerance the value of tolerance
3810 # @return the list of groups of nodes
3811 # @ingroup l2_modif_trsf
3812 def FindCoincidentNodes (self, Tolerance):
3813 return self.editor.FindCoincidentNodes(Tolerance)
3815 ## Finds groups of ajacent nodes within Tolerance.
3816 # @param Tolerance the value of tolerance
3817 # @param SubMeshOrGroup SubMesh or Group
3818 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3819 # @return the list of groups of nodes
3820 # @ingroup l2_modif_trsf
3821 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3822 if (isinstance( SubMeshOrGroup, Mesh )):
3823 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3824 if not isinstance( exceptNodes, list):
3825 exceptNodes = [ exceptNodes ]
3826 if exceptNodes and isinstance( exceptNodes[0], int):
3827 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3828 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3831 # @param GroupsOfNodes the list of groups of nodes
3832 # @ingroup l2_modif_trsf
3833 def MergeNodes (self, GroupsOfNodes):
3834 self.editor.MergeNodes(GroupsOfNodes)
3836 ## Finds the elements built on the same nodes.
3837 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3838 # @return a list of groups of equal elements
3839 # @ingroup l2_modif_trsf
3840 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3841 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
3842 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
3843 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3845 ## Merges elements in each given group.
3846 # @param GroupsOfElementsID groups of elements for merging
3847 # @ingroup l2_modif_trsf
3848 def MergeElements(self, GroupsOfElementsID):
3849 self.editor.MergeElements(GroupsOfElementsID)
3851 ## Leaves one element and removes all other elements built on the same nodes.
3852 # @ingroup l2_modif_trsf
3853 def MergeEqualElements(self):
3854 self.editor.MergeEqualElements()
3856 ## Sews free borders
3857 # @return SMESH::Sew_Error
3858 # @ingroup l2_modif_trsf
3859 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3860 FirstNodeID2, SecondNodeID2, LastNodeID2,
3861 CreatePolygons, CreatePolyedrs):
3862 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3863 FirstNodeID2, SecondNodeID2, LastNodeID2,
3864 CreatePolygons, CreatePolyedrs)
3866 ## Sews conform free borders
3867 # @return SMESH::Sew_Error
3868 # @ingroup l2_modif_trsf
3869 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3870 FirstNodeID2, SecondNodeID2):
3871 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3872 FirstNodeID2, SecondNodeID2)
3874 ## Sews border to side
3875 # @return SMESH::Sew_Error
3876 # @ingroup l2_modif_trsf
3877 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3878 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3879 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3880 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3882 ## Sews two sides of a mesh. The nodes belonging to Side1 are
3883 # merged with the nodes of elements of Side2.
3884 # The number of elements in theSide1 and in theSide2 must be
3885 # equal and they should have similar nodal connectivity.
3886 # The nodes to merge should belong to side borders and
3887 # the first node should be linked to the second.
3888 # @return SMESH::Sew_Error
3889 # @ingroup l2_modif_trsf
3890 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3891 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3892 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3893 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3894 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3895 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3897 ## Sets new nodes for the given element.
3898 # @param ide the element id
3899 # @param newIDs nodes ids
3900 # @return If the number of nodes does not correspond to the type of element - returns false
3901 # @ingroup l2_modif_edit
3902 def ChangeElemNodes(self, ide, newIDs):
3903 return self.editor.ChangeElemNodes(ide, newIDs)
3905 ## If during the last operation of MeshEditor some nodes were
3906 # created, this method returns the list of their IDs, \n
3907 # if new nodes were not created - returns empty list
3908 # @return the list of integer values (can be empty)
3909 # @ingroup l1_auxiliary
3910 def GetLastCreatedNodes(self):
3911 return self.editor.GetLastCreatedNodes()
3913 ## If during the last operation of MeshEditor some elements were
3914 # created this method returns the list of their IDs, \n
3915 # if new elements were not created - returns empty list
3916 # @return the list of integer values (can be empty)
3917 # @ingroup l1_auxiliary
3918 def GetLastCreatedElems(self):
3919 return self.editor.GetLastCreatedElems()
3921 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3922 # @param theNodes identifiers of nodes to be doubled
3923 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
3924 # nodes. If list of element identifiers is empty then nodes are doubled but
3925 # they not assigned to elements
3926 # @return TRUE if operation has been completed successfully, FALSE otherwise
3927 # @ingroup l2_modif_edit
3928 def DoubleNodes(self, theNodes, theModifiedElems):
3929 return self.editor.DoubleNodes(theNodes, theModifiedElems)
3931 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3932 # This method provided for convenience works as DoubleNodes() described above.
3933 # @param theNodeId identifiers of node to be doubled
3934 # @param theModifiedElems identifiers of elements to be updated
3935 # @return TRUE if operation has been completed successfully, FALSE otherwise
3936 # @ingroup l2_modif_edit
3937 def DoubleNode(self, theNodeId, theModifiedElems):
3938 return self.editor.DoubleNode(theNodeId, theModifiedElems)
3940 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3941 # This method provided for convenience works as DoubleNodes() described above.
3942 # @param theNodes group of nodes to be doubled
3943 # @param theModifiedElems group of elements to be updated.
3944 # @param theMakeGroup forces the generation of a group containing new nodes.
3945 # @return TRUE or a created group if operation has been completed successfully,
3946 # FALSE or None otherwise
3947 # @ingroup l2_modif_edit
3948 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
3950 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
3951 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
3953 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3954 # This method provided for convenience works as DoubleNodes() described above.
3955 # @param theNodes list of groups of nodes to be doubled
3956 # @param theModifiedElems list of groups of elements to be updated.
3957 # @param theMakeGroup forces the generation of a group containing new nodes.
3958 # @return TRUE if operation has been completed successfully, FALSE otherwise
3959 # @ingroup l2_modif_edit
3960 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
3962 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
3963 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
3965 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3966 # @param theElems - the list of elements (edges or faces) to be replicated
3967 # The nodes for duplication could be found from these elements
3968 # @param theNodesNot - list of nodes to NOT replicate
3969 # @param theAffectedElems - the list of elements (cells and edges) to which the
3970 # replicated nodes should be associated to.
3971 # @return TRUE if operation has been completed successfully, FALSE otherwise
3972 # @ingroup l2_modif_edit
3973 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
3974 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
3976 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3977 # @param theElems - the list of elements (edges or faces) to be replicated
3978 # The nodes for duplication could be found from these elements
3979 # @param theNodesNot - list of nodes to NOT replicate
3980 # @param theShape - shape to detect affected elements (element which geometric center
3981 # located on or inside shape).
3982 # The replicated nodes should be associated to affected elements.
3983 # @return TRUE if operation has been completed successfully, FALSE otherwise
3984 # @ingroup l2_modif_edit
3985 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
3986 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
3988 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3989 # This method provided for convenience works as DoubleNodes() described above.
3990 # @param theElems - group of of elements (edges or faces) to be replicated
3991 # @param theNodesNot - group of nodes not to replicated
3992 # @param theAffectedElems - group of elements to which the replicated nodes
3993 # should be associated to.
3994 # @param theMakeGroup forces the generation of a group containing new elements.
3995 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
3996 # @return TRUE or created groups (one or two) if operation has been completed successfully,
3997 # FALSE or None otherwise
3998 # @ingroup l2_modif_edit
3999 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4000 theMakeGroup=False, theMakeNodeGroup=False):
4001 if theMakeGroup or theMakeNodeGroup:
4002 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4004 theMakeGroup, theMakeNodeGroup)
4005 if theMakeGroup and theMakeNodeGroup:
4008 return twoGroups[ int(theMakeNodeGroup) ]
4009 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4011 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4012 # This method provided for convenience works as DoubleNodes() described above.
4013 # @param theElems - group of of elements (edges or faces) to be replicated
4014 # @param theNodesNot - group of nodes not to replicated
4015 # @param theShape - shape to detect affected elements (element which geometric center
4016 # located on or inside shape).
4017 # The replicated nodes should be associated to affected elements.
4018 # @ingroup l2_modif_edit
4019 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4020 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4022 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4023 # This method provided for convenience works as DoubleNodes() described above.
4024 # @param theElems - list of groups of elements (edges or faces) to be replicated
4025 # @param theNodesNot - list of groups of nodes not to replicated
4026 # @param theAffectedElems - group of elements to which the replicated nodes
4027 # should be associated to.
4028 # @param theMakeGroup forces the generation of a group containing new elements.
4029 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
4030 # @return TRUE or created groups (one or two) if operation has been completed successfully,
4031 # FALSE or None otherwise
4032 # @ingroup l2_modif_edit
4033 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4034 theMakeGroup=False, theMakeNodeGroup=False):
4035 if theMakeGroup or theMakeNodeGroup:
4036 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4038 theMakeGroup, theMakeNodeGroup)
4039 if theMakeGroup and theMakeNodeGroup:
4042 return twoGroups[ int(theMakeNodeGroup) ]
4043 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4045 ## Creates a hole in a mesh by doubling the nodes of some particular elements
4046 # This method provided for convenience works as DoubleNodes() described above.
4047 # @param theElems - list of groups of elements (edges or faces) to be replicated
4048 # @param theNodesNot - list of groups of nodes not to replicated
4049 # @param theShape - shape to detect affected elements (element which geometric center
4050 # located on or inside shape).
4051 # The replicated nodes should be associated to affected elements.
4052 # @return TRUE if operation has been completed successfully, FALSE otherwise
4053 # @ingroup l2_modif_edit
4054 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4055 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4057 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4058 # This method is the first step of DoubleNodeElemGroupsInRegion.
4059 # @param theElems - list of groups of elements (edges or faces) to be replicated
4060 # @param theNodesNot - list of groups of nodes not to replicated
4061 # @param theShape - shape to detect affected elements (element which geometric center
4062 # located on or inside shape).
4063 # The replicated nodes should be associated to affected elements.
4064 # @return groups of affected elements
4065 # @ingroup l2_modif_edit
4066 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4067 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4069 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4070 # The list of groups must describe a partition of the mesh volumes.
4071 # The nodes of the internal faces at the boundaries of the groups are doubled.
4072 # In option, the internal faces are replaced by flat elements.
4073 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4074 # @param theDomains - list of groups of volumes
4075 # @param createJointElems - if TRUE, create the elements
4076 # @return TRUE if operation has been completed successfully, FALSE otherwise
4077 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4078 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4080 ## Double nodes on some external faces and create flat elements.
4081 # Flat elements are mainly used by some types of mechanic calculations.
4083 # Each group of the list must be constituted of faces.
4084 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4085 # @param theGroupsOfFaces - list of groups of faces
4086 # @return TRUE if operation has been completed successfully, FALSE otherwise
4087 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4088 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4090 ## identify all the elements around a geom shape, get the faces delimiting the hole
4092 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4093 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4095 def _getFunctor(self, funcType ):
4096 fn = self.functors[ funcType._v ]
4098 fn = self.smeshpyD.GetFunctor(funcType)
4099 fn.SetMesh(self.mesh)
4100 self.functors[ funcType._v ] = fn
4103 def _valueFromFunctor(self, funcType, elemId):
4104 fn = self._getFunctor( funcType )
4105 if fn.GetElementType() == self.GetElementType(elemId, True):
4106 val = fn.GetValue(elemId)
4111 ## Get length of 1D element.
4112 # @param elemId mesh element ID
4113 # @return element's length value
4114 # @ingroup l1_measurements
4115 def GetLength(self, elemId):
4116 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4118 ## Get area of 2D element.
4119 # @param elemId mesh element ID
4120 # @return element's area value
4121 # @ingroup l1_measurements
4122 def GetArea(self, elemId):
4123 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4125 ## Get volume of 3D element.
4126 # @param elemId mesh element ID
4127 # @return element's volume value
4128 # @ingroup l1_measurements
4129 def GetVolume(self, elemId):
4130 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4132 ## Get maximum element length.
4133 # @param elemId mesh element ID
4134 # @return element's maximum length value
4135 # @ingroup l1_measurements
4136 def GetMaxElementLength(self, elemId):
4137 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4138 ftype = SMESH.FT_MaxElementLength3D
4140 ftype = SMESH.FT_MaxElementLength2D
4141 return self._valueFromFunctor(ftype, elemId)
4143 ## Get aspect ratio of 2D or 3D element.
4144 # @param elemId mesh element ID
4145 # @return element's aspect ratio value
4146 # @ingroup l1_measurements
4147 def GetAspectRatio(self, elemId):
4148 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4149 ftype = SMESH.FT_AspectRatio3D
4151 ftype = SMESH.FT_AspectRatio
4152 return self._valueFromFunctor(ftype, elemId)
4154 ## Get warping angle of 2D element.
4155 # @param elemId mesh element ID
4156 # @return element's warping angle value
4157 # @ingroup l1_measurements
4158 def GetWarping(self, elemId):
4159 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4161 ## Get minimum angle of 2D element.
4162 # @param elemId mesh element ID
4163 # @return element's minimum angle value
4164 # @ingroup l1_measurements
4165 def GetMinimumAngle(self, elemId):
4166 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4168 ## Get taper of 2D element.
4169 # @param elemId mesh element ID
4170 # @return element's taper value
4171 # @ingroup l1_measurements
4172 def GetTaper(self, elemId):
4173 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4175 ## Get skew of 2D element.
4176 # @param elemId mesh element ID
4177 # @return element's skew value
4178 # @ingroup l1_measurements
4179 def GetSkew(self, elemId):
4180 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4182 pass # end of Mesh class
4184 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4186 class Pattern(SMESH._objref_SMESH_Pattern):
4188 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4189 decrFun = lambda i: i-1
4190 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4191 theMesh.SetParameters(Parameters)
4192 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4194 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4195 decrFun = lambda i: i-1
4196 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4197 theMesh.SetParameters(Parameters)
4198 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4200 # Registering the new proxy for Pattern
4201 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4203 ## Private class used to bind methods creating algorithms to the class Mesh
4208 self.defaultAlgoType = ""
4209 self.algoTypeToClass = {}
4211 # Stores a python class of algorithm
4212 def add(self, algoClass):
4213 if type( algoClass ).__name__ == 'classobj' and \
4214 hasattr( algoClass, "algoType"):
4215 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4216 if not self.defaultAlgoType and \
4217 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4218 self.defaultAlgoType = algoClass.algoType
4219 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4221 # creates a copy of self and assign mesh to the copy
4222 def copy(self, mesh):
4223 other = algoCreator()
4224 other.defaultAlgoType = self.defaultAlgoType
4225 other.algoTypeToClass = self.algoTypeToClass
4229 # creates an instance of algorithm
4230 def __call__(self,algo="",geom=0,*args):
4231 algoType = self.defaultAlgoType
4232 for arg in args + (algo,geom):
4233 if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ):
4235 if isinstance( arg, str ) and arg:
4237 if not algoType and self.algoTypeToClass:
4238 algoType = self.algoTypeToClass.keys()[0]
4239 if self.algoTypeToClass.has_key( algoType ):
4240 #print "Create algo",algoType
4241 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4242 raise RuntimeError, "No class found for algo type %s" % algoType
4245 # Private class used to substitute and store variable parameters of hypotheses.
4247 class hypMethodWrapper:
4248 def __init__(self, hyp, method):
4250 self.method = method
4251 #print "REBIND:", method.__name__
4254 # call a method of hypothesis with calling SetVarParameter() before
4255 def __call__(self,*args):
4257 return self.method( self.hyp, *args ) # hypothesis method with no args
4259 #print "MethWrapper.__call__",self.method.__name__, args
4261 parsed = ParseParameters(*args) # replace variables with their values
4262 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4263 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4264 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4265 # maybe there is a replaced string arg which is not variable
4266 result = self.method( self.hyp, *args )
4267 except ValueError, detail: # raised by ParseParameters()
4269 result = self.method( self.hyp, *args )
4270 except omniORB.CORBA.BAD_PARAM:
4271 raise ValueError, detail # wrong variable name