1 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Francis KLOSS, OCC
24 # Python API for SALOME %Mesh module
26 ## @defgroup l1_auxiliary Auxiliary methods and structures
27 ## @defgroup l1_creating Creating meshes
29 ## @defgroup l2_impexp Importing and exporting meshes
30 ## @defgroup l2_construct Constructing meshes
31 ## @defgroup l2_algorithms Defining Algorithms
33 ## @defgroup l3_algos_basic Basic meshing algorithms
34 ## @defgroup l3_algos_proj Projection Algorithms
35 ## @defgroup l3_algos_radialp Radial Prism
36 ## @defgroup l3_algos_segmarv Segments around Vertex
37 ## @defgroup l3_algos_3dextr 3D extrusion meshing algorithm
40 ## @defgroup l2_hypotheses Defining hypotheses
42 ## @defgroup l3_hypos_1dhyps 1D Meshing Hypotheses
43 ## @defgroup l3_hypos_2dhyps 2D Meshing Hypotheses
44 ## @defgroup l3_hypos_maxvol Max Element Volume hypothesis
45 ## @defgroup l3_hypos_quad Quadrangle Parameters hypothesis
46 ## @defgroup l3_hypos_additi Additional Hypotheses
49 ## @defgroup l2_submeshes Constructing submeshes
50 ## @defgroup l2_compounds Building Compounds
51 ## @defgroup l2_editing Editing Meshes
54 ## @defgroup l1_meshinfo Mesh Information
55 ## @defgroup l1_controls Quality controls and Filtering
56 ## @defgroup l1_grouping Grouping elements
58 ## @defgroup l2_grps_create Creating groups
59 ## @defgroup l2_grps_edit Editing groups
60 ## @defgroup l2_grps_operon Using operations on groups
61 ## @defgroup l2_grps_delete Deleting Groups
64 ## @defgroup l1_modifying Modifying meshes
66 ## @defgroup l2_modif_add Adding nodes and elements
67 ## @defgroup l2_modif_del Removing nodes and elements
68 ## @defgroup l2_modif_edit Modifying nodes and elements
69 ## @defgroup l2_modif_renumber Renumbering nodes and elements
70 ## @defgroup l2_modif_trsf Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging)
71 ## @defgroup l2_modif_movenode Moving nodes
72 ## @defgroup l2_modif_throughp Mesh through point
73 ## @defgroup l2_modif_invdiag Diagonal inversion of elements
74 ## @defgroup l2_modif_unitetri Uniting triangles
75 ## @defgroup l2_modif_changori Changing orientation of elements
76 ## @defgroup l2_modif_cutquadr Cutting quadrangles
77 ## @defgroup l2_modif_smooth Smoothing
78 ## @defgroup l2_modif_extrurev Extrusion and Revolution
79 ## @defgroup l2_modif_patterns Pattern mapping
80 ## @defgroup l2_modif_tofromqu Convert to/from Quadratic Mesh
83 ## @defgroup l1_measurements Measurements
88 import SMESH # This is necessary for back compatibility
90 from smesh_algorithm import Mesh_Algorithm
95 ## @addtogroup l1_auxiliary
98 # MirrorType enumeration
99 POINT = SMESH_MeshEditor.POINT
100 AXIS = SMESH_MeshEditor.AXIS
101 PLANE = SMESH_MeshEditor.PLANE
103 # Smooth_Method enumeration
104 LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
105 CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
107 PrecisionConfusion = 1e-07
109 # TopAbs_State enumeration
110 [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
112 # Methods of splitting a hexahedron into tetrahedra
113 Hex_5Tet, Hex_6Tet, Hex_24Tet = 1, 2, 3
115 ## Converts an angle from degrees to radians
116 def DegreesToRadians(AngleInDegrees):
118 return AngleInDegrees * pi / 180.0
120 import salome_notebook
121 notebook = salome_notebook.notebook
122 # Salome notebook variable separator
125 ## Return list of variable values from salome notebook.
126 # The last argument, if is callable, is used to modify values got from notebook
127 def ParseParameters(*args):
132 if args and callable( args[-1] ):
133 args, varModifFun = args[:-1], args[-1]
134 for parameter in args:
136 Parameters += str(parameter) + var_separator
138 if isinstance(parameter,str):
139 # check if there is an inexistent variable name
140 if not notebook.isVariable(parameter):
141 raise ValueError, "Variable with name '" + parameter + "' doesn't exist!!!"
142 parameter = notebook.get(parameter)
145 parameter = varModifFun(parameter)
148 Result.append(parameter)
151 Parameters = Parameters[:-1]
152 Result.append( Parameters )
153 Result.append( hasVariables )
156 # Parse parameters converting variables to radians
157 def ParseAngles(*args):
158 return ParseParameters( *( args + (DegreesToRadians, )))
160 # Substitute PointStruct.__init__() to create SMESH.PointStruct using notebook variables.
161 # Parameters are stored in PointStruct.parameters attribute
162 def __initPointStruct(point,*args):
163 point.x, point.y, point.z, point.parameters,hasVars = ParseParameters(*args)
165 SMESH.PointStruct.__init__ = __initPointStruct
167 # Substitute AxisStruct.__init__() to create SMESH.AxisStruct using notebook variables.
168 # Parameters are stored in AxisStruct.parameters attribute
169 def __initAxisStruct(ax,*args):
170 ax.x, ax.y, ax.z, ax.vx, ax.vy, ax.vz, ax.parameters,hasVars = ParseParameters(*args)
172 SMESH.AxisStruct.__init__ = __initAxisStruct
175 def IsEqual(val1, val2, tol=PrecisionConfusion):
176 if abs(val1 - val2) < tol:
186 if isinstance(obj, SALOMEDS._objref_SObject):
189 ior = salome.orb.object_to_string(obj)
192 studies = salome.myStudyManager.GetOpenStudies()
193 for sname in studies:
194 s = salome.myStudyManager.GetStudyByName(sname)
196 sobj = s.FindObjectIOR(ior)
197 if not sobj: continue
198 return sobj.GetName()
199 if hasattr(obj, "GetName"):
200 # unknown CORBA object, having GetName() method
203 # unknown CORBA object, no GetName() method
206 if hasattr(obj, "GetName"):
207 # unknown non-CORBA object, having GetName() method
210 raise RuntimeError, "Null or invalid object"
212 ## Prints error message if a hypothesis was not assigned.
213 def TreatHypoStatus(status, hypName, geomName, isAlgo):
215 hypType = "algorithm"
217 hypType = "hypothesis"
219 if status == HYP_UNKNOWN_FATAL :
220 reason = "for unknown reason"
221 elif status == HYP_INCOMPATIBLE :
222 reason = "this hypothesis mismatches the algorithm"
223 elif status == HYP_NOTCONFORM :
224 reason = "a non-conform mesh would be built"
225 elif status == HYP_ALREADY_EXIST :
226 if isAlgo: return # it does not influence anything
227 reason = hypType + " of the same dimension is already assigned to this shape"
228 elif status == HYP_BAD_DIM :
229 reason = hypType + " mismatches the shape"
230 elif status == HYP_CONCURENT :
231 reason = "there are concurrent hypotheses on sub-shapes"
232 elif status == HYP_BAD_SUBSHAPE :
233 reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
234 elif status == HYP_BAD_GEOMETRY:
235 reason = "geometry mismatches the expectation of the algorithm"
236 elif status == HYP_HIDDEN_ALGO:
237 reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
238 elif status == HYP_HIDING_ALGO:
239 reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
240 elif status == HYP_NEED_SHAPE:
241 reason = "Algorithm can't work without shape"
244 hypName = '"' + hypName + '"'
245 geomName= '"' + geomName+ '"'
246 if status < HYP_UNKNOWN_FATAL and not geomName =='""':
247 print hypName, "was assigned to", geomName,"but", reason
248 elif not geomName == '""':
249 print hypName, "was not assigned to",geomName,":", reason
251 print hypName, "was not assigned:", reason
254 ## Private method. Add geom (sub-shape of the main shape) into the study if not yet there
255 def AssureGeomPublished(mesh, geom, name=''):
256 if not isinstance( geom, geompyDC.GEOM._objref_GEOM_Object ):
258 if not geom.IsSame( mesh.geom ) and \
259 not geom.GetStudyEntry() and \
260 mesh.smeshpyD.GetCurrentStudy():
262 studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
263 if studyID != mesh.geompyD.myStudyId:
264 mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
266 if not name and geom.GetShapeType() != geompyDC.GEOM.COMPOUND:
267 # for all groups SubShapeName() returns "Compound_-1"
268 name = mesh.geompyD.SubShapeName(geom, mesh.geom)
270 name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
272 mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
275 ## Return the first vertex of a geomertical edge by ignoring orienation
276 def FirstVertexOnCurve(edge):
277 from geompy import SubShapeAll, ShapeType, KindOfShape, PointCoordinates
278 vv = SubShapeAll( edge, ShapeType["VERTEX"])
280 raise TypeError, "Given object has no vertices"
281 if len( vv ) == 1: return vv[0]
282 info = KindOfShape(edge)
283 xyz = info[1:4] # coords of the first vertex
284 xyz1 = PointCoordinates( vv[0] )
285 xyz2 = PointCoordinates( vv[1] )
288 dist1 += abs( xyz[i] - xyz1[i] )
289 dist2 += abs( xyz[i] - xyz2[i] )
295 # end of l1_auxiliary
298 # All methods of this class are accessible directly from the smesh.py package.
299 class smeshDC(SMESH._objref_SMESH_Gen):
301 ## Dump component to the Python script
302 # This method overrides IDL function to allow default values for the parameters.
303 def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
304 return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
306 ## Set mode of DumpPython(), \a historical or \a snapshot.
307 # In the \a historical mode, the Python Dump script includes all commands
308 # performed by SMESH engine. In the \a snapshot mode, commands
309 # relating to objects removed from the Study are excluded from the script
310 # as well as commands not influencing the current state of meshes
311 def SetDumpPythonHistorical(self, isHistorical):
312 if isHistorical: val = "true"
314 SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
316 ## Sets the current study and Geometry component
317 # @ingroup l1_auxiliary
318 def init_smesh(self,theStudy,geompyD):
319 self.SetCurrentStudy(theStudy,geompyD)
321 ## Creates an empty Mesh. This mesh can have an underlying geometry.
322 # @param obj the Geometrical object on which the mesh is built. If not defined,
323 # the mesh will have no underlying geometry.
324 # @param name the name for the new mesh.
325 # @return an instance of Mesh class.
326 # @ingroup l2_construct
327 def Mesh(self, obj=0, name=0):
328 if isinstance(obj,str):
330 return Mesh(self,self.geompyD,obj,name)
332 ## Returns a long value from enumeration
333 # Should be used for SMESH.FunctorType enumeration
334 # @ingroup l1_controls
335 def EnumToLong(self,theItem):
338 ## Returns a string representation of the color.
339 # To be used with filters.
340 # @param c color value (SALOMEDS.Color)
341 # @ingroup l1_controls
342 def ColorToString(self,c):
344 if isinstance(c, SALOMEDS.Color):
345 val = "%s;%s;%s" % (c.R, c.G, c.B)
346 elif isinstance(c, str):
349 raise ValueError, "Color value should be of string or SALOMEDS.Color type"
352 ## Gets PointStruct from vertex
353 # @param theVertex a GEOM object(vertex)
354 # @return SMESH.PointStruct
355 # @ingroup l1_auxiliary
356 def GetPointStruct(self,theVertex):
357 [x, y, z] = self.geompyD.PointCoordinates(theVertex)
358 return PointStruct(x,y,z)
360 ## Gets DirStruct from vector
361 # @param theVector a GEOM object(vector)
362 # @return SMESH.DirStruct
363 # @ingroup l1_auxiliary
364 def GetDirStruct(self,theVector):
365 vertices = self.geompyD.SubShapeAll( theVector, geompyDC.ShapeType["VERTEX"] )
366 if(len(vertices) != 2):
367 print "Error: vector object is incorrect."
369 p1 = self.geompyD.PointCoordinates(vertices[0])
370 p2 = self.geompyD.PointCoordinates(vertices[1])
371 pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
372 dirst = DirStruct(pnt)
375 ## Makes DirStruct from a triplet
376 # @param x,y,z vector components
377 # @return SMESH.DirStruct
378 # @ingroup l1_auxiliary
379 def MakeDirStruct(self,x,y,z):
380 pnt = PointStruct(x,y,z)
381 return DirStruct(pnt)
383 ## Get AxisStruct from object
384 # @param theObj a GEOM object (line or plane)
385 # @return SMESH.AxisStruct
386 # @ingroup l1_auxiliary
387 def GetAxisStruct(self,theObj):
388 edges = self.geompyD.SubShapeAll( theObj, geompyDC.ShapeType["EDGE"] )
390 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
391 vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geompyDC.ShapeType["VERTEX"] )
392 vertex1 = self.geompyD.PointCoordinates(vertex1)
393 vertex2 = self.geompyD.PointCoordinates(vertex2)
394 vertex3 = self.geompyD.PointCoordinates(vertex3)
395 vertex4 = self.geompyD.PointCoordinates(vertex4)
396 v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
397 v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
398 normal = [ v1[1]*v2[2]-v2[1]*v1[2], v1[2]*v2[0]-v2[2]*v1[0], v1[0]*v2[1]-v2[0]*v1[1] ]
399 axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
401 elif len(edges) == 1:
402 vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geompyDC.ShapeType["VERTEX"] )
403 p1 = self.geompyD.PointCoordinates( vertex1 )
404 p2 = self.geompyD.PointCoordinates( vertex2 )
405 axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
409 # From SMESH_Gen interface:
410 # ------------------------
412 ## Sets the given name to the object
413 # @param obj the object to rename
414 # @param name a new object name
415 # @ingroup l1_auxiliary
416 def SetName(self, obj, name):
417 if isinstance( obj, Mesh ):
419 elif isinstance( obj, Mesh_Algorithm ):
420 obj = obj.GetAlgorithm()
421 ior = salome.orb.object_to_string(obj)
422 SMESH._objref_SMESH_Gen.SetName(self, ior, name)
424 ## Sets the current mode
425 # @ingroup l1_auxiliary
426 def SetEmbeddedMode( self,theMode ):
427 #self.SetEmbeddedMode(theMode)
428 SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
430 ## Gets the current mode
431 # @ingroup l1_auxiliary
432 def IsEmbeddedMode(self):
433 #return self.IsEmbeddedMode()
434 return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
436 ## Sets the current study
437 # @ingroup l1_auxiliary
438 def SetCurrentStudy( self, theStudy, geompyD = None ):
439 #self.SetCurrentStudy(theStudy)
442 geompyD = geompy.geom
445 self.SetGeomEngine(geompyD)
446 SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
449 notebook = salome_notebook.NoteBook( theStudy )
451 notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
453 ## Gets the current study
454 # @ingroup l1_auxiliary
455 def GetCurrentStudy(self):
456 #return self.GetCurrentStudy()
457 return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
459 ## Creates a Mesh object importing data from the given UNV file
460 # @return an instance of Mesh class
462 def CreateMeshesFromUNV( self,theFileName ):
463 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
464 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
467 ## Creates a Mesh object(s) importing data from the given MED file
468 # @return a list of Mesh class instances
470 def CreateMeshesFromMED( self,theFileName ):
471 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
473 for iMesh in range(len(aSmeshMeshes)) :
474 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
475 aMeshes.append(aMesh)
476 return aMeshes, aStatus
478 ## Creates a Mesh object(s) importing data from the given SAUV file
479 # @return a list of Mesh class instances
481 def CreateMeshesFromSAUV( self,theFileName ):
482 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
484 for iMesh in range(len(aSmeshMeshes)) :
485 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
486 aMeshes.append(aMesh)
487 return aMeshes, aStatus
489 ## Creates a Mesh object importing data from the given STL file
490 # @return an instance of Mesh class
492 def CreateMeshesFromSTL( self, theFileName ):
493 aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
494 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
497 ## Creates Mesh objects importing data from the given CGNS file
498 # @return an instance of Mesh class
500 def CreateMeshesFromCGNS( self, theFileName ):
501 aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
503 for iMesh in range(len(aSmeshMeshes)) :
504 aMesh = Mesh(self, self.geompyD, aSmeshMeshes[iMesh])
505 aMeshes.append(aMesh)
506 return aMeshes, aStatus
508 ## Concatenate the given meshes into one mesh.
509 # @return an instance of Mesh class
510 # @param meshes the meshes to combine into one mesh
511 # @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
512 # @param mergeNodesAndElements if true, equal nodes and elements aremerged
513 # @param mergeTolerance tolerance for merging nodes
514 # @param allGroups forces creation of groups of all elements
515 def Concatenate( self, meshes, uniteIdenticalGroups,
516 mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False):
517 if not meshes: return None
518 for i,m in enumerate(meshes):
519 if isinstance(m, Mesh):
520 meshes[i] = m.GetMesh()
521 mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
522 meshes[0].SetParameters(Parameters)
524 aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
525 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
527 aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
528 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
529 aMesh = Mesh(self, self.geompyD, aSmeshMesh)
532 ## Create a mesh by copying a part of another mesh.
533 # @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
534 # to copy nodes or elements not contained in any mesh object,
535 # pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
536 # @param meshName a name of the new mesh
537 # @param toCopyGroups to create in the new mesh groups the copied elements belongs to
538 # @param toKeepIDs to preserve IDs of the copied elements or not
539 # @return an instance of Mesh class
540 def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
541 if (isinstance( meshPart, Mesh )):
542 meshPart = meshPart.GetMesh()
543 mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
544 return Mesh(self, self.geompyD, mesh)
546 ## From SMESH_Gen interface
547 # @return the list of integer values
548 # @ingroup l1_auxiliary
549 def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
550 return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
552 ## From SMESH_Gen interface. Creates a pattern
553 # @return an instance of SMESH_Pattern
555 # <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
556 # @ingroup l2_modif_patterns
557 def GetPattern(self):
558 return SMESH._objref_SMESH_Gen.GetPattern(self)
560 ## Sets number of segments per diagonal of boundary box of geometry by which
561 # default segment length of appropriate 1D hypotheses is defined.
562 # Default value is 10
563 # @ingroup l1_auxiliary
564 def SetBoundaryBoxSegmentation(self, nbSegments):
565 SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
567 # Filtering. Auxiliary functions:
568 # ------------------------------
570 ## Creates an empty criterion
571 # @return SMESH.Filter.Criterion
572 # @ingroup l1_controls
573 def GetEmptyCriterion(self):
574 Type = self.EnumToLong(FT_Undefined)
575 Compare = self.EnumToLong(FT_Undefined)
579 UnaryOp = self.EnumToLong(FT_Undefined)
580 BinaryOp = self.EnumToLong(FT_Undefined)
583 Precision = -1 ##@1e-07
584 return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
585 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
587 ## Creates a criterion by the given parameters
588 # \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
589 # @param elementType the type of elements(NODE, EDGE, FACE, VOLUME)
590 # @param CritType the type of criterion (FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc.)
591 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
592 # @param Threshold the threshold value (range of ids as string, shape, numeric)
593 # @param UnaryOp FT_LogicalNOT or FT_Undefined
594 # @param BinaryOp a binary logical operation FT_LogicalAND, FT_LogicalOR or
595 # FT_Undefined (must be for the last criterion of all criteria)
596 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
597 # FT_LyingOnGeom, FT_CoplanarFaces criteria
598 # @return SMESH.Filter.Criterion
600 # <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
601 # @ingroup l1_controls
602 def GetCriterion(self,elementType,
604 Compare = FT_EqualTo,
606 UnaryOp=FT_Undefined,
607 BinaryOp=FT_Undefined,
609 if not CritType in SMESH.FunctorType._items:
610 raise TypeError, "CritType should be of SMESH.FunctorType"
611 aCriterion = self.GetEmptyCriterion()
612 aCriterion.TypeOfElement = elementType
613 aCriterion.Type = self.EnumToLong(CritType)
614 aCriterion.Tolerance = Tolerance
616 aThreshold = Threshold
618 if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
619 aCriterion.Compare = self.EnumToLong(Compare)
620 elif Compare == "=" or Compare == "==":
621 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
623 aCriterion.Compare = self.EnumToLong(FT_LessThan)
625 aCriterion.Compare = self.EnumToLong(FT_MoreThan)
626 elif Compare != FT_Undefined:
627 aCriterion.Compare = self.EnumToLong(FT_EqualTo)
630 if CritType in [FT_BelongToGeom, FT_BelongToPlane, FT_BelongToGenSurface,
631 FT_BelongToCylinder, FT_LyingOnGeom]:
632 # Checks that Threshold is GEOM object
633 if isinstance(aThreshold, geompyDC.GEOM._objref_GEOM_Object):
634 aCriterion.ThresholdStr = GetName(aThreshold)
635 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
636 if not aCriterion.ThresholdID:
637 raise RuntimeError, "Threshold shape must be published"
639 print "Error: The Threshold should be a shape."
641 if isinstance(UnaryOp,float):
642 aCriterion.Tolerance = UnaryOp
643 UnaryOp = FT_Undefined
645 elif CritType == FT_RangeOfIds:
646 # Checks that Threshold is string
647 if isinstance(aThreshold, str):
648 aCriterion.ThresholdStr = aThreshold
650 print "Error: The Threshold should be a string."
652 elif CritType == FT_CoplanarFaces:
653 # Checks the Threshold
654 if isinstance(aThreshold, int):
655 aCriterion.ThresholdID = str(aThreshold)
656 elif isinstance(aThreshold, str):
659 raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
660 aCriterion.ThresholdID = aThreshold
663 "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
664 elif CritType == FT_ElemGeomType:
665 # Checks the Threshold
667 aCriterion.Threshold = self.EnumToLong(aThreshold)
668 assert( aThreshold in SMESH.GeometryType._items )
670 if isinstance(aThreshold, int):
671 aCriterion.Threshold = aThreshold
673 print "Error: The Threshold should be an integer or SMESH.GeometryType."
677 elif CritType == FT_GroupColor:
678 # Checks the Threshold
680 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
682 print "Error: The threshold value should be of SALOMEDS.Color type"
685 elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
686 FT_LinearOrQuadratic, FT_BadOrientedVolume,
687 FT_BareBorderFace, FT_BareBorderVolume,
688 FT_OverConstrainedFace, FT_OverConstrainedVolume,
689 FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
690 # At this point the Threshold is unnecessary
691 if aThreshold == FT_LogicalNOT:
692 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
693 elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
694 aCriterion.BinaryOp = aThreshold
698 aThreshold = float(aThreshold)
699 aCriterion.Threshold = aThreshold
701 print "Error: The Threshold should be a number."
704 if Threshold == FT_LogicalNOT or UnaryOp == FT_LogicalNOT:
705 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
707 if Threshold in [FT_LogicalAND, FT_LogicalOR]:
708 aCriterion.BinaryOp = self.EnumToLong(Threshold)
710 if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
711 aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
713 if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
714 aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
718 ## Creates a filter with the given parameters
719 # @param elementType the type of elements in the group
720 # @param CritType the type of criterion ( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
721 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
722 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
723 # @param UnaryOp FT_LogicalNOT or FT_Undefined
724 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
725 # FT_LyingOnGeom, FT_CoplanarFaces and FT_EqualNodes criteria
726 # @return SMESH_Filter
728 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
729 # @ingroup l1_controls
730 def GetFilter(self,elementType,
731 CritType=FT_Undefined,
734 UnaryOp=FT_Undefined,
736 aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
737 aFilterMgr = self.CreateFilterManager()
738 aFilter = aFilterMgr.CreateFilter()
740 aCriteria.append(aCriterion)
741 aFilter.SetCriteria(aCriteria)
742 aFilterMgr.UnRegister()
745 ## Creates a filter from criteria
746 # @param criteria a list of criteria
747 # @return SMESH_Filter
749 # <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
750 # @ingroup l1_controls
751 def GetFilterFromCriteria(self,criteria):
752 aFilterMgr = self.CreateFilterManager()
753 aFilter = aFilterMgr.CreateFilter()
754 aFilter.SetCriteria(criteria)
755 aFilterMgr.UnRegister()
758 ## Creates a numerical functor by its type
759 # @param theCriterion FT_...; functor type
760 # @return SMESH_NumericalFunctor
761 # @ingroup l1_controls
762 def GetFunctor(self,theCriterion):
763 aFilterMgr = self.CreateFilterManager()
764 if theCriterion == FT_AspectRatio:
765 return aFilterMgr.CreateAspectRatio()
766 elif theCriterion == FT_AspectRatio3D:
767 return aFilterMgr.CreateAspectRatio3D()
768 elif theCriterion == FT_Warping:
769 return aFilterMgr.CreateWarping()
770 elif theCriterion == FT_MinimumAngle:
771 return aFilterMgr.CreateMinimumAngle()
772 elif theCriterion == FT_Taper:
773 return aFilterMgr.CreateTaper()
774 elif theCriterion == FT_Skew:
775 return aFilterMgr.CreateSkew()
776 elif theCriterion == FT_Area:
777 return aFilterMgr.CreateArea()
778 elif theCriterion == FT_Volume3D:
779 return aFilterMgr.CreateVolume3D()
780 elif theCriterion == FT_MaxElementLength2D:
781 return aFilterMgr.CreateMaxElementLength2D()
782 elif theCriterion == FT_MaxElementLength3D:
783 return aFilterMgr.CreateMaxElementLength3D()
784 elif theCriterion == FT_MultiConnection:
785 return aFilterMgr.CreateMultiConnection()
786 elif theCriterion == FT_MultiConnection2D:
787 return aFilterMgr.CreateMultiConnection2D()
788 elif theCriterion == FT_Length:
789 return aFilterMgr.CreateLength()
790 elif theCriterion == FT_Length2D:
791 return aFilterMgr.CreateLength2D()
793 print "Error: given parameter is not numerical functor type."
795 ## Creates hypothesis
796 # @param theHType mesh hypothesis type (string)
797 # @param theLibName mesh plug-in library name
798 # @return created hypothesis instance
799 def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
800 hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
802 if isinstance( hyp, SMESH._objref_SMESH_Algo ):
805 # wrap hypothesis methods
806 #print "HYPOTHESIS", theHType
807 for meth_name in dir( hyp.__class__ ):
808 if not meth_name.startswith("Get") and \
809 not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
810 method = getattr ( hyp.__class__, meth_name )
812 setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
816 ## Gets the mesh statistic
817 # @return dictionary "element type" - "count of elements"
818 # @ingroup l1_meshinfo
819 def GetMeshInfo(self, obj):
820 if isinstance( obj, Mesh ):
823 if hasattr(obj, "GetMeshInfo"):
824 values = obj.GetMeshInfo()
825 for i in range(SMESH.Entity_Last._v):
826 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
830 ## Get minimum distance between two objects
832 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
833 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
835 # @param src1 first source object
836 # @param src2 second source object
837 # @param id1 node/element id from the first source
838 # @param id2 node/element id from the second (or first) source
839 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
840 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
841 # @return minimum distance value
842 # @sa GetMinDistance()
843 # @ingroup l1_measurements
844 def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
845 result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
849 result = result.value
852 ## Get measure structure specifying minimum distance data between two objects
854 # If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
855 # If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
857 # @param src1 first source object
858 # @param src2 second source object
859 # @param id1 node/element id from the first source
860 # @param id2 node/element id from the second (or first) source
861 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
862 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
863 # @return Measure structure or None if input data is invalid
865 # @ingroup l1_measurements
866 def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
867 if isinstance(src1, Mesh): src1 = src1.mesh
868 if isinstance(src2, Mesh): src2 = src2.mesh
869 if src2 is None and id2 != 0: src2 = src1
870 if not hasattr(src1, "_narrow"): return None
871 src1 = src1._narrow(SMESH.SMESH_IDSource)
872 if not src1: return None
875 e = m.GetMeshEditor()
877 src1 = e.MakeIDSource([id1], SMESH.FACE)
879 src1 = e.MakeIDSource([id1], SMESH.NODE)
881 if hasattr(src2, "_narrow"):
882 src2 = src2._narrow(SMESH.SMESH_IDSource)
883 if src2 and id2 != 0:
885 e = m.GetMeshEditor()
887 src2 = e.MakeIDSource([id2], SMESH.FACE)
889 src2 = e.MakeIDSource([id2], SMESH.NODE)
892 aMeasurements = self.CreateMeasurements()
893 result = aMeasurements.MinDistance(src1, src2)
894 aMeasurements.UnRegister()
897 ## Get bounding box of the specified object(s)
898 # @param objects single source object or list of source objects
899 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
900 # @sa GetBoundingBox()
901 # @ingroup l1_measurements
902 def BoundingBox(self, objects):
903 result = self.GetBoundingBox(objects)
907 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
910 ## Get measure structure specifying bounding box data of the specified object(s)
911 # @param objects single source object or list of source objects
912 # @return Measure structure
914 # @ingroup l1_measurements
915 def GetBoundingBox(self, objects):
916 if isinstance(objects, tuple):
917 objects = list(objects)
918 if not isinstance(objects, list):
922 if isinstance(o, Mesh):
923 srclist.append(o.mesh)
924 elif hasattr(o, "_narrow"):
925 src = o._narrow(SMESH.SMESH_IDSource)
926 if src: srclist.append(src)
929 aMeasurements = self.CreateMeasurements()
930 result = aMeasurements.BoundingBox(srclist)
931 aMeasurements.UnRegister()
935 #Registering the new proxy for SMESH_Gen
936 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
942 ## This class allows defining and managing a mesh.
943 # It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
944 # It also has methods to define groups of mesh elements, to modify a mesh (by addition of
945 # new nodes and elements and by changing the existing entities), to get information
946 # about a mesh and to export a mesh into different formats.
955 # Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
956 # sets the GUI name of this mesh to \a name.
957 # @param smeshpyD an instance of smeshDC class
958 # @param geompyD an instance of geompyDC class
959 # @param obj Shape to be meshed or SMESH_Mesh object
960 # @param name Study name of the mesh
961 # @ingroup l2_construct
962 def __init__(self, smeshpyD, geompyD, obj=0, name=0):
963 self.smeshpyD=smeshpyD
969 if isinstance(obj, geompyDC.GEOM._objref_GEOM_Object):
971 # publish geom of mesh (issue 0021122)
972 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
974 studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
975 if studyID != geompyD.myStudyId:
976 geompyD.init_geom( smeshpyD.GetCurrentStudy())
978 geo_name = "%s_%s_for_meshing"%(self.geom.GetShapeType(), id(self.geom)%100)
979 geompyD.addToStudy( self.geom, geo_name )
980 self.mesh = self.smeshpyD.CreateMesh(self.geom)
982 elif isinstance(obj, SMESH._objref_SMESH_Mesh):
985 self.mesh = self.smeshpyD.CreateEmptyMesh()
987 self.smeshpyD.SetName(self.mesh, name)
988 elif obj != 0 and objHasName:
989 self.smeshpyD.SetName(self.mesh, GetName(obj))
992 self.geom = self.mesh.GetShapeToMesh()
994 self.editor = self.mesh.GetMeshEditor()
996 # set self to algoCreator's
997 for attrName in dir(self):
998 attr = getattr( self, attrName )
999 if isinstance( attr, algoCreator ):
1000 setattr( self, attrName, attr.copy( self ))
1002 ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1003 # @param theMesh a SMESH_Mesh object
1004 # @ingroup l2_construct
1005 def SetMesh(self, theMesh):
1007 self.geom = self.mesh.GetShapeToMesh()
1009 ## Returns the mesh, that is an instance of SMESH_Mesh interface
1010 # @return a SMESH_Mesh object
1011 # @ingroup l2_construct
1015 ## Gets the name of the mesh
1016 # @return the name of the mesh as a string
1017 # @ingroup l2_construct
1019 name = GetName(self.GetMesh())
1022 ## Sets a name to the mesh
1023 # @param name a new name of the mesh
1024 # @ingroup l2_construct
1025 def SetName(self, name):
1026 self.smeshpyD.SetName(self.GetMesh(), name)
1028 ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1029 # The subMesh object gives access to the IDs of nodes and elements.
1030 # @param geom a geometrical object (shape)
1031 # @param name a name for the submesh
1032 # @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1033 # @ingroup l2_submeshes
1034 def GetSubMesh(self, geom, name):
1035 AssureGeomPublished( self, geom, name )
1036 submesh = self.mesh.GetSubMesh( geom, name )
1039 ## Returns the shape associated to the mesh
1040 # @return a GEOM_Object
1041 # @ingroup l2_construct
1045 ## Associates the given shape to the mesh (entails the recreation of the mesh)
1046 # @param geom the shape to be meshed (GEOM_Object)
1047 # @ingroup l2_construct
1048 def SetShape(self, geom):
1049 self.mesh = self.smeshpyD.CreateMesh(geom)
1051 ## Loads mesh from the study after opening the study
1055 ## Returns true if the hypotheses are defined well
1056 # @param theSubObject a sub-shape of a mesh shape
1057 # @return True or False
1058 # @ingroup l2_construct
1059 def IsReadyToCompute(self, theSubObject):
1060 return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1062 ## Returns errors of hypotheses definition.
1063 # The list of errors is empty if everything is OK.
1064 # @param theSubObject a sub-shape of a mesh shape
1065 # @return a list of errors
1066 # @ingroup l2_construct
1067 def GetAlgoState(self, theSubObject):
1068 return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1070 ## Returns a geometrical object on which the given element was built.
1071 # The returned geometrical object, if not nil, is either found in the
1072 # study or published by this method with the given name
1073 # @param theElementID the id of the mesh element
1074 # @param theGeomName the user-defined name of the geometrical object
1075 # @return GEOM::GEOM_Object instance
1076 # @ingroup l2_construct
1077 def GetGeometryByMeshElement(self, theElementID, theGeomName):
1078 return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1080 ## Returns the mesh dimension depending on the dimension of the underlying shape
1081 # @return mesh dimension as an integer value [0,3]
1082 # @ingroup l1_auxiliary
1083 def MeshDimension(self):
1084 shells = self.geompyD.SubShapeAllIDs( self.geom, geompyDC.ShapeType["SHELL"] )
1085 if len( shells ) > 0 :
1087 elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1089 elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1095 ## Evaluates size of prospective mesh on a shape
1096 # @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1097 # To know predicted number of e.g. edges, inquire it this way
1098 # Evaluate()[ EnumToLong( Entity_Edge )]
1099 def Evaluate(self, geom=0):
1100 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1102 geom = self.mesh.GetShapeToMesh()
1105 return self.smeshpyD.Evaluate(self.mesh, geom)
1108 ## Computes the mesh and returns the status of the computation
1109 # @param geom geomtrical shape on which mesh data should be computed
1110 # @param discardModifs if True and the mesh has been edited since
1111 # a last total re-compute and that may prevent successful partial re-compute,
1112 # then the mesh is cleaned before Compute()
1113 # @return True or False
1114 # @ingroup l2_construct
1115 def Compute(self, geom=0, discardModifs=False):
1116 if geom == 0 or not isinstance(geom, geompyDC.GEOM._objref_GEOM_Object):
1118 geom = self.mesh.GetShapeToMesh()
1123 if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1125 ok = self.smeshpyD.Compute(self.mesh, geom)
1126 except SALOME.SALOME_Exception, ex:
1127 print "Mesh computation failed, exception caught:"
1128 print " ", ex.details.text
1131 print "Mesh computation failed, exception caught:"
1132 traceback.print_exc()
1136 # Treat compute errors
1137 computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1138 for err in computeErrors:
1140 if self.mesh.HasShapeToMesh():
1142 mainIOR = salome.orb.object_to_string(geom)
1143 for sname in salome.myStudyManager.GetOpenStudies():
1144 s = salome.myStudyManager.GetStudyByName(sname)
1146 mainSO = s.FindObjectIOR(mainIOR)
1147 if not mainSO: continue
1148 if err.subShapeID == 1:
1149 shapeText = ' on "%s"' % mainSO.GetName()
1150 subIt = s.NewChildIterator(mainSO)
1152 subSO = subIt.Value()
1154 obj = subSO.GetObject()
1155 if not obj: continue
1156 go = obj._narrow( geompyDC.GEOM._objref_GEOM_Object )
1158 ids = go.GetSubShapeIndices()
1159 if len(ids) == 1 and ids[0] == err.subShapeID:
1160 shapeText = ' on "%s"' % subSO.GetName()
1163 shape = self.geompyD.GetSubShape( geom, [err.subShapeID])
1165 shapeText = " on %s #%s" % (shape.GetShapeType(), err.subShapeID)
1167 shapeText = " on subshape #%s" % (err.subShapeID)
1169 shapeText = " on subshape #%s" % (err.subShapeID)
1171 stdErrors = ["OK", #COMPERR_OK
1172 "Invalid input mesh", #COMPERR_BAD_INPUT_MESH
1173 "std::exception", #COMPERR_STD_EXCEPTION
1174 "OCC exception", #COMPERR_OCC_EXCEPTION
1175 "SALOME exception", #COMPERR_SLM_EXCEPTION
1176 "Unknown exception", #COMPERR_EXCEPTION
1177 "Memory allocation problem", #COMPERR_MEMORY_PB
1178 "Algorithm failed", #COMPERR_ALGO_FAILED
1179 "Unexpected geometry", #COMPERR_BAD_SHAPE
1180 "Warning", #COMPERR_WARNING
1181 "Computation cancelled",#COMPERR_CANCELED
1182 "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1184 if err.code < len(stdErrors): errText = stdErrors[err.code]
1186 errText = "code %s" % -err.code
1187 if errText: errText += ". "
1188 errText += err.comment
1189 if allReasons != "":allReasons += "\n"
1190 allReasons += '- "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1194 errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1196 if err.isGlobalAlgo:
1204 reason = '%s %sD algorithm is missing' % (glob, dim)
1205 elif err.state == HYP_MISSING:
1206 reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1207 % (glob, dim, name, dim))
1208 elif err.state == HYP_NOTCONFORM:
1209 reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1210 elif err.state == HYP_BAD_PARAMETER:
1211 reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1212 % ( glob, dim, name ))
1213 elif err.state == HYP_BAD_GEOMETRY:
1214 reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1215 'geometry' % ( glob, dim, name ))
1217 reason = "For unknown reason."+\
1218 " Revise Mesh.Compute() implementation in smeshDC.py!"
1220 if allReasons != "":allReasons += "\n"
1221 allReasons += "- " + reason
1223 if not ok or allReasons != "":
1224 msg = '"' + GetName(self.mesh) + '"'
1225 if ok: msg += " has been computed with warnings"
1226 else: msg += " has not been computed"
1227 if allReasons != "": msg += ":"
1232 if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1233 smeshgui = salome.ImportComponentGUI("SMESH")
1234 smeshgui.Init(self.mesh.GetStudyId())
1235 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1236 salome.sg.updateObjBrowser(1)
1240 ## Return submesh objects list in meshing order
1241 # @return list of list of submesh objects
1242 # @ingroup l2_construct
1243 def GetMeshOrder(self):
1244 return self.mesh.GetMeshOrder()
1246 ## Return submesh objects list in meshing order
1247 # @return list of list of submesh objects
1248 # @ingroup l2_construct
1249 def SetMeshOrder(self, submeshes):
1250 return self.mesh.SetMeshOrder(submeshes)
1252 ## Removes all nodes and elements
1253 # @ingroup l2_construct
1256 if salome.sg.hasDesktop():
1257 smeshgui = salome.ImportComponentGUI("SMESH")
1258 smeshgui.Init(self.mesh.GetStudyId())
1259 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1260 salome.sg.updateObjBrowser(1)
1262 ## Removes all nodes and elements of indicated shape
1263 # @ingroup l2_construct
1264 def ClearSubMesh(self, geomId):
1265 self.mesh.ClearSubMesh(geomId)
1266 if salome.sg.hasDesktop():
1267 smeshgui = salome.ImportComponentGUI("SMESH")
1268 smeshgui.Init(self.mesh.GetStudyId())
1269 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1270 salome.sg.updateObjBrowser(1)
1272 ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + NETGEN
1273 # @param fineness [0.0,1.0] defines mesh fineness
1274 # @return True or False
1275 # @ingroup l3_algos_basic
1276 def AutomaticTetrahedralization(self, fineness=0):
1277 dim = self.MeshDimension()
1279 self.RemoveGlobalHypotheses()
1280 self.Segment().AutomaticLength(fineness)
1282 self.Triangle().LengthFromEdges()
1285 from NETGENPluginDC import NETGEN
1286 self.Tetrahedron(NETGEN)
1288 return self.Compute()
1290 ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1291 # @param fineness [0.0, 1.0] defines mesh fineness
1292 # @return True or False
1293 # @ingroup l3_algos_basic
1294 def AutomaticHexahedralization(self, fineness=0):
1295 dim = self.MeshDimension()
1296 # assign the hypotheses
1297 self.RemoveGlobalHypotheses()
1298 self.Segment().AutomaticLength(fineness)
1305 return self.Compute()
1307 ## Assigns a hypothesis
1308 # @param hyp a hypothesis to assign
1309 # @param geom a subhape of mesh geometry
1310 # @return SMESH.Hypothesis_Status
1311 # @ingroup l2_hypotheses
1312 def AddHypothesis(self, hyp, geom=0):
1313 if isinstance( hyp, Mesh_Algorithm ):
1314 hyp = hyp.GetAlgorithm()
1319 geom = self.mesh.GetShapeToMesh()
1321 AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1322 status = self.mesh.AddHypothesis(geom, hyp)
1323 isAlgo = hyp._narrow( SMESH_Algo )
1324 hyp_name = GetName( hyp )
1327 geom_name = GetName( geom )
1328 TreatHypoStatus( status, hyp_name, geom_name, isAlgo )
1331 ## Return True if an algorithm of hypothesis is assigned to a given shape
1332 # @param hyp a hypothesis to check
1333 # @param geom a subhape of mesh geometry
1334 # @return True of False
1335 # @ingroup l2_hypotheses
1336 def IsUsedHypothesis(self, hyp, geom):
1337 if not hyp or not geom:
1339 if isinstance( hyp, Mesh_Algorithm ):
1340 hyp = hyp.GetAlgorithm()
1342 hyps = self.GetHypothesisList(geom)
1344 if h.GetId() == hyp.GetId():
1348 ## Unassigns a hypothesis
1349 # @param hyp a hypothesis to unassign
1350 # @param geom a sub-shape of mesh geometry
1351 # @return SMESH.Hypothesis_Status
1352 # @ingroup l2_hypotheses
1353 def RemoveHypothesis(self, hyp, geom=0):
1354 if isinstance( hyp, Mesh_Algorithm ):
1355 hyp = hyp.GetAlgorithm()
1360 status = self.mesh.RemoveHypothesis(geom, hyp)
1363 ## Gets the list of hypotheses added on a geometry
1364 # @param geom a sub-shape of mesh geometry
1365 # @return the sequence of SMESH_Hypothesis
1366 # @ingroup l2_hypotheses
1367 def GetHypothesisList(self, geom):
1368 return self.mesh.GetHypothesisList( geom )
1370 ## Removes all global hypotheses
1371 # @ingroup l2_hypotheses
1372 def RemoveGlobalHypotheses(self):
1373 current_hyps = self.mesh.GetHypothesisList( self.geom )
1374 for hyp in current_hyps:
1375 self.mesh.RemoveHypothesis( self.geom, hyp )
1379 ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1380 ## allowing to overwrite the file if it exists or add the exported data to its contents
1381 # @param f is the file name
1382 # @param auto_groups boolean parameter for creating/not creating
1383 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1384 # the typical use is auto_groups=false.
1385 # @param version MED format version(MED_V2_1 or MED_V2_2)
1386 # @param overwrite boolean parameter for overwriting/not overwriting the file
1387 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1388 # @ingroup l2_impexp
1389 def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
1391 if isinstance( meshPart, list ):
1392 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1393 self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
1395 self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
1397 ## Exports the mesh in a file in SAUV format
1398 # @param f is the file name
1399 # @param auto_groups boolean parameter for creating/not creating
1400 # the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1401 # the typical use is auto_groups=false.
1402 # @ingroup l2_impexp
1403 def ExportSAUV(self, f, auto_groups=0):
1404 self.mesh.ExportSAUV(f, auto_groups)
1406 ## Exports the mesh in a file in DAT format
1407 # @param f the file name
1408 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1409 # @ingroup l2_impexp
1410 def ExportDAT(self, f, meshPart=None):
1412 if isinstance( meshPart, list ):
1413 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1414 self.mesh.ExportPartToDAT( meshPart, f )
1416 self.mesh.ExportDAT(f)
1418 ## Exports the mesh in a file in UNV format
1419 # @param f the file name
1420 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1421 # @ingroup l2_impexp
1422 def ExportUNV(self, f, meshPart=None):
1424 if isinstance( meshPart, list ):
1425 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1426 self.mesh.ExportPartToUNV( meshPart, f )
1428 self.mesh.ExportUNV(f)
1430 ## Export the mesh in a file in STL format
1431 # @param f the file name
1432 # @param ascii defines the file encoding
1433 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1434 # @ingroup l2_impexp
1435 def ExportSTL(self, f, ascii=1, meshPart=None):
1437 if isinstance( meshPart, list ):
1438 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1439 self.mesh.ExportPartToSTL( meshPart, f, ascii )
1441 self.mesh.ExportSTL(f, ascii)
1443 ## Exports the mesh in a file in CGNS format
1444 # @param f is the file name
1445 # @param overwrite boolean parameter for overwriting/not overwriting the file
1446 # @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1447 # @ingroup l2_impexp
1448 def ExportCGNS(self, f, overwrite=1, meshPart=None):
1449 if isinstance( meshPart, list ):
1450 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1451 if isinstance( meshPart, Mesh ):
1452 meshPart = meshPart.mesh
1454 meshPart = self.mesh
1455 self.mesh.ExportCGNS(meshPart, f, overwrite)
1457 ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1458 # Exports the mesh in a file in MED format and chooses the \a version of MED format
1459 ## allowing to overwrite the file if it exists or add the exported data to its contents
1460 # @param f the file name
1461 # @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1462 # @param opt boolean parameter for creating/not creating
1463 # the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1464 # @param overwrite boolean parameter for overwriting/not overwriting the file
1465 # @ingroup l2_impexp
1466 def ExportToMED(self, f, version, opt=0, overwrite=1):
1467 self.mesh.ExportToMEDX(f, opt, version, overwrite)
1469 # Operations with groups:
1470 # ----------------------
1472 ## Creates an empty mesh group
1473 # @param elementType the type of elements in the group
1474 # @param name the name of the mesh group
1475 # @return SMESH_Group
1476 # @ingroup l2_grps_create
1477 def CreateEmptyGroup(self, elementType, name):
1478 return self.mesh.CreateGroup(elementType, name)
1480 ## Creates a mesh group based on the geometric object \a grp
1481 # and gives a \a name, \n if this parameter is not defined
1482 # the name is the same as the geometric group name \n
1483 # Note: Works like GroupOnGeom().
1484 # @param grp a geometric group, a vertex, an edge, a face or a solid
1485 # @param name the name of the mesh group
1486 # @return SMESH_GroupOnGeom
1487 # @ingroup l2_grps_create
1488 def Group(self, grp, name=""):
1489 return self.GroupOnGeom(grp, name)
1491 ## Creates a mesh group based on the geometrical object \a grp
1492 # and gives a \a name, \n if this parameter is not defined
1493 # the name is the same as the geometrical group name
1494 # @param grp a geometrical group, a vertex, an edge, a face or a solid
1495 # @param name the name of the mesh group
1496 # @param typ the type of elements in the group. If not set, it is
1497 # automatically detected by the type of the geometry
1498 # @return SMESH_GroupOnGeom
1499 # @ingroup l2_grps_create
1500 def GroupOnGeom(self, grp, name="", typ=None):
1501 AssureGeomPublished( self, grp, name )
1503 name = grp.GetName()
1505 typ = self._groupTypeFromShape( grp )
1506 return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1508 ## Pivate method to get a type of group on geometry
1509 def _groupTypeFromShape( self, shape ):
1510 tgeo = str(shape.GetShapeType())
1511 if tgeo == "VERTEX":
1513 elif tgeo == "EDGE":
1515 elif tgeo == "FACE" or tgeo == "SHELL":
1517 elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1519 elif tgeo == "COMPOUND":
1520 sub = self.geompyD.SubShapeAll( shape, geompyDC.ShapeType["SHAPE"])
1522 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1523 return self._groupTypeFromShape( sub[0] )
1526 "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1529 ## Creates a mesh group with given \a name based on the \a filter which
1530 ## is a special type of group dynamically updating it's contents during
1531 ## mesh modification
1532 # @param typ the type of elements in the group
1533 # @param name the name of the mesh group
1534 # @param filter the filter defining group contents
1535 # @return SMESH_GroupOnFilter
1536 # @ingroup l2_grps_create
1537 def GroupOnFilter(self, typ, name, filter):
1538 return self.mesh.CreateGroupFromFilter(typ, name, filter)
1540 ## Creates a mesh group by the given ids of elements
1541 # @param groupName the name of the mesh group
1542 # @param elementType the type of elements in the group
1543 # @param elemIDs the list of ids
1544 # @return SMESH_Group
1545 # @ingroup l2_grps_create
1546 def MakeGroupByIds(self, groupName, elementType, elemIDs):
1547 group = self.mesh.CreateGroup(elementType, groupName)
1551 ## Creates a mesh group by the given conditions
1552 # @param groupName the name of the mesh group
1553 # @param elementType the type of elements in the group
1554 # @param CritType the type of criterion( FT_Taper, FT_Area, FT_RangeOfIds, FT_LyingOnGeom etc. )
1555 # @param Compare belongs to {FT_LessThan, FT_MoreThan, FT_EqualTo}
1556 # @param Threshold the threshold value (range of id ids as string, shape, numeric)
1557 # @param UnaryOp FT_LogicalNOT or FT_Undefined
1558 # @param Tolerance the tolerance used by FT_BelongToGeom, FT_BelongToSurface,
1559 # FT_LyingOnGeom, FT_CoplanarFaces criteria
1560 # @return SMESH_Group
1561 # @ingroup l2_grps_create
1565 CritType=FT_Undefined,
1568 UnaryOp=FT_Undefined,
1570 aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
1571 group = self.MakeGroupByCriterion(groupName, aCriterion)
1574 ## Creates a mesh group by the given criterion
1575 # @param groupName the name of the mesh group
1576 # @param Criterion the instance of Criterion class
1577 # @return SMESH_Group
1578 # @ingroup l2_grps_create
1579 def MakeGroupByCriterion(self, groupName, Criterion):
1580 aFilterMgr = self.smeshpyD.CreateFilterManager()
1581 aFilter = aFilterMgr.CreateFilter()
1583 aCriteria.append(Criterion)
1584 aFilter.SetCriteria(aCriteria)
1585 group = self.MakeGroupByFilter(groupName, aFilter)
1586 aFilterMgr.UnRegister()
1589 ## Creates a mesh group by the given criteria (list of criteria)
1590 # @param groupName the name of the mesh group
1591 # @param theCriteria the list of criteria
1592 # @return SMESH_Group
1593 # @ingroup l2_grps_create
1594 def MakeGroupByCriteria(self, groupName, theCriteria):
1595 aFilterMgr = self.smeshpyD.CreateFilterManager()
1596 aFilter = aFilterMgr.CreateFilter()
1597 aFilter.SetCriteria(theCriteria)
1598 group = self.MakeGroupByFilter(groupName, aFilter)
1599 aFilterMgr.UnRegister()
1602 ## Creates a mesh group by the given filter
1603 # @param groupName the name of the mesh group
1604 # @param theFilter the instance of Filter class
1605 # @return SMESH_Group
1606 # @ingroup l2_grps_create
1607 def MakeGroupByFilter(self, groupName, theFilter):
1608 group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
1609 theFilter.SetMesh( self.mesh )
1610 group.AddFrom( theFilter )
1614 # @ingroup l2_grps_delete
1615 def RemoveGroup(self, group):
1616 self.mesh.RemoveGroup(group)
1618 ## Removes a group with its contents
1619 # @ingroup l2_grps_delete
1620 def RemoveGroupWithContents(self, group):
1621 self.mesh.RemoveGroupWithContents(group)
1623 ## Gets the list of groups existing in the mesh
1624 # @return a sequence of SMESH_GroupBase
1625 # @ingroup l2_grps_create
1626 def GetGroups(self):
1627 return self.mesh.GetGroups()
1629 ## Gets the number of groups existing in the mesh
1630 # @return the quantity of groups as an integer value
1631 # @ingroup l2_grps_create
1633 return self.mesh.NbGroups()
1635 ## Gets the list of names of groups existing in the mesh
1636 # @return list of strings
1637 # @ingroup l2_grps_create
1638 def GetGroupNames(self):
1639 groups = self.GetGroups()
1641 for group in groups:
1642 names.append(group.GetName())
1645 ## Produces a union of two groups
1646 # A new group is created. All mesh elements that are
1647 # present in the initial groups are added to the new one
1648 # @return an instance of SMESH_Group
1649 # @ingroup l2_grps_operon
1650 def UnionGroups(self, group1, group2, name):
1651 return self.mesh.UnionGroups(group1, group2, name)
1653 ## Produces a union list of groups
1654 # New group is created. All mesh elements that are present in
1655 # initial groups are added to the new one
1656 # @return an instance of SMESH_Group
1657 # @ingroup l2_grps_operon
1658 def UnionListOfGroups(self, groups, name):
1659 return self.mesh.UnionListOfGroups(groups, name)
1661 ## Prodices an intersection of two groups
1662 # A new group is created. All mesh elements that are common
1663 # for the two initial groups are added to the new one.
1664 # @return an instance of SMESH_Group
1665 # @ingroup l2_grps_operon
1666 def IntersectGroups(self, group1, group2, name):
1667 return self.mesh.IntersectGroups(group1, group2, name)
1669 ## Produces an intersection of groups
1670 # New group is created. All mesh elements that are present in all
1671 # initial groups simultaneously are added to the new one
1672 # @return an instance of SMESH_Group
1673 # @ingroup l2_grps_operon
1674 def IntersectListOfGroups(self, groups, name):
1675 return self.mesh.IntersectListOfGroups(groups, name)
1677 ## Produces a cut of two groups
1678 # A new group is created. All mesh elements that are present in
1679 # the main group but are not present in the tool group are added to the new one
1680 # @return an instance of SMESH_Group
1681 # @ingroup l2_grps_operon
1682 def CutGroups(self, main_group, tool_group, name):
1683 return self.mesh.CutGroups(main_group, tool_group, name)
1685 ## Produces a cut of groups
1686 # A new group is created. All mesh elements that are present in main groups
1687 # but do not present in tool groups are added to the new one
1688 # @return an instance of SMESH_Group
1689 # @ingroup l2_grps_operon
1690 def CutListOfGroups(self, main_groups, tool_groups, name):
1691 return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
1693 ## Produces a group of elements of specified type using list of existing groups
1694 # A new group is created. System
1695 # 1) extracts all nodes on which groups elements are built
1696 # 2) combines all elements of specified dimension laying on these nodes
1697 # @return an instance of SMESH_Group
1698 # @ingroup l2_grps_operon
1699 def CreateDimGroup(self, groups, elem_type, name):
1700 return self.mesh.CreateDimGroup(groups, elem_type, name)
1703 ## Convert group on geom into standalone group
1704 # @ingroup l2_grps_delete
1705 def ConvertToStandalone(self, group):
1706 return self.mesh.ConvertToStandalone(group)
1708 # Get some info about mesh:
1709 # ------------------------
1711 ## Returns the log of nodes and elements added or removed
1712 # since the previous clear of the log.
1713 # @param clearAfterGet log is emptied after Get (safe if concurrents access)
1714 # @return list of log_block structures:
1719 # @ingroup l1_auxiliary
1720 def GetLog(self, clearAfterGet):
1721 return self.mesh.GetLog(clearAfterGet)
1723 ## Clears the log of nodes and elements added or removed since the previous
1724 # clear. Must be used immediately after GetLog if clearAfterGet is false.
1725 # @ingroup l1_auxiliary
1727 self.mesh.ClearLog()
1729 ## Toggles auto color mode on the object.
1730 # @param theAutoColor the flag which toggles auto color mode.
1731 # @ingroup l1_auxiliary
1732 def SetAutoColor(self, theAutoColor):
1733 self.mesh.SetAutoColor(theAutoColor)
1735 ## Gets flag of object auto color mode.
1736 # @return True or False
1737 # @ingroup l1_auxiliary
1738 def GetAutoColor(self):
1739 return self.mesh.GetAutoColor()
1741 ## Gets the internal ID
1742 # @return integer value, which is the internal Id of the mesh
1743 # @ingroup l1_auxiliary
1745 return self.mesh.GetId()
1748 # @return integer value, which is the study Id of the mesh
1749 # @ingroup l1_auxiliary
1750 def GetStudyId(self):
1751 return self.mesh.GetStudyId()
1753 ## Checks the group names for duplications.
1754 # Consider the maximum group name length stored in MED file.
1755 # @return True or False
1756 # @ingroup l1_auxiliary
1757 def HasDuplicatedGroupNamesMED(self):
1758 return self.mesh.HasDuplicatedGroupNamesMED()
1760 ## Obtains the mesh editor tool
1761 # @return an instance of SMESH_MeshEditor
1762 # @ingroup l1_modifying
1763 def GetMeshEditor(self):
1764 return self.mesh.GetMeshEditor()
1766 ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
1767 # can be passed as argument to a method accepting mesh, group or sub-mesh
1768 # @return an instance of SMESH_IDSource
1769 # @ingroup l1_auxiliary
1770 def GetIDSource(self, ids, elemType):
1771 return self.GetMeshEditor().MakeIDSource(ids, elemType)
1774 # @return an instance of SALOME_MED::MESH
1775 # @ingroup l1_auxiliary
1776 def GetMEDMesh(self):
1777 return self.mesh.GetMEDMesh()
1780 # Get informations about mesh contents:
1781 # ------------------------------------
1783 ## Gets the mesh stattistic
1784 # @return dictionary type element - count of elements
1785 # @ingroup l1_meshinfo
1786 def GetMeshInfo(self, obj = None):
1787 if not obj: obj = self.mesh
1788 return self.smeshpyD.GetMeshInfo(obj)
1790 ## Returns the number of nodes in the mesh
1791 # @return an integer value
1792 # @ingroup l1_meshinfo
1794 return self.mesh.NbNodes()
1796 ## Returns the number of elements in the mesh
1797 # @return an integer value
1798 # @ingroup l1_meshinfo
1799 def NbElements(self):
1800 return self.mesh.NbElements()
1802 ## Returns the number of 0d elements in the mesh
1803 # @return an integer value
1804 # @ingroup l1_meshinfo
1805 def Nb0DElements(self):
1806 return self.mesh.Nb0DElements()
1808 ## Returns the number of ball discrete elements in the mesh
1809 # @return an integer value
1810 # @ingroup l1_meshinfo
1812 return self.mesh.NbBalls()
1814 ## Returns the number of edges in the mesh
1815 # @return an integer value
1816 # @ingroup l1_meshinfo
1818 return self.mesh.NbEdges()
1820 ## Returns the number of edges with the given order in the mesh
1821 # @param elementOrder the order of elements:
1822 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1823 # @return an integer value
1824 # @ingroup l1_meshinfo
1825 def NbEdgesOfOrder(self, elementOrder):
1826 return self.mesh.NbEdgesOfOrder(elementOrder)
1828 ## Returns the number of faces in the mesh
1829 # @return an integer value
1830 # @ingroup l1_meshinfo
1832 return self.mesh.NbFaces()
1834 ## Returns the number of faces with the given order in the mesh
1835 # @param elementOrder the order of elements:
1836 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1837 # @return an integer value
1838 # @ingroup l1_meshinfo
1839 def NbFacesOfOrder(self, elementOrder):
1840 return self.mesh.NbFacesOfOrder(elementOrder)
1842 ## Returns the number of triangles in the mesh
1843 # @return an integer value
1844 # @ingroup l1_meshinfo
1845 def NbTriangles(self):
1846 return self.mesh.NbTriangles()
1848 ## Returns the number of triangles with the given order in the mesh
1849 # @param elementOrder is the order of elements:
1850 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1851 # @return an integer value
1852 # @ingroup l1_meshinfo
1853 def NbTrianglesOfOrder(self, elementOrder):
1854 return self.mesh.NbTrianglesOfOrder(elementOrder)
1856 ## Returns the number of quadrangles in the mesh
1857 # @return an integer value
1858 # @ingroup l1_meshinfo
1859 def NbQuadrangles(self):
1860 return self.mesh.NbQuadrangles()
1862 ## Returns the number of quadrangles 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 NbQuadranglesOfOrder(self, elementOrder):
1868 return self.mesh.NbQuadranglesOfOrder(elementOrder)
1870 ## Returns the number of biquadratic quadrangles in the mesh
1871 # @return an integer value
1872 # @ingroup l1_meshinfo
1873 def NbBiQuadQuadrangles(self):
1874 return self.mesh.NbBiQuadQuadrangles()
1876 ## Returns the number of polygons in the mesh
1877 # @return an integer value
1878 # @ingroup l1_meshinfo
1879 def NbPolygons(self):
1880 return self.mesh.NbPolygons()
1882 ## Returns the number of volumes in the mesh
1883 # @return an integer value
1884 # @ingroup l1_meshinfo
1885 def NbVolumes(self):
1886 return self.mesh.NbVolumes()
1888 ## Returns the number of volumes with the given order in the mesh
1889 # @param elementOrder the order of elements:
1890 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1891 # @return an integer value
1892 # @ingroup l1_meshinfo
1893 def NbVolumesOfOrder(self, elementOrder):
1894 return self.mesh.NbVolumesOfOrder(elementOrder)
1896 ## Returns the number of tetrahedrons in the mesh
1897 # @return an integer value
1898 # @ingroup l1_meshinfo
1900 return self.mesh.NbTetras()
1902 ## Returns the number of tetrahedrons with the given order in the mesh
1903 # @param elementOrder the order of elements:
1904 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1905 # @return an integer value
1906 # @ingroup l1_meshinfo
1907 def NbTetrasOfOrder(self, elementOrder):
1908 return self.mesh.NbTetrasOfOrder(elementOrder)
1910 ## Returns the number of hexahedrons in the mesh
1911 # @return an integer value
1912 # @ingroup l1_meshinfo
1914 return self.mesh.NbHexas()
1916 ## Returns the number of hexahedrons with the given order in the mesh
1917 # @param elementOrder the order of elements:
1918 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1919 # @return an integer value
1920 # @ingroup l1_meshinfo
1921 def NbHexasOfOrder(self, elementOrder):
1922 return self.mesh.NbHexasOfOrder(elementOrder)
1924 ## Returns the number of triquadratic hexahedrons in the mesh
1925 # @return an integer value
1926 # @ingroup l1_meshinfo
1927 def NbTriQuadraticHexas(self):
1928 return self.mesh.NbTriQuadraticHexas()
1930 ## Returns the number of pyramids in the mesh
1931 # @return an integer value
1932 # @ingroup l1_meshinfo
1933 def NbPyramids(self):
1934 return self.mesh.NbPyramids()
1936 ## Returns the number of pyramids with the given order in the mesh
1937 # @param elementOrder the order of elements:
1938 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1939 # @return an integer value
1940 # @ingroup l1_meshinfo
1941 def NbPyramidsOfOrder(self, elementOrder):
1942 return self.mesh.NbPyramidsOfOrder(elementOrder)
1944 ## Returns the number of prisms in the mesh
1945 # @return an integer value
1946 # @ingroup l1_meshinfo
1948 return self.mesh.NbPrisms()
1950 ## Returns the number of prisms with the given order in the mesh
1951 # @param elementOrder the order of elements:
1952 # ORDER_ANY, ORDER_LINEAR or ORDER_QUADRATIC
1953 # @return an integer value
1954 # @ingroup l1_meshinfo
1955 def NbPrismsOfOrder(self, elementOrder):
1956 return self.mesh.NbPrismsOfOrder(elementOrder)
1958 ## Returns the number of hexagonal prisms in the mesh
1959 # @return an integer value
1960 # @ingroup l1_meshinfo
1961 def NbHexagonalPrisms(self):
1962 return self.mesh.NbHexagonalPrisms()
1964 ## Returns the number of polyhedrons in the mesh
1965 # @return an integer value
1966 # @ingroup l1_meshinfo
1967 def NbPolyhedrons(self):
1968 return self.mesh.NbPolyhedrons()
1970 ## Returns the number of submeshes in the mesh
1971 # @return an integer value
1972 # @ingroup l1_meshinfo
1973 def NbSubMesh(self):
1974 return self.mesh.NbSubMesh()
1976 ## Returns the list of mesh elements IDs
1977 # @return the list of integer values
1978 # @ingroup l1_meshinfo
1979 def GetElementsId(self):
1980 return self.mesh.GetElementsId()
1982 ## Returns the list of IDs of mesh elements with the given type
1983 # @param elementType the required type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
1984 # @return list of integer values
1985 # @ingroup l1_meshinfo
1986 def GetElementsByType(self, elementType):
1987 return self.mesh.GetElementsByType(elementType)
1989 ## Returns the list of mesh nodes IDs
1990 # @return the list of integer values
1991 # @ingroup l1_meshinfo
1992 def GetNodesId(self):
1993 return self.mesh.GetNodesId()
1995 # Get the information about mesh elements:
1996 # ------------------------------------
1998 ## Returns the type of mesh element
1999 # @return the value from SMESH::ElementType enumeration
2000 # @ingroup l1_meshinfo
2001 def GetElementType(self, id, iselem):
2002 return self.mesh.GetElementType(id, iselem)
2004 ## Returns the geometric type of mesh element
2005 # @return the value from SMESH::EntityType enumeration
2006 # @ingroup l1_meshinfo
2007 def GetElementGeomType(self, id):
2008 return self.mesh.GetElementGeomType(id)
2010 ## Returns the list of submesh elements IDs
2011 # @param Shape a geom object(sub-shape) IOR
2012 # Shape must be the sub-shape of a ShapeToMesh()
2013 # @return the list of integer values
2014 # @ingroup l1_meshinfo
2015 def GetSubMeshElementsId(self, Shape):
2016 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2017 ShapeID = Shape.GetSubShapeIndices()[0]
2020 return self.mesh.GetSubMeshElementsId(ShapeID)
2022 ## Returns the list of submesh nodes IDs
2023 # @param Shape a geom object(sub-shape) IOR
2024 # Shape must be the sub-shape of a ShapeToMesh()
2025 # @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2026 # @return the list of integer values
2027 # @ingroup l1_meshinfo
2028 def GetSubMeshNodesId(self, Shape, all):
2029 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2030 ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2033 return self.mesh.GetSubMeshNodesId(ShapeID, all)
2035 ## Returns type of elements on given shape
2036 # @param Shape a geom object(sub-shape) IOR
2037 # Shape must be a sub-shape of a ShapeToMesh()
2038 # @return element type
2039 # @ingroup l1_meshinfo
2040 def GetSubMeshElementType(self, Shape):
2041 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2042 ShapeID = Shape.GetSubShapeIndices()[0]
2045 return self.mesh.GetSubMeshElementType(ShapeID)
2047 ## Gets the mesh description
2048 # @return string value
2049 # @ingroup l1_meshinfo
2051 return self.mesh.Dump()
2054 # Get the information about nodes and elements of a mesh by its IDs:
2055 # -----------------------------------------------------------
2057 ## Gets XYZ coordinates of a node
2058 # \n If there is no nodes for the given ID - returns an empty list
2059 # @return a list of double precision values
2060 # @ingroup l1_meshinfo
2061 def GetNodeXYZ(self, id):
2062 return self.mesh.GetNodeXYZ(id)
2064 ## Returns list of IDs of inverse elements for the given node
2065 # \n If there is no node for the given ID - returns an empty list
2066 # @return a list of integer values
2067 # @ingroup l1_meshinfo
2068 def GetNodeInverseElements(self, id):
2069 return self.mesh.GetNodeInverseElements(id)
2071 ## @brief Returns the position of a node on the shape
2072 # @return SMESH::NodePosition
2073 # @ingroup l1_meshinfo
2074 def GetNodePosition(self,NodeID):
2075 return self.mesh.GetNodePosition(NodeID)
2077 ## If the given element is a node, returns the ID of shape
2078 # \n If there is no node for the given ID - returns -1
2079 # @return an integer value
2080 # @ingroup l1_meshinfo
2081 def GetShapeID(self, id):
2082 return self.mesh.GetShapeID(id)
2084 ## Returns the ID of the result shape after
2085 # FindShape() from SMESH_MeshEditor for the given element
2086 # \n If there is no element for the given ID - returns -1
2087 # @return an integer value
2088 # @ingroup l1_meshinfo
2089 def GetShapeIDForElem(self,id):
2090 return self.mesh.GetShapeIDForElem(id)
2092 ## Returns the number of nodes for the given element
2093 # \n If there is no element for the given ID - returns -1
2094 # @return an integer value
2095 # @ingroup l1_meshinfo
2096 def GetElemNbNodes(self, id):
2097 return self.mesh.GetElemNbNodes(id)
2099 ## Returns the node ID the given index for the given element
2100 # \n If there is no element for the given ID - returns -1
2101 # \n If there is no node for the given index - returns -2
2102 # @return an integer value
2103 # @ingroup l1_meshinfo
2104 def GetElemNode(self, id, index):
2105 return self.mesh.GetElemNode(id, index)
2107 ## Returns the IDs of nodes of the given element
2108 # @return a list of integer values
2109 # @ingroup l1_meshinfo
2110 def GetElemNodes(self, id):
2111 return self.mesh.GetElemNodes(id)
2113 ## Returns true if the given node is the medium node in the given quadratic element
2114 # @ingroup l1_meshinfo
2115 def IsMediumNode(self, elementID, nodeID):
2116 return self.mesh.IsMediumNode(elementID, nodeID)
2118 ## Returns true if the given node is the medium node in one of quadratic elements
2119 # @ingroup l1_meshinfo
2120 def IsMediumNodeOfAnyElem(self, nodeID, elementType):
2121 return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2123 ## Returns the number of edges for the given element
2124 # @ingroup l1_meshinfo
2125 def ElemNbEdges(self, id):
2126 return self.mesh.ElemNbEdges(id)
2128 ## Returns the number of faces for the given element
2129 # @ingroup l1_meshinfo
2130 def ElemNbFaces(self, id):
2131 return self.mesh.ElemNbFaces(id)
2133 ## Returns nodes of given face (counted from zero) for given volumic element.
2134 # @ingroup l1_meshinfo
2135 def GetElemFaceNodes(self,elemId, faceIndex):
2136 return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2138 ## Returns an element based on all given nodes.
2139 # @ingroup l1_meshinfo
2140 def FindElementByNodes(self,nodes):
2141 return self.mesh.FindElementByNodes(nodes)
2143 ## Returns true if the given element is a polygon
2144 # @ingroup l1_meshinfo
2145 def IsPoly(self, id):
2146 return self.mesh.IsPoly(id)
2148 ## Returns true if the given element is quadratic
2149 # @ingroup l1_meshinfo
2150 def IsQuadratic(self, id):
2151 return self.mesh.IsQuadratic(id)
2153 ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2154 # @ingroup l1_meshinfo
2155 def GetBallDiameter(self, id):
2156 return self.mesh.GetBallDiameter(id)
2158 ## Returns XYZ coordinates of the barycenter of the given element
2159 # \n If there is no element for the given ID - returns an empty list
2160 # @return a list of three double values
2161 # @ingroup l1_meshinfo
2162 def BaryCenter(self, id):
2163 return self.mesh.BaryCenter(id)
2165 ## Passes mesh elements through the given filter and return IDs of fitting elements
2166 # @param theFilter SMESH_Filter
2167 # @return a list of ids
2168 # @ingroup l1_controls
2169 def GetIdsFromFilter(self, theFilter):
2170 theFilter.SetMesh( self.mesh )
2171 return theFilter.GetIDs()
2173 ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2174 # Returns a list of special structures (borders).
2175 # @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2176 # @ingroup l1_controls
2177 def GetFreeBorders(self):
2178 aFilterMgr = self.smeshpyD.CreateFilterManager()
2179 aPredicate = aFilterMgr.CreateFreeEdges()
2180 aPredicate.SetMesh(self.mesh)
2181 aBorders = aPredicate.GetBorders()
2182 aFilterMgr.UnRegister()
2186 # Get mesh measurements information:
2187 # ------------------------------------
2189 ## Get minimum distance between two nodes, elements or distance to the origin
2190 # @param id1 first node/element id
2191 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2192 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2193 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2194 # @return minimum distance value
2195 # @sa GetMinDistance()
2196 def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2197 aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2198 return aMeasure.value
2200 ## Get measure structure specifying minimum distance data between two objects
2201 # @param id1 first node/element id
2202 # @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2203 # @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2204 # @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2205 # @return Measure structure
2207 def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2209 id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2211 id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2214 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2216 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2221 aMeasurements = self.smeshpyD.CreateMeasurements()
2222 aMeasure = aMeasurements.MinDistance(id1, id2)
2223 aMeasurements.UnRegister()
2226 ## Get bounding box of the specified object(s)
2227 # @param objects single source object or list of source objects or list of nodes/elements IDs
2228 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2229 # @c False specifies that @a objects are nodes
2230 # @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2231 # @sa GetBoundingBox()
2232 def BoundingBox(self, objects=None, isElem=False):
2233 result = self.GetBoundingBox(objects, isElem)
2237 result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2240 ## Get measure structure specifying bounding box data of the specified object(s)
2241 # @param IDs single source object or list of source objects or list of nodes/elements IDs
2242 # @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2243 # @c False specifies that @a objects are nodes
2244 # @return Measure structure
2246 def GetBoundingBox(self, IDs=None, isElem=False):
2249 elif isinstance(IDs, tuple):
2251 if not isinstance(IDs, list):
2253 if len(IDs) > 0 and isinstance(IDs[0], int):
2257 if isinstance(o, Mesh):
2258 srclist.append(o.mesh)
2259 elif hasattr(o, "_narrow"):
2260 src = o._narrow(SMESH.SMESH_IDSource)
2261 if src: srclist.append(src)
2263 elif isinstance(o, list):
2265 srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2267 srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2270 aMeasurements = self.smeshpyD.CreateMeasurements()
2271 aMeasure = aMeasurements.BoundingBox(srclist)
2272 aMeasurements.UnRegister()
2275 # Mesh edition (SMESH_MeshEditor functionality):
2276 # ---------------------------------------------
2278 ## Removes the elements from the mesh by ids
2279 # @param IDsOfElements is a list of ids of elements to remove
2280 # @return True or False
2281 # @ingroup l2_modif_del
2282 def RemoveElements(self, IDsOfElements):
2283 return self.editor.RemoveElements(IDsOfElements)
2285 ## Removes nodes from mesh by ids
2286 # @param IDsOfNodes is a list of ids of nodes to remove
2287 # @return True or False
2288 # @ingroup l2_modif_del
2289 def RemoveNodes(self, IDsOfNodes):
2290 return self.editor.RemoveNodes(IDsOfNodes)
2292 ## Removes all orphan (free) nodes from mesh
2293 # @return number of the removed nodes
2294 # @ingroup l2_modif_del
2295 def RemoveOrphanNodes(self):
2296 return self.editor.RemoveOrphanNodes()
2298 ## Add a node to the mesh by coordinates
2299 # @return Id of the new node
2300 # @ingroup l2_modif_add
2301 def AddNode(self, x, y, z):
2302 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2303 if hasVars: self.mesh.SetParameters(Parameters)
2304 return self.editor.AddNode( x, y, z)
2306 ## Creates a 0D element on a node with given number.
2307 # @param IDOfNode the ID of node for creation of the element.
2308 # @return the Id of the new 0D element
2309 # @ingroup l2_modif_add
2310 def Add0DElement(self, IDOfNode):
2311 return self.editor.Add0DElement(IDOfNode)
2313 ## Creates a ball element on a node with given ID.
2314 # @param IDOfNode the ID of node for creation of the element.
2315 # @param diameter the bal diameter.
2316 # @return the Id of the new ball element
2317 # @ingroup l2_modif_add
2318 def AddBall(self, IDOfNode, diameter):
2319 return self.editor.AddBall( IDOfNode, diameter )
2321 ## Creates a linear or quadratic edge (this is determined
2322 # by the number of given nodes).
2323 # @param IDsOfNodes the list of node IDs for creation of the element.
2324 # The order of nodes in this list should correspond to the description
2325 # of MED. \n This description is located by the following link:
2326 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2327 # @return the Id of the new edge
2328 # @ingroup l2_modif_add
2329 def AddEdge(self, IDsOfNodes):
2330 return self.editor.AddEdge(IDsOfNodes)
2332 ## Creates a linear or quadratic face (this is determined
2333 # by the number of given nodes).
2334 # @param IDsOfNodes the list of node IDs for creation of the element.
2335 # The order of nodes in this list should correspond to the description
2336 # of MED. \n This description is located by the following link:
2337 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2338 # @return the Id of the new face
2339 # @ingroup l2_modif_add
2340 def AddFace(self, IDsOfNodes):
2341 return self.editor.AddFace(IDsOfNodes)
2343 ## Adds a polygonal face to the mesh by the list of node IDs
2344 # @param IdsOfNodes the list of node IDs for creation of the element.
2345 # @return the Id of the new face
2346 # @ingroup l2_modif_add
2347 def AddPolygonalFace(self, IdsOfNodes):
2348 return self.editor.AddPolygonalFace(IdsOfNodes)
2350 ## Creates both simple and quadratic volume (this is determined
2351 # by the number of given nodes).
2352 # @param IDsOfNodes the list of node IDs for creation of the element.
2353 # The order of nodes in this list should correspond to the description
2354 # of MED. \n This description is located by the following link:
2355 # http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2356 # @return the Id of the new volumic element
2357 # @ingroup l2_modif_add
2358 def AddVolume(self, IDsOfNodes):
2359 return self.editor.AddVolume(IDsOfNodes)
2361 ## Creates a volume of many faces, giving nodes for each face.
2362 # @param IdsOfNodes the list of node IDs for volume creation face by face.
2363 # @param Quantities the list of integer values, Quantities[i]
2364 # gives the quantity of nodes in face number i.
2365 # @return the Id of the new volumic element
2366 # @ingroup l2_modif_add
2367 def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2368 return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2370 ## Creates a volume of many faces, giving the IDs of the existing faces.
2371 # @param IdsOfFaces the list of face IDs for volume creation.
2373 # Note: The created volume will refer only to the nodes
2374 # of the given faces, not to the faces themselves.
2375 # @return the Id of the new volumic element
2376 # @ingroup l2_modif_add
2377 def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2378 return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2381 ## @brief Binds a node to a vertex
2382 # @param NodeID a node ID
2383 # @param Vertex a vertex or vertex ID
2384 # @return True if succeed else raises an exception
2385 # @ingroup l2_modif_add
2386 def SetNodeOnVertex(self, NodeID, Vertex):
2387 if ( isinstance( Vertex, geompyDC.GEOM._objref_GEOM_Object)):
2388 VertexID = Vertex.GetSubShapeIndices()[0]
2392 self.editor.SetNodeOnVertex(NodeID, VertexID)
2393 except SALOME.SALOME_Exception, inst:
2394 raise ValueError, inst.details.text
2398 ## @brief Stores the node position on an edge
2399 # @param NodeID a node ID
2400 # @param Edge an edge or edge ID
2401 # @param paramOnEdge a parameter on the edge where the node is located
2402 # @return True if succeed else raises an exception
2403 # @ingroup l2_modif_add
2404 def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2405 if ( isinstance( Edge, geompyDC.GEOM._objref_GEOM_Object)):
2406 EdgeID = Edge.GetSubShapeIndices()[0]
2410 self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2411 except SALOME.SALOME_Exception, inst:
2412 raise ValueError, inst.details.text
2415 ## @brief Stores node position on a face
2416 # @param NodeID a node ID
2417 # @param Face a face or face ID
2418 # @param u U parameter on the face where the node is located
2419 # @param v V parameter on the face where the node is located
2420 # @return True if succeed else raises an exception
2421 # @ingroup l2_modif_add
2422 def SetNodeOnFace(self, NodeID, Face, u, v):
2423 if ( isinstance( Face, geompyDC.GEOM._objref_GEOM_Object)):
2424 FaceID = Face.GetSubShapeIndices()[0]
2428 self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2429 except SALOME.SALOME_Exception, inst:
2430 raise ValueError, inst.details.text
2433 ## @brief Binds a node to a solid
2434 # @param NodeID a node ID
2435 # @param Solid a solid or solid ID
2436 # @return True if succeed else raises an exception
2437 # @ingroup l2_modif_add
2438 def SetNodeInVolume(self, NodeID, Solid):
2439 if ( isinstance( Solid, geompyDC.GEOM._objref_GEOM_Object)):
2440 SolidID = Solid.GetSubShapeIndices()[0]
2444 self.editor.SetNodeInVolume(NodeID, SolidID)
2445 except SALOME.SALOME_Exception, inst:
2446 raise ValueError, inst.details.text
2449 ## @brief Bind an element to a shape
2450 # @param ElementID an element ID
2451 # @param Shape a shape or shape ID
2452 # @return True if succeed else raises an exception
2453 # @ingroup l2_modif_add
2454 def SetMeshElementOnShape(self, ElementID, Shape):
2455 if ( isinstance( Shape, geompyDC.GEOM._objref_GEOM_Object)):
2456 ShapeID = Shape.GetSubShapeIndices()[0]
2460 self.editor.SetMeshElementOnShape(ElementID, ShapeID)
2461 except SALOME.SALOME_Exception, inst:
2462 raise ValueError, inst.details.text
2466 ## Moves the node with the given id
2467 # @param NodeID the id of the node
2468 # @param x a new X coordinate
2469 # @param y a new Y coordinate
2470 # @param z a new Z coordinate
2471 # @return True if succeed else False
2472 # @ingroup l2_modif_movenode
2473 def MoveNode(self, NodeID, x, y, z):
2474 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2475 if hasVars: self.mesh.SetParameters(Parameters)
2476 return self.editor.MoveNode(NodeID, x, y, z)
2478 ## Finds the node closest to a point and moves it to a point location
2479 # @param x the X coordinate of a point
2480 # @param y the Y coordinate of a point
2481 # @param z the Z coordinate of a point
2482 # @param NodeID if specified (>0), the node with this ID is moved,
2483 # otherwise, the node closest to point (@a x,@a y,@a z) is moved
2484 # @return the ID of a node
2485 # @ingroup l2_modif_throughp
2486 def MoveClosestNodeToPoint(self, x, y, z, NodeID):
2487 x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2488 if hasVars: self.mesh.SetParameters(Parameters)
2489 return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
2491 ## Finds the node closest to a point
2492 # @param x the X coordinate of a point
2493 # @param y the Y coordinate of a point
2494 # @param z the Z coordinate of a point
2495 # @return the ID of a node
2496 # @ingroup l2_modif_throughp
2497 def FindNodeClosestTo(self, x, y, z):
2498 #preview = self.mesh.GetMeshEditPreviewer()
2499 #return preview.MoveClosestNodeToPoint(x, y, z, -1)
2500 return self.editor.FindNodeClosestTo(x, y, z)
2502 ## Finds the elements where a point lays IN or ON
2503 # @param x the X coordinate of a point
2504 # @param y the Y coordinate of a point
2505 # @param z the Z coordinate of a point
2506 # @param elementType type of elements to find (SMESH.ALL type
2507 # means elements of any type excluding nodes, discrete and 0D elements)
2508 # @param meshPart a part of mesh (group, sub-mesh) to search within
2509 # @return list of IDs of found elements
2510 # @ingroup l2_modif_throughp
2511 def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
2513 return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
2515 return self.editor.FindElementsByPoint(x, y, z, elementType)
2517 # Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
2518 # 0-IN, 1-OUT, 2-ON, 3-UNKNOWN
2519 # TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
2521 def GetPointState(self, x, y, z):
2522 return self.editor.GetPointState(x, y, z)
2524 ## Finds the node closest to a point and moves it to a point location
2525 # @param x the X coordinate of a point
2526 # @param y the Y coordinate of a point
2527 # @param z the Z coordinate of a point
2528 # @return the ID of a moved node
2529 # @ingroup l2_modif_throughp
2530 def MeshToPassThroughAPoint(self, x, y, z):
2531 return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
2533 ## Replaces two neighbour triangles sharing Node1-Node2 link
2534 # with the triangles built on the same 4 nodes but having other common link.
2535 # @param NodeID1 the ID of the first node
2536 # @param NodeID2 the ID of the second node
2537 # @return false if proper faces were not found
2538 # @ingroup l2_modif_invdiag
2539 def InverseDiag(self, NodeID1, NodeID2):
2540 return self.editor.InverseDiag(NodeID1, NodeID2)
2542 ## Replaces two neighbour triangles sharing Node1-Node2 link
2543 # with a quadrangle built on the same 4 nodes.
2544 # @param NodeID1 the ID of the first node
2545 # @param NodeID2 the ID of the second node
2546 # @return false if proper faces were not found
2547 # @ingroup l2_modif_unitetri
2548 def DeleteDiag(self, NodeID1, NodeID2):
2549 return self.editor.DeleteDiag(NodeID1, NodeID2)
2551 ## Reorients elements by ids
2552 # @param IDsOfElements if undefined reorients all mesh elements
2553 # @return True if succeed else False
2554 # @ingroup l2_modif_changori
2555 def Reorient(self, IDsOfElements=None):
2556 if IDsOfElements == None:
2557 IDsOfElements = self.GetElementsId()
2558 return self.editor.Reorient(IDsOfElements)
2560 ## Reorients all elements of the object
2561 # @param theObject mesh, submesh or group
2562 # @return True if succeed else False
2563 # @ingroup l2_modif_changori
2564 def ReorientObject(self, theObject):
2565 if ( isinstance( theObject, Mesh )):
2566 theObject = theObject.GetMesh()
2567 return self.editor.ReorientObject(theObject)
2569 ## Reorient faces contained in \a the2DObject.
2570 # @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
2571 # @param theDirection is a desired direction of normal of \a theFace.
2572 # It can be either a GEOM vector or a list of coordinates [x,y,z].
2573 # @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
2574 # compared with theDirection. It can be either ID of face or a point
2575 # by which the face will be found. The point can be given as either
2576 # a GEOM vertex or a list of point coordinates.
2577 # @return number of reoriented faces
2578 # @ingroup l2_modif_changori
2579 def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
2581 if isinstance( the2DObject, Mesh ):
2582 the2DObject = the2DObject.GetMesh()
2583 if isinstance( the2DObject, list ):
2584 the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
2585 # check theDirection
2586 if isinstance( theDirection, geompyDC.GEOM._objref_GEOM_Object):
2587 theDirection = self.smeshpyD.GetDirStruct( theDirection )
2588 if isinstance( theDirection, list ):
2589 theDirection = self.smeshpyD.MakeDirStruct( *theDirection )
2590 # prepare theFace and thePoint
2591 theFace = theFaceOrPoint
2592 thePoint = PointStruct(0,0,0)
2593 if isinstance( theFaceOrPoint, geompyDC.GEOM._objref_GEOM_Object):
2594 thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
2596 if isinstance( theFaceOrPoint, list ):
2597 thePoint = PointStruct( *theFaceOrPoint )
2599 if isinstance( theFaceOrPoint, PointStruct ):
2600 thePoint = theFaceOrPoint
2602 return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
2604 ## Fuses the neighbouring triangles into quadrangles.
2605 # @param IDsOfElements The triangles to be fused,
2606 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2607 # @param MaxAngle is the maximum angle between element normals at which the fusion
2608 # is still performed; theMaxAngle is mesured in radians.
2609 # Also it could be a name of variable which defines angle in degrees.
2610 # @return TRUE in case of success, FALSE otherwise.
2611 # @ingroup l2_modif_unitetri
2612 def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
2614 if isinstance(MaxAngle,str):
2616 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2617 self.mesh.SetParameters(Parameters)
2618 if not IDsOfElements:
2619 IDsOfElements = self.GetElementsId()
2621 if ( isinstance( theCriterion, SMESH._objref_NumericalFunctor ) ):
2622 Functor = theCriterion
2624 Functor = self.smeshpyD.GetFunctor(theCriterion)
2625 return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
2627 ## Fuses the neighbouring triangles of the object into quadrangles
2628 # @param theObject is mesh, submesh or group
2629 # @param theCriterion is FT_...; used to choose a neighbour to fuse with.
2630 # @param MaxAngle a max angle between element normals at which the fusion
2631 # is still performed; theMaxAngle is mesured in radians.
2632 # @return TRUE in case of success, FALSE otherwise.
2633 # @ingroup l2_modif_unitetri
2634 def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
2635 MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
2636 self.mesh.SetParameters(Parameters)
2637 if ( isinstance( theObject, Mesh )):
2638 theObject = theObject.GetMesh()
2639 return self.editor.TriToQuadObject(theObject, self.smeshpyD.GetFunctor(theCriterion), MaxAngle)
2641 ## Splits quadrangles into triangles.
2642 # @param IDsOfElements the faces to be splitted.
2643 # @param theCriterion FT_...; used to choose a diagonal for splitting.
2644 # @return TRUE in case of success, FALSE otherwise.
2645 # @ingroup l2_modif_cutquadr
2646 def QuadToTri (self, IDsOfElements, theCriterion):
2647 if IDsOfElements == []:
2648 IDsOfElements = self.GetElementsId()
2649 return self.editor.QuadToTri(IDsOfElements, self.smeshpyD.GetFunctor(theCriterion))
2651 ## Splits quadrangles into triangles.
2652 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
2653 # @param theCriterion FT_...; used to choose a diagonal for splitting.
2654 # @return TRUE in case of success, FALSE otherwise.
2655 # @ingroup l2_modif_cutquadr
2656 def QuadToTriObject (self, theObject, theCriterion):
2657 if ( isinstance( theObject, Mesh )):
2658 theObject = theObject.GetMesh()
2659 return self.editor.QuadToTriObject(theObject, self.smeshpyD.GetFunctor(theCriterion))
2661 ## Splits quadrangles into triangles.
2662 # @param IDsOfElements the faces to be splitted
2663 # @param Diag13 is used to choose a diagonal for splitting.
2664 # @return TRUE in case of success, FALSE otherwise.
2665 # @ingroup l2_modif_cutquadr
2666 def SplitQuad (self, IDsOfElements, Diag13):
2667 if IDsOfElements == []:
2668 IDsOfElements = self.GetElementsId()
2669 return self.editor.SplitQuad(IDsOfElements, Diag13)
2671 ## Splits quadrangles into triangles.
2672 # @param theObject the object from which the list of elements is taken, this is mesh, submesh or group
2673 # @param Diag13 is used to choose a diagonal for splitting.
2674 # @return TRUE in case of success, FALSE otherwise.
2675 # @ingroup l2_modif_cutquadr
2676 def SplitQuadObject (self, theObject, Diag13):
2677 if ( isinstance( theObject, Mesh )):
2678 theObject = theObject.GetMesh()
2679 return self.editor.SplitQuadObject(theObject, Diag13)
2681 ## Finds a better splitting of the given quadrangle.
2682 # @param IDOfQuad the ID of the quadrangle to be splitted.
2683 # @param theCriterion FT_...; a criterion to choose a diagonal for splitting.
2684 # @return 1 if 1-3 diagonal is better, 2 if 2-4
2685 # diagonal is better, 0 if error occurs.
2686 # @ingroup l2_modif_cutquadr
2687 def BestSplit (self, IDOfQuad, theCriterion):
2688 return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
2690 ## Splits volumic elements into tetrahedrons
2691 # @param elemIDs either list of elements or mesh or group or submesh
2692 # @param method flags passing splitting method: Hex_5Tet, Hex_6Tet, Hex_24Tet
2693 # Hex_5Tet - split the hexahedron into 5 tetrahedrons, etc
2694 # @ingroup l2_modif_cutquadr
2695 def SplitVolumesIntoTetra(self, elemIDs, method=Hex_5Tet ):
2696 if isinstance( elemIDs, Mesh ):
2697 elemIDs = elemIDs.GetMesh()
2698 if ( isinstance( elemIDs, list )):
2699 elemIDs = self.editor.MakeIDSource(elemIDs, SMESH.VOLUME)
2700 self.editor.SplitVolumesIntoTetra(elemIDs, method)
2702 ## Splits quadrangle faces near triangular facets of volumes
2704 # @ingroup l1_auxiliary
2705 def SplitQuadsNearTriangularFacets(self):
2706 faces_array = self.GetElementsByType(SMESH.FACE)
2707 for face_id in faces_array:
2708 if self.GetElemNbNodes(face_id) == 4: # quadrangle
2709 quad_nodes = self.mesh.GetElemNodes(face_id)
2710 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
2711 isVolumeFound = False
2712 for node1_elem in node1_elems:
2713 if not isVolumeFound:
2714 if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
2715 nb_nodes = self.GetElemNbNodes(node1_elem)
2716 if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
2717 volume_elem = node1_elem
2718 volume_nodes = self.mesh.GetElemNodes(volume_elem)
2719 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
2720 if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
2721 isVolumeFound = True
2722 if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
2723 self.SplitQuad([face_id], False) # diagonal 2-4
2724 elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
2725 isVolumeFound = True
2726 self.SplitQuad([face_id], True) # diagonal 1-3
2727 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
2728 if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
2729 isVolumeFound = True
2730 self.SplitQuad([face_id], True) # diagonal 1-3
2732 ## @brief Splits hexahedrons into tetrahedrons.
2734 # This operation uses pattern mapping functionality for splitting.
2735 # @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
2736 # @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
2737 # pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
2738 # will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
2739 # key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
2740 # The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
2741 # @return TRUE in case of success, FALSE otherwise.
2742 # @ingroup l1_auxiliary
2743 def SplitHexaToTetras (self, theObject, theNode000, theNode001):
2744 # Pattern: 5.---------.6
2749 # (0,0,1) 4.---------.7 * |
2756 # (0,0,0) 0.---------.3
2757 pattern_tetra = "!!! Nb of points: \n 8 \n\
2767 !!! Indices of points of 6 tetras: \n\
2775 pattern = self.smeshpyD.GetPattern()
2776 isDone = pattern.LoadFromFile(pattern_tetra)
2778 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2781 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2782 isDone = pattern.MakeMesh(self.mesh, False, False)
2783 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2785 # split quafrangle faces near triangular facets of volumes
2786 self.SplitQuadsNearTriangularFacets()
2790 ## @brief Split hexahedrons into prisms.
2792 # Uses the pattern mapping functionality for splitting.
2793 # @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
2794 # @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
2795 # pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
2796 # will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
2797 # will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
2798 # Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
2799 # @return TRUE in case of success, FALSE otherwise.
2800 # @ingroup l1_auxiliary
2801 def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
2802 # Pattern: 5.---------.6
2807 # (0,0,1) 4.---------.7 |
2814 # (0,0,0) 0.---------.3
2815 pattern_prism = "!!! Nb of points: \n 8 \n\
2825 !!! Indices of points of 2 prisms: \n\
2829 pattern = self.smeshpyD.GetPattern()
2830 isDone = pattern.LoadFromFile(pattern_prism)
2832 print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
2835 pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
2836 isDone = pattern.MakeMesh(self.mesh, False, False)
2837 if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
2839 # Splits quafrangle faces near triangular facets of volumes
2840 self.SplitQuadsNearTriangularFacets()
2844 ## Smoothes elements
2845 # @param IDsOfElements the list if ids of elements to smooth
2846 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2847 # Note that nodes built on edges and boundary nodes are always fixed.
2848 # @param MaxNbOfIterations the maximum number of iterations
2849 # @param MaxAspectRatio varies in range [1.0, inf]
2850 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2851 # @return TRUE in case of success, FALSE otherwise.
2852 # @ingroup l2_modif_smooth
2853 def Smooth(self, IDsOfElements, IDsOfFixedNodes,
2854 MaxNbOfIterations, MaxAspectRatio, Method):
2855 if IDsOfElements == []:
2856 IDsOfElements = self.GetElementsId()
2857 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2858 self.mesh.SetParameters(Parameters)
2859 return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
2860 MaxNbOfIterations, MaxAspectRatio, Method)
2862 ## Smoothes elements which belong to the given object
2863 # @param theObject the object to smooth
2864 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2865 # Note that nodes built on edges and boundary nodes are always fixed.
2866 # @param MaxNbOfIterations the maximum number of iterations
2867 # @param MaxAspectRatio varies in range [1.0, inf]
2868 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2869 # @return TRUE in case of success, FALSE otherwise.
2870 # @ingroup l2_modif_smooth
2871 def SmoothObject(self, theObject, IDsOfFixedNodes,
2872 MaxNbOfIterations, MaxAspectRatio, Method):
2873 if ( isinstance( theObject, Mesh )):
2874 theObject = theObject.GetMesh()
2875 return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
2876 MaxNbOfIterations, MaxAspectRatio, Method)
2878 ## Parametrically smoothes the given elements
2879 # @param IDsOfElements the list if ids of elements to smooth
2880 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2881 # Note that nodes built on edges and boundary nodes are always fixed.
2882 # @param MaxNbOfIterations the maximum number of iterations
2883 # @param MaxAspectRatio varies in range [1.0, inf]
2884 # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2885 # @return TRUE in case of success, FALSE otherwise.
2886 # @ingroup l2_modif_smooth
2887 def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
2888 MaxNbOfIterations, MaxAspectRatio, Method):
2889 if IDsOfElements == []:
2890 IDsOfElements = self.GetElementsId()
2891 MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
2892 self.mesh.SetParameters(Parameters)
2893 return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
2894 MaxNbOfIterations, MaxAspectRatio, Method)
2896 ## Parametrically smoothes the elements which belong to the given object
2897 # @param theObject the object to smooth
2898 # @param IDsOfFixedNodes the list of ids of fixed nodes.
2899 # Note that nodes built on edges and boundary nodes are always fixed.
2900 # @param MaxNbOfIterations the maximum number of iterations
2901 # @param MaxAspectRatio varies in range [1.0, inf]
2902 # @param Method Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH)
2903 # @return TRUE in case of success, FALSE otherwise.
2904 # @ingroup l2_modif_smooth
2905 def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
2906 MaxNbOfIterations, MaxAspectRatio, Method):
2907 if ( isinstance( theObject, Mesh )):
2908 theObject = theObject.GetMesh()
2909 return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
2910 MaxNbOfIterations, MaxAspectRatio, Method)
2912 ## Converts the mesh to quadratic, deletes old elements, replacing
2913 # them with quadratic with the same id.
2914 # @param theForce3d new node creation method:
2915 # 0 - the medium node lies at the geometrical entity from which the mesh element is built
2916 # 1 - the medium node lies at the middle of the line segments connecting start and end node of a mesh element
2917 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2918 # @ingroup l2_modif_tofromqu
2919 def ConvertToQuadratic(self, theForce3d, theSubMesh=None):
2921 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
2923 self.editor.ConvertToQuadratic(theForce3d)
2925 ## Converts the mesh from quadratic to ordinary,
2926 # deletes old quadratic elements, \n replacing
2927 # them with ordinary mesh elements with the same id.
2928 # @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
2929 # @ingroup l2_modif_tofromqu
2930 def ConvertFromQuadratic(self, theSubMesh=None):
2932 self.editor.ConvertFromQuadraticObject(theSubMesh)
2934 return self.editor.ConvertFromQuadratic()
2936 ## Creates 2D mesh as skin on boundary faces of a 3D mesh
2937 # @return TRUE if operation has been completed successfully, FALSE otherwise
2938 # @ingroup l2_modif_edit
2939 def Make2DMeshFrom3D(self):
2940 return self.editor. Make2DMeshFrom3D()
2942 ## Creates missing boundary elements
2943 # @param elements - elements whose boundary is to be checked:
2944 # mesh, group, sub-mesh or list of elements
2945 # if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
2946 # @param dimension - defines type of boundary elements to create:
2947 # SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D
2948 # SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
2949 # @param groupName - a name of group to store created boundary elements in,
2950 # "" means not to create the group
2951 # @param meshName - a name of new mesh to store created boundary elements in,
2952 # "" means not to create the new mesh
2953 # @param toCopyElements - if true, the checked elements will be copied into
2954 # the new mesh else only boundary elements will be copied into the new mesh
2955 # @param toCopyExistingBondary - if true, not only new but also pre-existing
2956 # boundary elements will be copied into the new mesh
2957 # @return tuple (mesh, group) where bondary elements were added to
2958 # @ingroup l2_modif_edit
2959 def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
2960 toCopyElements=False, toCopyExistingBondary=False):
2961 if isinstance( elements, Mesh ):
2962 elements = elements.GetMesh()
2963 if ( isinstance( elements, list )):
2964 elemType = SMESH.ALL
2965 if elements: elemType = self.GetElementType( elements[0], iselem=True)
2966 elements = self.editor.MakeIDSource(elements, elemType)
2967 mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
2968 toCopyElements,toCopyExistingBondary)
2969 if mesh: mesh = self.smeshpyD.Mesh(mesh)
2973 # @brief Creates missing boundary elements around either the whole mesh or
2974 # groups of 2D elements
2975 # @param dimension - defines type of boundary elements to create
2976 # @param groupName - a name of group to store all boundary elements in,
2977 # "" means not to create the group
2978 # @param meshName - a name of a new mesh, which is a copy of the initial
2979 # mesh + created boundary elements; "" means not to create the new mesh
2980 # @param toCopyAll - if true, the whole initial mesh will be copied into
2981 # the new mesh else only boundary elements will be copied into the new mesh
2982 # @param groups - groups of 2D elements to make boundary around
2983 # @retval tuple( long, mesh, groups )
2984 # long - number of added boundary elements
2985 # mesh - the mesh where elements were added to
2986 # group - the group of boundary elements or None
2988 def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
2989 toCopyAll=False, groups=[]):
2990 nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
2992 if mesh: mesh = self.smeshpyD.Mesh(mesh)
2993 return nb, mesh, group
2995 ## Renumber mesh nodes
2996 # @ingroup l2_modif_renumber
2997 def RenumberNodes(self):
2998 self.editor.RenumberNodes()
3000 ## Renumber mesh elements
3001 # @ingroup l2_modif_renumber
3002 def RenumberElements(self):
3003 self.editor.RenumberElements()
3005 ## Generates new elements by rotation of the elements around the axis
3006 # @param IDsOfElements the list of ids of elements to sweep
3007 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3008 # @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3009 # @param NbOfSteps the number of steps
3010 # @param Tolerance tolerance
3011 # @param MakeGroups forces the generation of new groups from existing ones
3012 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3013 # of all steps, else - size of each step
3014 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3015 # @ingroup l2_modif_extrurev
3016 def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3017 MakeGroups=False, TotalAngle=False):
3018 if IDsOfElements == []:
3019 IDsOfElements = self.GetElementsId()
3020 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3021 Axis = self.smeshpyD.GetAxisStruct(Axis)
3022 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3023 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3024 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3025 self.mesh.SetParameters(Parameters)
3026 if TotalAngle and NbOfSteps:
3027 AngleInRadians /= NbOfSteps
3029 return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
3030 AngleInRadians, NbOfSteps, Tolerance)
3031 self.editor.RotationSweep(IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance)
3034 ## Generates new elements by rotation of the elements of object around the axis
3035 # @param theObject object which elements should be sweeped.
3036 # It can be a mesh, a sub mesh or a group.
3037 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3038 # @param AngleInRadians the angle of Rotation
3039 # @param NbOfSteps number of steps
3040 # @param Tolerance tolerance
3041 # @param MakeGroups forces the generation of new groups from existing ones
3042 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3043 # of all steps, else - size of each step
3044 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3045 # @ingroup l2_modif_extrurev
3046 def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3047 MakeGroups=False, TotalAngle=False):
3048 if ( isinstance( theObject, Mesh )):
3049 theObject = theObject.GetMesh()
3050 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3051 Axis = self.smeshpyD.GetAxisStruct(Axis)
3052 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3053 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3054 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3055 self.mesh.SetParameters(Parameters)
3056 if TotalAngle and NbOfSteps:
3057 AngleInRadians /= NbOfSteps
3059 return self.editor.RotationSweepObjectMakeGroups(theObject, Axis, AngleInRadians,
3060 NbOfSteps, Tolerance)
3061 self.editor.RotationSweepObject(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3064 ## Generates new elements by rotation of the elements of object around the axis
3065 # @param theObject object which elements should be sweeped.
3066 # It can be a mesh, a sub mesh or a group.
3067 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3068 # @param AngleInRadians the angle of Rotation
3069 # @param NbOfSteps number of steps
3070 # @param Tolerance tolerance
3071 # @param MakeGroups forces the generation of new groups from existing ones
3072 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3073 # of all steps, else - size of each step
3074 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3075 # @ingroup l2_modif_extrurev
3076 def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3077 MakeGroups=False, TotalAngle=False):
3078 if ( isinstance( theObject, Mesh )):
3079 theObject = theObject.GetMesh()
3080 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3081 Axis = self.smeshpyD.GetAxisStruct(Axis)
3082 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3083 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3084 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3085 self.mesh.SetParameters(Parameters)
3086 if TotalAngle and NbOfSteps:
3087 AngleInRadians /= NbOfSteps
3089 return self.editor.RotationSweepObject1DMakeGroups(theObject, Axis, AngleInRadians,
3090 NbOfSteps, Tolerance)
3091 self.editor.RotationSweepObject1D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3094 ## Generates new elements by rotation of the elements of object around the axis
3095 # @param theObject object which elements should be sweeped.
3096 # It can be a mesh, a sub mesh or a group.
3097 # @param Axis the axis of rotation, AxisStruct or line(geom object)
3098 # @param AngleInRadians the angle of Rotation
3099 # @param NbOfSteps number of steps
3100 # @param Tolerance tolerance
3101 # @param MakeGroups forces the generation of new groups from existing ones
3102 # @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3103 # of all steps, else - size of each step
3104 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3105 # @ingroup l2_modif_extrurev
3106 def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3107 MakeGroups=False, TotalAngle=False):
3108 if ( isinstance( theObject, Mesh )):
3109 theObject = theObject.GetMesh()
3110 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3111 Axis = self.smeshpyD.GetAxisStruct(Axis)
3112 AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3113 NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3114 Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3115 self.mesh.SetParameters(Parameters)
3116 if TotalAngle and NbOfSteps:
3117 AngleInRadians /= NbOfSteps
3119 return self.editor.RotationSweepObject2DMakeGroups(theObject, Axis, AngleInRadians,
3120 NbOfSteps, Tolerance)
3121 self.editor.RotationSweepObject2D(theObject, Axis, AngleInRadians, NbOfSteps, Tolerance)
3124 ## Generates new elements by extrusion of the elements with given ids
3125 # @param IDsOfElements the list of elements ids for extrusion
3126 # @param StepVector vector or DirStruct, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3127 # @param NbOfSteps the number of steps
3128 # @param MakeGroups forces the generation of new groups from existing ones
3129 # @param IsNodes is True if elements with given ids are nodes
3130 # @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3131 # @ingroup l2_modif_extrurev
3132 def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3133 if IDsOfElements == []:
3134 IDsOfElements = self.GetElementsId()
3135 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3136 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3137 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3138 Parameters = StepVector.PS.parameters + var_separator + Parameters
3139 self.mesh.SetParameters(Parameters)
3142 return self.editor.ExtrusionSweepMakeGroups0D(IDsOfElements, StepVector, NbOfSteps)
3144 return self.editor.ExtrusionSweepMakeGroups(IDsOfElements, StepVector, NbOfSteps)
3146 self.editor.ExtrusionSweep0D(IDsOfElements, StepVector, NbOfSteps)
3148 self.editor.ExtrusionSweep(IDsOfElements, StepVector, NbOfSteps)
3151 ## Generates new elements by extrusion of the elements with given ids
3152 # @param IDsOfElements is ids of elements
3153 # @param StepVector vector, defining the direction and value of extrusion
3154 # @param NbOfSteps the number of steps
3155 # @param ExtrFlags sets flags for extrusion
3156 # @param SewTolerance uses for comparing locations of nodes if flag
3157 # EXTRUSION_FLAG_SEW is set
3158 # @param MakeGroups forces the generation of new groups from existing ones
3159 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3160 # @ingroup l2_modif_extrurev
3161 def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3162 ExtrFlags, SewTolerance, MakeGroups=False):
3163 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3164 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3166 return self.editor.AdvancedExtrusionMakeGroups(IDsOfElements, StepVector, NbOfSteps,
3167 ExtrFlags, SewTolerance)
3168 self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
3169 ExtrFlags, SewTolerance)
3172 ## Generates new elements by extrusion of the elements which belong to the object
3173 # @param theObject the object which elements should be processed.
3174 # It can be a mesh, a sub mesh or a group.
3175 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3176 # @param NbOfSteps the number of steps
3177 # @param MakeGroups forces the generation of new groups from existing ones
3178 # @param IsNodes is True if elements which belong to the object are nodes
3179 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3180 # @ingroup l2_modif_extrurev
3181 def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3182 if ( isinstance( theObject, Mesh )):
3183 theObject = theObject.GetMesh()
3184 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3185 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3186 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3187 Parameters = StepVector.PS.parameters + var_separator + Parameters
3188 self.mesh.SetParameters(Parameters)
3191 return self.editor.ExtrusionSweepObject0DMakeGroups(theObject, StepVector, NbOfSteps)
3193 return self.editor.ExtrusionSweepObjectMakeGroups(theObject, StepVector, NbOfSteps)
3195 self.editor.ExtrusionSweepObject0D(theObject, StepVector, NbOfSteps)
3197 self.editor.ExtrusionSweepObject(theObject, StepVector, NbOfSteps)
3200 ## Generates new elements by extrusion of the elements which belong to the object
3201 # @param theObject object which elements should be processed.
3202 # It can be a mesh, a sub mesh or a group.
3203 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3204 # @param NbOfSteps the number of steps
3205 # @param MakeGroups to generate new groups from existing ones
3206 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3207 # @ingroup l2_modif_extrurev
3208 def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3209 if ( isinstance( theObject, Mesh )):
3210 theObject = theObject.GetMesh()
3211 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3212 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3213 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3214 Parameters = StepVector.PS.parameters + var_separator + Parameters
3215 self.mesh.SetParameters(Parameters)
3217 return self.editor.ExtrusionSweepObject1DMakeGroups(theObject, StepVector, NbOfSteps)
3218 self.editor.ExtrusionSweepObject1D(theObject, StepVector, NbOfSteps)
3221 ## Generates new elements by extrusion of the elements which belong to the object
3222 # @param theObject object which elements should be processed.
3223 # It can be a mesh, a sub mesh or a group.
3224 # @param StepVector vector, defining the direction and value of extrusion for one step (the total extrusion length will be NbOfSteps * ||StepVector||)
3225 # @param NbOfSteps the number of steps
3226 # @param MakeGroups forces the generation of new groups from existing ones
3227 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3228 # @ingroup l2_modif_extrurev
3229 def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3230 if ( isinstance( theObject, Mesh )):
3231 theObject = theObject.GetMesh()
3232 if ( isinstance( StepVector, geompyDC.GEOM._objref_GEOM_Object)):
3233 StepVector = self.smeshpyD.GetDirStruct(StepVector)
3234 NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3235 Parameters = StepVector.PS.parameters + var_separator + Parameters
3236 self.mesh.SetParameters(Parameters)
3238 return self.editor.ExtrusionSweepObject2DMakeGroups(theObject, StepVector, NbOfSteps)
3239 self.editor.ExtrusionSweepObject2D(theObject, StepVector, NbOfSteps)
3244 ## Generates new elements by extrusion of the given elements
3245 # The path of extrusion must be a meshed edge.
3246 # @param Base mesh or group, or submesh, or list of ids of elements for extrusion
3247 # @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
3248 # @param NodeStart the start node from Path. Defines the direction of extrusion
3249 # @param HasAngles allows the shape to be rotated around the path
3250 # to get the resulting mesh in a helical fashion
3251 # @param Angles list of angles in radians
3252 # @param LinearVariation forces the computation of rotation angles as linear
3253 # variation of the given Angles along path steps
3254 # @param HasRefPoint allows using the reference point
3255 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3256 # The User can specify any point as the Reference Point.
3257 # @param MakeGroups forces the generation of new groups from existing ones
3258 # @param ElemType type of elements for extrusion (if param Base is a mesh)
3259 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3260 # only SMESH::Extrusion_Error otherwise
3261 # @ingroup l2_modif_extrurev
3262 def ExtrusionAlongPathX(self, Base, Path, NodeStart,
3263 HasAngles, Angles, LinearVariation,
3264 HasRefPoint, RefPoint, MakeGroups, ElemType):
3265 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3266 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3268 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3269 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3270 self.mesh.SetParameters(Parameters)
3272 if (isinstance(Path, Mesh)): Path = Path.GetMesh()
3274 if isinstance(Base, list):
3276 if Base == []: IDsOfElements = self.GetElementsId()
3277 else: IDsOfElements = Base
3278 return self.editor.ExtrusionAlongPathX(IDsOfElements, Path, NodeStart,
3279 HasAngles, Angles, LinearVariation,
3280 HasRefPoint, RefPoint, MakeGroups, ElemType)
3282 if isinstance(Base, Mesh): Base = Base.GetMesh()
3283 if isinstance(Base, SMESH._objref_SMESH_Mesh) or isinstance(Base, SMESH._objref_SMESH_Group) or isinstance(Base, SMESH._objref_SMESH_subMesh):
3284 return self.editor.ExtrusionAlongPathObjX(Base, Path, NodeStart,
3285 HasAngles, Angles, LinearVariation,
3286 HasRefPoint, RefPoint, MakeGroups, ElemType)
3288 raise RuntimeError, "Invalid Base for ExtrusionAlongPathX"
3291 ## Generates new elements by extrusion of the given elements
3292 # The path of extrusion must be a meshed edge.
3293 # @param IDsOfElements ids of elements
3294 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
3295 # @param PathShape shape(edge) defines the sub-mesh for the path
3296 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3297 # @param HasAngles allows the shape to be rotated around the path
3298 # to get the resulting mesh in a helical fashion
3299 # @param Angles list of angles in radians
3300 # @param HasRefPoint allows using the reference point
3301 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3302 # The User can specify any point as the Reference Point.
3303 # @param MakeGroups forces the generation of new groups from existing ones
3304 # @param LinearVariation forces the computation of rotation angles as linear
3305 # variation of the given Angles along path steps
3306 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3307 # only SMESH::Extrusion_Error otherwise
3308 # @ingroup l2_modif_extrurev
3309 def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
3310 HasAngles, Angles, HasRefPoint, RefPoint,
3311 MakeGroups=False, LinearVariation=False):
3312 if IDsOfElements == []:
3313 IDsOfElements = self.GetElementsId()
3314 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3315 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3317 if ( isinstance( PathMesh, Mesh )):
3318 PathMesh = PathMesh.GetMesh()
3319 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3320 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3321 self.mesh.SetParameters(Parameters)
3322 if HasAngles and Angles and LinearVariation:
3323 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3326 return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
3327 PathShape, NodeStart, HasAngles,
3328 Angles, HasRefPoint, RefPoint)
3329 return self.editor.ExtrusionAlongPath(IDsOfElements, PathMesh, PathShape,
3330 NodeStart, HasAngles, Angles, HasRefPoint, RefPoint)
3332 ## Generates new elements by extrusion of the elements which belong to the object
3333 # The path of extrusion must be a meshed edge.
3334 # @param theObject the object which elements should be processed.
3335 # It can be a mesh, a sub mesh or a group.
3336 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3337 # @param PathShape shape(edge) defines the sub-mesh for the path
3338 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3339 # @param HasAngles allows the shape to be rotated around the path
3340 # to get the resulting mesh in a helical fashion
3341 # @param Angles list of angles
3342 # @param HasRefPoint allows using the reference point
3343 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3344 # The User can specify any point as the Reference Point.
3345 # @param MakeGroups forces the generation of new groups from existing ones
3346 # @param LinearVariation forces the computation of rotation angles as linear
3347 # variation of the given Angles along path steps
3348 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3349 # only SMESH::Extrusion_Error otherwise
3350 # @ingroup l2_modif_extrurev
3351 def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
3352 HasAngles, Angles, HasRefPoint, RefPoint,
3353 MakeGroups=False, LinearVariation=False):
3354 if ( isinstance( theObject, Mesh )):
3355 theObject = theObject.GetMesh()
3356 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3357 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3358 if ( isinstance( PathMesh, Mesh )):
3359 PathMesh = PathMesh.GetMesh()
3360 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3361 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3362 self.mesh.SetParameters(Parameters)
3363 if HasAngles and Angles and LinearVariation:
3364 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3367 return self.editor.ExtrusionAlongPathObjectMakeGroups(theObject, PathMesh,
3368 PathShape, NodeStart, HasAngles,
3369 Angles, HasRefPoint, RefPoint)
3370 return self.editor.ExtrusionAlongPathObject(theObject, PathMesh, PathShape,
3371 NodeStart, HasAngles, Angles, HasRefPoint,
3374 ## Generates new elements by extrusion of the elements which belong to the object
3375 # The path of extrusion must be a meshed edge.
3376 # @param theObject the object which elements should be processed.
3377 # It can be a mesh, a sub mesh or a group.
3378 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3379 # @param PathShape shape(edge) defines the sub-mesh for the path
3380 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3381 # @param HasAngles allows the shape to be rotated around the path
3382 # to get the resulting mesh in a helical fashion
3383 # @param Angles list of angles
3384 # @param HasRefPoint allows using the reference point
3385 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3386 # The User can specify any point as the Reference Point.
3387 # @param MakeGroups forces the generation of new groups from existing ones
3388 # @param LinearVariation forces the computation of rotation angles as linear
3389 # variation of the given Angles along path steps
3390 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3391 # only SMESH::Extrusion_Error otherwise
3392 # @ingroup l2_modif_extrurev
3393 def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
3394 HasAngles, Angles, HasRefPoint, RefPoint,
3395 MakeGroups=False, LinearVariation=False):
3396 if ( isinstance( theObject, Mesh )):
3397 theObject = theObject.GetMesh()
3398 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3399 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3400 if ( isinstance( PathMesh, Mesh )):
3401 PathMesh = PathMesh.GetMesh()
3402 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3403 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3404 self.mesh.SetParameters(Parameters)
3405 if HasAngles and Angles and LinearVariation:
3406 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3409 return self.editor.ExtrusionAlongPathObject1DMakeGroups(theObject, PathMesh,
3410 PathShape, NodeStart, HasAngles,
3411 Angles, HasRefPoint, RefPoint)
3412 return self.editor.ExtrusionAlongPathObject1D(theObject, PathMesh, PathShape,
3413 NodeStart, HasAngles, Angles, HasRefPoint,
3416 ## Generates new elements by extrusion of the elements which belong to the object
3417 # The path of extrusion must be a meshed edge.
3418 # @param theObject the object which elements should be processed.
3419 # It can be a mesh, a sub mesh or a group.
3420 # @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
3421 # @param PathShape shape(edge) defines the sub-mesh for the path
3422 # @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
3423 # @param HasAngles allows the shape to be rotated around the path
3424 # to get the resulting mesh in a helical fashion
3425 # @param Angles list of angles
3426 # @param HasRefPoint allows using the reference point
3427 # @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
3428 # The User can specify any point as the Reference Point.
3429 # @param MakeGroups forces the generation of new groups from existing ones
3430 # @param LinearVariation forces the computation of rotation angles as linear
3431 # variation of the given Angles along path steps
3432 # @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
3433 # only SMESH::Extrusion_Error otherwise
3434 # @ingroup l2_modif_extrurev
3435 def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
3436 HasAngles, Angles, HasRefPoint, RefPoint,
3437 MakeGroups=False, LinearVariation=False):
3438 if ( isinstance( theObject, Mesh )):
3439 theObject = theObject.GetMesh()
3440 if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
3441 RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
3442 if ( isinstance( PathMesh, Mesh )):
3443 PathMesh = PathMesh.GetMesh()
3444 Angles,AnglesParameters,hasVars = ParseAngles(Angles)
3445 Parameters = AnglesParameters + var_separator + RefPoint.parameters
3446 self.mesh.SetParameters(Parameters)
3447 if HasAngles and Angles and LinearVariation:
3448 Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
3451 return self.editor.ExtrusionAlongPathObject2DMakeGroups(theObject, PathMesh,
3452 PathShape, NodeStart, HasAngles,
3453 Angles, HasRefPoint, RefPoint)
3454 return self.editor.ExtrusionAlongPathObject2D(theObject, PathMesh, PathShape,
3455 NodeStart, HasAngles, Angles, HasRefPoint,
3458 ## Creates a symmetrical copy of mesh elements
3459 # @param IDsOfElements list of elements ids
3460 # @param Mirror is AxisStruct or geom object(point, line, plane)
3461 # @param theMirrorType is POINT, AXIS or PLANE
3462 # If the Mirror is a geom object this parameter is unnecessary
3463 # @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
3464 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3465 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3466 # @ingroup l2_modif_trsf
3467 def Mirror(self, IDsOfElements, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3468 if IDsOfElements == []:
3469 IDsOfElements = self.GetElementsId()
3470 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3471 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3472 self.mesh.SetParameters(Mirror.parameters)
3473 if Copy and MakeGroups:
3474 return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
3475 self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
3478 ## Creates a new mesh by a symmetrical copy of mesh elements
3479 # @param IDsOfElements the list of elements ids
3480 # @param Mirror is AxisStruct or geom object (point, line, plane)
3481 # @param theMirrorType is POINT, AXIS or PLANE
3482 # If the Mirror is a geom object this parameter is unnecessary
3483 # @param MakeGroups to generate new groups from existing ones
3484 # @param NewMeshName a name of the new mesh to create
3485 # @return instance of Mesh class
3486 # @ingroup l2_modif_trsf
3487 def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""):
3488 if IDsOfElements == []:
3489 IDsOfElements = self.GetElementsId()
3490 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3491 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3492 self.mesh.SetParameters(Mirror.parameters)
3493 mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
3494 MakeGroups, NewMeshName)
3495 return Mesh(self.smeshpyD,self.geompyD,mesh)
3497 ## Creates a symmetrical copy of the object
3498 # @param theObject mesh, submesh or group
3499 # @param Mirror AxisStruct or geom object (point, line, plane)
3500 # @param theMirrorType is POINT, AXIS or PLANE
3501 # If the Mirror is a geom object this parameter is unnecessary
3502 # @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
3503 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3504 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3505 # @ingroup l2_modif_trsf
3506 def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False):
3507 if ( isinstance( theObject, Mesh )):
3508 theObject = theObject.GetMesh()
3509 if ( isinstance( Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3510 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3511 self.mesh.SetParameters(Mirror.parameters)
3512 if Copy and MakeGroups:
3513 return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
3514 self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
3517 ## Creates a new mesh by a symmetrical copy of the object
3518 # @param theObject mesh, submesh or group
3519 # @param Mirror AxisStruct or geom object (point, line, plane)
3520 # @param theMirrorType POINT, AXIS or PLANE
3521 # If the Mirror is a geom object this parameter is unnecessary
3522 # @param MakeGroups forces the generation of new groups from existing ones
3523 # @param NewMeshName the name of the new mesh to create
3524 # @return instance of Mesh class
3525 # @ingroup l2_modif_trsf
3526 def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""):
3527 if ( isinstance( theObject, Mesh )):
3528 theObject = theObject.GetMesh()
3529 if (isinstance(Mirror, geompyDC.GEOM._objref_GEOM_Object)):
3530 Mirror = self.smeshpyD.GetAxisStruct(Mirror)
3531 self.mesh.SetParameters(Mirror.parameters)
3532 mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
3533 MakeGroups, NewMeshName)
3534 return Mesh( self.smeshpyD,self.geompyD,mesh )
3536 ## Translates the elements
3537 # @param IDsOfElements list of elements ids
3538 # @param Vector the direction of translation (DirStruct or vector)
3539 # @param Copy allows copying the translated elements
3540 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3541 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3542 # @ingroup l2_modif_trsf
3543 def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
3544 if IDsOfElements == []:
3545 IDsOfElements = self.GetElementsId()
3546 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3547 Vector = self.smeshpyD.GetDirStruct(Vector)
3548 self.mesh.SetParameters(Vector.PS.parameters)
3549 if Copy and MakeGroups:
3550 return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
3551 self.editor.Translate(IDsOfElements, Vector, Copy)
3554 ## Creates a new mesh of translated elements
3555 # @param IDsOfElements list of elements ids
3556 # @param Vector the direction of translation (DirStruct or vector)
3557 # @param MakeGroups forces the generation of new groups from existing ones
3558 # @param NewMeshName the name of the newly created mesh
3559 # @return instance of Mesh class
3560 # @ingroup l2_modif_trsf
3561 def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
3562 if IDsOfElements == []:
3563 IDsOfElements = self.GetElementsId()
3564 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3565 Vector = self.smeshpyD.GetDirStruct(Vector)
3566 self.mesh.SetParameters(Vector.PS.parameters)
3567 mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
3568 return Mesh ( self.smeshpyD, self.geompyD, mesh )
3570 ## Translates the object
3571 # @param theObject the object to translate (mesh, submesh, or group)
3572 # @param Vector direction of translation (DirStruct or geom vector)
3573 # @param Copy allows copying the translated elements
3574 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3575 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3576 # @ingroup l2_modif_trsf
3577 def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
3578 if ( isinstance( theObject, Mesh )):
3579 theObject = theObject.GetMesh()
3580 if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)):
3581 Vector = self.smeshpyD.GetDirStruct(Vector)
3582 self.mesh.SetParameters(Vector.PS.parameters)
3583 if Copy and MakeGroups:
3584 return self.editor.TranslateObjectMakeGroups(theObject, Vector)
3585 self.editor.TranslateObject(theObject, Vector, Copy)
3588 ## Creates a new mesh from the translated object
3589 # @param theObject the object to translate (mesh, submesh, or group)
3590 # @param Vector the direction of translation (DirStruct or geom vector)
3591 # @param MakeGroups forces the generation of new groups from existing ones
3592 # @param NewMeshName the name of the newly created mesh
3593 # @return instance of Mesh class
3594 # @ingroup l2_modif_trsf
3595 def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
3596 if (isinstance(theObject, Mesh)):
3597 theObject = theObject.GetMesh()
3598 if (isinstance(Vector, geompyDC.GEOM._objref_GEOM_Object)):
3599 Vector = self.smeshpyD.GetDirStruct(Vector)
3600 self.mesh.SetParameters(Vector.PS.parameters)
3601 mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
3602 return Mesh( self.smeshpyD, self.geompyD, mesh )
3606 ## Scales the object
3607 # @param theObject - the object to translate (mesh, submesh, or group)
3608 # @param thePoint - base point for scale
3609 # @param theScaleFact - list of 1-3 scale factors for axises
3610 # @param Copy - allows copying the translated elements
3611 # @param MakeGroups - forces the generation of new groups from existing
3613 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
3614 # empty list otherwise
3615 def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
3616 if ( isinstance( theObject, Mesh )):
3617 theObject = theObject.GetMesh()
3618 if ( isinstance( theObject, list )):
3619 theObject = self.GetIDSource(theObject, SMESH.ALL)
3621 self.mesh.SetParameters(thePoint.parameters)
3623 if Copy and MakeGroups:
3624 return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
3625 self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
3628 ## Creates a new mesh from the translated object
3629 # @param theObject - the object to translate (mesh, submesh, or group)
3630 # @param thePoint - base point for scale
3631 # @param theScaleFact - list of 1-3 scale factors for axises
3632 # @param MakeGroups - forces the generation of new groups from existing ones
3633 # @param NewMeshName - the name of the newly created mesh
3634 # @return instance of Mesh class
3635 def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
3636 if (isinstance(theObject, Mesh)):
3637 theObject = theObject.GetMesh()
3638 if ( isinstance( theObject, list )):
3639 theObject = self.GetIDSource(theObject,SMESH.ALL)
3641 self.mesh.SetParameters(thePoint.parameters)
3642 mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
3643 MakeGroups, NewMeshName)
3644 return Mesh( self.smeshpyD, self.geompyD, mesh )
3648 ## Rotates the elements
3649 # @param IDsOfElements list of elements ids
3650 # @param Axis the axis of rotation (AxisStruct or geom line)
3651 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3652 # @param Copy allows copying the rotated elements
3653 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3654 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3655 # @ingroup l2_modif_trsf
3656 def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
3657 if IDsOfElements == []:
3658 IDsOfElements = self.GetElementsId()
3659 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3660 Axis = self.smeshpyD.GetAxisStruct(Axis)
3661 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3662 Parameters = Axis.parameters + var_separator + Parameters
3663 self.mesh.SetParameters(Parameters)
3664 if Copy and MakeGroups:
3665 return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
3666 self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
3669 ## Creates a new mesh of rotated elements
3670 # @param IDsOfElements list of element ids
3671 # @param Axis the axis of rotation (AxisStruct or geom line)
3672 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3673 # @param MakeGroups forces the generation of new groups from existing ones
3674 # @param NewMeshName the name of the newly created mesh
3675 # @return instance of Mesh class
3676 # @ingroup l2_modif_trsf
3677 def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
3678 if IDsOfElements == []:
3679 IDsOfElements = self.GetElementsId()
3680 if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
3681 Axis = self.smeshpyD.GetAxisStruct(Axis)
3682 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3683 Parameters = Axis.parameters + var_separator + Parameters
3684 self.mesh.SetParameters(Parameters)
3685 mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
3686 MakeGroups, NewMeshName)
3687 return Mesh( self.smeshpyD, self.geompyD, mesh )
3689 ## Rotates the object
3690 # @param theObject the object to rotate( mesh, submesh, or group)
3691 # @param Axis the axis of rotation (AxisStruct or geom line)
3692 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3693 # @param Copy allows copying the rotated elements
3694 # @param MakeGroups forces the generation of new groups from existing ones (if Copy)
3695 # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3696 # @ingroup l2_modif_trsf
3697 def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
3698 if (isinstance(theObject, Mesh)):
3699 theObject = theObject.GetMesh()
3700 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3701 Axis = self.smeshpyD.GetAxisStruct(Axis)
3702 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3703 Parameters = Axis.parameters + ":" + Parameters
3704 self.mesh.SetParameters(Parameters)
3705 if Copy and MakeGroups:
3706 return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
3707 self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
3710 ## Creates a new mesh from the rotated object
3711 # @param theObject the object to rotate (mesh, submesh, or group)
3712 # @param Axis the axis of rotation (AxisStruct or geom line)
3713 # @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
3714 # @param MakeGroups forces the generation of new groups from existing ones
3715 # @param NewMeshName the name of the newly created mesh
3716 # @return instance of Mesh class
3717 # @ingroup l2_modif_trsf
3718 def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
3719 if (isinstance( theObject, Mesh )):
3720 theObject = theObject.GetMesh()
3721 if (isinstance(Axis, geompyDC.GEOM._objref_GEOM_Object)):
3722 Axis = self.smeshpyD.GetAxisStruct(Axis)
3723 AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
3724 Parameters = Axis.parameters + ":" + Parameters
3725 mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
3726 MakeGroups, NewMeshName)
3727 self.mesh.SetParameters(Parameters)
3728 return Mesh( self.smeshpyD, self.geompyD, mesh )
3730 ## Finds groups of ajacent nodes within Tolerance.
3731 # @param Tolerance the value of tolerance
3732 # @return the list of groups of nodes
3733 # @ingroup l2_modif_trsf
3734 def FindCoincidentNodes (self, Tolerance):
3735 return self.editor.FindCoincidentNodes(Tolerance)
3737 ## Finds groups of ajacent nodes within Tolerance.
3738 # @param Tolerance the value of tolerance
3739 # @param SubMeshOrGroup SubMesh or Group
3740 # @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
3741 # @return the list of groups of nodes
3742 # @ingroup l2_modif_trsf
3743 def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance, exceptNodes=[]):
3744 if (isinstance( SubMeshOrGroup, Mesh )):
3745 SubMeshOrGroup = SubMeshOrGroup.GetMesh()
3746 if not isinstance( exceptNodes, list):
3747 exceptNodes = [ exceptNodes ]
3748 if exceptNodes and isinstance( exceptNodes[0], int):
3749 exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE)]
3750 return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,exceptNodes)
3753 # @param GroupsOfNodes the list of groups of nodes
3754 # @ingroup l2_modif_trsf
3755 def MergeNodes (self, GroupsOfNodes):
3756 self.editor.MergeNodes(GroupsOfNodes)
3758 ## Finds the elements built on the same nodes.
3759 # @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
3760 # @return a list of groups of equal elements
3761 # @ingroup l2_modif_trsf
3762 def FindEqualElements (self, MeshOrSubMeshOrGroup):
3763 if ( isinstance( MeshOrSubMeshOrGroup, Mesh )):
3764 MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
3765 return self.editor.FindEqualElements(MeshOrSubMeshOrGroup)
3767 ## Merges elements in each given group.
3768 # @param GroupsOfElementsID groups of elements for merging
3769 # @ingroup l2_modif_trsf
3770 def MergeElements(self, GroupsOfElementsID):
3771 self.editor.MergeElements(GroupsOfElementsID)
3773 ## Leaves one element and removes all other elements built on the same nodes.
3774 # @ingroup l2_modif_trsf
3775 def MergeEqualElements(self):
3776 self.editor.MergeEqualElements()
3778 ## Sews free borders
3779 # @return SMESH::Sew_Error
3780 # @ingroup l2_modif_trsf
3781 def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3782 FirstNodeID2, SecondNodeID2, LastNodeID2,
3783 CreatePolygons, CreatePolyedrs):
3784 return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3785 FirstNodeID2, SecondNodeID2, LastNodeID2,
3786 CreatePolygons, CreatePolyedrs)
3788 ## Sews conform free borders
3789 # @return SMESH::Sew_Error
3790 # @ingroup l2_modif_trsf
3791 def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
3792 FirstNodeID2, SecondNodeID2):
3793 return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
3794 FirstNodeID2, SecondNodeID2)
3796 ## Sews border to side
3797 # @return SMESH::Sew_Error
3798 # @ingroup l2_modif_trsf
3799 def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3800 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
3801 return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
3802 FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
3804 ## Sews two sides of a mesh. The nodes belonging to Side1 are
3805 # merged with the nodes of elements of Side2.
3806 # The number of elements in theSide1 and in theSide2 must be
3807 # equal and they should have similar nodal connectivity.
3808 # The nodes to merge should belong to side borders and
3809 # the first node should be linked to the second.
3810 # @return SMESH::Sew_Error
3811 # @ingroup l2_modif_trsf
3812 def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
3813 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3814 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
3815 return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
3816 NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
3817 NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
3819 ## Sets new nodes for the given element.
3820 # @param ide the element id
3821 # @param newIDs nodes ids
3822 # @return If the number of nodes does not correspond to the type of element - returns false
3823 # @ingroup l2_modif_edit
3824 def ChangeElemNodes(self, ide, newIDs):
3825 return self.editor.ChangeElemNodes(ide, newIDs)
3827 ## If during the last operation of MeshEditor some nodes were
3828 # created, this method returns the list of their IDs, \n
3829 # if new nodes were not created - returns empty list
3830 # @return the list of integer values (can be empty)
3831 # @ingroup l1_auxiliary
3832 def GetLastCreatedNodes(self):
3833 return self.editor.GetLastCreatedNodes()
3835 ## If during the last operation of MeshEditor some elements were
3836 # created this method returns the list of their IDs, \n
3837 # if new elements were not created - returns empty list
3838 # @return the list of integer values (can be empty)
3839 # @ingroup l1_auxiliary
3840 def GetLastCreatedElems(self):
3841 return self.editor.GetLastCreatedElems()
3843 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3844 # @param theNodes identifiers of nodes to be doubled
3845 # @param theModifiedElems identifiers of elements to be updated by the new (doubled)
3846 # nodes. If list of element identifiers is empty then nodes are doubled but
3847 # they not assigned to elements
3848 # @return TRUE if operation has been completed successfully, FALSE otherwise
3849 # @ingroup l2_modif_edit
3850 def DoubleNodes(self, theNodes, theModifiedElems):
3851 return self.editor.DoubleNodes(theNodes, theModifiedElems)
3853 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3854 # This method provided for convenience works as DoubleNodes() described above.
3855 # @param theNodeId identifiers of node to be doubled
3856 # @param theModifiedElems identifiers of elements to be updated
3857 # @return TRUE if operation has been completed successfully, FALSE otherwise
3858 # @ingroup l2_modif_edit
3859 def DoubleNode(self, theNodeId, theModifiedElems):
3860 return self.editor.DoubleNode(theNodeId, theModifiedElems)
3862 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3863 # This method provided for convenience works as DoubleNodes() described above.
3864 # @param theNodes group of nodes to be doubled
3865 # @param theModifiedElems group of elements to be updated.
3866 # @param theMakeGroup forces the generation of a group containing new nodes.
3867 # @return TRUE or a created group if operation has been completed successfully,
3868 # FALSE or None otherwise
3869 # @ingroup l2_modif_edit
3870 def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
3872 return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
3873 return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
3875 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3876 # This method provided for convenience works as DoubleNodes() described above.
3877 # @param theNodes list of groups of nodes to be doubled
3878 # @param theModifiedElems list of groups of elements to be updated.
3879 # @param theMakeGroup forces the generation of a group containing new nodes.
3880 # @return TRUE if operation has been completed successfully, FALSE otherwise
3881 # @ingroup l2_modif_edit
3882 def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
3884 return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
3885 return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
3887 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3888 # @param theElems - the list of elements (edges or faces) to be replicated
3889 # The nodes for duplication could be found from these elements
3890 # @param theNodesNot - list of nodes to NOT replicate
3891 # @param theAffectedElems - the list of elements (cells and edges) to which the
3892 # replicated nodes should be associated to.
3893 # @return TRUE if operation has been completed successfully, FALSE otherwise
3894 # @ingroup l2_modif_edit
3895 def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
3896 return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
3898 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3899 # @param theElems - the list of elements (edges or faces) to be replicated
3900 # The nodes for duplication could be found from these elements
3901 # @param theNodesNot - list of nodes to NOT replicate
3902 # @param theShape - shape to detect affected elements (element which geometric center
3903 # located on or inside shape).
3904 # The replicated nodes should be associated to affected elements.
3905 # @return TRUE if operation has been completed successfully, FALSE otherwise
3906 # @ingroup l2_modif_edit
3907 def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
3908 return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
3910 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3911 # This method provided for convenience works as DoubleNodes() described above.
3912 # @param theElems - group of of elements (edges or faces) to be replicated
3913 # @param theNodesNot - group of nodes not to replicated
3914 # @param theAffectedElems - group of elements to which the replicated nodes
3915 # should be associated to.
3916 # @param theMakeGroup forces the generation of a group containing new elements.
3917 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
3918 # @return TRUE or created groups (one or two) if operation has been completed successfully,
3919 # FALSE or None otherwise
3920 # @ingroup l2_modif_edit
3921 def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
3922 theMakeGroup=False, theMakeNodeGroup=False):
3923 if theMakeGroup or theMakeNodeGroup:
3924 twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
3926 theMakeGroup, theMakeNodeGroup)
3927 if theMakeGroup and theMakeNodeGroup:
3930 return twoGroups[ int(theMakeNodeGroup) ]
3931 return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
3933 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3934 # This method provided for convenience works as DoubleNodes() described above.
3935 # @param theElems - group of of elements (edges or faces) to be replicated
3936 # @param theNodesNot - group of nodes not to replicated
3937 # @param theShape - shape to detect affected elements (element which geometric center
3938 # located on or inside shape).
3939 # The replicated nodes should be associated to affected elements.
3940 # @ingroup l2_modif_edit
3941 def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
3942 return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
3944 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3945 # This method provided for convenience works as DoubleNodes() described above.
3946 # @param theElems - list of groups of elements (edges or faces) to be replicated
3947 # @param theNodesNot - list of groups of nodes not to replicated
3948 # @param theAffectedElems - group of elements to which the replicated nodes
3949 # should be associated to.
3950 # @param theMakeGroup forces the generation of a group containing new elements.
3951 # @param theMakeNodeGroup forces the generation of a group containing new nodes.
3952 # @return TRUE or created groups (one or two) if operation has been completed successfully,
3953 # FALSE or None otherwise
3954 # @ingroup l2_modif_edit
3955 def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
3956 theMakeGroup=False, theMakeNodeGroup=False):
3957 if theMakeGroup or theMakeNodeGroup:
3958 twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
3960 theMakeGroup, theMakeNodeGroup)
3961 if theMakeGroup and theMakeNodeGroup:
3964 return twoGroups[ int(theMakeNodeGroup) ]
3965 return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
3967 ## Creates a hole in a mesh by doubling the nodes of some particular elements
3968 # This method provided for convenience works as DoubleNodes() described above.
3969 # @param theElems - list of groups of elements (edges or faces) to be replicated
3970 # @param theNodesNot - list of groups of nodes not to replicated
3971 # @param theShape - shape to detect affected elements (element which geometric center
3972 # located on or inside shape).
3973 # The replicated nodes should be associated to affected elements.
3974 # @return TRUE if operation has been completed successfully, FALSE otherwise
3975 # @ingroup l2_modif_edit
3976 def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
3977 return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
3979 ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
3980 # This method is the first step of DoubleNodeElemGroupsInRegion.
3981 # @param theElems - list of groups of elements (edges or faces) to be replicated
3982 # @param theNodesNot - list of groups of nodes not to replicated
3983 # @param theShape - shape to detect affected elements (element which geometric center
3984 # located on or inside shape).
3985 # The replicated nodes should be associated to affected elements.
3986 # @return groups of affected elements
3987 # @ingroup l2_modif_edit
3988 def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
3989 return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
3991 ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
3992 # The list of groups must describe a partition of the mesh volumes.
3993 # The nodes of the internal faces at the boundaries of the groups are doubled.
3994 # In option, the internal faces are replaced by flat elements.
3995 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
3996 # @param theDomains - list of groups of volumes
3997 # @param createJointElems - if TRUE, create the elements
3998 # @return TRUE if operation has been completed successfully, FALSE otherwise
3999 def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems ):
4000 return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems )
4002 ## Double nodes on some external faces and create flat elements.
4003 # Flat elements are mainly used by some types of mechanic calculations.
4005 # Each group of the list must be constituted of faces.
4006 # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4007 # @param theGroupsOfFaces - list of groups of faces
4008 # @return TRUE if operation has been completed successfully, FALSE otherwise
4009 def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4010 return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4012 ## identify all the elements around a geom shape, get the faces delimiting the hole
4014 def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4015 return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4017 def _valueFromFunctor(self, funcType, elemId):
4018 fn = self.smeshpyD.GetFunctor(funcType)
4019 fn.SetMesh(self.mesh)
4020 if fn.GetElementType() == self.GetElementType(elemId, True):
4021 val = fn.GetValue(elemId)
4026 ## Get length of 1D element.
4027 # @param elemId mesh element ID
4028 # @return element's length value
4029 # @ingroup l1_measurements
4030 def GetLength(self, elemId):
4031 return self._valueFromFunctor(SMESH.FT_Length, elemId)
4033 ## Get area of 2D element.
4034 # @param elemId mesh element ID
4035 # @return element's area value
4036 # @ingroup l1_measurements
4037 def GetArea(self, elemId):
4038 return self._valueFromFunctor(SMESH.FT_Area, elemId)
4040 ## Get volume of 3D element.
4041 # @param elemId mesh element ID
4042 # @return element's volume value
4043 # @ingroup l1_measurements
4044 def GetVolume(self, elemId):
4045 return self._valueFromFunctor(SMESH.FT_Volume3D, elemId)
4047 ## Get maximum element length.
4048 # @param elemId mesh element ID
4049 # @return element's maximum length value
4050 # @ingroup l1_measurements
4051 def GetMaxElementLength(self, elemId):
4052 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4053 ftype = SMESH.FT_MaxElementLength3D
4055 ftype = SMESH.FT_MaxElementLength2D
4056 return self._valueFromFunctor(ftype, elemId)
4058 ## Get aspect ratio of 2D or 3D element.
4059 # @param elemId mesh element ID
4060 # @return element's aspect ratio value
4061 # @ingroup l1_measurements
4062 def GetAspectRatio(self, elemId):
4063 if self.GetElementType(elemId, True) == SMESH.VOLUME:
4064 ftype = SMESH.FT_AspectRatio3D
4066 ftype = SMESH.FT_AspectRatio
4067 return self._valueFromFunctor(ftype, elemId)
4069 ## Get warping angle of 2D element.
4070 # @param elemId mesh element ID
4071 # @return element's warping angle value
4072 # @ingroup l1_measurements
4073 def GetWarping(self, elemId):
4074 return self._valueFromFunctor(SMESH.FT_Warping, elemId)
4076 ## Get minimum angle of 2D element.
4077 # @param elemId mesh element ID
4078 # @return element's minimum angle value
4079 # @ingroup l1_measurements
4080 def GetMinimumAngle(self, elemId):
4081 return self._valueFromFunctor(SMESH.FT_MinimumAngle, elemId)
4083 ## Get taper of 2D element.
4084 # @param elemId mesh element ID
4085 # @return element's taper value
4086 # @ingroup l1_measurements
4087 def GetTaper(self, elemId):
4088 return self._valueFromFunctor(SMESH.FT_Taper, elemId)
4090 ## Get skew of 2D element.
4091 # @param elemId mesh element ID
4092 # @return element's skew value
4093 # @ingroup l1_measurements
4094 def GetSkew(self, elemId):
4095 return self._valueFromFunctor(SMESH.FT_Skew, elemId)
4097 pass # end of Mesh class
4099 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
4101 class Pattern(SMESH._objref_SMESH_Pattern):
4103 def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
4104 decrFun = lambda i: i-1
4105 theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
4106 theMesh.SetParameters(Parameters)
4107 return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
4109 def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
4110 decrFun = lambda i: i-1
4111 theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
4112 theMesh.SetParameters(Parameters)
4113 return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
4115 # Registering the new proxy for Pattern
4116 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
4118 ## Private class used to bind methods creating algorithms to the class Mesh
4123 self.defaultAlgoType = ""
4124 self.algoTypeToClass = {}
4126 # Stores a python class of algorithm
4127 def add(self, algoClass):
4128 if type( algoClass ).__name__ == 'classobj' and \
4129 hasattr( algoClass, "algoType"):
4130 self.algoTypeToClass[ algoClass.algoType ] = algoClass
4131 if not self.defaultAlgoType and \
4132 hasattr( algoClass, "isDefault") and algoClass.isDefault:
4133 self.defaultAlgoType = algoClass.algoType
4134 #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
4136 # creates a copy of self and assign mesh to the copy
4137 def copy(self, mesh):
4138 other = algoCreator()
4139 other.defaultAlgoType = self.defaultAlgoType
4140 other.algoTypeToClass = self.algoTypeToClass
4144 # creates an instance of algorithm
4145 def __call__(self,algo="",geom=0,*args):
4146 algoType = self.defaultAlgoType
4147 for arg in args + (algo,geom):
4148 if isinstance( arg, geompyDC.GEOM._objref_GEOM_Object ):
4150 if isinstance( arg, str ) and arg:
4152 if not algoType and self.algoTypeToClass:
4153 algoType = self.algoTypeToClass.keys()[0]
4154 if self.algoTypeToClass.has_key( algoType ):
4155 #print "Create algo",algoType
4156 return self.algoTypeToClass[ algoType ]( self.mesh, geom )
4157 raise RuntimeError, "No class found for algo type %s" % algoType
4160 # Private class used to substitute and store variable parameters of hypotheses.
4162 class hypMethodWrapper:
4163 def __init__(self, hyp, method):
4165 self.method = method
4166 #print "REBIND:", method.__name__
4169 # call a method of hypothesis with calling SetVarParameter() before
4170 def __call__(self,*args):
4172 return self.method( self.hyp, *args ) # hypothesis method with no args
4174 #print "MethWrapper.__call__",self.method.__name__, args
4176 parsed = ParseParameters(*args) # replace variables with their values
4177 self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
4178 result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
4179 except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
4180 # maybe there is a replaced string arg which is not variable
4181 result = self.method( self.hyp, *args )
4182 except ValueError, detail: # raised by ParseParameters()
4184 result = self.method( self.hyp, *args )
4185 except omniORB.CORBA.BAD_PARAM:
4186 raise ValueError, detail # wrong variable name