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