Salome HOME
refs #256: 7.5.7. Quality check algorithms
[modules/smesh.git] / src / SMESH_SWIG / smeshBuilder.py
1 # Copyright (C) 2007-2016  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, or (at your option) any later version.
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   : smeshBuilder.py
20 #  Author : Francis KLOSS, OCC
21 #  Module : SMESH
22
23 ## @package smeshBuilder
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_segmarv Segments around Vertex
36 ##     @defgroup l3_algos_3dextr  3D extrusion meshing algorithm
37
38 ##   @}
39 ##   @defgroup l2_hypotheses Defining hypotheses
40 ##   @{
41 ##     @defgroup l3_hypos_1dhyps 1D Meshing Hypotheses
42 ##     @defgroup l3_hypos_2dhyps 2D Meshing Hypotheses
43 ##     @defgroup l3_hypos_maxvol Max Element Volume hypothesis
44 ##     @defgroup l3_hypos_quad Quadrangle Parameters hypothesis
45 ##     @defgroup l3_hypos_additi Additional Hypotheses
46
47 ##   @}
48 ##   @defgroup l2_submeshes Constructing submeshes
49 ##   @defgroup l2_compounds Building Compounds
50 ##   @defgroup l2_editing   Editing Meshes
51
52 ## @}
53 ## @defgroup l1_meshinfo  Mesh Information
54 ## @defgroup l1_controls  Quality controls and Filtering
55 ## @defgroup l1_grouping  Grouping elements
56 ## @{
57 ##   @defgroup l2_grps_create Creating groups
58 ##   @defgroup l2_grps_edit   Editing groups
59 ##   @defgroup l2_grps_operon Using operations on groups
60 ##   @defgroup l2_grps_delete Deleting Groups
61
62 ## @}
63 ## @defgroup l1_modifying Modifying meshes
64 ## @{
65 ##   @defgroup l2_modif_add      Adding nodes and elements
66 ##   @defgroup l2_modif_del      Removing nodes and elements
67 ##   @defgroup l2_modif_edit     Modifying nodes and elements
68 ##   @defgroup l2_modif_renumber Renumbering nodes and elements
69 ##   @defgroup l2_modif_trsf     Transforming meshes (Translation, Rotation, Symmetry, Sewing, Merging)
70 ##   @defgroup l2_modif_movenode Moving nodes
71 ##   @defgroup l2_modif_throughp Mesh through point
72 ##   @defgroup l2_modif_unitetri Uniting triangles
73 ##   @defgroup l2_modif_cutquadr Cutting elements
74 ##   @defgroup l2_modif_changori Changing orientation of elements
75 ##   @defgroup l2_modif_smooth   Smoothing
76 ##   @defgroup l2_modif_extrurev Extrusion and Revolution
77 ##   @defgroup l2_modif_patterns Pattern mapping
78 ##   @defgroup l2_modif_tofromqu Convert to/from Quadratic Mesh
79
80 ## @}
81 ## @defgroup l1_measurements Measurements
82
83 import salome
84 from salome.geom import geomBuilder
85
86 import SMESH # This is necessary for back compatibility
87 from   SMESH import *
88 from   salome.smesh.smesh_algorithm import Mesh_Algorithm
89
90 import SALOME
91 import SALOMEDS
92 import os
93
94 class MeshMeta(type):
95     def __instancecheck__(cls, inst):
96         """Implement isinstance(inst, cls)."""
97         return any(cls.__subclasscheck__(c)
98                    for c in {type(inst), inst.__class__})
99
100     def __subclasscheck__(cls, sub):
101         """Implement issubclass(sub, cls)."""
102         return type.__subclasscheck__(cls, sub) or (cls.__name__ == sub.__name__ and cls.__module__ == sub.__module__)
103
104 ## @addtogroup l1_auxiliary
105 ## @{
106
107 ## Converts an angle from degrees to radians
108 def DegreesToRadians(AngleInDegrees):
109     from math import pi
110     return AngleInDegrees * pi / 180.0
111
112 import salome_notebook
113 notebook = salome_notebook.notebook
114 # Salome notebook variable separator
115 var_separator = ":"
116
117 ## Return list of variable values from salome notebook.
118 #  The last argument, if is callable, is used to modify values got from notebook
119 def ParseParameters(*args):
120     Result = []
121     Parameters = ""
122     hasVariables = False
123     varModifFun=None
124     if args and callable( args[-1] ):
125         args, varModifFun = args[:-1], args[-1]
126     for parameter in args:
127
128         Parameters += str(parameter) + var_separator
129
130         if isinstance(parameter,str):
131             # check if there is an inexistent variable name
132             if not notebook.isVariable(parameter):
133                 raise ValueError, "Variable with name '" + parameter + "' doesn't exist!!!"
134             parameter = notebook.get(parameter)
135             hasVariables = True
136             if varModifFun:
137                 parameter = varModifFun(parameter)
138                 pass
139             pass
140         Result.append(parameter)
141
142         pass
143     Parameters = Parameters[:-1]
144     Result.append( Parameters )
145     Result.append( hasVariables )
146     return Result
147
148 # Parse parameters converting variables to radians
149 def ParseAngles(*args):
150     return ParseParameters( *( args + (DegreesToRadians, )))
151
152 # Substitute PointStruct.__init__() to create SMESH.PointStruct using notebook variables.
153 # Parameters are stored in PointStruct.parameters attribute
154 def __initPointStruct(point,*args):
155     point.x, point.y, point.z, point.parameters,hasVars = ParseParameters(*args)
156     pass
157 SMESH.PointStruct.__init__ = __initPointStruct
158
159 # Substitute AxisStruct.__init__() to create SMESH.AxisStruct using notebook variables.
160 # Parameters are stored in AxisStruct.parameters attribute
161 def __initAxisStruct(ax,*args):
162     if len( args ) != 6:
163         raise RuntimeError,\
164               "Bad nb args (%s) passed in SMESH.AxisStruct(x,y,z,dx,dy,dz)"%(len( args ))
165     ax.x, ax.y, ax.z, ax.vx, ax.vy, ax.vz, ax.parameters,hasVars = ParseParameters(*args)
166     pass
167 SMESH.AxisStruct.__init__ = __initAxisStruct
168
169 smeshPrecisionConfusion = 1.e-07
170 def IsEqual(val1, val2, tol=smeshPrecisionConfusion):
171     if abs(val1 - val2) < tol:
172         return True
173     return False
174
175 NO_NAME = "NoName"
176
177 ## Gets object name
178 def GetName(obj):
179     if obj:
180         # object not null
181         if isinstance(obj, SALOMEDS._objref_SObject):
182             # study object
183             return obj.GetName()
184         try:
185             ior  = salome.orb.object_to_string(obj)
186         except:
187             ior = None
188         if ior:
189             # CORBA object
190             studies = salome.myStudyManager.GetOpenStudies()
191             for sname in studies:
192                 s = salome.myStudyManager.GetStudyByName(sname)
193                 if not s: continue
194                 sobj = s.FindObjectIOR(ior)
195                 if not sobj: continue
196                 return sobj.GetName()
197             if hasattr(obj, "GetName"):
198                 # unknown CORBA object, having GetName() method
199                 return obj.GetName()
200             else:
201                 # unknown CORBA object, no GetName() method
202                 return NO_NAME
203             pass
204         if hasattr(obj, "GetName"):
205             # unknown non-CORBA object, having GetName() method
206             return obj.GetName()
207         pass
208     raise RuntimeError, "Null or invalid object"
209
210 ## Prints error message if a hypothesis was not assigned.
211 def TreatHypoStatus(status, hypName, geomName, isAlgo, mesh):
212     if isAlgo:
213         hypType = "algorithm"
214     else:
215         hypType = "hypothesis"
216         pass
217     reason = ""
218     if hasattr( status, "__getitem__" ):
219         status,reason = status[0],status[1]
220     if status == HYP_UNKNOWN_FATAL :
221         reason = "for unknown reason"
222     elif status == HYP_INCOMPATIBLE :
223         reason = "this hypothesis mismatches the algorithm"
224     elif status == HYP_NOTCONFORM :
225         reason = "a non-conform mesh would be built"
226     elif status == HYP_ALREADY_EXIST :
227         if isAlgo: return # it does not influence anything
228         reason = hypType + " of the same dimension is already assigned to this shape"
229     elif status == HYP_BAD_DIM :
230         reason = hypType + " mismatches the shape"
231     elif status == HYP_CONCURENT :
232         reason = "there are concurrent hypotheses on sub-shapes"
233     elif status == HYP_BAD_SUBSHAPE :
234         reason = "the shape is neither the main one, nor its sub-shape, nor a valid group"
235     elif status == HYP_BAD_GEOMETRY:
236         reason = "the algorithm is not applicable to this geometry"
237     elif status == HYP_HIDDEN_ALGO:
238         reason = "it is hidden by an algorithm of an upper dimension, which generates elements of all dimensions"
239     elif status == HYP_HIDING_ALGO:
240         reason = "it hides algorithms of lower dimensions by generating elements of all dimensions"
241     elif status == HYP_NEED_SHAPE:
242         reason = "algorithm can't work without shape"
243     elif status == HYP_INCOMPAT_HYPS:
244         pass
245     else:
246         return
247     where = geomName
248     if where:
249         where = '"%s"' % geomName
250         if mesh:
251             meshName = GetName( mesh )
252             if meshName and meshName != NO_NAME:
253                 where = '"%s" shape in "%s" mesh ' % ( geomName, meshName )
254     if status < HYP_UNKNOWN_FATAL and where:
255         print '"%s" was assigned to %s but %s' %( hypName, where, reason )
256     elif where:
257         print '"%s" was not assigned to %s : %s' %( hypName, where, reason )
258     else:
259         print '"%s" was not assigned : %s' %( hypName, reason )
260         pass
261
262 ## Private method. Add geom (sub-shape of the main shape) into the study if not yet there
263 def AssureGeomPublished(mesh, geom, name=''):
264     if not isinstance( geom, geomBuilder.GEOM._objref_GEOM_Object ):
265         return
266     if not geom.GetStudyEntry() and \
267            mesh.smeshpyD.GetCurrentStudy():
268         ## set the study
269         studyID = mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
270         if studyID != mesh.geompyD.myStudyId:
271             mesh.geompyD.init_geom( mesh.smeshpyD.GetCurrentStudy())
272         ## get a name
273         if not name and geom.GetShapeType() != geomBuilder.GEOM.COMPOUND:
274             # for all groups SubShapeName() returns "Compound_-1"
275             name = mesh.geompyD.SubShapeName(geom, mesh.geom)
276         if not name:
277             name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
278         ## publish
279         mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
280     return
281
282 ## Return the first vertex of a geometrical edge by ignoring orientation
283 def FirstVertexOnCurve(mesh, edge):
284     vv = mesh.geompyD.SubShapeAll( edge, geomBuilder.geomBuilder.ShapeType["VERTEX"])
285     if not vv:
286         raise TypeError, "Given object has no vertices"
287     if len( vv ) == 1: return vv[0]
288     v0   = mesh.geompyD.MakeVertexOnCurve(edge,0.)
289     xyz  = mesh.geompyD.PointCoordinates( v0 ) # coords of the first vertex
290     xyz1 = mesh.geompyD.PointCoordinates( vv[0] )
291     xyz2 = mesh.geompyD.PointCoordinates( vv[1] )
292     dist1, dist2 = 0,0
293     for i in range(3):
294         dist1 += abs( xyz[i] - xyz1[i] )
295         dist2 += abs( xyz[i] - xyz2[i] )
296     if dist1 < dist2:
297         return vv[0]
298     else:
299         return vv[1]
300
301 # end of l1_auxiliary
302 ## @}
303
304
305 # Warning: smeshInst is a singleton
306 smeshInst = None
307 engine = None
308 doLcc = False
309 created = False
310
311 ## This class allows to create, load or manipulate meshes.
312 #  It has a set of methods to create, load or copy meshes, to combine several meshes, etc.
313 #  It also has methods to get infos and measure meshes.
314 class smeshBuilder(object, SMESH._objref_SMESH_Gen):
315
316     # MirrorType enumeration
317     POINT = SMESH_MeshEditor.POINT
318     AXIS =  SMESH_MeshEditor.AXIS
319     PLANE = SMESH_MeshEditor.PLANE
320
321     # Smooth_Method enumeration
322     LAPLACIAN_SMOOTH = SMESH_MeshEditor.LAPLACIAN_SMOOTH
323     CENTROIDAL_SMOOTH = SMESH_MeshEditor.CENTROIDAL_SMOOTH
324
325     PrecisionConfusion = smeshPrecisionConfusion
326
327     # TopAbs_State enumeration
328     [TopAbs_IN, TopAbs_OUT, TopAbs_ON, TopAbs_UNKNOWN] = range(4)
329
330     # Methods of splitting a hexahedron into tetrahedra
331     Hex_5Tet, Hex_6Tet, Hex_24Tet, Hex_2Prisms, Hex_4Prisms = 1, 2, 3, 1, 2
332
333     def __new__(cls):
334         global engine
335         global smeshInst
336         global doLcc
337         #print "==== __new__", engine, smeshInst, doLcc
338
339         if smeshInst is None:
340             # smesh engine is either retrieved from engine, or created
341             smeshInst = engine
342             # Following test avoids a recursive loop
343             if doLcc:
344                 if smeshInst is not None:
345                     # smesh engine not created: existing engine found
346                     doLcc = False
347                 if doLcc:
348                     doLcc = False
349                     # FindOrLoadComponent called:
350                     # 1. CORBA resolution of server
351                     # 2. the __new__ method is called again
352                     #print "==== smeshInst = lcc.FindOrLoadComponent ", engine, smeshInst, doLcc
353                     smeshInst = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
354             else:
355                 # FindOrLoadComponent not called
356                 if smeshInst is None:
357                     # smeshBuilder instance is created from lcc.FindOrLoadComponent
358                     #print "==== smeshInst = super(smeshBuilder,cls).__new__(cls) ", engine, smeshInst, doLcc
359                     smeshInst = super(smeshBuilder,cls).__new__(cls)
360                 else:
361                     # smesh engine not created: existing engine found
362                     #print "==== existing ", engine, smeshInst, doLcc
363                     pass
364             #print "====1 ", smeshInst
365             return smeshInst
366
367         #print "====2 ", smeshInst
368         return smeshInst
369
370     def __init__(self):
371         global created
372         #print "--------------- smeshbuilder __init__ ---", created
373         if not created:
374           created = True
375           SMESH._objref_SMESH_Gen.__init__(self)
376
377     ## Dump component to the Python script
378     #  This method overrides IDL function to allow default values for the parameters.
379     def DumpPython(self, theStudy, theIsPublished=True, theIsMultiFile=True):
380         return SMESH._objref_SMESH_Gen.DumpPython(self, theStudy, theIsPublished, theIsMultiFile)
381
382     ## Set mode of DumpPython(), \a historical or \a snapshot.
383     # In the \a historical mode, the Python Dump script includes all commands
384     # performed by SMESH engine. In the \a snapshot mode, commands
385     # relating to objects removed from the Study are excluded from the script
386     # as well as commands not influencing the current state of meshes
387     def SetDumpPythonHistorical(self, isHistorical):
388         if isHistorical: val = "true"
389         else:            val = "false"
390         SMESH._objref_SMESH_Gen.SetOption(self, "historical_python_dump", val)
391
392     ## Sets the current study and Geometry component
393     #  @ingroup l1_auxiliary
394     def init_smesh(self,theStudy,geompyD = None):
395         #print "init_smesh"
396         self.SetCurrentStudy(theStudy,geompyD)
397         if theStudy:
398             global notebook
399             notebook.myStudy = theStudy
400
401     ## Creates a mesh. This can be either an empty mesh, possibly having an underlying geometry,
402     #  or a mesh wrapping a CORBA mesh given as a parameter.
403     #  @param obj either (1) a CORBA mesh (SMESH._objref_SMESH_Mesh) got e.g. by calling
404     #         salome.myStudy.FindObjectID("0:1:2:3").GetObject() or
405     #         (2) a Geometrical object for meshing or
406     #         (3) none.
407     #  @param name the name for the new mesh.
408     #  @return an instance of Mesh class.
409     #  @ingroup l2_construct
410     def Mesh(self, obj=0, name=0):
411         if isinstance(obj,str):
412             obj,name = name,obj
413         return Mesh(self,self.geompyD,obj,name)
414
415     ## Returns a long value from enumeration
416     #  @ingroup l1_controls
417     def EnumToLong(self,theItem):
418         return theItem._v
419
420     ## Returns a string representation of the color.
421     #  To be used with filters.
422     #  @param c color value (SALOMEDS.Color)
423     #  @ingroup l1_controls
424     def ColorToString(self,c):
425         val = ""
426         if isinstance(c, SALOMEDS.Color):
427             val = "%s;%s;%s" % (c.R, c.G, c.B)
428         elif isinstance(c, str):
429             val = c
430         else:
431             raise ValueError, "Color value should be of string or SALOMEDS.Color type"
432         return val
433
434     ## Gets PointStruct from vertex
435     #  @param theVertex a GEOM object(vertex)
436     #  @return SMESH.PointStruct
437     #  @ingroup l1_auxiliary
438     def GetPointStruct(self,theVertex):
439         [x, y, z] = self.geompyD.PointCoordinates(theVertex)
440         return PointStruct(x,y,z)
441
442     ## Gets DirStruct from vector
443     #  @param theVector a GEOM object(vector)
444     #  @return SMESH.DirStruct
445     #  @ingroup l1_auxiliary
446     def GetDirStruct(self,theVector):
447         vertices = self.geompyD.SubShapeAll( theVector, geomBuilder.geomBuilder.ShapeType["VERTEX"] )
448         if(len(vertices) != 2):
449             print "Error: vector object is incorrect."
450             return None
451         p1 = self.geompyD.PointCoordinates(vertices[0])
452         p2 = self.geompyD.PointCoordinates(vertices[1])
453         pnt = PointStruct(p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
454         dirst = DirStruct(pnt)
455         return dirst
456
457     ## Makes DirStruct from a triplet
458     #  @param x,y,z vector components
459     #  @return SMESH.DirStruct
460     #  @ingroup l1_auxiliary
461     def MakeDirStruct(self,x,y,z):
462         pnt = PointStruct(x,y,z)
463         return DirStruct(pnt)
464
465     ## Get AxisStruct from object
466     #  @param theObj a GEOM object (line or plane)
467     #  @return SMESH.AxisStruct
468     #  @ingroup l1_auxiliary
469     def GetAxisStruct(self,theObj):
470         import GEOM
471         edges = self.geompyD.SubShapeAll( theObj, geomBuilder.geomBuilder.ShapeType["EDGE"] )
472         axis = None
473         if len(edges) > 1:
474             vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
475             vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
476             vertex1 = self.geompyD.PointCoordinates(vertex1)
477             vertex2 = self.geompyD.PointCoordinates(vertex2)
478             vertex3 = self.geompyD.PointCoordinates(vertex3)
479             vertex4 = self.geompyD.PointCoordinates(vertex4)
480             v1 = [vertex2[0]-vertex1[0], vertex2[1]-vertex1[1], vertex2[2]-vertex1[2]]
481             v2 = [vertex4[0]-vertex3[0], vertex4[1]-vertex3[1], vertex4[2]-vertex3[2]]
482             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] ]
483             axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
484             axis._mirrorType = SMESH.SMESH_MeshEditor.PLANE
485         elif len(edges) == 1:
486             vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
487             p1 = self.geompyD.PointCoordinates( vertex1 )
488             p2 = self.geompyD.PointCoordinates( vertex2 )
489             axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
490             axis._mirrorType = SMESH.SMESH_MeshEditor.AXIS
491         elif theObj.GetShapeType() == GEOM.VERTEX:
492             x,y,z = self.geompyD.PointCoordinates( theObj )
493             axis = AxisStruct( x,y,z, 1,0,0,)
494             axis._mirrorType = SMESH.SMESH_MeshEditor.POINT
495         return axis
496
497     # From SMESH_Gen interface:
498     # ------------------------
499
500     ## Sets the given name to the object
501     #  @param obj the object to rename
502     #  @param name a new object name
503     #  @ingroup l1_auxiliary
504     def SetName(self, obj, name):
505         if isinstance( obj, Mesh ):
506             obj = obj.GetMesh()
507         elif isinstance( obj, Mesh_Algorithm ):
508             obj = obj.GetAlgorithm()
509         ior  = salome.orb.object_to_string(obj)
510         SMESH._objref_SMESH_Gen.SetName(self, ior, name)
511
512     ## Sets the current mode
513     #  @ingroup l1_auxiliary
514     def SetEmbeddedMode( self,theMode ):
515         SMESH._objref_SMESH_Gen.SetEmbeddedMode(self,theMode)
516
517     ## Gets the current mode
518     #  @ingroup l1_auxiliary
519     def IsEmbeddedMode(self):
520         return SMESH._objref_SMESH_Gen.IsEmbeddedMode(self)
521
522     ## Sets the current study. Calling SetCurrentStudy( None ) allows to
523     #  switch OFF automatic pubilishing in the Study of mesh objects.
524     #  @ingroup l1_auxiliary
525     def SetCurrentStudy( self, theStudy, geompyD = None ):
526         if not geompyD:
527             from salome.geom import geomBuilder
528             geompyD = geomBuilder.geom
529             pass
530         self.geompyD=geompyD
531         self.SetGeomEngine(geompyD)
532         SMESH._objref_SMESH_Gen.SetCurrentStudy(self,theStudy)
533         global notebook
534         if theStudy:
535             notebook = salome_notebook.NoteBook( theStudy )
536         else:
537             notebook = salome_notebook.NoteBook( salome_notebook.PseudoStudyForNoteBook() )
538         if theStudy:
539             sb = theStudy.NewBuilder()
540             sc = theStudy.FindComponent("SMESH")
541             if sc: sb.LoadWith(sc, self)
542             pass
543         pass
544
545     ## Gets the current study
546     #  @ingroup l1_auxiliary
547     def GetCurrentStudy(self):
548         return SMESH._objref_SMESH_Gen.GetCurrentStudy(self)
549
550     ## Creates a Mesh object importing data from the given UNV file
551     #  @return an instance of Mesh class
552     #  @ingroup l2_impexp
553     def CreateMeshesFromUNV( self,theFileName ):
554         aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromUNV(self,theFileName)
555         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
556         return aMesh
557
558     ## Creates a Mesh object(s) importing data from the given MED file
559     #  @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
560     #  @ingroup l2_impexp
561     def CreateMeshesFromMED( self,theFileName ):
562         aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromMED(self,theFileName)
563         aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
564         return aMeshes, aStatus
565
566     ## Creates a Mesh object(s) importing data from the given SAUV file
567     #  @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
568     #  @ingroup l2_impexp
569     def CreateMeshesFromSAUV( self,theFileName ):
570         aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromSAUV(self,theFileName)
571         aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
572         return aMeshes, aStatus
573
574     ## Creates a Mesh object importing data from the given STL file
575     #  @return an instance of Mesh class
576     #  @ingroup l2_impexp
577     def CreateMeshesFromSTL( self, theFileName ):
578         aSmeshMesh = SMESH._objref_SMESH_Gen.CreateMeshesFromSTL(self,theFileName)
579         aMesh = Mesh(self, self.geompyD, aSmeshMesh)
580         return aMesh
581
582     ## Creates Mesh objects importing data from the given CGNS file
583     #  @return a tuple ( list of Mesh class instances, SMESH.DriverMED_ReadStatus )
584     #  @ingroup l2_impexp
585     def CreateMeshesFromCGNS( self, theFileName ):
586         aSmeshMeshes, aStatus = SMESH._objref_SMESH_Gen.CreateMeshesFromCGNS(self,theFileName)
587         aMeshes = [ Mesh(self, self.geompyD, m) for m in aSmeshMeshes ]
588         return aMeshes, aStatus
589
590     ## Creates a Mesh object importing data from the given GMF file.
591     #  GMF files must have .mesh extension for the ASCII format and .meshb for
592     #  the binary format.
593     #  @return [ an instance of Mesh class, SMESH.ComputeError ]
594     #  @ingroup l2_impexp
595     def CreateMeshesFromGMF( self, theFileName ):
596         aSmeshMesh, error = SMESH._objref_SMESH_Gen.CreateMeshesFromGMF(self,
597                                                                         theFileName,
598                                                                         True)
599         if error.comment: print "*** CreateMeshesFromGMF() errors:\n", error.comment
600         return Mesh(self, self.geompyD, aSmeshMesh), error
601
602     ## Concatenate the given meshes into one mesh. All groups of input meshes will be
603     #  present in the new mesh.
604     #  @param meshes the meshes, sub-meshes and groups to combine into one mesh
605     #  @param uniteIdenticalGroups if true, groups with same names are united, else they are renamed
606     #  @param mergeNodesAndElements if true, equal nodes and elements are merged
607     #  @param mergeTolerance tolerance for merging nodes
608     #  @param allGroups forces creation of groups corresponding to every input mesh
609     #  @param name name of a new mesh
610     #  @return an instance of Mesh class
611     #  @ingroup l2_compounds
612     def Concatenate( self, meshes, uniteIdenticalGroups,
613                      mergeNodesAndElements = False, mergeTolerance = 1e-5, allGroups = False,
614                      name = ""):
615         if not meshes: return None
616         for i,m in enumerate(meshes):
617             if isinstance(m, Mesh):
618                 meshes[i] = m.GetMesh()
619         mergeTolerance,Parameters,hasVars = ParseParameters(mergeTolerance)
620         meshes[0].SetParameters(Parameters)
621         if allGroups:
622             aSmeshMesh = SMESH._objref_SMESH_Gen.ConcatenateWithGroups(
623                 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
624         else:
625             aSmeshMesh = SMESH._objref_SMESH_Gen.Concatenate(
626                 self,meshes,uniteIdenticalGroups,mergeNodesAndElements,mergeTolerance)
627         aMesh = Mesh(self, self.geompyD, aSmeshMesh, name=name)
628         return aMesh
629
630     ## Create a mesh by copying a part of another mesh.
631     #  @param meshPart a part of mesh to copy, either a Mesh, a sub-mesh or a group;
632     #                  to copy nodes or elements not contained in any mesh object,
633     #                  pass result of Mesh.GetIDSource( list_of_ids, type ) as meshPart
634     #  @param meshName a name of the new mesh
635     #  @param toCopyGroups to create in the new mesh groups the copied elements belongs to
636     #  @param toKeepIDs to preserve order of the copied elements or not
637     #  @return an instance of Mesh class
638     def CopyMesh( self, meshPart, meshName, toCopyGroups=False, toKeepIDs=False):
639         if (isinstance( meshPart, Mesh )):
640             meshPart = meshPart.GetMesh()
641         mesh = SMESH._objref_SMESH_Gen.CopyMesh( self,meshPart,meshName,toCopyGroups,toKeepIDs )
642         return Mesh(self, self.geompyD, mesh)
643
644     ## From SMESH_Gen interface
645     #  @return the list of integer values
646     #  @ingroup l1_auxiliary
647     def GetSubShapesId( self, theMainObject, theListOfSubObjects ):
648         return SMESH._objref_SMESH_Gen.GetSubShapesId(self,theMainObject, theListOfSubObjects)
649
650     ## From SMESH_Gen interface. Creates a pattern
651     #  @return an instance of SMESH_Pattern
652     #
653     #  <a href="../tui_modifying_meshes_page.html#tui_pattern_mapping">Example of Patterns usage</a>
654     #  @ingroup l2_modif_patterns
655     def GetPattern(self):
656         return SMESH._objref_SMESH_Gen.GetPattern(self)
657
658     ## Sets number of segments per diagonal of boundary box of geometry by which
659     #  default segment length of appropriate 1D hypotheses is defined.
660     #  Default value is 10
661     #  @ingroup l1_auxiliary
662     def SetBoundaryBoxSegmentation(self, nbSegments):
663         SMESH._objref_SMESH_Gen.SetBoundaryBoxSegmentation(self,nbSegments)
664
665     # Filtering. Auxiliary functions:
666     # ------------------------------
667
668     ## Creates an empty criterion
669     #  @return SMESH.Filter.Criterion
670     #  @ingroup l1_controls
671     def GetEmptyCriterion(self):
672         Type = self.EnumToLong(FT_Undefined)
673         Compare = self.EnumToLong(FT_Undefined)
674         Threshold = 0
675         ThresholdStr = ""
676         ThresholdID = ""
677         UnaryOp = self.EnumToLong(FT_Undefined)
678         BinaryOp = self.EnumToLong(FT_Undefined)
679         Tolerance = 1e-07
680         TypeOfElement = ALL
681         Precision = -1 ##@1e-07
682         return Filter.Criterion(Type, Compare, Threshold, ThresholdStr, ThresholdID,
683                                 UnaryOp, BinaryOp, Tolerance, TypeOfElement, Precision)
684
685     ## Creates a criterion by the given parameters
686     #  \n Criterion structures allow to define complex filters by combining them with logical operations (AND / OR) (see example below)
687     #  @param elementType the type of elements(SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
688     #  @param CritType the type of criterion (SMESH.FT_Taper, SMESH.FT_Area, etc.)
689     #          Type SMESH.FunctorType._items in the Python Console to see all values.
690     #          Note that the items starting from FT_LessThan are not suitable for CritType.
691     #  @param Compare  belongs to {SMESH.FT_LessThan, SMESH.FT_MoreThan, SMESH.FT_EqualTo}
692     #  @param Threshold the threshold value (range of ids as string, shape, numeric)
693     #  @param UnaryOp  SMESH.FT_LogicalNOT or SMESH.FT_Undefined
694     #  @param BinaryOp a binary logical operation SMESH.FT_LogicalAND, SMESH.FT_LogicalOR or
695     #                  SMESH.FT_Undefined
696     #  @param Tolerance the tolerance used by SMESH.FT_BelongToGeom, SMESH.FT_BelongToSurface,
697     #         SMESH.FT_LyingOnGeom, SMESH.FT_CoplanarFaces criteria
698     #  @return SMESH.Filter.Criterion
699     #
700     #  <a href="../tui_filters_page.html#combining_filters">Example of Criteria usage</a>
701     #  @ingroup l1_controls
702     def GetCriterion(self,elementType,
703                      CritType,
704                      Compare = FT_EqualTo,
705                      Threshold="",
706                      UnaryOp=FT_Undefined,
707                      BinaryOp=FT_Undefined,
708                      Tolerance=1e-07):
709         if not CritType in SMESH.FunctorType._items:
710             raise TypeError, "CritType should be of SMESH.FunctorType"
711         aCriterion               = self.GetEmptyCriterion()
712         aCriterion.TypeOfElement = elementType
713         aCriterion.Type          = self.EnumToLong(CritType)
714         aCriterion.Tolerance     = Tolerance
715
716         aThreshold = Threshold
717
718         if Compare in [FT_LessThan, FT_MoreThan, FT_EqualTo]:
719             aCriterion.Compare = self.EnumToLong(Compare)
720         elif Compare == "=" or Compare == "==":
721             aCriterion.Compare = self.EnumToLong(FT_EqualTo)
722         elif Compare == "<":
723             aCriterion.Compare = self.EnumToLong(FT_LessThan)
724         elif Compare == ">":
725             aCriterion.Compare = self.EnumToLong(FT_MoreThan)
726         elif Compare != FT_Undefined:
727             aCriterion.Compare = self.EnumToLong(FT_EqualTo)
728             aThreshold = Compare
729
730         if CritType in [FT_BelongToGeom,     FT_BelongToPlane, FT_BelongToGenSurface,
731                         FT_BelongToCylinder, FT_LyingOnGeom]:
732             # Check that Threshold is GEOM object
733             if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object):
734                 aCriterion.ThresholdStr = GetName(aThreshold)
735                 aCriterion.ThresholdID  = aThreshold.GetStudyEntry()
736                 if not aCriterion.ThresholdID:
737                     name = aCriterion.ThresholdStr
738                     if not name:
739                         name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
740                     aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
741             # or a name of GEOM object
742             elif isinstance( aThreshold, str ):
743                 aCriterion.ThresholdStr = aThreshold
744             else:
745                 raise TypeError, "The Threshold should be a shape."
746             if isinstance(UnaryOp,float):
747                 aCriterion.Tolerance = UnaryOp
748                 UnaryOp = FT_Undefined
749                 pass
750         elif CritType == FT_BelongToMeshGroup:
751             # Check that Threshold is a group
752             if isinstance(aThreshold, SMESH._objref_SMESH_GroupBase):
753                 if aThreshold.GetType() != elementType:
754                     raise ValueError, "Group type mismatches Element type"
755                 aCriterion.ThresholdStr = aThreshold.GetName()
756                 aCriterion.ThresholdID  = salome.orb.object_to_string( aThreshold )
757                 study = self.GetCurrentStudy()
758                 if study:
759                     so = study.FindObjectIOR( aCriterion.ThresholdID )
760                     if so:
761                         entry = so.GetID()
762                         if entry:
763                             aCriterion.ThresholdID = entry
764             else:
765                 raise TypeError, "The Threshold should be a Mesh Group"
766         elif CritType == FT_RangeOfIds:
767             # Check that Threshold is string
768             if isinstance(aThreshold, str):
769                 aCriterion.ThresholdStr = aThreshold
770             else:
771                 raise TypeError, "The Threshold should be a string."
772         elif CritType == FT_CoplanarFaces:
773             # Check the Threshold
774             if isinstance(aThreshold, int):
775                 aCriterion.ThresholdID = str(aThreshold)
776             elif isinstance(aThreshold, str):
777                 ID = int(aThreshold)
778                 if ID < 1:
779                     raise ValueError, "Invalid ID of mesh face: '%s'"%aThreshold
780                 aCriterion.ThresholdID = aThreshold
781             else:
782                 raise TypeError,\
783                       "The Threshold should be an ID of mesh face and not '%s'"%aThreshold
784         elif CritType == FT_ConnectedElements:
785             # Check the Threshold
786             if isinstance(aThreshold, geomBuilder.GEOM._objref_GEOM_Object): # shape
787                 aCriterion.ThresholdID = aThreshold.GetStudyEntry()
788                 if not aCriterion.ThresholdID:
789                     name = aThreshold.GetName()
790                     if not name:
791                         name = "%s_%s"%(aThreshold.GetShapeType(), id(aThreshold)%10000)
792                     aCriterion.ThresholdID = self.geompyD.addToStudy( aThreshold, name )
793             elif isinstance(aThreshold, int): # node id
794                 aCriterion.Threshold = aThreshold
795             elif isinstance(aThreshold, list): # 3 point coordinates
796                 if len( aThreshold ) < 3:
797                     raise ValueError, "too few point coordinates, must be 3"
798                 aCriterion.ThresholdStr = " ".join( [str(c) for c in aThreshold[:3]] )
799             elif isinstance(aThreshold, str):
800                 if aThreshold.isdigit():
801                     aCriterion.Threshold = aThreshold # node id
802                 else:
803                     aCriterion.ThresholdStr = aThreshold # hope that it's point coordinates
804             else:
805                 raise TypeError,\
806                       "The Threshold should either a VERTEX, or a node ID, "\
807                       "or a list of point coordinates and not '%s'"%aThreshold
808         elif CritType == FT_ElemGeomType:
809             # Check the Threshold
810             try:
811                 aCriterion.Threshold = self.EnumToLong(aThreshold)
812                 assert( aThreshold in SMESH.GeometryType._items )
813             except:
814                 if isinstance(aThreshold, int):
815                     aCriterion.Threshold = aThreshold
816                 else:
817                     raise TypeError, "The Threshold should be an integer or SMESH.GeometryType."
818                 pass
819             pass
820         elif CritType == FT_EntityType:
821             # Check the Threshold
822             try:
823                 aCriterion.Threshold = self.EnumToLong(aThreshold)
824                 assert( aThreshold in SMESH.EntityType._items )
825             except:
826                 if isinstance(aThreshold, int):
827                     aCriterion.Threshold = aThreshold
828                 else:
829                     raise TypeError, "The Threshold should be an integer or SMESH.EntityType."
830                 pass
831             pass
832         
833         elif CritType == FT_GroupColor:
834             # Check the Threshold
835             try:
836                 aCriterion.ThresholdStr = self.ColorToString(aThreshold)
837             except:
838                 raise TypeError, "The threshold value should be of SALOMEDS.Color type"
839             pass
840         elif CritType in [FT_FreeBorders, FT_FreeEdges, FT_FreeNodes, FT_FreeFaces,
841                           FT_LinearOrQuadratic, FT_BadOrientedVolume,
842                           FT_BareBorderFace, FT_BareBorderVolume,
843                           FT_OverConstrainedFace, FT_OverConstrainedVolume,
844                           FT_EqualNodes,FT_EqualEdges,FT_EqualFaces,FT_EqualVolumes ]:
845             # At this point the Threshold is unnecessary
846             if aThreshold ==  FT_LogicalNOT:
847                 aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
848             elif aThreshold in [FT_LogicalAND, FT_LogicalOR]:
849                 aCriterion.BinaryOp = aThreshold
850         else:
851             # Check Threshold
852             try:
853                 aThreshold = float(aThreshold)
854                 aCriterion.Threshold = aThreshold
855             except:
856                 raise TypeError, "The Threshold should be a number."
857                 return None
858
859         if Threshold ==  FT_LogicalNOT or UnaryOp ==  FT_LogicalNOT:
860             aCriterion.UnaryOp = self.EnumToLong(FT_LogicalNOT)
861
862         if Threshold in [FT_LogicalAND, FT_LogicalOR]:
863             aCriterion.BinaryOp = self.EnumToLong(Threshold)
864
865         if UnaryOp in [FT_LogicalAND, FT_LogicalOR]:
866             aCriterion.BinaryOp = self.EnumToLong(UnaryOp)
867
868         if BinaryOp in [FT_LogicalAND, FT_LogicalOR]:
869             aCriterion.BinaryOp = self.EnumToLong(BinaryOp)
870
871         return aCriterion
872
873     ## Creates a filter with the given parameters
874     #  @param elementType the type of elements (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
875     #  @param CritType the type of criterion (SMESH.FT_Taper, SMESH.FT_Area, etc.)
876     #          Type SMESH.FunctorType._items in the Python Console to see all values.
877     #          Note that the items starting from FT_LessThan are not suitable for CritType.
878     #  @param Compare  belongs to {SMESH.FT_LessThan, SMESH.FT_MoreThan, SMESH.FT_EqualTo}
879     #  @param Threshold the threshold value (range of ids as string, shape, numeric)
880     #  @param UnaryOp  SMESH.FT_LogicalNOT or SMESH.FT_Undefined
881     #  @param Tolerance the tolerance used by SMESH.FT_BelongToGeom, SMESH.FT_BelongToSurface,
882     #         SMESH.FT_LyingOnGeom, SMESH.FT_CoplanarFaces and SMESH.FT_EqualNodes criteria
883     #  @param mesh the mesh to initialize the filter with
884     #  @return SMESH_Filter
885     #
886     #  <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
887     #  @ingroup l1_controls
888     def GetFilter(self,elementType,
889                   CritType=FT_Undefined,
890                   Compare=FT_EqualTo,
891                   Threshold="",
892                   UnaryOp=FT_Undefined,
893                   Tolerance=1e-07,
894                   mesh=None):
895         aCriterion = self.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
896         aFilterMgr = self.CreateFilterManager()
897         aFilter = aFilterMgr.CreateFilter()
898         aCriteria = []
899         aCriteria.append(aCriterion)
900         aFilter.SetCriteria(aCriteria)
901         if mesh:
902             if isinstance( mesh, Mesh ): aFilter.SetMesh( mesh.GetMesh() )
903             else                       : aFilter.SetMesh( mesh )
904         aFilterMgr.UnRegister()
905         return aFilter
906
907     ## Creates a filter from criteria
908     #  @param criteria a list of criteria
909     #  @param binOp binary operator used when binary operator of criteria is undefined
910     #  @return SMESH_Filter
911     #
912     #  <a href="../tui_filters_page.html#tui_filters">Example of Filters usage</a>
913     #  @ingroup l1_controls
914     def GetFilterFromCriteria(self,criteria, binOp=SMESH.FT_LogicalAND):
915         for i in range( len( criteria ) - 1 ):
916             if criteria[i].BinaryOp == self.EnumToLong( SMESH.FT_Undefined ):
917                 criteria[i].BinaryOp = self.EnumToLong( binOp )
918         aFilterMgr = self.CreateFilterManager()
919         aFilter = aFilterMgr.CreateFilter()
920         aFilter.SetCriteria(criteria)
921         aFilterMgr.UnRegister()
922         return aFilter
923
924     ## Creates a numerical functor by its type
925     #  @param theCriterion functor type - an item of SMESH.FunctorType enumeration.
926     #          Type SMESH.FunctorType._items in the Python Console to see all items.
927     #          Note that not all items correspond to numerical functors.
928     #  @return SMESH_NumericalFunctor
929     #  @ingroup l1_controls
930     def GetFunctor(self,theCriterion):
931         if isinstance( theCriterion, SMESH._objref_NumericalFunctor ):
932             return theCriterion
933         aFilterMgr = self.CreateFilterManager()
934         functor = None
935         if theCriterion == FT_AspectRatio:
936             functor = aFilterMgr.CreateAspectRatio()
937         elif theCriterion == FT_AspectRatio3D:
938             functor = aFilterMgr.CreateAspectRatio3D()
939         elif theCriterion == FT_Warping:
940             functor = aFilterMgr.CreateWarping()
941         elif theCriterion == FT_MinimumAngle:
942             functor = aFilterMgr.CreateMinimumAngle()
943         elif theCriterion == FT_Taper:
944             functor = aFilterMgr.CreateTaper()
945         elif theCriterion == FT_Skew:
946             functor = aFilterMgr.CreateSkew()
947         elif theCriterion == FT_Area:
948             functor = aFilterMgr.CreateArea()
949         elif theCriterion == FT_Volume3D:
950             functor = aFilterMgr.CreateVolume3D()
951         elif theCriterion == FT_MaxElementLength2D:
952             functor = aFilterMgr.CreateMaxElementLength2D()
953         elif theCriterion == FT_MaxElementLength3D:
954             functor = aFilterMgr.CreateMaxElementLength3D()
955         elif theCriterion == FT_MultiConnection:
956             functor = aFilterMgr.CreateMultiConnection()
957         elif theCriterion == FT_MultiConnection2D:
958             functor = aFilterMgr.CreateMultiConnection2D()
959         elif theCriterion == FT_Length:
960             functor = aFilterMgr.CreateLength()
961         elif theCriterion == FT_Length2D:
962             functor = aFilterMgr.CreateLength2D()
963         elif theCriterion == FT_Deflection2D:
964             functor = aFilterMgr.CreateDeflection2D()
965         elif theCriterion == FT_NodeConnectivityNumber:
966             functor = aFilterMgr.CreateNodeConnectivityNumber()
967         elif theCriterion == FT_BallDiameter:
968             functor = aFilterMgr.CreateBallDiameter()
969         else:
970             print "Error: given parameter is not numerical functor type."
971         aFilterMgr.UnRegister()
972         return functor
973
974     ## Creates hypothesis
975     #  @param theHType mesh hypothesis type (string)
976     #  @param theLibName mesh plug-in library name
977     #  @return created hypothesis instance
978     def CreateHypothesis(self, theHType, theLibName="libStdMeshersEngine.so"):
979         hyp = SMESH._objref_SMESH_Gen.CreateHypothesis(self, theHType, theLibName )
980
981         if isinstance( hyp, SMESH._objref_SMESH_Algo ):
982             return hyp
983
984         # wrap hypothesis methods
985         #print "HYPOTHESIS", theHType
986         for meth_name in dir( hyp.__class__ ):
987             if not meth_name.startswith("Get") and \
988                not meth_name in dir ( SMESH._objref_SMESH_Hypothesis ):
989                 method = getattr ( hyp.__class__, meth_name )
990                 if callable(method):
991                     setattr( hyp, meth_name, hypMethodWrapper( hyp, method ))
992
993         return hyp
994
995     ## Gets the mesh statistic
996     #  @return dictionary "element type" - "count of elements"
997     #  @ingroup l1_meshinfo
998     def GetMeshInfo(self, obj):
999         if isinstance( obj, Mesh ):
1000             obj = obj.GetMesh()
1001         d = {}
1002         if hasattr(obj, "GetMeshInfo"):
1003             values = obj.GetMeshInfo()
1004             for i in range(SMESH.Entity_Last._v):
1005                 if i < len(values): d[SMESH.EntityType._item(i)]=values[i]
1006             pass
1007         return d
1008
1009     ## Get minimum distance between two objects
1010     #
1011     #  If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
1012     #  If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
1013     #
1014     #  @param src1 first source object
1015     #  @param src2 second source object
1016     #  @param id1 node/element id from the first source
1017     #  @param id2 node/element id from the second (or first) source
1018     #  @param isElem1 @c True if @a id1 is element id, @c False if it is node id
1019     #  @param isElem2 @c True if @a id2 is element id, @c False if it is node id
1020     #  @return minimum distance value
1021     #  @sa GetMinDistance()
1022     #  @ingroup l1_measurements
1023     def MinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
1024         result = self.GetMinDistance(src1, src2, id1, id2, isElem1, isElem2)
1025         if result is None:
1026             result = 0.0
1027         else:
1028             result = result.value
1029         return result
1030
1031     ## Get measure structure specifying minimum distance data between two objects
1032     #
1033     #  If @a src2 is None, and @a id2 = 0, distance from @a src1 / @a id1 to the origin is computed.
1034     #  If @a src2 is None, and @a id2 != 0, it is assumed that both @a id1 and @a id2 belong to @a src1.
1035     #
1036     #  @param src1 first source object
1037     #  @param src2 second source object
1038     #  @param id1 node/element id from the first source
1039     #  @param id2 node/element id from the second (or first) source
1040     #  @param isElem1 @c True if @a id1 is element id, @c False if it is node id
1041     #  @param isElem2 @c True if @a id2 is element id, @c False if it is node id
1042     #  @return Measure structure or None if input data is invalid
1043     #  @sa MinDistance()
1044     #  @ingroup l1_measurements
1045     def GetMinDistance(self, src1, src2=None, id1=0, id2=0, isElem1=False, isElem2=False):
1046         if isinstance(src1, Mesh): src1 = src1.mesh
1047         if isinstance(src2, Mesh): src2 = src2.mesh
1048         if src2 is None and id2 != 0: src2 = src1
1049         if not hasattr(src1, "_narrow"): return None
1050         src1 = src1._narrow(SMESH.SMESH_IDSource)
1051         if not src1: return None
1052         unRegister = genObjUnRegister()
1053         if id1 != 0:
1054             m = src1.GetMesh()
1055             e = m.GetMeshEditor()
1056             if isElem1:
1057                 src1 = e.MakeIDSource([id1], SMESH.FACE)
1058             else:
1059                 src1 = e.MakeIDSource([id1], SMESH.NODE)
1060             unRegister.set( src1 )
1061             pass
1062         if hasattr(src2, "_narrow"):
1063             src2 = src2._narrow(SMESH.SMESH_IDSource)
1064             if src2 and id2 != 0:
1065                 m = src2.GetMesh()
1066                 e = m.GetMeshEditor()
1067                 if isElem2:
1068                     src2 = e.MakeIDSource([id2], SMESH.FACE)
1069                 else:
1070                     src2 = e.MakeIDSource([id2], SMESH.NODE)
1071                 unRegister.set( src2 )
1072                 pass
1073             pass
1074         aMeasurements = self.CreateMeasurements()
1075         unRegister.set( aMeasurements )
1076         result = aMeasurements.MinDistance(src1, src2)
1077         return result
1078
1079     ## Get bounding box of the specified object(s)
1080     #  @param objects single source object or list of source objects
1081     #  @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
1082     #  @sa GetBoundingBox()
1083     #  @ingroup l1_measurements
1084     def BoundingBox(self, objects):
1085         result = self.GetBoundingBox(objects)
1086         if result is None:
1087             result = (0.0,)*6
1088         else:
1089             result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
1090         return result
1091
1092     ## Get measure structure specifying bounding box data of the specified object(s)
1093     #  @param objects single source object or list of source objects
1094     #  @return Measure structure
1095     #  @sa BoundingBox()
1096     #  @ingroup l1_measurements
1097     def GetBoundingBox(self, objects):
1098         if isinstance(objects, tuple):
1099             objects = list(objects)
1100         if not isinstance(objects, list):
1101             objects = [objects]
1102         srclist = []
1103         for o in objects:
1104             if isinstance(o, Mesh):
1105                 srclist.append(o.mesh)
1106             elif hasattr(o, "_narrow"):
1107                 src = o._narrow(SMESH.SMESH_IDSource)
1108                 if src: srclist.append(src)
1109                 pass
1110             pass
1111         aMeasurements = self.CreateMeasurements()
1112         result = aMeasurements.BoundingBox(srclist)
1113         aMeasurements.UnRegister()
1114         return result
1115
1116     ## Get sum of lengths of all 1D elements in the mesh object.
1117     #  @param obj mesh, submesh or group
1118     #  @return sum of lengths of all 1D elements
1119     #  @ingroup l1_measurements
1120     def GetLength(self, obj):
1121         if isinstance(obj, Mesh): obj = obj.mesh
1122         if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1123         aMeasurements = self.CreateMeasurements()
1124         value = aMeasurements.Length(obj)
1125         aMeasurements.UnRegister()
1126         return value
1127
1128     ## Get sum of areas of all 2D elements in the mesh object.
1129     #  @param obj mesh, submesh or group
1130     #  @return sum of areas of all 2D elements
1131     #  @ingroup l1_measurements
1132     def GetArea(self, obj):
1133         if isinstance(obj, Mesh): obj = obj.mesh
1134         if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1135         aMeasurements = self.CreateMeasurements()
1136         value = aMeasurements.Area(obj)
1137         aMeasurements.UnRegister()
1138         return value
1139
1140     ## Get sum of volumes of all 3D elements in the mesh object.
1141     #  @param obj mesh, submesh or group
1142     #  @return sum of volumes of all 3D elements
1143     #  @ingroup l1_measurements
1144     def GetVolume(self, obj):
1145         if isinstance(obj, Mesh): obj = obj.mesh
1146         if isinstance(obj, Mesh_Algorithm): obj = obj.GetSubMesh()
1147         aMeasurements = self.CreateMeasurements()
1148         value = aMeasurements.Volume(obj)
1149         aMeasurements.UnRegister()
1150         return value
1151
1152     pass # end of class smeshBuilder
1153
1154 import omniORB
1155 #Registering the new proxy for SMESH_Gen
1156 omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
1157
1158 ## Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1159 #  interface to create or load meshes.
1160 #
1161 #  Typical use is:
1162 #  \code
1163 #    import salome
1164 #    salome.salome_init()
1165 #    from salome.smesh import smeshBuilder
1166 #    smesh = smeshBuilder.New(salome.myStudy)
1167 #  \endcode
1168 #  @param  study     SALOME study, generally obtained by salome.myStudy.
1169 #  @param  instance  CORBA proxy of SMESH Engine. If None, the default Engine is used.
1170 #  @return smeshBuilder instance
1171
1172 def New( study, instance=None):
1173     """
1174     Create a new smeshBuilder instance.The smeshBuilder class provides the Python
1175     interface to create or load meshes.
1176
1177     Typical use is:
1178         import salome
1179         salome.salome_init()
1180         from salome.smesh import smeshBuilder
1181         smesh = smeshBuilder.New(salome.myStudy)
1182
1183     Parameters:
1184         study     SALOME study, generally obtained by salome.myStudy.
1185         instance  CORBA proxy of SMESH Engine. If None, the default Engine is used.
1186     Returns:
1187         smeshBuilder instance
1188     """
1189     global engine
1190     global smeshInst
1191     global doLcc
1192     engine = instance
1193     if engine is None:
1194       doLcc = True
1195     smeshInst = smeshBuilder()
1196     assert isinstance(smeshInst,smeshBuilder), "Smesh engine class is %s but should be smeshBuilder.smeshBuilder. Import salome.smesh.smeshBuilder before creating the instance."%smeshInst.__class__
1197     smeshInst.init_smesh(study)
1198     return smeshInst
1199
1200
1201 # Public class: Mesh
1202 # ==================
1203
1204 ## This class allows defining and managing a mesh.
1205 #  It has a set of methods to build a mesh on the given geometry, including the definition of sub-meshes.
1206 #  It also has methods to define groups of mesh elements, to modify a mesh (by addition of
1207 #  new nodes and elements and by changing the existing entities), to get information
1208 #  about a mesh and to export a mesh into different formats.
1209 class Mesh:
1210     __metaclass__ = MeshMeta
1211
1212     geom = 0
1213     mesh = 0
1214     editor = 0
1215
1216     ## Constructor
1217     #
1218     #  Creates a mesh on the shape \a obj (or an empty mesh if \a obj is equal to 0) and
1219     #  sets the GUI name of this mesh to \a name.
1220     #  @param smeshpyD an instance of smeshBuilder class
1221     #  @param geompyD an instance of geomBuilder class
1222     #  @param obj Shape to be meshed or SMESH_Mesh object
1223     #  @param name Study name of the mesh
1224     #  @ingroup l2_construct
1225     def __init__(self, smeshpyD, geompyD, obj=0, name=0):
1226         self.smeshpyD=smeshpyD
1227         self.geompyD=geompyD
1228         if obj is None:
1229             obj = 0
1230         objHasName = False
1231         if obj != 0:
1232             if isinstance(obj, geomBuilder.GEOM._objref_GEOM_Object):
1233                 self.geom = obj
1234                 objHasName = True
1235                 # publish geom of mesh (issue 0021122)
1236                 if not self.geom.GetStudyEntry() and smeshpyD.GetCurrentStudy():
1237                     objHasName = False
1238                     studyID = smeshpyD.GetCurrentStudy()._get_StudyId()
1239                     if studyID != geompyD.myStudyId:
1240                         geompyD.init_geom( smeshpyD.GetCurrentStudy())
1241                         pass
1242                     if name:
1243                         geo_name = name + " shape"
1244                     else:
1245                         geo_name = "%s_%s to mesh"%(self.geom.GetShapeType(), id(self.geom)%100)
1246                     geompyD.addToStudy( self.geom, geo_name )
1247                 self.SetMesh( self.smeshpyD.CreateMesh(self.geom) )
1248
1249             elif isinstance(obj, SMESH._objref_SMESH_Mesh):
1250                 self.SetMesh(obj)
1251         else:
1252             self.SetMesh( self.smeshpyD.CreateEmptyMesh() )
1253         if name:
1254             self.smeshpyD.SetName(self.mesh, name)
1255         elif objHasName:
1256             self.smeshpyD.SetName(self.mesh, GetName(obj)) # + " mesh"
1257
1258         if not self.geom:
1259             self.geom = self.mesh.GetShapeToMesh()
1260
1261         self.editor   = self.mesh.GetMeshEditor()
1262         self.functors = [None] * SMESH.FT_Undefined._v
1263
1264         # set self to algoCreator's
1265         for attrName in dir(self):
1266             attr = getattr( self, attrName )
1267             if isinstance( attr, algoCreator ):
1268                 setattr( self, attrName, attr.copy( self ))
1269                 pass
1270             pass
1271         pass
1272
1273     ## Destructor. Clean-up resources
1274     def __del__(self):
1275         if self.mesh:
1276             #self.mesh.UnRegister()
1277             pass
1278         pass
1279         
1280     ## Initializes the Mesh object from an instance of SMESH_Mesh interface
1281     #  @param theMesh a SMESH_Mesh object
1282     #  @ingroup l2_construct
1283     def SetMesh(self, theMesh):
1284         # do not call Register() as this prevents mesh servant deletion at closing study
1285         #if self.mesh: self.mesh.UnRegister()
1286         self.mesh = theMesh
1287         if self.mesh:
1288             #self.mesh.Register()
1289             self.geom = self.mesh.GetShapeToMesh()
1290         pass
1291
1292     ## Returns the mesh, that is an instance of SMESH_Mesh interface
1293     #  @return a SMESH_Mesh object
1294     #  @ingroup l2_construct
1295     def GetMesh(self):
1296         return self.mesh
1297
1298     ## Gets the name of the mesh
1299     #  @return the name of the mesh as a string
1300     #  @ingroup l2_construct
1301     def GetName(self):
1302         name = GetName(self.GetMesh())
1303         return name
1304
1305     ## Sets a name to the mesh
1306     #  @param name a new name of the mesh
1307     #  @ingroup l2_construct
1308     def SetName(self, name):
1309         self.smeshpyD.SetName(self.GetMesh(), name)
1310
1311     ## Gets the subMesh object associated to a \a theSubObject geometrical object.
1312     #  The subMesh object gives access to the IDs of nodes and elements.
1313     #  @param geom a geometrical object (shape)
1314     #  @param name a name for the submesh
1315     #  @return an object of type SMESH_SubMesh, representing a part of mesh, which lies on the given shape
1316     #  @ingroup l2_submeshes
1317     def GetSubMesh(self, geom, name):
1318         AssureGeomPublished( self, geom, name )
1319         submesh = self.mesh.GetSubMesh( geom, name )
1320         return submesh
1321
1322     ## Returns the shape associated to the mesh
1323     #  @return a GEOM_Object
1324     #  @ingroup l2_construct
1325     def GetShape(self):
1326         return self.geom
1327
1328     ## Associates the given shape to the mesh (entails the recreation of the mesh)
1329     #  @param geom the shape to be meshed (GEOM_Object)
1330     #  @ingroup l2_construct
1331     def SetShape(self, geom):
1332         self.mesh = self.smeshpyD.CreateMesh(geom)
1333
1334     ## Loads mesh from the study after opening the study
1335     def Load(self):
1336         self.mesh.Load()
1337
1338     ## Returns true if the hypotheses are defined well
1339     #  @param theSubObject a sub-shape of a mesh shape
1340     #  @return True or False
1341     #  @ingroup l2_construct
1342     def IsReadyToCompute(self, theSubObject):
1343         return self.smeshpyD.IsReadyToCompute(self.mesh, theSubObject)
1344
1345     ## Returns errors of hypotheses definition.
1346     #  The list of errors is empty if everything is OK.
1347     #  @param theSubObject a sub-shape of a mesh shape
1348     #  @return a list of errors
1349     #  @ingroup l2_construct
1350     def GetAlgoState(self, theSubObject):
1351         return self.smeshpyD.GetAlgoState(self.mesh, theSubObject)
1352
1353     ## Returns a geometrical object on which the given element was built.
1354     #  The returned geometrical object, if not nil, is either found in the
1355     #  study or published by this method with the given name
1356     #  @param theElementID the id of the mesh element
1357     #  @param theGeomName the user-defined name of the geometrical object
1358     #  @return GEOM::GEOM_Object instance
1359     #  @ingroup l2_construct
1360     def GetGeometryByMeshElement(self, theElementID, theGeomName):
1361         return self.smeshpyD.GetGeometryByMeshElement( self.mesh, theElementID, theGeomName )
1362
1363     ## Returns the mesh dimension depending on the dimension of the underlying shape
1364     #  or, if the mesh is not based on any shape, basing on deimension of elements
1365     #  @return mesh dimension as an integer value [0,3]
1366     #  @ingroup l1_auxiliary
1367     def MeshDimension(self):
1368         if self.mesh.HasShapeToMesh():
1369             shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
1370             if len( shells ) > 0 :
1371                 return 3
1372             elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
1373                 return 2
1374             elif self.geompyD.NumberOfEdges( self.geom ) > 0 :
1375                 return 1
1376             else:
1377                 return 0;
1378         else:
1379             if self.NbVolumes() > 0: return 3
1380             if self.NbFaces()   > 0: return 2
1381             if self.NbEdges()   > 0: return 1
1382         return 0
1383
1384     ## Evaluates size of prospective mesh on a shape
1385     #  @return a list where i-th element is a number of elements of i-th SMESH.EntityType
1386     #  To know predicted number of e.g. edges, inquire it this way
1387     #  Evaluate()[ EnumToLong( Entity_Edge )]
1388     def Evaluate(self, geom=0):
1389         if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1390             if self.geom == 0:
1391                 geom = self.mesh.GetShapeToMesh()
1392             else:
1393                 geom = self.geom
1394         return self.smeshpyD.Evaluate(self.mesh, geom)
1395
1396
1397     ## Computes the mesh and returns the status of the computation
1398     #  @param geom geomtrical shape on which mesh data should be computed
1399     #  @param discardModifs if True and the mesh has been edited since
1400     #         a last total re-compute and that may prevent successful partial re-compute,
1401     #         then the mesh is cleaned before Compute()
1402     #  @param refresh if @c True, Object browser is automatically updated (when running in GUI)
1403     #  @return True or False
1404     #  @ingroup l2_construct
1405     def Compute(self, geom=0, discardModifs=False, refresh=False):
1406         if geom == 0 or not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
1407             if self.geom == 0:
1408                 geom = self.mesh.GetShapeToMesh()
1409             else:
1410                 geom = self.geom
1411         ok = False
1412         try:
1413             if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
1414                 self.mesh.Clear()
1415             ok = self.smeshpyD.Compute(self.mesh, geom)
1416         except SALOME.SALOME_Exception, ex:
1417             print "Mesh computation failed, exception caught:"
1418             print "    ", ex.details.text
1419         except:
1420             import traceback
1421             print "Mesh computation failed, exception caught:"
1422             traceback.print_exc()
1423         if True:#not ok:
1424             allReasons = ""
1425
1426             # Treat compute errors
1427             computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, geom )
1428             shapeText = ""
1429             for err in computeErrors:
1430                 if self.mesh.HasShapeToMesh():
1431                     shapeText = " on %s" % self.GetSubShapeName( err.subShapeID )
1432                 errText = ""
1433                 stdErrors = ["OK",                   #COMPERR_OK
1434                              "Invalid input mesh",   #COMPERR_BAD_INPUT_MESH
1435                              "std::exception",       #COMPERR_STD_EXCEPTION
1436                              "OCC exception",        #COMPERR_OCC_EXCEPTION
1437                              "..",                   #COMPERR_SLM_EXCEPTION
1438                              "Unknown exception",    #COMPERR_EXCEPTION
1439                              "Memory allocation problem", #COMPERR_MEMORY_PB
1440                              "Algorithm failed",     #COMPERR_ALGO_FAILED
1441                              "Unexpected geometry",  #COMPERR_BAD_SHAPE
1442                              "Warning",              #COMPERR_WARNING
1443                              "Computation cancelled",#COMPERR_CANCELED
1444                              "No mesh on sub-shape"] #COMPERR_NO_MESH_ON_SHAPE
1445                 if err.code > 0:
1446                     if err.code < len(stdErrors): errText = stdErrors[err.code]
1447                 else:
1448                     errText = "code %s" % -err.code
1449                 if errText: errText += ". "
1450                 errText += err.comment
1451                 if allReasons != "":allReasons += "\n"
1452                 if ok:
1453                     allReasons += '-  "%s"%s - %s' %(err.algoName, shapeText, errText)
1454                 else:
1455                     allReasons += '-  "%s" failed%s. Error: %s' %(err.algoName, shapeText, errText)
1456                 pass
1457
1458             # Treat hyp errors
1459             errors = self.smeshpyD.GetAlgoState( self.mesh, geom )
1460             for err in errors:
1461                 if err.isGlobalAlgo:
1462                     glob = "global"
1463                 else:
1464                     glob = "local"
1465                     pass
1466                 dim = err.algoDim
1467                 name = err.algoName
1468                 if len(name) == 0:
1469                     reason = '%s %sD algorithm is missing' % (glob, dim)
1470                 elif err.state == HYP_MISSING:
1471                     reason = ('%s %sD algorithm "%s" misses %sD hypothesis'
1472                               % (glob, dim, name, dim))
1473                 elif err.state == HYP_NOTCONFORM:
1474                     reason = 'Global "Not Conform mesh allowed" hypothesis is missing'
1475                 elif err.state == HYP_BAD_PARAMETER:
1476                     reason = ('Hypothesis of %s %sD algorithm "%s" has a bad parameter value'
1477                               % ( glob, dim, name ))
1478                 elif err.state == HYP_BAD_GEOMETRY:
1479                     reason = ('%s %sD algorithm "%s" is assigned to mismatching'
1480                               'geometry' % ( glob, dim, name ))
1481                 elif err.state == HYP_HIDDEN_ALGO:
1482                     reason = ('%s %sD algorithm "%s" is ignored due to presence of a %s '
1483                               'algorithm of upper dimension generating %sD mesh'
1484                               % ( glob, dim, name, glob, dim ))
1485                 else:
1486                     reason = ("For unknown reason. "
1487                               "Developer, revise Mesh.Compute() implementation in smeshBuilder.py!")
1488                     pass
1489                 if allReasons != "":allReasons += "\n"
1490                 allReasons += "-  " + reason
1491                 pass
1492             if not ok or allReasons != "":
1493                 msg = '"' + GetName(self.mesh) + '"'
1494                 if ok: msg += " has been computed with warnings"
1495                 else:  msg += " has not been computed"
1496                 if allReasons != "": msg += ":"
1497                 else:                msg += "."
1498                 print msg
1499                 print allReasons
1500             pass
1501         if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
1502             if not isinstance( refresh, list): # not a call from subMesh.Compute()
1503                 smeshgui = salome.ImportComponentGUI("SMESH")
1504                 smeshgui.Init(self.mesh.GetStudyId())
1505                 smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), ok, (self.NbNodes()==0) )
1506                 if refresh: salome.sg.updateObjBrowser(True)
1507
1508         return ok
1509
1510     ## Return a list of error messages (SMESH.ComputeError) of the last Compute()
1511     def GetComputeErrors(self, shape=0 ):
1512         if shape == 0:
1513             shape = self.mesh.GetShapeToMesh()
1514         return self.smeshpyD.GetComputeErrors( self.mesh, shape )
1515
1516     ## Return a name of a sub-shape by its ID
1517     #  @param subShapeID a unique ID of a sub-shape
1518     #  @return a string describing the sub-shape; possible variants:
1519     #  - "Face_12"    (published sub-shape)
1520     #  - FACE #3      (not published sub-shape)
1521     #  - sub-shape #3 (invalid sub-shape ID)
1522     #  - #3           (error in this function)
1523     def GetSubShapeName(self, subShapeID ):
1524         if not self.mesh.HasShapeToMesh():
1525             return ""
1526         try:
1527             shapeText = ""
1528             mainIOR  = salome.orb.object_to_string( self.GetShape() )
1529             for sname in salome.myStudyManager.GetOpenStudies():
1530                 s = salome.myStudyManager.GetStudyByName(sname)
1531                 if not s: continue
1532                 mainSO = s.FindObjectIOR(mainIOR)
1533                 if not mainSO: continue
1534                 if subShapeID == 1:
1535                     shapeText = '"%s"' % mainSO.GetName()
1536                 subIt = s.NewChildIterator(mainSO)
1537                 while subIt.More():
1538                     subSO = subIt.Value()
1539                     subIt.Next()
1540                     obj = subSO.GetObject()
1541                     if not obj: continue
1542                     go = obj._narrow( geomBuilder.GEOM._objref_GEOM_Object )
1543                     if not go: continue
1544                     try:
1545                         ids = self.geompyD.GetSubShapeID( self.GetShape(), go )
1546                     except:
1547                         continue
1548                     if ids == subShapeID:
1549                         shapeText = '"%s"' % subSO.GetName()
1550                         break
1551             if not shapeText:
1552                 shape = self.geompyD.GetSubShape( self.GetShape(), [subShapeID])
1553                 if shape:
1554                     shapeText = '%s #%s' % (shape.GetShapeType(), subShapeID)
1555                 else:
1556                     shapeText = 'sub-shape #%s' % (subShapeID)
1557         except:
1558             shapeText = "#%s" % (subShapeID)
1559         return shapeText
1560
1561     ## Return a list of sub-shapes meshing of which failed, grouped into GEOM groups by
1562     #  error of an algorithm
1563     #  @param publish if @c True, the returned groups will be published in the study
1564     #  @return a list of GEOM groups each named after a failed algorithm
1565     def GetFailedShapes(self, publish=False):
1566
1567         algo2shapes = {}
1568         computeErrors = self.smeshpyD.GetComputeErrors( self.mesh, self.GetShape() )
1569         for err in computeErrors:
1570             shape = self.geompyD.GetSubShape( self.GetShape(), [err.subShapeID])
1571             if not shape: continue
1572             if err.algoName in algo2shapes:
1573                 algo2shapes[ err.algoName ].append( shape )
1574             else:
1575                 algo2shapes[ err.algoName ] = [ shape ]
1576             pass
1577
1578         groups = []
1579         for algoName, shapes in algo2shapes.items():
1580             while shapes:
1581                 groupType = self.smeshpyD.EnumToLong( shapes[0].GetShapeType() )
1582                 otherTypeShapes = []
1583                 sameTypeShapes  = []
1584                 group = self.geompyD.CreateGroup( self.geom, groupType )
1585                 for shape in shapes:
1586                     if shape.GetShapeType() == shapes[0].GetShapeType():
1587                         sameTypeShapes.append( shape )
1588                     else:
1589                         otherTypeShapes.append( shape )
1590                 self.geompyD.UnionList( group, sameTypeShapes )
1591                 if otherTypeShapes:
1592                     group.SetName( "%s %s" % ( algoName, shapes[0].GetShapeType() ))
1593                 else:
1594                     group.SetName( algoName )
1595                 groups.append( group )
1596                 shapes = otherTypeShapes
1597             pass
1598         if publish:
1599             for group in groups:
1600                 self.geompyD.addToStudyInFather( self.geom, group, group.GetName() )
1601         return groups
1602
1603     ## Return sub-mesh objects list in meshing order
1604     #  @return list of lists of sub-meshes
1605     #  @ingroup l2_construct
1606     def GetMeshOrder(self):
1607         return self.mesh.GetMeshOrder()
1608
1609     ## Set order in which concurrent sub-meshes sould be meshed
1610     #  @param submeshes list of lists of sub-meshes
1611     #  @ingroup l2_construct
1612     def SetMeshOrder(self, submeshes):
1613         return self.mesh.SetMeshOrder(submeshes)
1614
1615     ## Removes all nodes and elements
1616     #  @param refresh if @c True, Object browser is automatically updated (when running in GUI)
1617     #  @ingroup l2_construct
1618     def Clear(self, refresh=False):
1619         self.mesh.Clear()
1620         if ( salome.sg.hasDesktop() and 
1621              salome.myStudyManager.GetStudyByID( self.mesh.GetStudyId() ) ):
1622             smeshgui = salome.ImportComponentGUI("SMESH")
1623             smeshgui.Init(self.mesh.GetStudyId())
1624             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1625             if refresh: salome.sg.updateObjBrowser(True)
1626
1627     ## Removes all nodes and elements of indicated shape
1628     #  @param refresh if @c True, Object browser is automatically updated (when running in GUI)
1629     #  @param geomId the ID of a sub-shape to remove elements on
1630     #  @ingroup l2_construct
1631     def ClearSubMesh(self, geomId, refresh=False):
1632         self.mesh.ClearSubMesh(geomId)
1633         if salome.sg.hasDesktop():
1634             smeshgui = salome.ImportComponentGUI("SMESH")
1635             smeshgui.Init(self.mesh.GetStudyId())
1636             smeshgui.SetMeshIcon( salome.ObjectToID( self.mesh ), False, True )
1637             if refresh: salome.sg.updateObjBrowser(True)
1638
1639     ## Computes a tetrahedral mesh using AutomaticLength + MEFISTO + Tetrahedron
1640     #  @param fineness [0.0,1.0] defines mesh fineness
1641     #  @return True or False
1642     #  @ingroup l3_algos_basic
1643     def AutomaticTetrahedralization(self, fineness=0):
1644         dim = self.MeshDimension()
1645         # assign hypotheses
1646         self.RemoveGlobalHypotheses()
1647         self.Segment().AutomaticLength(fineness)
1648         if dim > 1 :
1649             self.Triangle().LengthFromEdges()
1650             pass
1651         if dim > 2 :
1652             self.Tetrahedron()
1653             pass
1654         return self.Compute()
1655
1656     ## Computes an hexahedral mesh using AutomaticLength + Quadrangle + Hexahedron
1657     #  @param fineness [0.0, 1.0] defines mesh fineness
1658     #  @return True or False
1659     #  @ingroup l3_algos_basic
1660     def AutomaticHexahedralization(self, fineness=0):
1661         dim = self.MeshDimension()
1662         # assign the hypotheses
1663         self.RemoveGlobalHypotheses()
1664         self.Segment().AutomaticLength(fineness)
1665         if dim > 1 :
1666             self.Quadrangle()
1667             pass
1668         if dim > 2 :
1669             self.Hexahedron()
1670             pass
1671         return self.Compute()
1672
1673     ## Assigns a hypothesis
1674     #  @param hyp a hypothesis to assign
1675     #  @param geom a subhape of mesh geometry
1676     #  @return SMESH.Hypothesis_Status
1677     #  @ingroup l2_hypotheses
1678     def AddHypothesis(self, hyp, geom=0):
1679         if isinstance( hyp, geomBuilder.GEOM._objref_GEOM_Object ):
1680             hyp, geom = geom, hyp
1681         if isinstance( hyp, Mesh_Algorithm ):
1682             hyp = hyp.GetAlgorithm()
1683             pass
1684         if not geom:
1685             geom = self.geom
1686             if not geom:
1687                 geom = self.mesh.GetShapeToMesh()
1688             pass
1689         isApplicable = True
1690         if self.mesh.HasShapeToMesh():
1691             hyp_type     = hyp.GetName()
1692             lib_name     = hyp.GetLibName()
1693             # checkAll    = ( not geom.IsSame( self.mesh.GetShapeToMesh() ))
1694             # if checkAll and geom:
1695             #     checkAll = geom.GetType() == 37
1696             checkAll     = False
1697             isApplicable = self.smeshpyD.IsApplicable(hyp_type, lib_name, geom, checkAll)
1698         if isApplicable:
1699             AssureGeomPublished( self, geom, "shape for %s" % hyp.GetName())
1700             status = self.mesh.AddHypothesis(geom, hyp)
1701         else:
1702             status = HYP_BAD_GEOMETRY,""
1703         hyp_name = GetName( hyp )
1704         geom_name = ""
1705         if geom:
1706             geom_name = geom.GetName()
1707         isAlgo = hyp._narrow( SMESH_Algo )
1708         TreatHypoStatus( status, hyp_name, geom_name, isAlgo, self )
1709         return status
1710
1711     ## Return True if an algorithm of hypothesis is assigned to a given shape
1712     #  @param hyp a hypothesis to check
1713     #  @param geom a subhape of mesh geometry
1714     #  @return True of False
1715     #  @ingroup l2_hypotheses
1716     def IsUsedHypothesis(self, hyp, geom):
1717         if not hyp: # or not geom
1718             return False
1719         if isinstance( hyp, Mesh_Algorithm ):
1720             hyp = hyp.GetAlgorithm()
1721             pass
1722         hyps = self.GetHypothesisList(geom)
1723         for h in hyps:
1724             if h.GetId() == hyp.GetId():
1725                 return True
1726         return False
1727
1728     ## Unassigns a hypothesis
1729     #  @param hyp a hypothesis to unassign
1730     #  @param geom a sub-shape of mesh geometry
1731     #  @return SMESH.Hypothesis_Status
1732     #  @ingroup l2_hypotheses
1733     def RemoveHypothesis(self, hyp, geom=0):
1734         if not hyp:
1735             return None
1736         if isinstance( hyp, Mesh_Algorithm ):
1737             hyp = hyp.GetAlgorithm()
1738             pass
1739         shape = geom
1740         if not shape:
1741             shape = self.geom
1742             pass
1743         if self.IsUsedHypothesis( hyp, shape ):
1744             return self.mesh.RemoveHypothesis( shape, hyp )
1745         hypName = GetName( hyp )
1746         geoName = GetName( shape )
1747         print "WARNING: RemoveHypothesis() failed as '%s' is not assigned to '%s' shape" % ( hypName, geoName )
1748         return None
1749
1750     ## Gets the list of hypotheses added on a geometry
1751     #  @param geom a sub-shape of mesh geometry
1752     #  @return the sequence of SMESH_Hypothesis
1753     #  @ingroup l2_hypotheses
1754     def GetHypothesisList(self, geom):
1755         return self.mesh.GetHypothesisList( geom )
1756
1757     ## Removes all global hypotheses
1758     #  @ingroup l2_hypotheses
1759     def RemoveGlobalHypotheses(self):
1760         current_hyps = self.mesh.GetHypothesisList( self.geom )
1761         for hyp in current_hyps:
1762             self.mesh.RemoveHypothesis( self.geom, hyp )
1763             pass
1764         pass
1765
1766    ## Exports the mesh in a file in MED format and chooses the \a version of MED format
1767     ## allowing to overwrite the file if it exists or add the exported data to its contents
1768     #  @param f is the file name
1769     #  @param auto_groups boolean parameter for creating/not creating
1770     #  the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1771     #  the typical use is auto_groups=false.
1772     #  @param version MED format version(MED_V2_1 or MED_V2_2)
1773     #  @param overwrite boolean parameter for overwriting/not overwriting the file
1774     #  @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1775     #  @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1776     #         - 1D if all mesh nodes lie on OX coordinate axis, or
1777     #         - 2D if all mesh nodes lie on XOY coordinate plane, or
1778     #         - 3D in the rest cases.
1779     #         If @a autoDimension is @c False, the space dimension is always 3.
1780     #  @param fields : list of GEOM fields defined on the shape to mesh.
1781     #  @param geomAssocFields : each character of this string means a need to export a 
1782     #         corresponding field; correspondence between fields and characters is following:
1783     #         - 'v' stands for _vertices_ field;
1784     #         - 'e' stands for _edges_ field;
1785     #         - 'f' stands for _faces_ field;
1786     #         - 's' stands for _solids_ field.
1787     #  @ingroup l2_impexp
1788     def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
1789                   overwrite=1, meshPart=None, autoDimension=True, fields=[], geomAssocFields=''):
1790         if meshPart or fields or geomAssocFields:
1791             unRegister = genObjUnRegister()
1792             if isinstance( meshPart, list ):
1793                 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1794                 unRegister.set( meshPart )
1795             self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension,
1796                                        fields, geomAssocFields)
1797         else:
1798             self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
1799
1800     ## Exports the mesh in a file in SAUV format
1801     #  @param f is the file name
1802     #  @param auto_groups boolean parameter for creating/not creating
1803     #  the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1804     #  the typical use is auto_groups=false.
1805     #  @ingroup l2_impexp
1806     def ExportSAUV(self, f, auto_groups=0):
1807         self.mesh.ExportSAUV(f, auto_groups)
1808
1809     ## Exports the mesh in a file in DAT format
1810     #  @param f the file name
1811     #  @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1812     #  @ingroup l2_impexp
1813     def ExportDAT(self, f, meshPart=None):
1814         if meshPart:
1815             unRegister = genObjUnRegister()
1816             if isinstance( meshPart, list ):
1817                 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1818                 unRegister.set( meshPart )
1819             self.mesh.ExportPartToDAT( meshPart, f )
1820         else:
1821             self.mesh.ExportDAT(f)
1822
1823     ## Exports the mesh in a file in UNV format
1824     #  @param f the file name
1825     #  @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1826     #  @ingroup l2_impexp
1827     def ExportUNV(self, f, meshPart=None):
1828         if meshPart:
1829             unRegister = genObjUnRegister()
1830             if isinstance( meshPart, list ):
1831                 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1832                 unRegister.set( meshPart )
1833             self.mesh.ExportPartToUNV( meshPart, f )
1834         else:
1835             self.mesh.ExportUNV(f)
1836
1837     ## Export the mesh in a file in STL format
1838     #  @param f the file name
1839     #  @param ascii defines the file encoding
1840     #  @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1841     #  @ingroup l2_impexp
1842     def ExportSTL(self, f, ascii=1, meshPart=None):
1843         if meshPart:
1844             unRegister = genObjUnRegister()
1845             if isinstance( meshPart, list ):
1846                 meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1847                 unRegister.set( meshPart )
1848             self.mesh.ExportPartToSTL( meshPart, f, ascii )
1849         else:
1850             self.mesh.ExportSTL(f, ascii)
1851
1852     ## Exports the mesh in a file in CGNS format
1853     #  @param f is the file name
1854     #  @param overwrite boolean parameter for overwriting/not overwriting the file
1855     #  @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1856     #  @ingroup l2_impexp
1857     def ExportCGNS(self, f, overwrite=1, meshPart=None):
1858         unRegister = genObjUnRegister()
1859         if isinstance( meshPart, list ):
1860             meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1861             unRegister.set( meshPart )
1862         if isinstance( meshPart, Mesh ):
1863             meshPart = meshPart.mesh
1864         elif not meshPart:
1865             meshPart = self.mesh
1866         self.mesh.ExportCGNS(meshPart, f, overwrite)
1867
1868     ## Exports the mesh in a file in GMF format.
1869     #  GMF files must have .mesh extension for the ASCII format and .meshb for
1870     #  the bynary format. Other extensions are not allowed.
1871     #  @param f is the file name
1872     #  @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
1873     #  @ingroup l2_impexp
1874     def ExportGMF(self, f, meshPart=None):
1875         unRegister = genObjUnRegister()
1876         if isinstance( meshPart, list ):
1877             meshPart = self.GetIDSource( meshPart, SMESH.ALL )
1878             unRegister.set( meshPart )
1879         if isinstance( meshPart, Mesh ):
1880             meshPart = meshPart.mesh
1881         elif not meshPart:
1882             meshPart = self.mesh
1883         self.mesh.ExportGMF(meshPart, f, True)
1884
1885     ## Deprecated, used only for compatibility! Please, use ExportToMEDX() method instead.
1886     #  Exports the mesh in a file in MED format and chooses the \a version of MED format
1887     ## allowing to overwrite the file if it exists or add the exported data to its contents
1888     #  @param f the file name
1889     #  @param version values are SMESH.MED_V2_1, SMESH.MED_V2_2
1890     #  @param opt boolean parameter for creating/not creating
1891     #         the groups Group_On_All_Nodes, Group_On_All_Faces, ...
1892     #  @param overwrite boolean parameter for overwriting/not overwriting the file
1893     #  @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
1894     #         - 1D if all mesh nodes lie on OX coordinate axis, or
1895     #         - 2D if all mesh nodes lie on XOY coordinate plane, or
1896     #         - 3D in the rest cases.
1897     #
1898     #         If @a autoDimension is @c False, the space dimension is always 3.
1899     #  @ingroup l2_impexp
1900     def ExportToMED(self, f, version, opt=0, overwrite=1, autoDimension=True):
1901         self.mesh.ExportToMEDX(f, opt, version, overwrite, autoDimension)
1902
1903     # Operations with groups:
1904     # ----------------------
1905
1906     ## Creates an empty mesh group
1907     #  @param elementType the type of elements in the group; either of 
1908     #         (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
1909     #  @param name the name of the mesh group
1910     #  @return SMESH_Group
1911     #  @ingroup l2_grps_create
1912     def CreateEmptyGroup(self, elementType, name):
1913         return self.mesh.CreateGroup(elementType, name)
1914
1915     ## Creates a mesh group based on the geometric object \a grp
1916     #  and gives a \a name, \n if this parameter is not defined
1917     #  the name is the same as the geometric group name \n
1918     #  Note: Works like GroupOnGeom().
1919     #  @param grp  a geometric group, a vertex, an edge, a face or a solid
1920     #  @param name the name of the mesh group
1921     #  @return SMESH_GroupOnGeom
1922     #  @ingroup l2_grps_create
1923     def Group(self, grp, name=""):
1924         return self.GroupOnGeom(grp, name)
1925
1926     ## Creates a mesh group based on the geometrical object \a grp
1927     #  and gives a \a name, \n if this parameter is not defined
1928     #  the name is the same as the geometrical group name
1929     #  @param grp  a geometrical group, a vertex, an edge, a face or a solid
1930     #  @param name the name of the mesh group
1931     #  @param typ  the type of elements in the group; either of 
1932     #         (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME). If not set, it is
1933     #         automatically detected by the type of the geometry
1934     #  @return SMESH_GroupOnGeom
1935     #  @ingroup l2_grps_create
1936     def GroupOnGeom(self, grp, name="", typ=None):
1937         AssureGeomPublished( self, grp, name )
1938         if name == "":
1939             name = grp.GetName()
1940         if not typ:
1941             typ = self._groupTypeFromShape( grp )
1942         return self.mesh.CreateGroupFromGEOM(typ, name, grp)
1943
1944     ## Pivate method to get a type of group on geometry
1945     def _groupTypeFromShape( self, shape ):
1946         tgeo = str(shape.GetShapeType())
1947         if tgeo == "VERTEX":
1948             typ = NODE
1949         elif tgeo == "EDGE":
1950             typ = EDGE
1951         elif tgeo == "FACE" or tgeo == "SHELL":
1952             typ = FACE
1953         elif tgeo == "SOLID" or tgeo == "COMPSOLID":
1954             typ = VOLUME
1955         elif tgeo == "COMPOUND":
1956             sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
1957             if not sub:
1958                 raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
1959             return self._groupTypeFromShape( sub[0] )
1960         else:
1961             raise ValueError, \
1962                   "_groupTypeFromShape(): invalid geometry '%s'" % GetName(shape)
1963         return typ
1964
1965     ## Creates a mesh group with given \a name based on the \a filter which
1966     ## is a special type of group dynamically updating it's contents during
1967     ## mesh modification
1968     #  @param typ  the type of elements in the group; either of 
1969     #         (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
1970     #  @param name the name of the mesh group
1971     #  @param filter the filter defining group contents
1972     #  @return SMESH_GroupOnFilter
1973     #  @ingroup l2_grps_create
1974     def GroupOnFilter(self, typ, name, filter):
1975         return self.mesh.CreateGroupFromFilter(typ, name, filter)
1976
1977     ## Creates a mesh group by the given ids of elements
1978     #  @param groupName the name of the mesh group
1979     #  @param elementType the type of elements in the group; either of 
1980     #         (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
1981     #  @param elemIDs either the list of ids, group, sub-mesh, or filter
1982     #  @return SMESH_Group
1983     #  @ingroup l2_grps_create
1984     def MakeGroupByIds(self, groupName, elementType, elemIDs):
1985         group = self.mesh.CreateGroup(elementType, groupName)
1986         if hasattr( elemIDs, "GetIDs" ):
1987             if hasattr( elemIDs, "SetMesh" ):
1988                 elemIDs.SetMesh( self.GetMesh() )
1989             group.AddFrom( elemIDs )
1990         else:
1991             group.Add(elemIDs)
1992         return group
1993
1994     ## Creates a mesh group by the given conditions
1995     #  @param groupName the name of the mesh group
1996     #  @param elementType the type of elements(SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME)
1997     #  @param CritType the type of criterion (SMESH.FT_Taper, SMESH.FT_Area, etc.)
1998     #          Type SMESH.FunctorType._items in the Python Console to see all values.
1999     #          Note that the items starting from FT_LessThan are not suitable for CritType.
2000     #  @param Compare  belongs to {SMESH.FT_LessThan, SMESH.FT_MoreThan, SMESH.FT_EqualTo}
2001     #  @param Threshold the threshold value (range of ids as string, shape, numeric)
2002     #  @param UnaryOp  SMESH.FT_LogicalNOT or SMESH.FT_Undefined
2003     #  @param Tolerance the tolerance used by SMESH.FT_BelongToGeom, SMESH.FT_BelongToSurface,
2004     #         SMESH.FT_LyingOnGeom, SMESH.FT_CoplanarFaces criteria
2005     #  @return SMESH_GroupOnFilter
2006     #  @ingroup l2_grps_create
2007     def MakeGroup(self,
2008                   groupName,
2009                   elementType,
2010                   CritType=FT_Undefined,
2011                   Compare=FT_EqualTo,
2012                   Threshold="",
2013                   UnaryOp=FT_Undefined,
2014                   Tolerance=1e-07):
2015         aCriterion = self.smeshpyD.GetCriterion(elementType, CritType, Compare, Threshold, UnaryOp, FT_Undefined,Tolerance)
2016         group = self.MakeGroupByCriterion(groupName, aCriterion)
2017         return group
2018
2019     ## Creates a mesh group by the given criterion
2020     #  @param groupName the name of the mesh group
2021     #  @param Criterion the instance of Criterion class
2022     #  @return SMESH_GroupOnFilter
2023     #  @ingroup l2_grps_create
2024     def MakeGroupByCriterion(self, groupName, Criterion):
2025         return self.MakeGroupByCriteria( groupName, [Criterion] )
2026
2027     ## Creates a mesh group by the given criteria (list of criteria)
2028     #  @param groupName the name of the mesh group
2029     #  @param theCriteria the list of criteria
2030     #  @param binOp binary operator used when binary operator of criteria is undefined
2031     #  @return SMESH_GroupOnFilter
2032     #  @ingroup l2_grps_create
2033     def MakeGroupByCriteria(self, groupName, theCriteria, binOp=SMESH.FT_LogicalAND):
2034         aFilter = self.smeshpyD.GetFilterFromCriteria( theCriteria, binOp )
2035         group = self.MakeGroupByFilter(groupName, aFilter)
2036         return group
2037
2038     ## Creates a mesh group by the given filter
2039     #  @param groupName the name of the mesh group
2040     #  @param theFilter the instance of Filter class
2041     #  @return SMESH_GroupOnFilter
2042     #  @ingroup l2_grps_create
2043     def MakeGroupByFilter(self, groupName, theFilter):
2044         #group = self.CreateEmptyGroup(theFilter.GetElementType(), groupName)
2045         #theFilter.SetMesh( self.mesh )
2046         #group.AddFrom( theFilter )
2047         group = self.GroupOnFilter( theFilter.GetElementType(), groupName, theFilter )
2048         return group
2049
2050     ## Removes a group
2051     #  @ingroup l2_grps_delete
2052     def RemoveGroup(self, group):
2053         self.mesh.RemoveGroup(group)
2054
2055     ## Removes a group with its contents
2056     #  @ingroup l2_grps_delete
2057     def RemoveGroupWithContents(self, group):
2058         self.mesh.RemoveGroupWithContents(group)
2059
2060     ## Gets the list of groups existing in the mesh in the order
2061     #  of creation (starting from the oldest one)
2062     #  @param elemType type of elements the groups contain; either of 
2063     #         (SMESH.ALL, SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME);
2064     #         by default groups of elements of all types are returned
2065     #  @return a sequence of SMESH_GroupBase
2066     #  @ingroup l2_grps_create
2067     def GetGroups(self, elemType = SMESH.ALL):
2068         groups = self.mesh.GetGroups()
2069         if elemType == SMESH.ALL:
2070             return groups
2071         typedGroups = []
2072         for g in groups:
2073             if g.GetType() == elemType:
2074                 typedGroups.append( g )
2075                 pass
2076             pass
2077         return typedGroups
2078
2079     ## Gets the number of groups existing in the mesh
2080     #  @return the quantity of groups as an integer value
2081     #  @ingroup l2_grps_create
2082     def NbGroups(self):
2083         return self.mesh.NbGroups()
2084
2085     ## Gets the list of names of groups existing in the mesh
2086     #  @return list of strings
2087     #  @ingroup l2_grps_create
2088     def GetGroupNames(self):
2089         groups = self.GetGroups()
2090         names = []
2091         for group in groups:
2092             names.append(group.GetName())
2093         return names
2094
2095     ## Finds groups by name and type
2096     #  @param name name of the group of interest
2097     #  @param elemType type of elements the groups contain; either of 
2098     #         (SMESH.ALL, SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME);
2099     #         by default one group of any type of elements is returned
2100     #         if elemType == SMESH.ALL then all groups of any type are returned
2101     #  @return a list of SMESH_GroupBase's
2102     #  @ingroup l2_grps_create
2103     def GetGroupByName(self, name, elemType = None):
2104         groups = []
2105         for group in self.GetGroups():
2106             if group.GetName() == name:
2107                 if elemType is None:
2108                     return [group]
2109                 if ( elemType == SMESH.ALL or 
2110                      group.GetType() == elemType ):
2111                     groups.append( group )
2112         return groups
2113
2114     ## Produces a union of two groups.
2115     #  A new group is created. All mesh elements that are
2116     #  present in the initial groups are added to the new one
2117     #  @return an instance of SMESH_Group
2118     #  @ingroup l2_grps_operon
2119     def UnionGroups(self, group1, group2, name):
2120         return self.mesh.UnionGroups(group1, group2, name)
2121
2122     ## Produces a union list of groups.
2123     #  New group is created. All mesh elements that are present in
2124     #  initial groups are added to the new one
2125     #  @return an instance of SMESH_Group
2126     #  @ingroup l2_grps_operon
2127     def UnionListOfGroups(self, groups, name):
2128       return self.mesh.UnionListOfGroups(groups, name)
2129
2130     ## Prodices an intersection of two groups.
2131     #  A new group is created. All mesh elements that are common
2132     #  for the two initial groups are added to the new one.
2133     #  @return an instance of SMESH_Group
2134     #  @ingroup l2_grps_operon
2135     def IntersectGroups(self, group1, group2, name):
2136         return self.mesh.IntersectGroups(group1, group2, name)
2137
2138     ## Produces an intersection of groups.
2139     #  New group is created. All mesh elements that are present in all
2140     #  initial groups simultaneously are added to the new one
2141     #  @return an instance of SMESH_Group
2142     #  @ingroup l2_grps_operon
2143     def IntersectListOfGroups(self, groups, name):
2144       return self.mesh.IntersectListOfGroups(groups, name)
2145
2146     ## Produces a cut of two groups.
2147     #  A new group is created. All mesh elements that are present in
2148     #  the main group but are not present in the tool group are added to the new one
2149     #  @return an instance of SMESH_Group
2150     #  @ingroup l2_grps_operon
2151     def CutGroups(self, main_group, tool_group, name):
2152         return self.mesh.CutGroups(main_group, tool_group, name)
2153
2154     ## Produces a cut of groups.
2155     #  A new group is created. All mesh elements that are present in main groups
2156     #  but do not present in tool groups are added to the new one
2157     #  @return an instance of SMESH_Group
2158     #  @ingroup l2_grps_operon
2159     def CutListOfGroups(self, main_groups, tool_groups, name):
2160         return self.mesh.CutListOfGroups(main_groups, tool_groups, name)
2161
2162     ##
2163     #  Create a standalone group of entities basing on nodes of other groups.
2164     #  \param groups - list of reference groups, sub-meshes or filters, of any type.
2165     #  \param elemType - a type of elements to include to the new group; either of 
2166     #         (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME).
2167     #  \param name - a name of the new group.
2168     #  \param nbCommonNodes - a criterion of inclusion of an element to the new group
2169     #         basing on number of element nodes common with reference \a groups.
2170     #         Meaning of possible values are:
2171     #         - SMESH.ALL_NODES - include if all nodes are common,
2172     #         - SMESH.MAIN - include if all corner nodes are common (meaningful for a quadratic mesh),
2173     #         - SMESH.AT_LEAST_ONE - include if one or more node is common,
2174     #         - SMEHS.MAJORITY - include if half of nodes or more are common.
2175     #  \param underlyingOnly - if \c True (default), an element is included to the
2176     #         new group provided that it is based on nodes of an element of \a groups;
2177     #         in this case the reference \a groups are supposed to be of higher dimension
2178     #         than \a elemType, which can be useful for example to get all faces lying on
2179     #         volumes of the reference \a groups.
2180     #  @return an instance of SMESH_Group
2181     #  @ingroup l2_grps_operon
2182     def CreateDimGroup(self, groups, elemType, name,
2183                        nbCommonNodes = SMESH.ALL_NODES, underlyingOnly = True):
2184         if isinstance( groups, SMESH._objref_SMESH_IDSource ):
2185             groups = [groups]
2186         return self.mesh.CreateDimGroup(groups, elemType, name, nbCommonNodes, underlyingOnly)
2187
2188
2189     ## Convert group on geom into standalone group
2190     #  @ingroup l2_grps_edit
2191     def ConvertToStandalone(self, group):
2192         return self.mesh.ConvertToStandalone(group)
2193
2194     # Get some info about mesh:
2195     # ------------------------
2196
2197     ## Returns the log of nodes and elements added or removed
2198     #  since the previous clear of the log.
2199     #  @param clearAfterGet log is emptied after Get (safe if concurrents access)
2200     #  @return list of log_block structures:
2201     #                                        commandType
2202     #                                        number
2203     #                                        coords
2204     #                                        indexes
2205     #  @ingroup l1_auxiliary
2206     def GetLog(self, clearAfterGet):
2207         return self.mesh.GetLog(clearAfterGet)
2208
2209     ## Clears the log of nodes and elements added or removed since the previous
2210     #  clear. Must be used immediately after GetLog if clearAfterGet is false.
2211     #  @ingroup l1_auxiliary
2212     def ClearLog(self):
2213         self.mesh.ClearLog()
2214
2215     ## Toggles auto color mode on the object.
2216     #  @param theAutoColor the flag which toggles auto color mode.
2217     #  @ingroup l1_auxiliary
2218     def SetAutoColor(self, theAutoColor):
2219         self.mesh.SetAutoColor(theAutoColor)
2220
2221     ## Gets flag of object auto color mode.
2222     #  @return True or False
2223     #  @ingroup l1_auxiliary
2224     def GetAutoColor(self):
2225         return self.mesh.GetAutoColor()
2226
2227     ## Gets the internal ID
2228     #  @return integer value, which is the internal Id of the mesh
2229     #  @ingroup l1_auxiliary
2230     def GetId(self):
2231         return self.mesh.GetId()
2232
2233     ## Get the study Id
2234     #  @return integer value, which is the study Id of the mesh
2235     #  @ingroup l1_auxiliary
2236     def GetStudyId(self):
2237         return self.mesh.GetStudyId()
2238
2239     ## Checks the group names for duplications.
2240     #  Consider the maximum group name length stored in MED file.
2241     #  @return True or False
2242     #  @ingroup l1_auxiliary
2243     def HasDuplicatedGroupNamesMED(self):
2244         return self.mesh.HasDuplicatedGroupNamesMED()
2245
2246     ## Obtains the mesh editor tool
2247     #  @return an instance of SMESH_MeshEditor
2248     #  @ingroup l1_modifying
2249     def GetMeshEditor(self):
2250         return self.editor
2251
2252     ## Wrap a list of IDs of elements or nodes into SMESH_IDSource which
2253     #  can be passed as argument to a method accepting mesh, group or sub-mesh
2254     #  @param ids list of IDs
2255     #  @param elemType type of elements; this parameter is used to distinguish
2256     #         IDs of nodes from IDs of elements; by default ids are treated as
2257     #         IDs of elements; use SMESH.NODE if ids are IDs of nodes.
2258     #  @return an instance of SMESH_IDSource
2259     #  @warning call UnRegister() for the returned object as soon as it is no more useful:
2260     #          idSrc = mesh.GetIDSource( [1,3,5], SMESH.NODE )
2261     #          mesh.DoSomething( idSrc )
2262     #          idSrc.UnRegister()
2263     #  @ingroup l1_auxiliary
2264     def GetIDSource(self, ids, elemType = SMESH.ALL):
2265         if isinstance( ids, int ):
2266             ids = [ids]
2267         return self.editor.MakeIDSource(ids, elemType)
2268
2269
2270     # Get informations about mesh contents:
2271     # ------------------------------------
2272
2273     ## Gets the mesh stattistic
2274     #  @return dictionary type element - count of elements
2275     #  @ingroup l1_meshinfo
2276     def GetMeshInfo(self, obj = None):
2277         if not obj: obj = self.mesh
2278         return self.smeshpyD.GetMeshInfo(obj)
2279
2280     ## Returns the number of nodes in the mesh
2281     #  @return an integer value
2282     #  @ingroup l1_meshinfo
2283     def NbNodes(self):
2284         return self.mesh.NbNodes()
2285
2286     ## Returns the number of elements in the mesh
2287     #  @return an integer value
2288     #  @ingroup l1_meshinfo
2289     def NbElements(self):
2290         return self.mesh.NbElements()
2291
2292     ## Returns the number of 0d elements in the mesh
2293     #  @return an integer value
2294     #  @ingroup l1_meshinfo
2295     def Nb0DElements(self):
2296         return self.mesh.Nb0DElements()
2297
2298     ## Returns the number of ball discrete elements in the mesh
2299     #  @return an integer value
2300     #  @ingroup l1_meshinfo
2301     def NbBalls(self):
2302         return self.mesh.NbBalls()
2303
2304     ## Returns the number of edges in the mesh
2305     #  @return an integer value
2306     #  @ingroup l1_meshinfo
2307     def NbEdges(self):
2308         return self.mesh.NbEdges()
2309
2310     ## Returns the number of edges with the given order in the mesh
2311     #  @param elementOrder the order of elements:
2312     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2313     #  @return an integer value
2314     #  @ingroup l1_meshinfo
2315     def NbEdgesOfOrder(self, elementOrder):
2316         return self.mesh.NbEdgesOfOrder(elementOrder)
2317
2318     ## Returns the number of faces in the mesh
2319     #  @return an integer value
2320     #  @ingroup l1_meshinfo
2321     def NbFaces(self):
2322         return self.mesh.NbFaces()
2323
2324     ## Returns the number of faces with the given order in the mesh
2325     #  @param elementOrder the order of elements:
2326     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2327     #  @return an integer value
2328     #  @ingroup l1_meshinfo
2329     def NbFacesOfOrder(self, elementOrder):
2330         return self.mesh.NbFacesOfOrder(elementOrder)
2331
2332     ## Returns the number of triangles in the mesh
2333     #  @return an integer value
2334     #  @ingroup l1_meshinfo
2335     def NbTriangles(self):
2336         return self.mesh.NbTriangles()
2337
2338     ## Returns the number of triangles with the given order in the mesh
2339     #  @param elementOrder is the order of elements:
2340     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2341     #  @return an integer value
2342     #  @ingroup l1_meshinfo
2343     def NbTrianglesOfOrder(self, elementOrder):
2344         return self.mesh.NbTrianglesOfOrder(elementOrder)
2345
2346     ## Returns the number of biquadratic triangles in the mesh
2347     #  @return an integer value
2348     #  @ingroup l1_meshinfo
2349     def NbBiQuadTriangles(self):
2350         return self.mesh.NbBiQuadTriangles()
2351
2352     ## Returns the number of quadrangles in the mesh
2353     #  @return an integer value
2354     #  @ingroup l1_meshinfo
2355     def NbQuadrangles(self):
2356         return self.mesh.NbQuadrangles()
2357
2358     ## Returns the number of quadrangles with the given order in the mesh
2359     #  @param elementOrder the order of elements:
2360     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2361     #  @return an integer value
2362     #  @ingroup l1_meshinfo
2363     def NbQuadranglesOfOrder(self, elementOrder):
2364         return self.mesh.NbQuadranglesOfOrder(elementOrder)
2365
2366     ## Returns the number of biquadratic quadrangles in the mesh
2367     #  @return an integer value
2368     #  @ingroup l1_meshinfo
2369     def NbBiQuadQuadrangles(self):
2370         return self.mesh.NbBiQuadQuadrangles()
2371
2372     ## Returns the number of polygons of given order in the mesh
2373     #  @param elementOrder the order of elements:
2374     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2375     #  @return an integer value
2376     #  @ingroup l1_meshinfo
2377     def NbPolygons(self, elementOrder = SMESH.ORDER_ANY):
2378         return self.mesh.NbPolygonsOfOrder(elementOrder)
2379
2380     ## Returns the number of volumes in the mesh
2381     #  @return an integer value
2382     #  @ingroup l1_meshinfo
2383     def NbVolumes(self):
2384         return self.mesh.NbVolumes()
2385
2386     ## Returns the number of volumes with the given order in the mesh
2387     #  @param elementOrder  the order of elements:
2388     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2389     #  @return an integer value
2390     #  @ingroup l1_meshinfo
2391     def NbVolumesOfOrder(self, elementOrder):
2392         return self.mesh.NbVolumesOfOrder(elementOrder)
2393
2394     ## Returns the number of tetrahedrons in the mesh
2395     #  @return an integer value
2396     #  @ingroup l1_meshinfo
2397     def NbTetras(self):
2398         return self.mesh.NbTetras()
2399
2400     ## Returns the number of tetrahedrons with the given order in the mesh
2401     #  @param elementOrder  the order of elements:
2402     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2403     #  @return an integer value
2404     #  @ingroup l1_meshinfo
2405     def NbTetrasOfOrder(self, elementOrder):
2406         return self.mesh.NbTetrasOfOrder(elementOrder)
2407
2408     ## Returns the number of hexahedrons in the mesh
2409     #  @return an integer value
2410     #  @ingroup l1_meshinfo
2411     def NbHexas(self):
2412         return self.mesh.NbHexas()
2413
2414     ## Returns the number of hexahedrons with the given order in the mesh
2415     #  @param elementOrder  the order of elements:
2416     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2417     #  @return an integer value
2418     #  @ingroup l1_meshinfo
2419     def NbHexasOfOrder(self, elementOrder):
2420         return self.mesh.NbHexasOfOrder(elementOrder)
2421
2422     ## Returns the number of triquadratic hexahedrons in the mesh
2423     #  @return an integer value
2424     #  @ingroup l1_meshinfo
2425     def NbTriQuadraticHexas(self):
2426         return self.mesh.NbTriQuadraticHexas()
2427
2428     ## Returns the number of pyramids in the mesh
2429     #  @return an integer value
2430     #  @ingroup l1_meshinfo
2431     def NbPyramids(self):
2432         return self.mesh.NbPyramids()
2433
2434     ## Returns the number of pyramids with the given order in the mesh
2435     #  @param elementOrder  the order of elements:
2436     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2437     #  @return an integer value
2438     #  @ingroup l1_meshinfo
2439     def NbPyramidsOfOrder(self, elementOrder):
2440         return self.mesh.NbPyramidsOfOrder(elementOrder)
2441
2442     ## Returns the number of prisms in the mesh
2443     #  @return an integer value
2444     #  @ingroup l1_meshinfo
2445     def NbPrisms(self):
2446         return self.mesh.NbPrisms()
2447
2448     ## Returns the number of prisms with the given order in the mesh
2449     #  @param elementOrder  the order of elements:
2450     #         SMESH.ORDER_ANY, SMESH.ORDER_LINEAR or SMESH.ORDER_QUADRATIC
2451     #  @return an integer value
2452     #  @ingroup l1_meshinfo
2453     def NbPrismsOfOrder(self, elementOrder):
2454         return self.mesh.NbPrismsOfOrder(elementOrder)
2455
2456     ## Returns the number of hexagonal prisms in the mesh
2457     #  @return an integer value
2458     #  @ingroup l1_meshinfo
2459     def NbHexagonalPrisms(self):
2460         return self.mesh.NbHexagonalPrisms()
2461
2462     ## Returns the number of polyhedrons in the mesh
2463     #  @return an integer value
2464     #  @ingroup l1_meshinfo
2465     def NbPolyhedrons(self):
2466         return self.mesh.NbPolyhedrons()
2467
2468     ## Returns the number of submeshes in the mesh
2469     #  @return an integer value
2470     #  @ingroup l1_meshinfo
2471     def NbSubMesh(self):
2472         return self.mesh.NbSubMesh()
2473
2474     ## Returns the list of mesh elements IDs
2475     #  @return the list of integer values
2476     #  @ingroup l1_meshinfo
2477     def GetElementsId(self):
2478         return self.mesh.GetElementsId()
2479
2480     ## Returns the list of IDs of mesh elements with the given type
2481     #  @param elementType  the required type of elements, either of
2482     #         (SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2483     #  @return list of integer values
2484     #  @ingroup l1_meshinfo
2485     def GetElementsByType(self, elementType):
2486         return self.mesh.GetElementsByType(elementType)
2487
2488     ## Returns the list of mesh nodes IDs
2489     #  @return the list of integer values
2490     #  @ingroup l1_meshinfo
2491     def GetNodesId(self):
2492         return self.mesh.GetNodesId()
2493
2494     # Get the information about mesh elements:
2495     # ------------------------------------
2496
2497     ## Returns the type of mesh element
2498     #  @return the value from SMESH::ElementType enumeration
2499     #          Type SMESH.ElementType._items in the Python Console to see all possible values.
2500     #  @ingroup l1_meshinfo
2501     def GetElementType(self, id, iselem=True):
2502         return self.mesh.GetElementType(id, iselem)
2503
2504     ## Returns the geometric type of mesh element
2505     #  @return the value from SMESH::EntityType enumeration
2506     #          Type SMESH.EntityType._items in the Python Console to see all possible values.
2507     #  @ingroup l1_meshinfo
2508     def GetElementGeomType(self, id):
2509         return self.mesh.GetElementGeomType(id)
2510
2511     ## Returns the shape type of mesh element
2512     #  @return the value from SMESH::GeometryType enumeration.
2513     #          Type SMESH.GeometryType._items in the Python Console to see all possible values.
2514     #  @ingroup l1_meshinfo
2515     def GetElementShape(self, id):
2516         return self.mesh.GetElementShape(id)
2517
2518     ## Returns the list of submesh elements IDs
2519     #  @param Shape a geom object(sub-shape)
2520     #         Shape must be the sub-shape of a ShapeToMesh()
2521     #  @return the list of integer values
2522     #  @ingroup l1_meshinfo
2523     def GetSubMeshElementsId(self, Shape):
2524         if isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object):
2525             ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2526         else:
2527             ShapeID = Shape
2528         return self.mesh.GetSubMeshElementsId(ShapeID)
2529
2530     ## Returns the list of submesh nodes IDs
2531     #  @param Shape a geom object(sub-shape)
2532     #         Shape must be the sub-shape of a ShapeToMesh()
2533     #  @param all If true, gives all nodes of submesh elements, otherwise gives only submesh nodes
2534     #  @return the list of integer values
2535     #  @ingroup l1_meshinfo
2536     def GetSubMeshNodesId(self, Shape, all):
2537         if isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object):
2538             ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2539         else:
2540             ShapeID = Shape
2541         return self.mesh.GetSubMeshNodesId(ShapeID, all)
2542
2543     ## Returns type of elements on given shape
2544     #  @param Shape a geom object(sub-shape)
2545     #         Shape must be a sub-shape of a ShapeToMesh()
2546     #  @return element type
2547     #  @ingroup l1_meshinfo
2548     def GetSubMeshElementType(self, Shape):
2549         if isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object):
2550             ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
2551         else:
2552             ShapeID = Shape
2553         return self.mesh.GetSubMeshElementType(ShapeID)
2554
2555     ## Gets the mesh description
2556     #  @return string value
2557     #  @ingroup l1_meshinfo
2558     def Dump(self):
2559         return self.mesh.Dump()
2560
2561
2562     # Get the information about nodes and elements of a mesh by its IDs:
2563     # -----------------------------------------------------------
2564
2565     ## Gets XYZ coordinates of a node
2566     #  \n If there is no nodes for the given ID - returns an empty list
2567     #  @return a list of double precision values
2568     #  @ingroup l1_meshinfo
2569     def GetNodeXYZ(self, id):
2570         return self.mesh.GetNodeXYZ(id)
2571
2572     ## Returns list of IDs of inverse elements for the given node
2573     #  \n If there is no node for the given ID - returns an empty list
2574     #  @return a list of integer values
2575     #  @ingroup l1_meshinfo
2576     def GetNodeInverseElements(self, id):
2577         return self.mesh.GetNodeInverseElements(id)
2578
2579     ## @brief Returns the position of a node on the shape
2580     #  @return SMESH::NodePosition
2581     #  @ingroup l1_meshinfo
2582     def GetNodePosition(self,NodeID):
2583         return self.mesh.GetNodePosition(NodeID)
2584
2585     ## @brief Returns the position of an element on the shape
2586     #  @return SMESH::ElementPosition
2587     #  @ingroup l1_meshinfo
2588     def GetElementPosition(self,ElemID):
2589         return self.mesh.GetElementPosition(ElemID)
2590
2591     ## Returns the ID of the shape, on which the given node was generated.
2592     #  @return an integer value > 0 or -1 if there is no node for the given
2593     #          ID or the node is not assigned to any geometry
2594     #  @ingroup l1_meshinfo
2595     def GetShapeID(self, id):
2596         return self.mesh.GetShapeID(id)
2597
2598     ## Returns the ID of the shape, on which the given element was generated.
2599     #  @return an integer value > 0 or -1 if there is no element for the given
2600     #          ID or the element is not assigned to any geometry
2601     #  @ingroup l1_meshinfo
2602     def GetShapeIDForElem(self,id):
2603         return self.mesh.GetShapeIDForElem(id)
2604
2605     ## Returns the number of nodes of the given element
2606     #  @return an integer value > 0 or -1 if there is no element for the given ID
2607     #  @ingroup l1_meshinfo
2608     def GetElemNbNodes(self, id):
2609         return self.mesh.GetElemNbNodes(id)
2610
2611     ## Returns the node ID the given (zero based) index for the given element
2612     #  \n If there is no element for the given ID - returns -1
2613     #  \n If there is no node for the given index - returns -2
2614     #  @return an integer value
2615     #  @ingroup l1_meshinfo
2616     def GetElemNode(self, id, index):
2617         return self.mesh.GetElemNode(id, index)
2618
2619     ## Returns the IDs of nodes of the given element
2620     #  @return a list of integer values
2621     #  @ingroup l1_meshinfo
2622     def GetElemNodes(self, id):
2623         return self.mesh.GetElemNodes(id)
2624
2625     ## Returns true if the given node is the medium node in the given quadratic element
2626     #  @ingroup l1_meshinfo
2627     def IsMediumNode(self, elementID, nodeID):
2628         return self.mesh.IsMediumNode(elementID, nodeID)
2629
2630     ## Returns true if the given node is the medium node in one of quadratic elements
2631     #  @param nodeID ID of the node
2632     #  @param elementType  the type of elements to check a state of the node, either of
2633     #         (SMESH.ALL, SMESH.NODE, SMESH.EDGE, SMESH.FACE or SMESH.VOLUME)
2634     #  @ingroup l1_meshinfo
2635     def IsMediumNodeOfAnyElem(self, nodeID, elementType = SMESH.ALL ):
2636         return self.mesh.IsMediumNodeOfAnyElem(nodeID, elementType)
2637
2638     ## Returns the number of edges for the given element
2639     #  @ingroup l1_meshinfo
2640     def ElemNbEdges(self, id):
2641         return self.mesh.ElemNbEdges(id)
2642
2643     ## Returns the number of faces for the given element
2644     #  @ingroup l1_meshinfo
2645     def ElemNbFaces(self, id):
2646         return self.mesh.ElemNbFaces(id)
2647
2648     ## Returns nodes of given face (counted from zero) for given volumic element.
2649     #  @ingroup l1_meshinfo
2650     def GetElemFaceNodes(self,elemId, faceIndex):
2651         return self.mesh.GetElemFaceNodes(elemId, faceIndex)
2652
2653     ## Returns three components of normal of given mesh face
2654     #  (or an empty array in KO case)
2655     #  @ingroup l1_meshinfo
2656     def GetFaceNormal(self, faceId, normalized=False):
2657         return self.mesh.GetFaceNormal(faceId,normalized)
2658
2659     ## Returns an element based on all given nodes.
2660     #  @ingroup l1_meshinfo
2661     def FindElementByNodes(self,nodes):
2662         return self.mesh.FindElementByNodes(nodes)
2663
2664     ## Returns true if the given element is a polygon
2665     #  @ingroup l1_meshinfo
2666     def IsPoly(self, id):
2667         return self.mesh.IsPoly(id)
2668
2669     ## Returns true if the given element is quadratic
2670     #  @ingroup l1_meshinfo
2671     def IsQuadratic(self, id):
2672         return self.mesh.IsQuadratic(id)
2673
2674     ## Returns diameter of a ball discrete element or zero in case of an invalid \a id
2675     #  @ingroup l1_meshinfo
2676     def GetBallDiameter(self, id):
2677         return self.mesh.GetBallDiameter(id)
2678
2679     ## Returns XYZ coordinates of the barycenter of the given element
2680     #  \n If there is no element for the given ID - returns an empty list
2681     #  @return a list of three double values
2682     #  @ingroup l1_meshinfo
2683     def BaryCenter(self, id):
2684         return self.mesh.BaryCenter(id)
2685
2686     ## Passes mesh elements through the given filter and return IDs of fitting elements
2687     #  @param theFilter SMESH_Filter
2688     #  @return a list of ids
2689     #  @ingroup l1_controls
2690     def GetIdsFromFilter(self, theFilter):
2691         theFilter.SetMesh( self.mesh )
2692         return theFilter.GetIDs()
2693
2694     ## Verifies whether a 2D mesh element has free edges (edges connected to one face only)\n
2695     #  Returns a list of special structures (borders).
2696     #  @return a list of SMESH.FreeEdges.Border structure: edge id and ids of two its nodes.
2697     #  @ingroup l1_controls
2698     def GetFreeBorders(self):
2699         aFilterMgr = self.smeshpyD.CreateFilterManager()
2700         aPredicate = aFilterMgr.CreateFreeEdges()
2701         aPredicate.SetMesh(self.mesh)
2702         aBorders = aPredicate.GetBorders()
2703         aFilterMgr.UnRegister()
2704         return aBorders
2705
2706
2707     # Get mesh measurements information:
2708     # ------------------------------------
2709
2710     ## Get minimum distance between two nodes, elements or distance to the origin
2711     #  @param id1 first node/element id
2712     #  @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2713     #  @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2714     #  @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2715     #  @return minimum distance value
2716     #  @sa GetMinDistance()
2717     def MinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2718         aMeasure = self.GetMinDistance(id1, id2, isElem1, isElem2)
2719         return aMeasure.value
2720
2721     ## Get measure structure specifying minimum distance data between two objects
2722     #  @param id1 first node/element id
2723     #  @param id2 second node/element id (if 0, distance from @a id1 to the origin is computed)
2724     #  @param isElem1 @c True if @a id1 is element id, @c False if it is node id
2725     #  @param isElem2 @c True if @a id2 is element id, @c False if it is node id
2726     #  @return Measure structure
2727     #  @sa MinDistance()
2728     def GetMinDistance(self, id1, id2=0, isElem1=False, isElem2=False):
2729         if isElem1:
2730             id1 = self.editor.MakeIDSource([id1], SMESH.FACE)
2731         else:
2732             id1 = self.editor.MakeIDSource([id1], SMESH.NODE)
2733         if id2 != 0:
2734             if isElem2:
2735                 id2 = self.editor.MakeIDSource([id2], SMESH.FACE)
2736             else:
2737                 id2 = self.editor.MakeIDSource([id2], SMESH.NODE)
2738             pass
2739         else:
2740             id2 = None
2741
2742         aMeasurements = self.smeshpyD.CreateMeasurements()
2743         aMeasure = aMeasurements.MinDistance(id1, id2)
2744         genObjUnRegister([aMeasurements,id1, id2])
2745         return aMeasure
2746
2747     ## Get bounding box of the specified object(s)
2748     #  @param objects single source object or list of source objects or list of nodes/elements IDs
2749     #  @param isElem if @a objects is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2750     #  @c False specifies that @a objects are nodes
2751     #  @return tuple of six values (minX, minY, minZ, maxX, maxY, maxZ)
2752     #  @sa GetBoundingBox()
2753     def BoundingBox(self, objects=None, isElem=False):
2754         result = self.GetBoundingBox(objects, isElem)
2755         if result is None:
2756             result = (0.0,)*6
2757         else:
2758             result = (result.minX, result.minY, result.minZ, result.maxX, result.maxY, result.maxZ)
2759         return result
2760
2761     ## Get measure structure specifying bounding box data of the specified object(s)
2762     #  @param IDs single source object or list of source objects or list of nodes/elements IDs
2763     #  @param isElem if @a IDs is a list of IDs, @c True value in this parameters specifies that @a objects are elements,
2764     #  @c False specifies that @a objects are nodes
2765     #  @return Measure structure
2766     #  @sa BoundingBox()
2767     def GetBoundingBox(self, IDs=None, isElem=False):
2768         if IDs is None:
2769             IDs = [self.mesh]
2770         elif isinstance(IDs, tuple):
2771             IDs = list(IDs)
2772         if not isinstance(IDs, list):
2773             IDs = [IDs]
2774         if len(IDs) > 0 and isinstance(IDs[0], int):
2775             IDs = [IDs]
2776         srclist = []
2777         unRegister = genObjUnRegister()
2778         for o in IDs:
2779             if isinstance(o, Mesh):
2780                 srclist.append(o.mesh)
2781             elif hasattr(o, "_narrow"):
2782                 src = o._narrow(SMESH.SMESH_IDSource)
2783                 if src: srclist.append(src)
2784                 pass
2785             elif isinstance(o, list):
2786                 if isElem:
2787                     srclist.append(self.editor.MakeIDSource(o, SMESH.FACE))
2788                 else:
2789                     srclist.append(self.editor.MakeIDSource(o, SMESH.NODE))
2790                 unRegister.set( srclist[-1] )
2791                 pass
2792             pass
2793         aMeasurements = self.smeshpyD.CreateMeasurements()
2794         unRegister.set( aMeasurements )
2795         aMeasure = aMeasurements.BoundingBox(srclist)
2796         return aMeasure
2797
2798     # Mesh edition (SMESH_MeshEditor functionality):
2799     # ---------------------------------------------
2800
2801     ## Removes the elements from the mesh by ids
2802     #  @param IDsOfElements is a list of ids of elements to remove
2803     #  @return True or False
2804     #  @ingroup l2_modif_del
2805     def RemoveElements(self, IDsOfElements):
2806         return self.editor.RemoveElements(IDsOfElements)
2807
2808     ## Removes nodes from mesh by ids
2809     #  @param IDsOfNodes is a list of ids of nodes to remove
2810     #  @return True or False
2811     #  @ingroup l2_modif_del
2812     def RemoveNodes(self, IDsOfNodes):
2813         return self.editor.RemoveNodes(IDsOfNodes)
2814
2815     ## Removes all orphan (free) nodes from mesh
2816     #  @return number of the removed nodes
2817     #  @ingroup l2_modif_del
2818     def RemoveOrphanNodes(self):
2819         return self.editor.RemoveOrphanNodes()
2820
2821     ## Add a node to the mesh by coordinates
2822     #  @return Id of the new node
2823     #  @ingroup l2_modif_add
2824     def AddNode(self, x, y, z):
2825         x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
2826         if hasVars: self.mesh.SetParameters(Parameters)
2827         return self.editor.AddNode( x, y, z)
2828
2829     ## Creates a 0D element on a node with given number.
2830     #  @param IDOfNode the ID of node for creation of the element.
2831     #  @param DuplicateElements to add one more 0D element to a node or not
2832     #  @return the Id of the new 0D element
2833     #  @ingroup l2_modif_add
2834     def Add0DElement( self, IDOfNode, DuplicateElements=True ):
2835         return self.editor.Add0DElement( IDOfNode, DuplicateElements )
2836
2837     ## Create 0D elements on all nodes of the given elements except those 
2838     #  nodes on which a 0D element already exists.
2839     #  @param theObject an object on whose nodes 0D elements will be created.
2840     #         It can be mesh, sub-mesh, group, list of element IDs or a holder
2841     #         of nodes IDs created by calling mesh.GetIDSource( nodes, SMESH.NODE )
2842     #  @param theGroupName optional name of a group to add 0D elements created
2843     #         and/or found on nodes of \a theObject.
2844     #  @param DuplicateElements to add one more 0D element to a node or not
2845     #  @return an object (a new group or a temporary SMESH_IDSource) holding
2846     #          IDs of new and/or found 0D elements. IDs of 0D elements 
2847     #          can be retrieved from the returned object by calling GetIDs()
2848     #  @ingroup l2_modif_add
2849     def Add0DElementsToAllNodes(self, theObject, theGroupName="", DuplicateElements=False):
2850         unRegister = genObjUnRegister()
2851         if isinstance( theObject, Mesh ):
2852             theObject = theObject.GetMesh()
2853         elif isinstance( theObject, list ):
2854             theObject = self.GetIDSource( theObject, SMESH.ALL )
2855             unRegister.set( theObject )
2856         return self.editor.Create0DElementsOnAllNodes( theObject, theGroupName, DuplicateElements )
2857
2858     ## Creates a ball element on a node with given ID.
2859     #  @param IDOfNode the ID of node for creation of the element.
2860     #  @param diameter the bal diameter.
2861     #  @return the Id of the new ball element
2862     #  @ingroup l2_modif_add
2863     def AddBall(self, IDOfNode, diameter):
2864         return self.editor.AddBall( IDOfNode, diameter )
2865
2866     ## Creates a linear or quadratic edge (this is determined
2867     #  by the number of given nodes).
2868     #  @param IDsOfNodes the list of node IDs for creation of the element.
2869     #  The order of nodes in this list should correspond to the description
2870     #  of MED. \n This description is located by the following link:
2871     #  http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2872     #  @return the Id of the new edge
2873     #  @ingroup l2_modif_add
2874     def AddEdge(self, IDsOfNodes):
2875         return self.editor.AddEdge(IDsOfNodes)
2876
2877     ## Creates a linear or quadratic face (this is determined
2878     #  by the number of given nodes).
2879     #  @param IDsOfNodes the list of node IDs for creation of the element.
2880     #  The order of nodes in this list should correspond to the description
2881     #  of MED. \n This description is located by the following link:
2882     #  http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2883     #  @return the Id of the new face
2884     #  @ingroup l2_modif_add
2885     def AddFace(self, IDsOfNodes):
2886         return self.editor.AddFace(IDsOfNodes)
2887
2888     ## Adds a polygonal face to the mesh by the list of node IDs
2889     #  @param IdsOfNodes the list of node IDs for creation of the element.
2890     #  @return the Id of the new face
2891     #  @ingroup l2_modif_add
2892     def AddPolygonalFace(self, IdsOfNodes):
2893         return self.editor.AddPolygonalFace(IdsOfNodes)
2894
2895     ## Adds a quadratic polygonal face to the mesh by the list of node IDs
2896     #  @param IdsOfNodes the list of node IDs for creation of the element;
2897     #         corner nodes follow first.
2898     #  @return the Id of the new face
2899     #  @ingroup l2_modif_add
2900     def AddQuadPolygonalFace(self, IdsOfNodes):
2901         return self.editor.AddQuadPolygonalFace(IdsOfNodes)
2902
2903     ## Creates both simple and quadratic volume (this is determined
2904     #  by the number of given nodes).
2905     #  @param IDsOfNodes the list of node IDs for creation of the element.
2906     #  The order of nodes in this list should correspond to the description
2907     #  of MED. \n This description is located by the following link:
2908     #  http://www.code-aster.org/outils/med/html/modele_de_donnees.html#3.
2909     #  @return the Id of the new volumic element
2910     #  @ingroup l2_modif_add
2911     def AddVolume(self, IDsOfNodes):
2912         return self.editor.AddVolume(IDsOfNodes)
2913
2914     ## Creates a volume of many faces, giving nodes for each face.
2915     #  @param IdsOfNodes the list of node IDs for volume creation face by face.
2916     #  @param Quantities the list of integer values, Quantities[i]
2917     #         gives the quantity of nodes in face number i.
2918     #  @return the Id of the new volumic element
2919     #  @ingroup l2_modif_add
2920     def AddPolyhedralVolume (self, IdsOfNodes, Quantities):
2921         return self.editor.AddPolyhedralVolume(IdsOfNodes, Quantities)
2922
2923     ## Creates a volume of many faces, giving the IDs of the existing faces.
2924     #  @param IdsOfFaces the list of face IDs for volume creation.
2925     #
2926     #  Note:  The created volume will refer only to the nodes
2927     #         of the given faces, not to the faces themselves.
2928     #  @return the Id of the new volumic element
2929     #  @ingroup l2_modif_add
2930     def AddPolyhedralVolumeByFaces (self, IdsOfFaces):
2931         return self.editor.AddPolyhedralVolumeByFaces(IdsOfFaces)
2932
2933
2934     ## @brief Binds a node to a vertex
2935     #  @param NodeID a node ID
2936     #  @param Vertex a vertex or vertex ID
2937     #  @return True if succeed else raises an exception
2938     #  @ingroup l2_modif_add
2939     def SetNodeOnVertex(self, NodeID, Vertex):
2940         if ( isinstance( Vertex, geomBuilder.GEOM._objref_GEOM_Object)):
2941             VertexID = self.geompyD.GetSubShapeID( self.geom, Vertex )
2942         else:
2943             VertexID = Vertex
2944         try:
2945             self.editor.SetNodeOnVertex(NodeID, VertexID)
2946         except SALOME.SALOME_Exception, inst:
2947             raise ValueError, inst.details.text
2948         return True
2949
2950
2951     ## @brief Stores the node position on an edge
2952     #  @param NodeID a node ID
2953     #  @param Edge an edge or edge ID
2954     #  @param paramOnEdge a parameter on the edge where the node is located
2955     #  @return True if succeed else raises an exception
2956     #  @ingroup l2_modif_add
2957     def SetNodeOnEdge(self, NodeID, Edge, paramOnEdge):
2958         if ( isinstance( Edge, geomBuilder.GEOM._objref_GEOM_Object)):
2959             EdgeID = self.geompyD.GetSubShapeID( self.geom, Edge )
2960         else:
2961             EdgeID = Edge
2962         try:
2963             self.editor.SetNodeOnEdge(NodeID, EdgeID, paramOnEdge)
2964         except SALOME.SALOME_Exception, inst:
2965             raise ValueError, inst.details.text
2966         return True
2967
2968     ## @brief Stores node position on a face
2969     #  @param NodeID a node ID
2970     #  @param Face a face or face ID
2971     #  @param u U parameter on the face where the node is located
2972     #  @param v V parameter on the face where the node is located
2973     #  @return True if succeed else raises an exception
2974     #  @ingroup l2_modif_add
2975     def SetNodeOnFace(self, NodeID, Face, u, v):
2976         if ( isinstance( Face, geomBuilder.GEOM._objref_GEOM_Object)):
2977             FaceID = self.geompyD.GetSubShapeID( self.geom, Face )
2978         else:
2979             FaceID = Face
2980         try:
2981             self.editor.SetNodeOnFace(NodeID, FaceID, u, v)
2982         except SALOME.SALOME_Exception, inst:
2983             raise ValueError, inst.details.text
2984         return True
2985
2986     ## @brief Binds a node to a solid
2987     #  @param NodeID a node ID
2988     #  @param Solid  a solid or solid ID
2989     #  @return True if succeed else raises an exception
2990     #  @ingroup l2_modif_add
2991     def SetNodeInVolume(self, NodeID, Solid):
2992         if ( isinstance( Solid, geomBuilder.GEOM._objref_GEOM_Object)):
2993             SolidID = self.geompyD.GetSubShapeID( self.geom, Solid )
2994         else:
2995             SolidID = Solid
2996         try:
2997             self.editor.SetNodeInVolume(NodeID, SolidID)
2998         except SALOME.SALOME_Exception, inst:
2999             raise ValueError, inst.details.text
3000         return True
3001
3002     ## @brief Bind an element to a shape
3003     #  @param ElementID an element ID
3004     #  @param Shape a shape or shape ID
3005     #  @return True if succeed else raises an exception
3006     #  @ingroup l2_modif_add
3007     def SetMeshElementOnShape(self, ElementID, Shape):
3008         if ( isinstance( Shape, geomBuilder.GEOM._objref_GEOM_Object)):
3009             ShapeID = self.geompyD.GetSubShapeID( self.geom, Shape )
3010         else:
3011             ShapeID = Shape
3012         try:
3013             self.editor.SetMeshElementOnShape(ElementID, ShapeID)
3014         except SALOME.SALOME_Exception, inst:
3015             raise ValueError, inst.details.text
3016         return True
3017
3018
3019     ## Moves the node with the given id
3020     #  @param NodeID the id of the node
3021     #  @param x  a new X coordinate
3022     #  @param y  a new Y coordinate
3023     #  @param z  a new Z coordinate
3024     #  @return True if succeed else False
3025     #  @ingroup l2_modif_movenode
3026     def MoveNode(self, NodeID, x, y, z):
3027         x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
3028         if hasVars: self.mesh.SetParameters(Parameters)
3029         return self.editor.MoveNode(NodeID, x, y, z)
3030
3031     ## Finds the node closest to a point and moves it to a point location
3032     #  @param x  the X coordinate of a point
3033     #  @param y  the Y coordinate of a point
3034     #  @param z  the Z coordinate of a point
3035     #  @param NodeID if specified (>0), the node with this ID is moved,
3036     #  otherwise, the node closest to point (@a x,@a y,@a z) is moved
3037     #  @return the ID of a node
3038     #  @ingroup l2_modif_throughp
3039     def MoveClosestNodeToPoint(self, x, y, z, NodeID):
3040         x,y,z,Parameters,hasVars = ParseParameters(x,y,z)
3041         if hasVars: self.mesh.SetParameters(Parameters)
3042         return self.editor.MoveClosestNodeToPoint(x, y, z, NodeID)
3043
3044     ## Finds the node closest to a point
3045     #  @param x  the X coordinate of a point
3046     #  @param y  the Y coordinate of a point
3047     #  @param z  the Z coordinate of a point
3048     #  @return the ID of a node
3049     #  @ingroup l2_modif_throughp
3050     def FindNodeClosestTo(self, x, y, z):
3051         #preview = self.mesh.GetMeshEditPreviewer()
3052         #return preview.MoveClosestNodeToPoint(x, y, z, -1)
3053         return self.editor.FindNodeClosestTo(x, y, z)
3054
3055     ## Finds the elements where a point lays IN or ON
3056     #  @param x  the X coordinate of a point
3057     #  @param y  the Y coordinate of a point
3058     #  @param z  the Z coordinate of a point
3059     #  @param elementType type of elements to find; either of 
3060     #         (SMESH.NODE, SMESH.EDGE, SMESH.FACE, SMESH.VOLUME); SMESH.ALL type
3061     #         means elements of any type excluding nodes, discrete and 0D elements.
3062     #  @param meshPart a part of mesh (group, sub-mesh) to search within
3063     #  @return list of IDs of found elements
3064     #  @ingroup l2_modif_throughp
3065     def FindElementsByPoint(self, x, y, z, elementType = SMESH.ALL, meshPart=None):
3066         if meshPart:
3067             return self.editor.FindAmongElementsByPoint( meshPart, x, y, z, elementType );
3068         else:
3069             return self.editor.FindElementsByPoint(x, y, z, elementType)
3070
3071     ## Return point state in a closed 2D mesh in terms of TopAbs_State enumeration:
3072     #  0-IN, 1-OUT, 2-ON, 3-UNKNOWN
3073     #  UNKNOWN state means that either mesh is wrong or the analysis fails.
3074     def GetPointState(self, x, y, z):
3075         return self.editor.GetPointState(x, y, z)
3076
3077     ## Check if a 2D mesh is manifold
3078     #  @ingroup l1_controls
3079     def IsManifold(self):
3080         return self.editor.IsManifold()
3081
3082     ## Check if orientation of 2D elements is coherent
3083     #  @ingroup l1_controls
3084     def IsCoherentOrientation2D(self):
3085         return self.editor.IsCoherentOrientation2D()
3086
3087     ## Finds the node closest to a point and moves it to a point location
3088     #  @param x  the X coordinate of a point
3089     #  @param y  the Y coordinate of a point
3090     #  @param z  the Z coordinate of a point
3091     #  @return the ID of a moved node
3092     #  @ingroup l2_modif_throughp
3093     def MeshToPassThroughAPoint(self, x, y, z):
3094         return self.editor.MoveClosestNodeToPoint(x, y, z, -1)
3095
3096     ## Replaces two neighbour triangles sharing Node1-Node2 link
3097     #  with the triangles built on the same 4 nodes but having other common link.
3098     #  @param NodeID1  the ID of the first node
3099     #  @param NodeID2  the ID of the second node
3100     #  @return false if proper faces were not found
3101     #  @ingroup l2_modif_cutquadr
3102     def InverseDiag(self, NodeID1, NodeID2):
3103         return self.editor.InverseDiag(NodeID1, NodeID2)
3104
3105     ## Replaces two neighbour triangles sharing Node1-Node2 link
3106     #  with a quadrangle built on the same 4 nodes.
3107     #  @param NodeID1  the ID of the first node
3108     #  @param NodeID2  the ID of the second node
3109     #  @return false if proper faces were not found
3110     #  @ingroup l2_modif_unitetri
3111     def DeleteDiag(self, NodeID1, NodeID2):
3112         return self.editor.DeleteDiag(NodeID1, NodeID2)
3113
3114     ## Reorients elements by ids
3115     #  @param IDsOfElements if undefined reorients all mesh elements
3116     #  @return True if succeed else False
3117     #  @ingroup l2_modif_changori
3118     def Reorient(self, IDsOfElements=None):
3119         if IDsOfElements == None:
3120             IDsOfElements = self.GetElementsId()
3121         return self.editor.Reorient(IDsOfElements)
3122
3123     ## Reorients all elements of the object
3124     #  @param theObject mesh, submesh or group
3125     #  @return True if succeed else False
3126     #  @ingroup l2_modif_changori
3127     def ReorientObject(self, theObject):
3128         if ( isinstance( theObject, Mesh )):
3129             theObject = theObject.GetMesh()
3130         return self.editor.ReorientObject(theObject)
3131
3132     ## Reorient faces contained in \a the2DObject.
3133     #  @param the2DObject is a mesh, sub-mesh, group or list of IDs of 2D elements
3134     #  @param theDirection is a desired direction of normal of \a theFace.
3135     #         It can be either a GEOM vector or a list of coordinates [x,y,z].
3136     #  @param theFaceOrPoint defines a face of \a the2DObject whose normal will be
3137     #         compared with theDirection. It can be either ID of face or a point
3138     #         by which the face will be found. The point can be given as either
3139     #         a GEOM vertex or a list of point coordinates.
3140     #  @return number of reoriented faces
3141     #  @ingroup l2_modif_changori
3142     def Reorient2D(self, the2DObject, theDirection, theFaceOrPoint ):
3143         unRegister = genObjUnRegister()
3144         # check the2DObject
3145         if isinstance( the2DObject, Mesh ):
3146             the2DObject = the2DObject.GetMesh()
3147         if isinstance( the2DObject, list ):
3148             the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
3149             unRegister.set( the2DObject )
3150         # check theDirection
3151         if isinstance( theDirection, geomBuilder.GEOM._objref_GEOM_Object):
3152             theDirection = self.smeshpyD.GetDirStruct( theDirection )
3153         if isinstance( theDirection, list ):
3154             theDirection = self.smeshpyD.MakeDirStruct( *theDirection  )
3155         # prepare theFace and thePoint
3156         theFace = theFaceOrPoint
3157         thePoint = PointStruct(0,0,0)
3158         if isinstance( theFaceOrPoint, geomBuilder.GEOM._objref_GEOM_Object):
3159             thePoint = self.smeshpyD.GetPointStruct( theFaceOrPoint )
3160             theFace = -1
3161         if isinstance( theFaceOrPoint, list ):
3162             thePoint = PointStruct( *theFaceOrPoint )
3163             theFace = -1
3164         if isinstance( theFaceOrPoint, PointStruct ):
3165             thePoint = theFaceOrPoint
3166             theFace = -1
3167         return self.editor.Reorient2D( the2DObject, theDirection, theFace, thePoint )
3168
3169     ## Reorient faces according to adjacent volumes.
3170     #  @param the2DObject is a mesh, sub-mesh, group or list of
3171     #         either IDs of faces or face groups.
3172     #  @param the3DObject is a mesh, sub-mesh, group or list of IDs of volumes.
3173     #  @param theOutsideNormal to orient faces to have their normals
3174     #         pointing either \a outside or \a inside the adjacent volumes.
3175     #  @return number of reoriented faces.
3176     #  @ingroup l2_modif_changori
3177     def Reorient2DBy3D(self, the2DObject, the3DObject, theOutsideNormal=True ):
3178         unRegister = genObjUnRegister()
3179         # check the2DObject
3180         if not isinstance( the2DObject, list ):
3181             the2DObject = [ the2DObject ]
3182         elif the2DObject and isinstance( the2DObject[0], int ):
3183             the2DObject = self.GetIDSource( the2DObject, SMESH.FACE )
3184             unRegister.set( the2DObject )
3185             the2DObject = [ the2DObject ]
3186         for i,obj2D in enumerate( the2DObject ):
3187             if isinstance( obj2D, Mesh ):
3188                 the2DObject[i] = obj2D.GetMesh()
3189             if isinstance( obj2D, list ):
3190                 the2DObject[i] = self.GetIDSource( obj2D, SMESH.FACE )
3191                 unRegister.set( the2DObject[i] )
3192         # check the3DObject
3193         if isinstance( the3DObject, Mesh ):
3194             the3DObject = the3DObject.GetMesh()
3195         if isinstance( the3DObject, list ):
3196             the3DObject = self.GetIDSource( the3DObject, SMESH.VOLUME )
3197             unRegister.set( the3DObject )
3198         return self.editor.Reorient2DBy3D( the2DObject, the3DObject, theOutsideNormal )
3199
3200     ## Fuses the neighbouring triangles into quadrangles.
3201     #  @param IDsOfElements The triangles to be fused.
3202     #  @param theCriterion  a numerical functor, in terms of enum SMESH.FunctorType, used to
3203     #          applied to possible quadrangles to choose a neighbour to fuse with.
3204     #          Type SMESH.FunctorType._items in the Python Console to see all items.
3205     #          Note that not all items correspond to numerical functors.
3206     #  @param MaxAngle      is the maximum angle between element normals at which the fusion
3207     #          is still performed; theMaxAngle is mesured in radians.
3208     #          Also it could be a name of variable which defines angle in degrees.
3209     #  @return TRUE in case of success, FALSE otherwise.
3210     #  @ingroup l2_modif_unitetri
3211     def TriToQuad(self, IDsOfElements, theCriterion, MaxAngle):
3212         MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
3213         self.mesh.SetParameters(Parameters)
3214         if not IDsOfElements:
3215             IDsOfElements = self.GetElementsId()
3216         Functor = self.smeshpyD.GetFunctor(theCriterion)
3217         return self.editor.TriToQuad(IDsOfElements, Functor, MaxAngle)
3218
3219     ## Fuses the neighbouring triangles of the object into quadrangles
3220     #  @param theObject is mesh, submesh or group
3221     #  @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType,
3222     #          applied to possible quadrangles to choose a neighbour to fuse with.
3223     #          Type SMESH.FunctorType._items in the Python Console to see all items.
3224     #          Note that not all items correspond to numerical functors.
3225     #  @param MaxAngle   a max angle between element normals at which the fusion
3226     #          is still performed; theMaxAngle is mesured in radians.
3227     #  @return TRUE in case of success, FALSE otherwise.
3228     #  @ingroup l2_modif_unitetri
3229     def TriToQuadObject (self, theObject, theCriterion, MaxAngle):
3230         MaxAngle,Parameters,hasVars = ParseAngles(MaxAngle)
3231         self.mesh.SetParameters(Parameters)
3232         if isinstance( theObject, Mesh ):
3233             theObject = theObject.GetMesh()
3234         Functor = self.smeshpyD.GetFunctor(theCriterion)
3235         return self.editor.TriToQuadObject(theObject, Functor, MaxAngle)
3236
3237     ## Splits quadrangles into triangles.
3238     #  @param IDsOfElements the faces to be splitted.
3239     #  @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3240     #         choose a diagonal for splitting. If @a theCriterion is None, which is a default
3241     #         value, then quadrangles will be split by the smallest diagonal.
3242     #         Type SMESH.FunctorType._items in the Python Console to see all items.
3243     #         Note that not all items correspond to numerical functors.
3244     #  @return TRUE in case of success, FALSE otherwise.
3245     #  @ingroup l2_modif_cutquadr
3246     def QuadToTri (self, IDsOfElements, theCriterion = None):
3247         if IDsOfElements == []:
3248             IDsOfElements = self.GetElementsId()
3249         if theCriterion is None:
3250             theCriterion = FT_MaxElementLength2D
3251         Functor = self.smeshpyD.GetFunctor(theCriterion)
3252         return self.editor.QuadToTri(IDsOfElements, Functor)
3253
3254     ## Splits quadrangles into triangles.
3255     #  @param theObject the object from which the list of elements is taken,
3256     #         this is mesh, submesh or group
3257     #  @param theCriterion is a numerical functor, in terms of enum SMESH.FunctorType, used to
3258     #         choose a diagonal for splitting. If @a theCriterion is None, which is a default
3259     #         value, then quadrangles will be split by the smallest diagonal.
3260     #         Type SMESH.FunctorType._items in the Python Console to see all items.
3261     #         Note that not all items correspond to numerical functors.
3262     #  @return TRUE in case of success, FALSE otherwise.
3263     #  @ingroup l2_modif_cutquadr
3264     def QuadToTriObject (self, theObject, theCriterion = None):
3265         if ( isinstance( theObject, Mesh )):
3266             theObject = theObject.GetMesh()
3267         if theCriterion is None:
3268             theCriterion = FT_MaxElementLength2D
3269         Functor = self.smeshpyD.GetFunctor(theCriterion)
3270         return self.editor.QuadToTriObject(theObject, Functor)
3271
3272     ## Splits each of given quadrangles into 4 triangles. A node is added at the center of
3273     #  a quadrangle.
3274     #  @param theElements the faces to be splitted. This can be either mesh, sub-mesh,
3275     #         group or a list of face IDs. By default all quadrangles are split
3276     #  @ingroup l2_modif_cutquadr
3277     def QuadTo4Tri (self, theElements=[]):
3278         unRegister = genObjUnRegister()
3279         if isinstance( theElements, Mesh ):
3280             theElements = theElements.mesh
3281         elif not theElements:
3282             theElements = self.mesh
3283         elif isinstance( theElements, list ):
3284             theElements = self.GetIDSource( theElements, SMESH.FACE )
3285             unRegister.set( theElements )
3286         return self.editor.QuadTo4Tri( theElements )
3287
3288     ## Splits quadrangles into triangles.
3289     #  @param IDsOfElements the faces to be splitted
3290     #  @param Diag13        is used to choose a diagonal for splitting.
3291     #  @return TRUE in case of success, FALSE otherwise.
3292     #  @ingroup l2_modif_cutquadr
3293     def SplitQuad (self, IDsOfElements, Diag13):
3294         if IDsOfElements == []:
3295             IDsOfElements = self.GetElementsId()
3296         return self.editor.SplitQuad(IDsOfElements, Diag13)
3297
3298     ## Splits quadrangles into triangles.
3299     #  @param theObject the object from which the list of elements is taken,
3300     #         this is mesh, submesh or group
3301     #  @param Diag13    is used to choose a diagonal for splitting.
3302     #  @return TRUE in case of success, FALSE otherwise.
3303     #  @ingroup l2_modif_cutquadr
3304     def SplitQuadObject (self, theObject, Diag13):
3305         if ( isinstance( theObject, Mesh )):
3306             theObject = theObject.GetMesh()
3307         return self.editor.SplitQuadObject(theObject, Diag13)
3308
3309     ## Finds a better splitting of the given quadrangle.
3310     #  @param IDOfQuad   the ID of the quadrangle to be splitted.
3311     #  @param theCriterion  is a numerical functor, in terms of enum SMESH.FunctorType, used to
3312     #         choose a diagonal for splitting.
3313     #         Type SMESH.FunctorType._items in the Python Console to see all items.
3314     #         Note that not all items correspond to numerical functors.
3315     #  @return 1 if 1-3 diagonal is better, 2 if 2-4
3316     #          diagonal is better, 0 if error occurs.
3317     #  @ingroup l2_modif_cutquadr
3318     def BestSplit (self, IDOfQuad, theCriterion):
3319         return self.editor.BestSplit(IDOfQuad, self.smeshpyD.GetFunctor(theCriterion))
3320
3321     ## Splits volumic elements into tetrahedrons
3322     #  @param elems either a list of elements or a mesh or a group or a submesh or a filter
3323     #  @param method  flags passing splitting method:
3324     #         smesh.Hex_5Tet, smesh.Hex_6Tet, smesh.Hex_24Tet.
3325     #         smesh.Hex_5Tet - to split the hexahedron into 5 tetrahedrons, etc.
3326     #  @ingroup l2_modif_cutquadr
3327     def SplitVolumesIntoTetra(self, elems, method=smeshBuilder.Hex_5Tet ):
3328         unRegister = genObjUnRegister()
3329         if isinstance( elems, Mesh ):
3330             elems = elems.GetMesh()
3331         if ( isinstance( elems, list )):
3332             elems = self.editor.MakeIDSource(elems, SMESH.VOLUME)
3333             unRegister.set( elems )
3334         self.editor.SplitVolumesIntoTetra(elems, method)
3335         return
3336
3337     ## Split bi-quadratic elements into linear ones without creation of additional nodes:
3338     #   - bi-quadratic triangle will be split into 3 linear quadrangles;
3339     #   - bi-quadratic quadrangle will be split into 4 linear quadrangles;
3340     #   - tri-quadratic hexahedron will be split into 8 linear hexahedra.
3341     #   Quadratic elements of lower dimension  adjacent to the split bi-quadratic element
3342     #   will be split in order to keep the mesh conformal.
3343     #  @param elems - elements to split: sub-meshes, groups, filters or element IDs;
3344     #         if None (default), all bi-quadratic elements will be split
3345     #  @ingroup l2_modif_cutquadr
3346     def SplitBiQuadraticIntoLinear(self, elems=None):
3347         unRegister = genObjUnRegister()
3348         if elems and isinstance( elems, list ) and isinstance( elems[0], int ):
3349             elems = self.editor.MakeIDSource(elems, SMESH.ALL)
3350             unRegister.set( elems )
3351         if elems is None:
3352             elems = [ self.GetMesh() ]
3353         if isinstance( elems, Mesh ):
3354             elems = [ elems.GetMesh() ]
3355         if not isinstance( elems, list ):
3356             elems = [elems]
3357         self.editor.SplitBiQuadraticIntoLinear( elems )
3358
3359     ## Splits hexahedra into prisms
3360     #  @param elems either a list of elements or a mesh or a group or a submesh or a filter
3361     #  @param startHexPoint a point used to find a hexahedron for which @a facetNormal
3362     #         gives a normal vector defining facets to split into triangles.
3363     #         @a startHexPoint can be either a triple of coordinates or a vertex.
3364     #  @param facetNormal a normal to a facet to split into triangles of a
3365     #         hexahedron found by @a startHexPoint.
3366     #         @a facetNormal can be either a triple of coordinates or an edge.
3367     #  @param method  flags passing splitting method: smesh.Hex_2Prisms, smesh.Hex_4Prisms.
3368     #         smesh.Hex_2Prisms - to split the hexahedron into 2 prisms, etc.
3369     #  @param allDomains if @c False, only hexahedra adjacent to one closest
3370     #         to @a startHexPoint are split, else @a startHexPoint
3371     #         is used to find the facet to split in all domains present in @a elems.
3372     #  @ingroup l2_modif_cutquadr
3373     def SplitHexahedraIntoPrisms(self, elems, startHexPoint, facetNormal,
3374                                  method=smeshBuilder.Hex_2Prisms, allDomains=False ):
3375         # IDSource
3376         unRegister = genObjUnRegister()
3377         if isinstance( elems, Mesh ):
3378             elems = elems.GetMesh()
3379         if ( isinstance( elems, list )):
3380             elems = self.editor.MakeIDSource(elems, SMESH.VOLUME)
3381             unRegister.set( elems )
3382             pass
3383         # axis
3384         if isinstance( startHexPoint, geomBuilder.GEOM._objref_GEOM_Object):
3385             startHexPoint = self.smeshpyD.GetPointStruct( startHexPoint )
3386         elif isinstance( startHexPoint, list ):
3387             startHexPoint = SMESH.PointStruct( startHexPoint[0],
3388                                                startHexPoint[1],
3389                                                startHexPoint[2])
3390         if isinstance( facetNormal, geomBuilder.GEOM._objref_GEOM_Object):
3391             facetNormal = self.smeshpyD.GetDirStruct( facetNormal )
3392         elif isinstance( facetNormal, list ):
3393             facetNormal = self.smeshpyD.MakeDirStruct( facetNormal[0],
3394                                                        facetNormal[1],
3395                                                        facetNormal[2])
3396         self.mesh.SetParameters( startHexPoint.parameters + facetNormal.PS.parameters )
3397
3398         self.editor.SplitHexahedraIntoPrisms(elems, startHexPoint, facetNormal, method, allDomains)
3399
3400     ## Splits quadrangle faces near triangular facets of volumes
3401     #
3402     #  @ingroup l1_auxiliary
3403     def SplitQuadsNearTriangularFacets(self):
3404         faces_array = self.GetElementsByType(SMESH.FACE)
3405         for face_id in faces_array:
3406             if self.GetElemNbNodes(face_id) == 4: # quadrangle
3407                 quad_nodes = self.mesh.GetElemNodes(face_id)
3408                 node1_elems = self.GetNodeInverseElements(quad_nodes[1 -1])
3409                 isVolumeFound = False
3410                 for node1_elem in node1_elems:
3411                     if not isVolumeFound:
3412                         if self.GetElementType(node1_elem, True) == SMESH.VOLUME:
3413                             nb_nodes = self.GetElemNbNodes(node1_elem)
3414                             if 3 < nb_nodes and nb_nodes < 7: # tetra or penta, or prism
3415                                 volume_elem = node1_elem
3416                                 volume_nodes = self.mesh.GetElemNodes(volume_elem)
3417                                 if volume_nodes.count(quad_nodes[2 -1]) > 0: # 1,2
3418                                     if volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,2,4
3419                                         isVolumeFound = True
3420                                         if volume_nodes.count(quad_nodes[3 -1]) == 0: # 1,2,4 & !3
3421                                             self.SplitQuad([face_id], False) # diagonal 2-4
3422                                     elif volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,2,3 & !4
3423                                         isVolumeFound = True
3424                                         self.SplitQuad([face_id], True) # diagonal 1-3
3425                                 elif volume_nodes.count(quad_nodes[4 -1]) > 0: # 1,4 & !2
3426                                     if volume_nodes.count(quad_nodes[3 -1]) > 0: # 1,4,3 & !2
3427                                         isVolumeFound = True
3428                                         self.SplitQuad([face_id], True) # diagonal 1-3
3429
3430     ## @brief Splits hexahedrons into tetrahedrons.
3431     #
3432     #  This operation uses pattern mapping functionality for splitting.
3433     #  @param theObject the object from which the list of hexahedrons is taken; this is mesh, submesh or group.
3434     #  @param theNode000,theNode001 within the range [0,7]; gives the orientation of the
3435     #         pattern relatively each hexahedron: the (0,0,0) key-point of the pattern
3436     #         will be mapped into <VAR>theNode000</VAR>-th node of each volume, the (0,0,1)
3437     #         key-point will be mapped into <VAR>theNode001</VAR>-th node of each volume.
3438     #         The (0,0,0) key-point of the used pattern corresponds to a non-split corner.
3439     #  @return TRUE in case of success, FALSE otherwise.
3440     #  @ingroup l1_auxiliary
3441     def SplitHexaToTetras (self, theObject, theNode000, theNode001):
3442         # Pattern:     5.---------.6
3443         #              /|#*      /|
3444         #             / | #*    / |
3445         #            /  |  # * /  |
3446         #           /   |   # /*  |
3447         # (0,0,1) 4.---------.7 * |
3448         #          |#*  |1   | # *|
3449         #          | # *.----|---#.2
3450         #          |  #/ *   |   /
3451         #          |  /#  *  |  /
3452         #          | /   # * | /
3453         #          |/      #*|/
3454         # (0,0,0) 0.---------.3
3455         pattern_tetra = "!!! Nb of points: \n 8 \n\
3456         !!! Points: \n\
3457         0 0 0  !- 0 \n\
3458         0 1 0  !- 1 \n\
3459         1 1 0  !- 2 \n\
3460         1 0 0  !- 3 \n\
3461         0 0 1  !- 4 \n\
3462         0 1 1  !- 5 \n\
3463         1 1 1  !- 6 \n\
3464         1 0 1  !- 7 \n\
3465         !!! Indices of points of 6 tetras: \n\
3466         0 3 4 1 \n\
3467         7 4 3 1 \n\
3468         4 7 5 1 \n\
3469         6 2 5 7 \n\
3470         1 5 2 7 \n\
3471         2 3 1 7 \n"
3472
3473         pattern = self.smeshpyD.GetPattern()
3474         isDone  = pattern.LoadFromFile(pattern_tetra)
3475         if not isDone:
3476             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3477             return isDone
3478
3479         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3480         isDone = pattern.MakeMesh(self.mesh, False, False)
3481         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3482
3483         # split quafrangle faces near triangular facets of volumes
3484         self.SplitQuadsNearTriangularFacets()
3485
3486         return isDone
3487
3488     ## @brief Split hexahedrons into prisms.
3489     #
3490     #  Uses the pattern mapping functionality for splitting.
3491     #  @param theObject the object (mesh, submesh or group) from where the list of hexahedrons is taken;
3492     #  @param theNode000,theNode001 (within the range [0,7]) gives the orientation of the
3493     #         pattern relatively each hexahedron: keypoint (0,0,0) of the pattern
3494     #         will be mapped into the <VAR>theNode000</VAR>-th node of each volume, keypoint (0,0,1)
3495     #         will be mapped into the <VAR>theNode001</VAR>-th node of each volume.
3496     #         Edge (0,0,0)-(0,0,1) of used pattern connects two not split corners.
3497     #  @return TRUE in case of success, FALSE otherwise.
3498     #  @ingroup l1_auxiliary
3499     def SplitHexaToPrisms (self, theObject, theNode000, theNode001):
3500         # Pattern:     5.---------.6
3501         #              /|#       /|
3502         #             / | #     / |
3503         #            /  |  #   /  |
3504         #           /   |   # /   |
3505         # (0,0,1) 4.---------.7   |
3506         #          |    |    |    |
3507         #          |   1.----|----.2
3508         #          |   / *   |   /
3509         #          |  /   *  |  /
3510         #          | /     * | /
3511         #          |/       *|/
3512         # (0,0,0) 0.---------.3
3513         pattern_prism = "!!! Nb of points: \n 8 \n\
3514         !!! Points: \n\
3515         0 0 0  !- 0 \n\
3516         0 1 0  !- 1 \n\
3517         1 1 0  !- 2 \n\
3518         1 0 0  !- 3 \n\
3519         0 0 1  !- 4 \n\
3520         0 1 1  !- 5 \n\
3521         1 1 1  !- 6 \n\
3522         1 0 1  !- 7 \n\
3523         !!! Indices of points of 2 prisms: \n\
3524         0 1 3 4 5 7 \n\
3525         2 3 1 6 7 5 \n"
3526
3527         pattern = self.smeshpyD.GetPattern()
3528         isDone  = pattern.LoadFromFile(pattern_prism)
3529         if not isDone:
3530             print 'Pattern.LoadFromFile :', pattern.GetErrorCode()
3531             return isDone
3532
3533         pattern.ApplyToHexahedrons(self.mesh, theObject.GetIDs(), theNode000, theNode001)
3534         isDone = pattern.MakeMesh(self.mesh, False, False)
3535         if not isDone: print 'Pattern.MakeMesh :', pattern.GetErrorCode()
3536
3537         # Splits quafrangle faces near triangular facets of volumes
3538         self.SplitQuadsNearTriangularFacets()
3539
3540         return isDone
3541
3542     ## Smoothes elements
3543     #  @param IDsOfElements the list if ids of elements to smooth
3544     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
3545     #  Note that nodes built on edges and boundary nodes are always fixed.
3546     #  @param MaxNbOfIterations the maximum number of iterations
3547     #  @param MaxAspectRatio varies in range [1.0, inf]
3548     #  @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3549     #         or Centroidal (smesh.CENTROIDAL_SMOOTH)
3550     #  @return TRUE in case of success, FALSE otherwise.
3551     #  @ingroup l2_modif_smooth
3552     def Smooth(self, IDsOfElements, IDsOfFixedNodes,
3553                MaxNbOfIterations, MaxAspectRatio, Method):
3554         if IDsOfElements == []:
3555             IDsOfElements = self.GetElementsId()
3556         MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3557         self.mesh.SetParameters(Parameters)
3558         return self.editor.Smooth(IDsOfElements, IDsOfFixedNodes,
3559                                   MaxNbOfIterations, MaxAspectRatio, Method)
3560
3561     ## Smoothes elements which belong to the given object
3562     #  @param theObject the object to smooth
3563     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
3564     #  Note that nodes built on edges and boundary nodes are always fixed.
3565     #  @param MaxNbOfIterations the maximum number of iterations
3566     #  @param MaxAspectRatio varies in range [1.0, inf]
3567     #  @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3568     #         or Centroidal (smesh.CENTROIDAL_SMOOTH)
3569     #  @return TRUE in case of success, FALSE otherwise.
3570     #  @ingroup l2_modif_smooth
3571     def SmoothObject(self, theObject, IDsOfFixedNodes,
3572                      MaxNbOfIterations, MaxAspectRatio, Method):
3573         if ( isinstance( theObject, Mesh )):
3574             theObject = theObject.GetMesh()
3575         return self.editor.SmoothObject(theObject, IDsOfFixedNodes,
3576                                         MaxNbOfIterations, MaxAspectRatio, Method)
3577
3578     ## Parametrically smoothes the given elements
3579     #  @param IDsOfElements the list if ids of elements to smooth
3580     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
3581     #  Note that nodes built on edges and boundary nodes are always fixed.
3582     #  @param MaxNbOfIterations the maximum number of iterations
3583     #  @param MaxAspectRatio varies in range [1.0, inf]
3584     #  @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3585     #         or Centroidal (smesh.CENTROIDAL_SMOOTH)
3586     #  @return TRUE in case of success, FALSE otherwise.
3587     #  @ingroup l2_modif_smooth
3588     def SmoothParametric(self, IDsOfElements, IDsOfFixedNodes,
3589                          MaxNbOfIterations, MaxAspectRatio, Method):
3590         if IDsOfElements == []:
3591             IDsOfElements = self.GetElementsId()
3592         MaxNbOfIterations,MaxAspectRatio,Parameters,hasVars = ParseParameters(MaxNbOfIterations,MaxAspectRatio)
3593         self.mesh.SetParameters(Parameters)
3594         return self.editor.SmoothParametric(IDsOfElements, IDsOfFixedNodes,
3595                                             MaxNbOfIterations, MaxAspectRatio, Method)
3596
3597     ## Parametrically smoothes the elements which belong to the given object
3598     #  @param theObject the object to smooth
3599     #  @param IDsOfFixedNodes the list of ids of fixed nodes.
3600     #  Note that nodes built on edges and boundary nodes are always fixed.
3601     #  @param MaxNbOfIterations the maximum number of iterations
3602     #  @param MaxAspectRatio varies in range [1.0, inf]
3603     #  @param Method is either Laplacian (smesh.LAPLACIAN_SMOOTH)
3604     #         or Centroidal (smesh.CENTROIDAL_SMOOTH)
3605     #  @return TRUE in case of success, FALSE otherwise.
3606     #  @ingroup l2_modif_smooth
3607     def SmoothParametricObject(self, theObject, IDsOfFixedNodes,
3608                                MaxNbOfIterations, MaxAspectRatio, Method):
3609         if ( isinstance( theObject, Mesh )):
3610             theObject = theObject.GetMesh()
3611         return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes,
3612                                                   MaxNbOfIterations, MaxAspectRatio, Method)
3613
3614     ## Converts the mesh to quadratic or bi-quadratic, deletes old elements, replacing
3615     #  them with quadratic with the same id.
3616     #  @param theForce3d new node creation method:
3617     #         0 - the medium node lies at the geometrical entity from which the mesh element is built
3618     #         1 - the medium node lies at the middle of the line segments connecting two nodes of a mesh element
3619     #  @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3620     #  @param theToBiQuad If True, converts the mesh to bi-quadratic
3621     #  @ingroup l2_modif_tofromqu
3622     def ConvertToQuadratic(self, theForce3d=False, theSubMesh=None, theToBiQuad=False):
3623         if isinstance( theSubMesh, Mesh ):
3624             theSubMesh = theSubMesh.mesh
3625         if theToBiQuad:
3626             self.editor.ConvertToBiQuadratic(theForce3d,theSubMesh)
3627         else:
3628             if theSubMesh:
3629                 self.editor.ConvertToQuadraticObject(theForce3d,theSubMesh)
3630             else:
3631                 self.editor.ConvertToQuadratic(theForce3d)
3632         error = self.editor.GetLastError()
3633         if error and error.comment:
3634             print error.comment
3635             
3636     ## Converts the mesh from quadratic to ordinary,
3637     #  deletes old quadratic elements, \n replacing
3638     #  them with ordinary mesh elements with the same id.
3639     #  @param theSubMesh a group or a sub-mesh to convert; WARNING: in this case the mesh can become not conformal
3640     #  @ingroup l2_modif_tofromqu
3641     def ConvertFromQuadratic(self, theSubMesh=None):
3642         if theSubMesh:
3643             self.editor.ConvertFromQuadraticObject(theSubMesh)
3644         else:
3645             return self.editor.ConvertFromQuadratic()
3646
3647     ## Creates 2D mesh as skin on boundary faces of a 3D mesh
3648     #  @return TRUE if operation has been completed successfully, FALSE otherwise
3649     #  @ingroup l2_modif_edit
3650     def Make2DMeshFrom3D(self):
3651         return self.editor.Make2DMeshFrom3D()
3652
3653     ## Creates missing boundary elements
3654     #  @param elements - elements whose boundary is to be checked:
3655     #                    mesh, group, sub-mesh or list of elements
3656     #   if elements is mesh, it must be the mesh whose MakeBoundaryMesh() is called
3657     #  @param dimension - defines type of boundary elements to create, either of
3658     #                     { SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D }
3659     #    SMESH.BND_1DFROM3D creates mesh edges on all borders of free facets of 3D cells
3660     #  @param groupName - a name of group to store created boundary elements in,
3661     #                     "" means not to create the group
3662     #  @param meshName - a name of new mesh to store created boundary elements in,
3663     #                     "" means not to create the new mesh
3664     #  @param toCopyElements - if true, the checked elements will be copied into
3665     #     the new mesh else only boundary elements will be copied into the new mesh
3666     #  @param toCopyExistingBondary - if true, not only new but also pre-existing
3667     #     boundary elements will be copied into the new mesh
3668     #  @return tuple (mesh, group) where boundary elements were added to
3669     #  @ingroup l2_modif_edit
3670     def MakeBoundaryMesh(self, elements, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3671                          toCopyElements=False, toCopyExistingBondary=False):
3672         unRegister = genObjUnRegister()
3673         if isinstance( elements, Mesh ):
3674             elements = elements.GetMesh()
3675         if ( isinstance( elements, list )):
3676             elemType = SMESH.ALL
3677             if elements: elemType = self.GetElementType( elements[0], iselem=True)
3678             elements = self.editor.MakeIDSource(elements, elemType)
3679             unRegister.set( elements )
3680         mesh, group = self.editor.MakeBoundaryMesh(elements,dimension,groupName,meshName,
3681                                                    toCopyElements,toCopyExistingBondary)
3682         if mesh: mesh = self.smeshpyD.Mesh(mesh)
3683         return mesh, group
3684
3685     ##
3686     # @brief Creates missing boundary elements around either the whole mesh or 
3687     #    groups of elements
3688     #  @param dimension - defines type of boundary elements to create, either of
3689     #                     { SMESH.BND_2DFROM3D, SMESH.BND_1DFROM3D, SMESH.BND_1DFROM2D }
3690     #  @param groupName - a name of group to store all boundary elements in,
3691     #    "" means not to create the group
3692     #  @param meshName - a name of a new mesh, which is a copy of the initial 
3693     #    mesh + created boundary elements; "" means not to create the new mesh
3694     #  @param toCopyAll - if true, the whole initial mesh will be copied into
3695     #    the new mesh else only boundary elements will be copied into the new mesh
3696     #  @param groups - groups of elements to make boundary around
3697     #  @retval tuple( long, mesh, groups )
3698     #                 long - number of added boundary elements
3699     #                 mesh - the mesh where elements were added to
3700     #                 group - the group of boundary elements or None
3701     #
3702     def MakeBoundaryElements(self, dimension=SMESH.BND_2DFROM3D, groupName="", meshName="",
3703                              toCopyAll=False, groups=[]):
3704         nb, mesh, group = self.editor.MakeBoundaryElements(dimension,groupName,meshName,
3705                                                            toCopyAll,groups)
3706         if mesh: mesh = self.smeshpyD.Mesh(mesh)
3707         return nb, mesh, group
3708
3709     ## Renumber mesh nodes (Obsolete, does nothing)
3710     #  @ingroup l2_modif_renumber
3711     def RenumberNodes(self):
3712         self.editor.RenumberNodes()
3713
3714     ## Renumber mesh elements (Obsole, does nothing)
3715     #  @ingroup l2_modif_renumber
3716     def RenumberElements(self):
3717         self.editor.RenumberElements()
3718
3719     ## Private method converting \a arg into a list of SMESH_IdSource's
3720     def _getIdSourceList(self, arg, idType, unRegister):
3721         if arg and isinstance( arg, list ):
3722             if isinstance( arg[0], int ):
3723                 arg = self.GetIDSource( arg, idType )
3724                 unRegister.set( arg )
3725             elif isinstance( arg[0], Mesh ):
3726                 arg[0] = arg[0].GetMesh()
3727         elif isinstance( arg, Mesh ):
3728             arg = arg.GetMesh()
3729         if arg and isinstance( arg, SMESH._objref_SMESH_IDSource ):
3730             arg = [arg]
3731         return arg
3732
3733     ## Generates new elements by rotation of the given elements and nodes around the axis
3734     #  @param nodes - nodes to revolve: a list including ids, groups, sub-meshes or a mesh
3735     #  @param edges - edges to revolve: a list including ids, groups, sub-meshes or a mesh
3736     #  @param faces - faces to revolve: a list including ids, groups, sub-meshes or a mesh
3737     #  @param Axis the axis of rotation: AxisStruct, line (geom object) or [x,y,z,dx,dy,dz]
3738     #  @param AngleInRadians the angle of Rotation (in radians) or a name of variable
3739     #         which defines angle in degrees
3740     #  @param NbOfSteps the number of steps
3741     #  @param Tolerance tolerance
3742     #  @param MakeGroups forces the generation of new groups from existing ones
3743     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3744     #                    of all steps, else - size of each step
3745     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3746     #  @ingroup l2_modif_extrurev
3747     def RotationSweepObjects(self, nodes, edges, faces, Axis, AngleInRadians, NbOfSteps, Tolerance,
3748                              MakeGroups=False, TotalAngle=False):
3749         unRegister = genObjUnRegister()
3750         nodes = self._getIdSourceList( nodes, SMESH.NODE, unRegister )
3751         edges = self._getIdSourceList( edges, SMESH.EDGE, unRegister )
3752         faces = self._getIdSourceList( faces, SMESH.FACE, unRegister )
3753
3754         if isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object):
3755             Axis = self.smeshpyD.GetAxisStruct( Axis )
3756         if isinstance( Axis, list ):
3757             Axis = SMESH.AxisStruct( *Axis )
3758
3759         AngleInRadians,AngleParameters,hasVars = ParseAngles(AngleInRadians)
3760         NbOfSteps,Tolerance,Parameters,hasVars = ParseParameters(NbOfSteps,Tolerance)
3761         Parameters = Axis.parameters + var_separator + AngleParameters + var_separator + Parameters
3762         self.mesh.SetParameters(Parameters)
3763         if TotalAngle and NbOfSteps:
3764             AngleInRadians /= NbOfSteps
3765         return self.editor.RotationSweepObjects( nodes, edges, faces,
3766                                                  Axis, AngleInRadians,
3767                                                  NbOfSteps, Tolerance, MakeGroups)
3768
3769     ## Generates new elements by rotation of the elements around the axis
3770     #  @param IDsOfElements the list of ids of elements to sweep
3771     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3772     #  @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
3773     #  @param NbOfSteps the number of steps
3774     #  @param Tolerance tolerance
3775     #  @param MakeGroups forces the generation of new groups from existing ones
3776     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3777     #                    of all steps, else - size of each step
3778     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3779     #  @ingroup l2_modif_extrurev
3780     def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
3781                       MakeGroups=False, TotalAngle=False):
3782         return self.RotationSweepObjects([], IDsOfElements, IDsOfElements, Axis,
3783                                          AngleInRadians, NbOfSteps, Tolerance,
3784                                          MakeGroups, TotalAngle)
3785
3786     ## Generates new elements by rotation of the elements of object around the axis
3787     #  @param theObject object which elements should be sweeped.
3788     #                   It can be a mesh, a sub mesh or a group.
3789     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3790     #  @param AngleInRadians the angle of Rotation
3791     #  @param NbOfSteps number of steps
3792     #  @param Tolerance tolerance
3793     #  @param MakeGroups forces the generation of new groups from existing ones
3794     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3795     #                    of all steps, else - size of each step
3796     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3797     #  @ingroup l2_modif_extrurev
3798     def RotationSweepObject(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3799                             MakeGroups=False, TotalAngle=False):
3800         return self.RotationSweepObjects( [], theObject, theObject, Axis,
3801                                           AngleInRadians, NbOfSteps, Tolerance,
3802                                           MakeGroups, TotalAngle )
3803
3804     ## Generates new elements by rotation of the elements of object around the axis
3805     #  @param theObject object which elements should be sweeped.
3806     #                   It can be a mesh, a sub mesh or a group.
3807     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3808     #  @param AngleInRadians the angle of Rotation
3809     #  @param NbOfSteps number of steps
3810     #  @param Tolerance tolerance
3811     #  @param MakeGroups forces the generation of new groups from existing ones
3812     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3813     #                    of all steps, else - size of each step
3814     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3815     #  @ingroup l2_modif_extrurev
3816     def RotationSweepObject1D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3817                               MakeGroups=False, TotalAngle=False):
3818         return self.RotationSweepObjects([],theObject,[], Axis,
3819                                          AngleInRadians, NbOfSteps, Tolerance,
3820                                          MakeGroups, TotalAngle)
3821
3822     ## Generates new elements by rotation of the elements of object around the axis
3823     #  @param theObject object which elements should be sweeped.
3824     #                   It can be a mesh, a sub mesh or a group.
3825     #  @param Axis the axis of rotation, AxisStruct or line(geom object)
3826     #  @param AngleInRadians the angle of Rotation
3827     #  @param NbOfSteps number of steps
3828     #  @param Tolerance tolerance
3829     #  @param MakeGroups forces the generation of new groups from existing ones
3830     #  @param TotalAngle gives meaning of AngleInRadians: if True then it is an angular size
3831     #                    of all steps, else - size of each step
3832     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3833     #  @ingroup l2_modif_extrurev
3834     def RotationSweepObject2D(self, theObject, Axis, AngleInRadians, NbOfSteps, Tolerance,
3835                               MakeGroups=False, TotalAngle=False):
3836         return self.RotationSweepObjects([],[],theObject, Axis, AngleInRadians,
3837                                          NbOfSteps, Tolerance, MakeGroups, TotalAngle)
3838
3839     ## Generates new elements by extrusion of the given elements and nodes
3840     #  @param nodes nodes to extrude: a list including ids, groups, sub-meshes or a mesh
3841     #  @param edges edges to extrude: a list including ids, groups, sub-meshes or a mesh
3842     #  @param faces faces to extrude: a list including ids, groups, sub-meshes or a mesh
3843     #  @param StepVector vector or DirStruct or 3 vector components, defining
3844     #         the direction and value of extrusion for one step (the total extrusion
3845     #         length will be NbOfSteps * ||StepVector||)
3846     #  @param NbOfSteps the number of steps
3847     #  @param MakeGroups forces the generation of new groups from existing ones
3848     #  @param scaleFactors optional scale factors to apply during extrusion
3849     #  @param linearVariation if @c True, scaleFactors are spread over all @a scaleFactors,
3850     #         else scaleFactors[i] is applied to nodes at the i-th extrusion step
3851     #  @param basePoint optional scaling center; if not provided, a gravity center of
3852     #         nodes and elements being extruded is used as the scaling center.
3853     #         It can be either
3854     #         - a list of tree components of the point or
3855     #         - a node ID or
3856     #         - a GEOM point
3857     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3858     #  @ingroup l2_modif_extrurev
3859     def ExtrusionSweepObjects(self, nodes, edges, faces, StepVector, NbOfSteps, MakeGroups=False,
3860                               scaleFactors=[], linearVariation=False, basePoint=[] ):
3861         unRegister = genObjUnRegister()
3862         nodes = self._getIdSourceList( nodes, SMESH.NODE, unRegister )
3863         edges = self._getIdSourceList( edges, SMESH.EDGE, unRegister )
3864         faces = self._getIdSourceList( faces, SMESH.FACE, unRegister )
3865
3866         if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
3867             StepVector = self.smeshpyD.GetDirStruct(StepVector)
3868         if isinstance( StepVector, list ):
3869             StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
3870
3871         if isinstance( basePoint, int):
3872             xyz = self.GetNodeXYZ( basePoint )
3873             if not xyz:
3874                 raise RuntimeError, "Invalid node ID: %s" % basePoint
3875             basePoint = xyz
3876         if isinstance( basePoint, geomBuilder.GEOM._objref_GEOM_Object ):
3877             basePoint = self.geompyD.PointCoordinates( basePoint )
3878
3879         NbOfSteps,Parameters,hasVars = ParseParameters(NbOfSteps)
3880         Parameters = StepVector.PS.parameters + var_separator + Parameters
3881         self.mesh.SetParameters(Parameters)
3882
3883         return self.editor.ExtrusionSweepObjects( nodes, edges, faces,
3884                                                   StepVector, NbOfSteps,
3885                                                   scaleFactors, linearVariation, basePoint,
3886                                                   MakeGroups)
3887
3888
3889     ## Generates new elements by extrusion of the elements with given ids
3890     #  @param IDsOfElements the list of ids of elements or nodes for extrusion
3891     #  @param StepVector vector or DirStruct or 3 vector components, defining
3892     #         the direction and value of extrusion for one step (the total extrusion
3893     #         length will be NbOfSteps * ||StepVector||)
3894     #  @param NbOfSteps the number of steps
3895     #  @param MakeGroups forces the generation of new groups from existing ones
3896     #  @param IsNodes is True if elements with given ids are nodes
3897     #  @return the list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3898     #  @ingroup l2_modif_extrurev
3899     def ExtrusionSweep(self, IDsOfElements, StepVector, NbOfSteps, MakeGroups=False, IsNodes = False):
3900         n,e,f = [],[],[]
3901         if IsNodes: n = IDsOfElements
3902         else      : e,f, = IDsOfElements,IDsOfElements
3903         return self.ExtrusionSweepObjects(n,e,f, StepVector, NbOfSteps, MakeGroups)
3904
3905     ## Generates new elements by extrusion along the normal to a discretized surface or wire
3906     #  @param Elements elements to extrude - a list including ids, groups, sub-meshes or a mesh.
3907     #         Only faces can be extruded so far. A sub-mesh should be a sub-mesh on geom faces.
3908     #  @param StepSize length of one extrusion step (the total extrusion
3909     #         length will be \a NbOfSteps * \a StepSize ).
3910     #  @param NbOfSteps number of extrusion steps.
3911     #  @param ByAverageNormal if True each node is translated by \a StepSize
3912     #         along the average of the normal vectors to the faces sharing the node;
3913     #         else each node is translated along the same average normal till
3914     #         intersection with the plane got by translation of the face sharing
3915     #         the node along its own normal by \a StepSize.
3916     #  @param UseInputElemsOnly to use only \a Elements when computing extrusion direction
3917     #         for every node of \a Elements.
3918     #  @param MakeGroups forces generation of new groups from existing ones.
3919     #  @param Dim dimension of elements to extrude: 2 - faces or 1 - edges. Extrusion of edges
3920     #         is not yet implemented. This parameter is used if \a Elements contains
3921     #         both faces and edges, i.e. \a Elements is a Mesh.
3922     #  @return the list of created groups (SMESH_GroupBase) if \a MakeGroups=True,
3923     #          empty list otherwise.
3924     #  @ingroup l2_modif_extrurev
3925     def ExtrusionByNormal(self, Elements, StepSize, NbOfSteps,
3926                           ByAverageNormal=False, UseInputElemsOnly=True, MakeGroups=False, Dim = 2):
3927         unRegister = genObjUnRegister()
3928         if isinstance( Elements, Mesh ):
3929             Elements = [ Elements.GetMesh() ]
3930         if isinstance( Elements, list ):
3931             if not Elements:
3932                 raise RuntimeError, "Elements empty!"
3933             if isinstance( Elements[0], int ):
3934                 Elements = self.GetIDSource( Elements, SMESH.ALL )
3935                 unRegister.set( Elements )
3936         if not isinstance( Elements, list ):
3937             Elements = [ Elements ]
3938         StepSize,NbOfSteps,Parameters,hasVars = ParseParameters(StepSize,NbOfSteps)
3939         self.mesh.SetParameters(Parameters)
3940         return self.editor.ExtrusionByNormal(Elements, StepSize, NbOfSteps,
3941                                              ByAverageNormal, UseInputElemsOnly, MakeGroups, Dim)
3942
3943     ## Generates new elements by extrusion of the elements or nodes which belong to the object
3944     #  @param theObject the object whose elements or nodes should be processed.
3945     #                   It can be a mesh, a sub-mesh or a group.
3946     #  @param StepVector vector or DirStruct or 3 vector components, defining
3947     #         the direction and value of extrusion for one step (the total extrusion
3948     #         length will be NbOfSteps * ||StepVector||)
3949     #  @param NbOfSteps the number of steps
3950     #  @param MakeGroups forces the generation of new groups from existing ones
3951     #  @param IsNodes is True if elements to extrude are nodes
3952     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3953     #  @ingroup l2_modif_extrurev
3954     def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False, IsNodes=False):
3955         n,e,f = [],[],[]
3956         if IsNodes: n    = theObject
3957         else      : e,f, = theObject,theObject
3958         return self.ExtrusionSweepObjects(n,e,f, StepVector, NbOfSteps, MakeGroups)
3959
3960     ## Generates new elements by extrusion of edges which belong to the object
3961     #  @param theObject object whose 1D elements should be processed.
3962     #                   It can be a mesh, a sub-mesh or a group.
3963     #  @param StepVector vector or DirStruct or 3 vector components, defining
3964     #         the direction and value of extrusion for one step (the total extrusion
3965     #         length will be NbOfSteps * ||StepVector||)
3966     #  @param NbOfSteps the number of steps
3967     #  @param MakeGroups to generate new groups from existing ones
3968     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3969     #  @ingroup l2_modif_extrurev
3970     def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3971         return self.ExtrusionSweepObjects([],theObject,[], StepVector, NbOfSteps, MakeGroups)
3972
3973     ## Generates new elements by extrusion of faces which belong to the object
3974     #  @param theObject object whose 2D elements should be processed.
3975     #                   It can be a mesh, a sub-mesh or a group.
3976     #  @param StepVector vector or DirStruct or 3 vector components, defining
3977     #         the direction and value of extrusion for one step (the total extrusion
3978     #         length will be NbOfSteps * ||StepVector||)
3979     #  @param NbOfSteps the number of steps
3980     #  @param MakeGroups forces the generation of new groups from existing ones
3981     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3982     #  @ingroup l2_modif_extrurev
3983     def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False):
3984         return self.ExtrusionSweepObjects([],[],theObject, StepVector, NbOfSteps, MakeGroups)
3985
3986     ## Generates new elements by extrusion of the elements with given ids
3987     #  @param IDsOfElements is ids of elements
3988     #  @param StepVector vector or DirStruct or 3 vector components, defining
3989     #         the direction and value of extrusion for one step (the total extrusion
3990     #         length will be NbOfSteps * ||StepVector||)
3991     #  @param NbOfSteps the number of steps
3992     #  @param ExtrFlags sets flags for extrusion
3993     #  @param SewTolerance uses for comparing locations of nodes if flag
3994     #         EXTRUSION_FLAG_SEW is set
3995     #  @param MakeGroups forces the generation of new groups from existing ones
3996     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
3997     #  @ingroup l2_modif_extrurev
3998     def AdvancedExtrusion(self, IDsOfElements, StepVector, NbOfSteps,
3999                           ExtrFlags, SewTolerance, MakeGroups=False):
4000         if isinstance( StepVector, geomBuilder.GEOM._objref_GEOM_Object):
4001             StepVector = self.smeshpyD.GetDirStruct(StepVector)
4002         if isinstance( StepVector, list ):
4003             StepVector = self.smeshpyD.MakeDirStruct(*StepVector)
4004         return self.editor.AdvancedExtrusion(IDsOfElements, StepVector, NbOfSteps,
4005                                              ExtrFlags, SewTolerance, MakeGroups)
4006
4007     ## Generates new elements by extrusion of the given elements and nodes along the path.
4008     #  The path of extrusion must be a meshed edge.
4009     #  @param Nodes nodes to extrude: a list including ids, groups, sub-meshes or a mesh
4010     #  @param Edges edges to extrude: a list including ids, groups, sub-meshes or a mesh
4011     #  @param Faces faces to extrude: a list including ids, groups, sub-meshes or a mesh
4012     #  @param PathMesh 1D mesh or 1D sub-mesh, along which proceeds the extrusion
4013     #  @param PathShape shape (edge) defines the sub-mesh of PathMesh if PathMesh
4014     #         contains not only path segments, else it can be None
4015     #  @param NodeStart the first or the last node on the path. Defines the direction of extrusion
4016     #  @param HasAngles allows the shape to be rotated around the path
4017     #                   to get the resulting mesh in a helical fashion
4018     #  @param Angles list of angles
4019     #  @param LinearVariation forces the computation of rotation angles as linear
4020     #                         variation of the given Angles along path steps
4021     #  @param HasRefPoint allows using the reference point
4022     #  @param RefPoint the point around which the shape is rotated (the mass center of the
4023     #         shape by default). The User can specify any point as the Reference Point.
4024     #  @param MakeGroups forces the generation of new groups from existing ones
4025     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error
4026     #  @ingroup l2_modif_extrurev
4027     def ExtrusionAlongPathObjects(self, Nodes, Edges, Faces, PathMesh, PathShape=None,
4028                                   NodeStart=1, HasAngles=False, Angles=[], LinearVariation=False,
4029                                   HasRefPoint=False, RefPoint=[0,0,0], MakeGroups=False):
4030         unRegister = genObjUnRegister()
4031         Nodes = self._getIdSourceList( Nodes, SMESH.NODE, unRegister )
4032         Edges = self._getIdSourceList( Edges, SMESH.EDGE, unRegister )
4033         Faces = self._getIdSourceList( Faces, SMESH.FACE, unRegister )
4034
4035         if isinstance( RefPoint, geomBuilder.GEOM._objref_GEOM_Object):
4036             RefPoint = self.smeshpyD.GetPointStruct(RefPoint)
4037         if isinstance( RefPoint, list ):
4038             if not RefPoint: RefPoint = [0,0,0]
4039             RefPoint = SMESH.PointStruct( *RefPoint )
4040         if isinstance( PathMesh, Mesh ):
4041             PathMesh = PathMesh.GetMesh()
4042         Angles,AnglesParameters,hasVars = ParseAngles(Angles)
4043         Parameters = AnglesParameters + var_separator + RefPoint.parameters
4044         self.mesh.SetParameters(Parameters)
4045         return self.editor.ExtrusionAlongPathObjects(Nodes, Edges, Faces,
4046                                                      PathMesh, PathShape, NodeStart,
4047                                                      HasAngles, Angles, LinearVariation,
4048                                                      HasRefPoint, RefPoint, MakeGroups)
4049
4050     ## Generates new elements by extrusion of the given elements
4051     #  The path of extrusion must be a meshed edge.
4052     #  @param Base mesh or group, or sub-mesh, or list of ids of elements for extrusion
4053     #  @param Path - 1D mesh or 1D sub-mesh, along which proceeds the extrusion
4054     #  @param NodeStart the start node from Path. Defines the direction of extrusion
4055     #  @param HasAngles allows the shape to be rotated around the path
4056     #                   to get the resulting mesh in a helical fashion
4057     #  @param Angles list of angles in radians
4058     #  @param LinearVariation forces the computation of rotation angles as linear
4059     #                         variation of the given Angles along path steps
4060     #  @param HasRefPoint allows using the reference point
4061     #  @param RefPoint the point around which the elements are rotated (the mass
4062     #         center of the elements by default).
4063     #         The User can specify any point as the Reference Point.
4064     #         RefPoint can be either GEOM Vertex, [x,y,z] or SMESH.PointStruct
4065     #  @param MakeGroups forces the generation of new groups from existing ones
4066     #  @param ElemType type of elements for extrusion (if param Base is a mesh)
4067     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4068     #          only SMESH::Extrusion_Error otherwise
4069     #  @ingroup l2_modif_extrurev
4070     def ExtrusionAlongPathX(self, Base, Path, NodeStart,
4071                             HasAngles=False, Angles=[], LinearVariation=False,
4072                             HasRefPoint=False, RefPoint=[0,0,0], MakeGroups=False,
4073                             ElemType=SMESH.FACE):
4074         n,e,f = [],[],[]
4075         if ElemType == SMESH.NODE: n = Base
4076         if ElemType == SMESH.EDGE: e = Base
4077         if ElemType == SMESH.FACE: f = Base
4078         gr,er = self.ExtrusionAlongPathObjects(n,e,f, Path, None, NodeStart,
4079                                                HasAngles, Angles, LinearVariation,
4080                                                HasRefPoint, RefPoint, MakeGroups)
4081         if MakeGroups: return gr,er
4082         return er
4083
4084     ## Generates new elements by extrusion of the given elements
4085     #  The path of extrusion must be a meshed edge.
4086     #  @param IDsOfElements ids of elements
4087     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which proceeds the extrusion
4088     #  @param PathShape shape(edge) defines the sub-mesh for the path
4089     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
4090     #  @param HasAngles allows the shape to be rotated around the path
4091     #                   to get the resulting mesh in a helical fashion
4092     #  @param Angles list of angles in radians
4093     #  @param HasRefPoint allows using the reference point
4094     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
4095     #         The User can specify any point as the Reference Point.
4096     #  @param MakeGroups forces the generation of new groups from existing ones
4097     #  @param LinearVariation forces the computation of rotation angles as linear
4098     #                         variation of the given Angles along path steps
4099     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4100     #          only SMESH::Extrusion_Error otherwise
4101     #  @ingroup l2_modif_extrurev
4102     def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
4103                            HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
4104                            MakeGroups=False, LinearVariation=False):
4105         n,e,f = [],IDsOfElements,IDsOfElements
4106         gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape,
4107                                                NodeStart, HasAngles, Angles,
4108                                                LinearVariation,
4109                                                HasRefPoint, RefPoint, MakeGroups)
4110         if MakeGroups: return gr,er
4111         return er
4112
4113     ## Generates new elements by extrusion of the elements which belong to the object
4114     #  The path of extrusion must be a meshed edge.
4115     #  @param theObject the object whose elements should be processed.
4116     #                   It can be a mesh, a sub-mesh or a group.
4117     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
4118     #  @param PathShape shape(edge) defines the sub-mesh for the path
4119     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
4120     #  @param HasAngles allows the shape to be rotated around the path
4121     #                   to get the resulting mesh in a helical fashion
4122     #  @param Angles list of angles
4123     #  @param HasRefPoint allows using the reference point
4124     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
4125     #         The User can specify any point as the Reference Point.
4126     #  @param MakeGroups forces the generation of new groups from existing ones
4127     #  @param LinearVariation forces the computation of rotation angles as linear
4128     #                         variation of the given Angles along path steps
4129     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4130     #          only SMESH::Extrusion_Error otherwise
4131     #  @ingroup l2_modif_extrurev
4132     def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart,
4133                                  HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
4134                                  MakeGroups=False, LinearVariation=False):
4135         n,e,f = [],theObject,theObject
4136         gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart,
4137                                                HasAngles, Angles, LinearVariation,
4138                                                HasRefPoint, RefPoint, MakeGroups)
4139         if MakeGroups: return gr,er
4140         return er
4141
4142     ## Generates new elements by extrusion of mesh segments which belong to the object
4143     #  The path of extrusion must be a meshed edge.
4144     #  @param theObject the object whose 1D elements should be processed.
4145     #                   It can be a mesh, a sub-mesh or a group.
4146     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
4147     #  @param PathShape shape(edge) defines the sub-mesh for the path
4148     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
4149     #  @param HasAngles allows the shape to be rotated around the path
4150     #                   to get the resulting mesh in a helical fashion
4151     #  @param Angles list of angles
4152     #  @param HasRefPoint allows using the reference point
4153     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
4154     #         The User can specify any point as the Reference Point.
4155     #  @param MakeGroups forces the generation of new groups from existing ones
4156     #  @param LinearVariation forces the computation of rotation angles as linear
4157     #                         variation of the given Angles along path steps
4158     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4159     #          only SMESH::Extrusion_Error otherwise
4160     #  @ingroup l2_modif_extrurev
4161     def ExtrusionAlongPathObject1D(self, theObject, PathMesh, PathShape, NodeStart,
4162                                    HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
4163                                    MakeGroups=False, LinearVariation=False):
4164         n,e,f = [],theObject,[]
4165         gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart,
4166                                                HasAngles, Angles, LinearVariation,
4167                                                HasRefPoint, RefPoint, MakeGroups)
4168         if MakeGroups: return gr,er
4169         return er
4170
4171     ## Generates new elements by extrusion of faces which belong to the object
4172     #  The path of extrusion must be a meshed edge.
4173     #  @param theObject the object whose 2D elements should be processed.
4174     #                   It can be a mesh, a sub-mesh or a group.
4175     #  @param PathMesh mesh containing a 1D sub-mesh on the edge, along which the extrusion proceeds
4176     #  @param PathShape shape(edge) defines the sub-mesh for the path
4177     #  @param NodeStart the first or the last node on the edge. Defines the direction of extrusion
4178     #  @param HasAngles allows the shape to be rotated around the path
4179     #                   to get the resulting mesh in a helical fashion
4180     #  @param Angles list of angles
4181     #  @param HasRefPoint allows using the reference point
4182     #  @param RefPoint the point around which the shape is rotated (the mass center of the shape by default).
4183     #         The User can specify any point as the Reference Point.
4184     #  @param MakeGroups forces the generation of new groups from existing ones
4185     #  @param LinearVariation forces the computation of rotation angles as linear
4186     #                         variation of the given Angles along path steps
4187     #  @return list of created groups (SMESH_GroupBase) and SMESH::Extrusion_Error if MakeGroups=True,
4188     #          only SMESH::Extrusion_Error otherwise
4189     #  @ingroup l2_modif_extrurev
4190     def ExtrusionAlongPathObject2D(self, theObject, PathMesh, PathShape, NodeStart,
4191                                    HasAngles=False, Angles=[], HasRefPoint=False, RefPoint=[],
4192                                    MakeGroups=False, LinearVariation=False):
4193         n,e,f = [],[],theObject
4194         gr,er = self.ExtrusionAlongPathObjects(n,e,f, PathMesh, PathShape, NodeStart,
4195                                                HasAngles, Angles, LinearVariation,
4196                                                HasRefPoint, RefPoint, MakeGroups)
4197         if MakeGroups: return gr,er
4198         return er
4199
4200     ## Creates a symmetrical copy of mesh elements
4201     #  @param IDsOfElements list of elements ids
4202     #  @param Mirror is AxisStruct or geom object(point, line, plane)
4203     #  @param theMirrorType smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE
4204     #         If the Mirror is a geom object this parameter is unnecessary
4205     #  @param Copy allows to copy element (Copy is 1) or to replace with its mirroring (Copy is 0)
4206     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4207     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4208     #  @ingroup l2_modif_trsf
4209     def Mirror(self, IDsOfElements, Mirror, theMirrorType=None, Copy=0, MakeGroups=False):
4210         if IDsOfElements == []:
4211             IDsOfElements = self.GetElementsId()
4212         if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4213             Mirror        = self.smeshpyD.GetAxisStruct(Mirror)
4214             theMirrorType = Mirror._mirrorType
4215         else:
4216             self.mesh.SetParameters(Mirror.parameters)
4217         if Copy and MakeGroups:
4218             return self.editor.MirrorMakeGroups(IDsOfElements, Mirror, theMirrorType)
4219         self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy)
4220         return []
4221
4222     ## Creates a new mesh by a symmetrical copy of mesh elements
4223     #  @param IDsOfElements the list of elements ids
4224     #  @param Mirror is AxisStruct or geom object (point, line, plane)
4225     #  @param theMirrorType smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE
4226     #         If the Mirror is a geom object this parameter is unnecessary
4227     #  @param MakeGroups to generate new groups from existing ones
4228     #  @param NewMeshName a name of the new mesh to create
4229     #  @return instance of Mesh class
4230     #  @ingroup l2_modif_trsf
4231     def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType=0, MakeGroups=0, NewMeshName=""):
4232         if IDsOfElements == []:
4233             IDsOfElements = self.GetElementsId()
4234         if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4235             Mirror        = self.smeshpyD.GetAxisStruct(Mirror)
4236             theMirrorType = Mirror._mirrorType
4237         else:
4238             self.mesh.SetParameters(Mirror.parameters)
4239         mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType,
4240                                           MakeGroups, NewMeshName)
4241         return Mesh(self.smeshpyD,self.geompyD,mesh)
4242
4243     ## Creates a symmetrical copy of the object
4244     #  @param theObject mesh, submesh or group
4245     #  @param Mirror AxisStruct or geom object (point, line, plane)
4246     #  @param theMirrorType smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE
4247     #         If the Mirror is a geom object this parameter is unnecessary
4248     #  @param Copy allows copying the element (Copy is 1) or replacing it with its mirror (Copy is 0)
4249     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4250     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4251     #  @ingroup l2_modif_trsf
4252     def MirrorObject (self, theObject, Mirror, theMirrorType=None, Copy=0, MakeGroups=False):
4253         if ( isinstance( theObject, Mesh )):
4254             theObject = theObject.GetMesh()
4255         if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4256             Mirror        = self.smeshpyD.GetAxisStruct(Mirror)
4257             theMirrorType = Mirror._mirrorType
4258         else:
4259             self.mesh.SetParameters(Mirror.parameters)
4260         if Copy and MakeGroups:
4261             return self.editor.MirrorObjectMakeGroups(theObject, Mirror, theMirrorType)
4262         self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy)
4263         return []
4264
4265     ## Creates a new mesh by a symmetrical copy of the object
4266     #  @param theObject mesh, submesh or group
4267     #  @param Mirror AxisStruct or geom object (point, line, plane)
4268     #  @param theMirrorType smeshBuilder.POINT, smeshBuilder.AXIS or smeshBuilder.PLANE
4269     #         If the Mirror is a geom object this parameter is unnecessary
4270     #  @param MakeGroups forces the generation of new groups from existing ones
4271     #  @param NewMeshName the name of the new mesh to create
4272     #  @return instance of Mesh class
4273     #  @ingroup l2_modif_trsf
4274     def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType=0,MakeGroups=0,NewMeshName=""):
4275         if ( isinstance( theObject, Mesh )):
4276             theObject = theObject.GetMesh()
4277         if ( isinstance( Mirror, geomBuilder.GEOM._objref_GEOM_Object)):
4278             Mirror        = self.smeshpyD.GetAxisStruct(Mirror)
4279             theMirrorType = Mirror._mirrorType
4280         else:
4281             self.mesh.SetParameters(Mirror.parameters)
4282         mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType,
4283                                                 MakeGroups, NewMeshName)
4284         return Mesh( self.smeshpyD,self.geompyD,mesh )
4285
4286     ## Translates the elements
4287     #  @param IDsOfElements list of elements ids
4288     #  @param Vector the direction of translation (DirStruct or vector or 3 vector components)
4289     #  @param Copy allows copying the translated elements
4290     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4291     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4292     #  @ingroup l2_modif_trsf
4293     def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False):
4294         if IDsOfElements == []:
4295             IDsOfElements = self.GetElementsId()
4296         if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
4297             Vector = self.smeshpyD.GetDirStruct(Vector)
4298         if isinstance( Vector, list ):
4299             Vector = self.smeshpyD.MakeDirStruct(*Vector)
4300         self.mesh.SetParameters(Vector.PS.parameters)
4301         if Copy and MakeGroups:
4302             return self.editor.TranslateMakeGroups(IDsOfElements, Vector)
4303         self.editor.Translate(IDsOfElements, Vector, Copy)
4304         return []
4305
4306     ## Creates a new mesh of translated elements
4307     #  @param IDsOfElements list of elements ids
4308     #  @param Vector the direction of translation (DirStruct or vector or 3 vector components)
4309     #  @param MakeGroups forces the generation of new groups from existing ones
4310     #  @param NewMeshName the name of the newly created mesh
4311     #  @return instance of Mesh class
4312     #  @ingroup l2_modif_trsf
4313     def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""):
4314         if IDsOfElements == []:
4315             IDsOfElements = self.GetElementsId()
4316         if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
4317             Vector = self.smeshpyD.GetDirStruct(Vector)
4318         if isinstance( Vector, list ):
4319             Vector = self.smeshpyD.MakeDirStruct(*Vector)
4320         self.mesh.SetParameters(Vector.PS.parameters)
4321         mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName)
4322         return Mesh ( self.smeshpyD, self.geompyD, mesh )
4323
4324     ## Translates the object
4325     #  @param theObject the object to translate (mesh, submesh, or group)
4326     #  @param Vector direction of translation (DirStruct or geom vector or 3 vector components)
4327     #  @param Copy allows copying the translated elements
4328     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4329     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4330     #  @ingroup l2_modif_trsf
4331     def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False):
4332         if ( isinstance( theObject, Mesh )):
4333             theObject = theObject.GetMesh()
4334         if ( isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object)):
4335             Vector = self.smeshpyD.GetDirStruct(Vector)
4336         if isinstance( Vector, list ):
4337             Vector = self.smeshpyD.MakeDirStruct(*Vector)
4338         self.mesh.SetParameters(Vector.PS.parameters)
4339         if Copy and MakeGroups:
4340             return self.editor.TranslateObjectMakeGroups(theObject, Vector)
4341         self.editor.TranslateObject(theObject, Vector, Copy)
4342         return []
4343
4344     ## Creates a new mesh from the translated object
4345     #  @param theObject the object to translate (mesh, submesh, or group)
4346     #  @param Vector the direction of translation (DirStruct or geom vector or 3 vector components)
4347     #  @param MakeGroups forces the generation of new groups from existing ones
4348     #  @param NewMeshName the name of the newly created mesh
4349     #  @return instance of Mesh class
4350     #  @ingroup l2_modif_trsf
4351     def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""):
4352         if isinstance( theObject, Mesh ):
4353             theObject = theObject.GetMesh()
4354         if isinstance( Vector, geomBuilder.GEOM._objref_GEOM_Object ):
4355             Vector = self.smeshpyD.GetDirStruct(Vector)
4356         if isinstance( Vector, list ):
4357             Vector = self.smeshpyD.MakeDirStruct(*Vector)
4358         self.mesh.SetParameters(Vector.PS.parameters)
4359         mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName)
4360         return Mesh( self.smeshpyD, self.geompyD, mesh )
4361
4362
4363
4364     ## Scales the object
4365     #  @param theObject - the object to translate (mesh, submesh, or group)
4366     #  @param thePoint - base point for scale (SMESH.PointStruct or list of 3 coordinates)
4367     #  @param theScaleFact - list of 1-3 scale factors for axises
4368     #  @param Copy - allows copying the translated elements
4369     #  @param MakeGroups - forces the generation of new groups from existing
4370     #                      ones (if Copy)
4371     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True,
4372     #          empty list otherwise
4373     def Scale(self, theObject, thePoint, theScaleFact, Copy, MakeGroups=False):
4374         unRegister = genObjUnRegister()
4375         if ( isinstance( theObject, Mesh )):
4376             theObject = theObject.GetMesh()
4377         if ( isinstance( theObject, list )):
4378             theObject = self.GetIDSource(theObject, SMESH.ALL)
4379             unRegister.set( theObject )
4380         if ( isinstance( thePoint, list )):
4381             thePoint = PointStruct( thePoint[0], thePoint[1], thePoint[2] )
4382         if ( isinstance( theScaleFact, float )):
4383              theScaleFact = [theScaleFact]
4384         if ( isinstance( theScaleFact, int )):
4385              theScaleFact = [ float(theScaleFact)]
4386
4387         self.mesh.SetParameters(thePoint.parameters)
4388
4389         if Copy and MakeGroups:
4390             return self.editor.ScaleMakeGroups(theObject, thePoint, theScaleFact)
4391         self.editor.Scale(theObject, thePoint, theScaleFact, Copy)
4392         return []
4393
4394     ## Creates a new mesh from the translated object
4395     #  @param theObject - the object to translate (mesh, submesh, or group)
4396     #  @param thePoint - base point for scale (SMESH.PointStruct or list of 3 coordinates)
4397     #  @param theScaleFact - list of 1-3 scale factors for axises
4398     #  @param MakeGroups - forces the generation of new groups from existing ones
4399     #  @param NewMeshName - the name of the newly created mesh
4400     #  @return instance of Mesh class
4401     def ScaleMakeMesh(self, theObject, thePoint, theScaleFact, MakeGroups=False, NewMeshName=""):
4402         unRegister = genObjUnRegister()
4403         if (isinstance(theObject, Mesh)):
4404             theObject = theObject.GetMesh()
4405         if ( isinstance( theObject, list )):
4406             theObject = self.GetIDSource(theObject,SMESH.ALL)
4407             unRegister.set( theObject )
4408         if ( isinstance( thePoint, list )):
4409             thePoint = PointStruct( thePoint[0], thePoint[1], thePoint[2] )
4410         if ( isinstance( theScaleFact, float )):
4411              theScaleFact = [theScaleFact]
4412         if ( isinstance( theScaleFact, int )):
4413              theScaleFact = [ float(theScaleFact)]
4414
4415         self.mesh.SetParameters(thePoint.parameters)
4416         mesh = self.editor.ScaleMakeMesh(theObject, thePoint, theScaleFact,
4417                                          MakeGroups, NewMeshName)
4418         return Mesh( self.smeshpyD, self.geompyD, mesh )
4419
4420
4421
4422     ## Rotates the elements
4423     #  @param IDsOfElements list of elements ids
4424     #  @param Axis the axis of rotation (AxisStruct or geom line)
4425     #  @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4426     #  @param Copy allows copying the rotated elements
4427     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4428     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4429     #  @ingroup l2_modif_trsf
4430     def Rotate (self, IDsOfElements, Axis, AngleInRadians, Copy, MakeGroups=False):
4431         if IDsOfElements == []:
4432             IDsOfElements = self.GetElementsId()
4433         if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4434             Axis = self.smeshpyD.GetAxisStruct(Axis)
4435         AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4436         Parameters = Axis.parameters + var_separator + Parameters
4437         self.mesh.SetParameters(Parameters)
4438         if Copy and MakeGroups:
4439             return self.editor.RotateMakeGroups(IDsOfElements, Axis, AngleInRadians)
4440         self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy)
4441         return []
4442
4443     ## Creates a new mesh of rotated elements
4444     #  @param IDsOfElements list of element ids
4445     #  @param Axis the axis of rotation (AxisStruct or geom line)
4446     #  @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4447     #  @param MakeGroups forces the generation of new groups from existing ones
4448     #  @param NewMeshName the name of the newly created mesh
4449     #  @return instance of Mesh class
4450     #  @ingroup l2_modif_trsf
4451     def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""):
4452         if IDsOfElements == []:
4453             IDsOfElements = self.GetElementsId()
4454         if ( isinstance( Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4455             Axis = self.smeshpyD.GetAxisStruct(Axis)
4456         AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4457         Parameters = Axis.parameters + var_separator + Parameters
4458         self.mesh.SetParameters(Parameters)
4459         mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians,
4460                                           MakeGroups, NewMeshName)
4461         return Mesh( self.smeshpyD, self.geompyD, mesh )
4462
4463     ## Rotates the object
4464     #  @param theObject the object to rotate( mesh, submesh, or group)
4465     #  @param Axis the axis of rotation (AxisStruct or geom line)
4466     #  @param AngleInRadians the angle of rotation (in radians) or a name of variable which defines angle in degrees
4467     #  @param Copy allows copying the rotated elements
4468     #  @param MakeGroups forces the generation of new groups from existing ones (if Copy)
4469     #  @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise
4470     #  @ingroup l2_modif_trsf
4471     def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False):
4472         if (isinstance(theObject, Mesh)):
4473             theObject = theObject.GetMesh()
4474         if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4475             Axis = self.smeshpyD.GetAxisStruct(Axis)
4476         AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4477         Parameters = Axis.parameters + ":" + Parameters
4478         self.mesh.SetParameters(Parameters)
4479         if Copy and MakeGroups:
4480             return self.editor.RotateObjectMakeGroups(theObject, Axis, AngleInRadians)
4481         self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy)
4482         return []
4483
4484     ## Creates a new mesh from the rotated object
4485     #  @param theObject the object to rotate (mesh, submesh, or group)
4486     #  @param Axis the axis of rotation (AxisStruct or geom line)
4487     #  @param AngleInRadians the angle of rotation (in radians)  or a name of variable which defines angle in degrees
4488     #  @param MakeGroups forces the generation of new groups from existing ones
4489     #  @param NewMeshName the name of the newly created mesh
4490     #  @return instance of Mesh class
4491     #  @ingroup l2_modif_trsf
4492     def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""):
4493         if (isinstance( theObject, Mesh )):
4494             theObject = theObject.GetMesh()
4495         if (isinstance(Axis, geomBuilder.GEOM._objref_GEOM_Object)):
4496             Axis = self.smeshpyD.GetAxisStruct(Axis)
4497         AngleInRadians,Parameters,hasVars = ParseAngles(AngleInRadians)
4498         Parameters = Axis.parameters + ":" + Parameters
4499         mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians,
4500                                                        MakeGroups, NewMeshName)
4501         self.mesh.SetParameters(Parameters)
4502         return Mesh( self.smeshpyD, self.geompyD, mesh )
4503
4504     ## Finds groups of adjacent nodes within Tolerance.
4505     #  @param Tolerance the value of tolerance
4506     #  @param SeparateCornerAndMediumNodes if @c True, in quadratic mesh puts
4507     #         corner and medium nodes in separate groups thus preventing
4508     #         their further merge.
4509     #  @return the list of groups of nodes IDs (e.g. [[1,12,13],[4,25]])
4510     #  @ingroup l2_modif_trsf
4511     def FindCoincidentNodes (self, Tolerance, SeparateCornerAndMediumNodes=False):
4512         return self.editor.FindCoincidentNodes( Tolerance, SeparateCornerAndMediumNodes )
4513
4514     ## Finds groups of ajacent nodes within Tolerance.
4515     #  @param Tolerance the value of tolerance
4516     #  @param SubMeshOrGroup SubMesh, Group or Filter
4517     #  @param exceptNodes list of either SubMeshes, Groups or node IDs to exclude from search
4518     #  @param SeparateCornerAndMediumNodes if @c True, in quadratic mesh puts
4519     #         corner and medium nodes in separate groups thus preventing
4520     #         their further merge.
4521     #  @return the list of groups of nodes IDs (e.g. [[1,12,13],[4,25]])
4522     #  @ingroup l2_modif_trsf
4523     def FindCoincidentNodesOnPart (self, SubMeshOrGroup, Tolerance,
4524                                    exceptNodes=[], SeparateCornerAndMediumNodes=False):
4525         unRegister = genObjUnRegister()
4526         if (isinstance( SubMeshOrGroup, Mesh )):
4527             SubMeshOrGroup = SubMeshOrGroup.GetMesh()
4528         if not isinstance( exceptNodes, list ):
4529             exceptNodes = [ exceptNodes ]
4530         if exceptNodes and isinstance( exceptNodes[0], int ):
4531             exceptNodes = [ self.GetIDSource( exceptNodes, SMESH.NODE )]
4532             unRegister.set( exceptNodes )
4533         return self.editor.FindCoincidentNodesOnPartBut(SubMeshOrGroup, Tolerance,
4534                                                         exceptNodes, SeparateCornerAndMediumNodes)
4535
4536     ## Merges nodes
4537     #  @param GroupsOfNodes a list of groups of nodes IDs for merging
4538     #         (e.g. [[1,12,13],[25,4]], then nodes 12, 13 and 4 will be removed and replaced
4539     #         by nodes 1 and 25 correspondingly in all elements and groups
4540     #  @param NodesToKeep nodes to keep in the mesh: a list of groups, sub-meshes or node IDs.
4541     #         If @a NodesToKeep does not include a node to keep for some group to merge,
4542     #         then the first node in the group is kept.
4543     #  @ingroup l2_modif_trsf
4544     def MergeNodes (self, GroupsOfNodes, NodesToKeep=[]):
4545         # NodesToKeep are converted to SMESH_IDSource in meshEditor.MergeNodes()
4546         self.editor.MergeNodes(GroupsOfNodes,NodesToKeep)
4547
4548     ## Finds the elements built on the same nodes.
4549     #  @param MeshOrSubMeshOrGroup Mesh or SubMesh, or Group of elements for searching
4550     #  @return the list of groups of equal elements IDs (e.g. [[1,12,13],[4,25]])
4551     #  @ingroup l2_modif_trsf
4552     def FindEqualElements (self, MeshOrSubMeshOrGroup=None):
4553         if not MeshOrSubMeshOrGroup:
4554             MeshOrSubMeshOrGroup=self.mesh
4555         elif isinstance( MeshOrSubMeshOrGroup, Mesh ):
4556             MeshOrSubMeshOrGroup = MeshOrSubMeshOrGroup.GetMesh()
4557         return self.editor.FindEqualElements( MeshOrSubMeshOrGroup )
4558
4559     ## Merges elements in each given group.
4560     #  @param GroupsOfElementsID a list of groups of elements IDs for merging
4561     #        (e.g. [[1,12,13],[25,4]], then elements 12, 13 and 4 will be removed and
4562     #        replaced by elements 1 and 25 in all groups)
4563     #  @ingroup l2_modif_trsf
4564     def MergeElements(self, GroupsOfElementsID):
4565         self.editor.MergeElements(GroupsOfElementsID)
4566
4567     ## Leaves one element and removes all other elements built on the same nodes.
4568     #  @ingroup l2_modif_trsf
4569     def MergeEqualElements(self):
4570         self.editor.MergeEqualElements()
4571
4572     ## Returns all or only closed free borders
4573     #  @return list of SMESH.FreeBorder's
4574     #  @ingroup l2_modif_trsf
4575     def FindFreeBorders(self, ClosedOnly=True):
4576         return self.editor.FindFreeBorders( ClosedOnly )
4577
4578     ## Fill with 2D elements a hole defined by a SMESH.FreeBorder.
4579     #  @param FreeBorder either a SMESH.FreeBorder or a list on node IDs. These nodes
4580     #         must describe all sequential nodes of the hole border. The first and the last
4581     #         nodes must be the same. Use FindFreeBorders() to get nodes of holes.
4582     #  @ingroup l2_modif_trsf
4583     def FillHole(self, holeNodes):
4584         if holeNodes and isinstance( holeNodes, list ) and isinstance( holeNodes[0], int ):
4585             holeNodes = SMESH.FreeBorder(nodeIDs=holeNodes)
4586         if not isinstance( holeNodes, SMESH.FreeBorder ):
4587             raise TypeError, "holeNodes must be either SMESH.FreeBorder or list of integer and not %s" % holeNodes
4588         self.editor.FillHole( holeNodes )
4589
4590     ## Returns groups of FreeBorder's coincident within the given tolerance.
4591     #  @param tolerance the tolerance. If the tolerance <= 0.0 then one tenth of an average
4592     #         size of elements adjacent to free borders being compared is used.
4593     #  @return SMESH.CoincidentFreeBorders structure
4594     #  @ingroup l2_modif_trsf
4595     def FindCoincidentFreeBorders (self, tolerance=0.):
4596         return self.editor.FindCoincidentFreeBorders( tolerance )
4597         
4598     ## Sew FreeBorder's of each group
4599     #  @param freeBorders either a SMESH.CoincidentFreeBorders structure or a list of lists
4600     #         where each enclosed list contains node IDs of a group of coincident free
4601     #         borders such that each consequent triple of IDs within a group describes
4602     #         a free border in a usual way: n1, n2, nLast - i.e. 1st node, 2nd node and
4603     #         last node of a border.
4604     #         For example [[1, 2, 10, 20, 21, 40], [11, 12, 15, 55, 54, 41]] describes two
4605     #         groups of coincident free borders, each group including two borders.
4606     #  @param createPolygons if @c True faces adjacent to free borders are converted to
4607     #         polygons if a node of opposite border falls on a face edge, else such
4608     #         faces are split into several ones.
4609     #  @param createPolyhedra if @c True volumes adjacent to free borders are converted to
4610     #         polyhedra if a node of opposite border falls on a volume edge, else such
4611     #         volumes, if any, remain intact and the mesh becomes non-conformal.
4612     #  @return a number of successfully sewed groups
4613     #  @ingroup l2_modif_trsf
4614     def SewCoincidentFreeBorders (self, freeBorders, createPolygons=False, createPolyhedra=False):
4615         if freeBorders and isinstance( freeBorders, list ):
4616             # construct SMESH.CoincidentFreeBorders
4617             if isinstance( freeBorders[0], int ):
4618                 freeBorders = [freeBorders]
4619             borders = []
4620             coincidentGroups = []
4621             for nodeList in freeBorders:
4622                 if not nodeList or len( nodeList ) % 3:
4623                     raise ValueError, "Wrong number of nodes in this group: %s" % nodeList
4624                 group = []
4625                 while nodeList:
4626                     group.append  ( SMESH.FreeBorderPart( len(borders), 0, 1, 2 ))
4627                     borders.append( SMESH.FreeBorder( nodeList[:3] ))
4628                     nodeList = nodeList[3:]
4629                     pass
4630                 coincidentGroups.append( group )
4631                 pass
4632             freeBorders = SMESH.CoincidentFreeBorders( borders, coincidentGroups )
4633
4634         return self.editor.SewCoincidentFreeBorders( freeBorders, createPolygons, createPolyhedra )
4635
4636     ## Sews free borders
4637     #  @return SMESH::Sew_Error
4638     #  @ingroup l2_modif_trsf
4639     def SewFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4640                         FirstNodeID2, SecondNodeID2, LastNodeID2,
4641                         CreatePolygons, CreatePolyedrs):
4642         return self.editor.SewFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4643                                           FirstNodeID2, SecondNodeID2, LastNodeID2,
4644                                           CreatePolygons, CreatePolyedrs)
4645
4646     ## Sews conform free borders
4647     #  @return SMESH::Sew_Error
4648     #  @ingroup l2_modif_trsf
4649     def SewConformFreeBorders (self, FirstNodeID1, SecondNodeID1, LastNodeID1,
4650                                FirstNodeID2, SecondNodeID2):
4651         return self.editor.SewConformFreeBorders(FirstNodeID1, SecondNodeID1, LastNodeID1,
4652                                                  FirstNodeID2, SecondNodeID2)
4653
4654     ## Sews border to side
4655     #  @return SMESH::Sew_Error
4656     #  @ingroup l2_modif_trsf
4657     def SewBorderToSide (self, FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4658                          FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs):
4659         return self.editor.SewBorderToSide(FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
4660                                            FirstNodeIDOnSide, LastNodeIDOnSide, CreatePolygons, CreatePolyedrs)
4661
4662     ## Sews two sides of a mesh. The nodes belonging to Side1 are
4663     #  merged with the nodes of elements of Side2.
4664     #  The number of elements in theSide1 and in theSide2 must be
4665     #  equal and they should have similar nodal connectivity.
4666     #  The nodes to merge should belong to side borders and
4667     #  the first node should be linked to the second.
4668     #  @return SMESH::Sew_Error
4669     #  @ingroup l2_modif_trsf
4670     def SewSideElements (self, IDsOfSide1Elements, IDsOfSide2Elements,
4671                          NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4672                          NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge):
4673         return self.editor.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
4674                                            NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
4675                                            NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
4676
4677     ## Sets new nodes for the given element.
4678     #  @param ide the element id
4679     #  @param newIDs nodes ids
4680     #  @return If the number of nodes does not correspond to the type of element - returns false
4681     #  @ingroup l2_modif_edit
4682     def ChangeElemNodes(self, ide, newIDs):
4683         return self.editor.ChangeElemNodes(ide, newIDs)
4684
4685     ## If during the last operation of MeshEditor some nodes were
4686     #  created, this method returns the list of their IDs, \n
4687     #  if new nodes were not created - returns empty list
4688     #  @return the list of integer values (can be empty)
4689     #  @ingroup l1_auxiliary
4690     def GetLastCreatedNodes(self):
4691         return self.editor.GetLastCreatedNodes()
4692
4693     ## If during the last operation of MeshEditor some elements were
4694     #  created this method returns the list of their IDs, \n
4695     #  if new elements were not created - returns empty list
4696     #  @return the list of integer values (can be empty)
4697     #  @ingroup l1_auxiliary
4698     def GetLastCreatedElems(self):
4699         return self.editor.GetLastCreatedElems()
4700
4701     ## Clears sequences of nodes and elements created by mesh edition oparations
4702     #  @ingroup l1_auxiliary
4703     def ClearLastCreated(self):
4704         self.editor.ClearLastCreated()
4705
4706     ## Creates duplicates of given elements, i.e. creates new elements based on the 
4707     #  same nodes as the given ones.
4708     #  @param theElements - container of elements to duplicate. It can be a Mesh,
4709     #         sub-mesh, group, filter or a list of element IDs. If \a theElements is
4710     #         a Mesh, elements of highest dimension are duplicated
4711     #  @param theGroupName - a name of group to contain the generated elements.
4712     #                    If a group with such a name already exists, the new elements
4713     #                    are added to the existng group, else a new group is created.
4714     #                    If \a theGroupName is empty, new elements are not added 
4715     #                    in any group.
4716     # @return a group where the new elements are added. None if theGroupName == "".
4717     #  @ingroup l2_modif_edit
4718     def DoubleElements(self, theElements, theGroupName=""):
4719         unRegister = genObjUnRegister()
4720         if isinstance( theElements, Mesh ):
4721             theElements = theElements.mesh
4722         elif isinstance( theElements, list ):
4723             theElements = self.GetIDSource( theElements, SMESH.ALL )
4724             unRegister.set( theElements )
4725         return self.editor.DoubleElements(theElements, theGroupName)
4726
4727     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4728     #  @param theNodes identifiers of nodes to be doubled
4729     #  @param theModifiedElems identifiers of elements to be updated by the new (doubled)
4730     #         nodes. If list of element identifiers is empty then nodes are doubled but
4731     #         they not assigned to elements
4732     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4733     #  @ingroup l2_modif_edit
4734     def DoubleNodes(self, theNodes, theModifiedElems):
4735         return self.editor.DoubleNodes(theNodes, theModifiedElems)
4736
4737     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4738     #  This method provided for convenience works as DoubleNodes() described above.
4739     #  @param theNodeId identifiers of node to be doubled
4740     #  @param theModifiedElems identifiers of elements to be updated
4741     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4742     #  @ingroup l2_modif_edit
4743     def DoubleNode(self, theNodeId, theModifiedElems):
4744         return self.editor.DoubleNode(theNodeId, theModifiedElems)
4745
4746     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4747     #  This method provided for convenience works as DoubleNodes() described above.
4748     #  @param theNodes group of nodes to be doubled
4749     #  @param theModifiedElems group of elements to be updated.
4750     #  @param theMakeGroup forces the generation of a group containing new nodes.
4751     #  @return TRUE or a created group if operation has been completed successfully,
4752     #          FALSE or None otherwise
4753     #  @ingroup l2_modif_edit
4754     def DoubleNodeGroup(self, theNodes, theModifiedElems, theMakeGroup=False):
4755         if theMakeGroup:
4756             return self.editor.DoubleNodeGroupNew(theNodes, theModifiedElems)
4757         return self.editor.DoubleNodeGroup(theNodes, theModifiedElems)
4758
4759     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4760     #  This method provided for convenience works as DoubleNodes() described above.
4761     #  @param theNodes list of groups of nodes to be doubled
4762     #  @param theModifiedElems list of groups of elements to be updated.
4763     #  @param theMakeGroup forces the generation of a group containing new nodes.
4764     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4765     #  @ingroup l2_modif_edit
4766     def DoubleNodeGroups(self, theNodes, theModifiedElems, theMakeGroup=False):
4767         if theMakeGroup:
4768             return self.editor.DoubleNodeGroupsNew(theNodes, theModifiedElems)
4769         return self.editor.DoubleNodeGroups(theNodes, theModifiedElems)
4770
4771     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4772     #  @param theElems - the list of elements (edges or faces) to be replicated
4773     #         The nodes for duplication could be found from these elements
4774     #  @param theNodesNot - list of nodes to NOT replicate
4775     #  @param theAffectedElems - the list of elements (cells and edges) to which the
4776     #         replicated nodes should be associated to.
4777     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4778     #  @ingroup l2_modif_edit
4779     def DoubleNodeElem(self, theElems, theNodesNot, theAffectedElems):
4780         return self.editor.DoubleNodeElem(theElems, theNodesNot, theAffectedElems)
4781
4782     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4783     #  @param theElems - the list of elements (edges or faces) to be replicated
4784     #         The nodes for duplication could be found from these elements
4785     #  @param theNodesNot - list of nodes to NOT replicate
4786     #  @param theShape - shape to detect affected elements (element which geometric center
4787     #         located on or inside shape).
4788     #         The replicated nodes should be associated to affected elements.
4789     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4790     #  @ingroup l2_modif_edit
4791     def DoubleNodeElemInRegion(self, theElems, theNodesNot, theShape):
4792         return self.editor.DoubleNodeElemInRegion(theElems, theNodesNot, theShape)
4793
4794     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4795     #  This method provided for convenience works as DoubleNodes() described above.
4796     #  @param theElems - group of of elements (edges or faces) to be replicated
4797     #  @param theNodesNot - group of nodes not to replicated
4798     #  @param theAffectedElems - group of elements to which the replicated nodes
4799     #         should be associated to.
4800     #  @param theMakeGroup forces the generation of a group containing new elements.
4801     #  @param theMakeNodeGroup forces the generation of a group containing new nodes.
4802     #  @return TRUE or created groups (one or two) if operation has been completed successfully,
4803     #          FALSE or None otherwise
4804     #  @ingroup l2_modif_edit
4805     def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems,
4806                              theMakeGroup=False, theMakeNodeGroup=False):
4807         if theMakeGroup or theMakeNodeGroup:
4808             twoGroups = self.editor.DoubleNodeElemGroup2New(theElems, theNodesNot,
4809                                                             theAffectedElems,
4810                                                             theMakeGroup, theMakeNodeGroup)
4811             if theMakeGroup and theMakeNodeGroup:
4812                 return twoGroups
4813             else:
4814                 return twoGroups[ int(theMakeNodeGroup) ]
4815         return self.editor.DoubleNodeElemGroup(theElems, theNodesNot, theAffectedElems)
4816
4817     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4818     #  This method provided for convenience works as DoubleNodes() described above.
4819     #  @param theElems - group of of elements (edges or faces) to be replicated
4820     #  @param theNodesNot - group of nodes not to replicated
4821     #  @param theShape - shape to detect affected elements (element which geometric center
4822     #         located on or inside shape).
4823     #         The replicated nodes should be associated to affected elements.
4824     #  @ingroup l2_modif_edit
4825     def DoubleNodeElemGroupInRegion(self, theElems, theNodesNot, theShape):
4826         return self.editor.DoubleNodeElemGroupInRegion(theElems, theNodesNot, theShape)
4827
4828     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4829     #  This method provided for convenience works as DoubleNodes() described above.
4830     #  @param theElems - list of groups of elements (edges or faces) to be replicated
4831     #  @param theNodesNot - list of groups of nodes not to replicated
4832     #  @param theAffectedElems - group of elements to which the replicated nodes
4833     #         should be associated to.
4834     #  @param theMakeGroup forces the generation of a group containing new elements.
4835     #  @param theMakeNodeGroup forces the generation of a group containing new nodes.
4836     #  @return TRUE or created groups (one or two) if operation has been completed successfully,
4837     #          FALSE or None otherwise
4838     #  @ingroup l2_modif_edit
4839     def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems,
4840                              theMakeGroup=False, theMakeNodeGroup=False):
4841         if theMakeGroup or theMakeNodeGroup:
4842             twoGroups = self.editor.DoubleNodeElemGroups2New(theElems, theNodesNot,
4843                                                              theAffectedElems,
4844                                                              theMakeGroup, theMakeNodeGroup)
4845             if theMakeGroup and theMakeNodeGroup:
4846                 return twoGroups
4847             else:
4848                 return twoGroups[ int(theMakeNodeGroup) ]
4849         return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems)
4850
4851     ## Creates a hole in a mesh by doubling the nodes of some particular elements
4852     #  This method provided for convenience works as DoubleNodes() described above.
4853     #  @param theElems - list of groups of elements (edges or faces) to be replicated
4854     #  @param theNodesNot - list of groups of nodes not to replicated
4855     #  @param theShape - shape to detect affected elements (element which geometric center
4856     #         located on or inside shape).
4857     #         The replicated nodes should be associated to affected elements.
4858     #  @return TRUE if operation has been completed successfully, FALSE otherwise
4859     #  @ingroup l2_modif_edit
4860     def DoubleNodeElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4861         return self.editor.DoubleNodeElemGroupsInRegion(theElems, theNodesNot, theShape)
4862
4863     ## Identify the elements that will be affected by node duplication (actual duplication is not performed.
4864     #  This method is the first step of DoubleNodeElemGroupsInRegion.
4865     #  @param theElems - list of groups of elements (edges or faces) to be replicated
4866     #  @param theNodesNot - list of groups of nodes not to replicated
4867     #  @param theShape - shape to detect affected elements (element which geometric center
4868     #         located on or inside shape).
4869     #         The replicated nodes should be associated to affected elements.
4870     #  @return groups of affected elements
4871     #  @ingroup l2_modif_edit
4872     def AffectedElemGroupsInRegion(self, theElems, theNodesNot, theShape):
4873         return self.editor.AffectedElemGroupsInRegion(theElems, theNodesNot, theShape)
4874
4875     ## Double nodes on shared faces between groups of volumes and create flat elements on demand.
4876     # The list of groups must describe a partition of the mesh volumes.
4877     # The nodes of the internal faces at the boundaries of the groups are doubled.
4878     # In option, the internal faces are replaced by flat elements.
4879     # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4880     # @param theDomains - list of groups of volumes
4881     # @param createJointElems - if TRUE, create the elements
4882     # @param onAllBoundaries - if TRUE, the nodes and elements are also created on
4883     #        the boundary between \a theDomains and the rest mesh
4884     # @return TRUE if operation has been completed successfully, FALSE otherwise
4885     def DoubleNodesOnGroupBoundaries(self, theDomains, createJointElems, onAllBoundaries=False ):
4886        return self.editor.DoubleNodesOnGroupBoundaries( theDomains, createJointElems, onAllBoundaries )
4887
4888     ## Double nodes on some external faces and create flat elements.
4889     # Flat elements are mainly used by some types of mechanic calculations.
4890     #
4891     # Each group of the list must be constituted of faces.
4892     # Triangles are transformed in prisms, and quadrangles in hexahedrons.
4893     # @param theGroupsOfFaces - list of groups of faces
4894     # @return TRUE if operation has been completed successfully, FALSE otherwise
4895     def CreateFlatElementsOnFacesGroups(self, theGroupsOfFaces ):
4896         return self.editor.CreateFlatElementsOnFacesGroups( theGroupsOfFaces )
4897     
4898     ## identify all the elements around a geom shape, get the faces delimiting the hole
4899     #
4900     def CreateHoleSkin(self, radius, theShape, groupName, theNodesCoords):
4901         return self.editor.CreateHoleSkin( radius, theShape, groupName, theNodesCoords )
4902
4903     ## Return a cached numerical functor by its type.
4904     #  @param theCriterion functor type - an item of SMESH.FunctorType enumeration.
4905     #          Type SMESH.FunctorType._items in the Python Console to see all items.
4906     #          Note that not all items correspond to numerical functors.
4907     #  @return SMESH_NumericalFunctor. The functor is already initialized
4908     #          with a mesh
4909     #  @ingroup l1_measurements
4910     def GetFunctor(self, funcType ):
4911         fn = self.functors[ funcType._v ]
4912         if not fn:
4913             fn = self.smeshpyD.GetFunctor(funcType)
4914             fn.SetMesh(self.mesh)
4915             self.functors[ funcType._v ] = fn
4916         return fn
4917
4918     ## Returns value of a functor for a given element
4919     #  @param funcType an item of SMESH.FunctorType enum
4920     #         Type "SMESH.FunctorType._items" in the Python Console to see all items.
4921     #  @param elemId element or node ID
4922     #  @param isElem @a elemId is ID of element or node
4923     #  @return the functor value or zero in case of invalid arguments
4924     def FunctorValue(self, funcType, elemId, isElem=True):
4925         fn = self.GetFunctor( funcType )
4926         if fn.GetElementType() == self.GetElementType(elemId, isElem):
4927             val = fn.GetValue(elemId)
4928         else:
4929             val = 0
4930         return val
4931
4932     ## Get length of 1D element or sum of lengths of all 1D mesh elements
4933     #  @param elemId mesh element ID (if not defined - sum of length of all 1D elements will be calculated)
4934     #  @return element's length value if \a elemId is specified or sum of all 1D mesh elements' lengths otherwise
4935     #  @ingroup l1_measurements
4936     def GetLength(self, elemId=None):
4937         length = 0
4938         if elemId == None:
4939             length = self.smeshpyD.GetLength(self)
4940         else:
4941             length = self.FunctorValue(SMESH.FT_Length, elemId)
4942         return length
4943
4944     ## Get area of 2D element or sum of areas of all 2D mesh elements
4945     #  @param elemId mesh element ID (if not defined - sum of areas of all 2D elements will be calculated)
4946     #  @return element's area value if \a elemId is specified or sum of all 2D mesh elements' areas otherwise
4947     #  @ingroup l1_measurements
4948     def GetArea(self, elemId=None):
4949         area = 0
4950         if elemId == None:
4951             area = self.smeshpyD.GetArea(self)
4952         else:
4953             area = self.FunctorValue(SMESH.FT_Area, elemId)
4954         return area
4955
4956     ## Get volume of 3D element or sum of volumes of all 3D mesh elements
4957     #  @param elemId mesh element ID (if not defined - sum of volumes of all 3D elements will be calculated)
4958     #  @return element's volume value if \a elemId is specified or sum of all 3D mesh elements' volumes otherwise
4959     #  @ingroup l1_measurements
4960     def GetVolume(self, elemId=None):
4961         volume = 0
4962         if elemId == None:
4963             volume = self.smeshpyD.GetVolume(self)
4964         else:
4965             volume = self.FunctorValue(SMESH.FT_Volume3D, elemId)
4966         return volume
4967
4968     ## Get maximum element length.
4969     #  @param elemId mesh element ID
4970     #  @return element's maximum length value
4971     #  @ingroup l1_measurements
4972     def GetMaxElementLength(self, elemId):
4973         if self.GetElementType(elemId, True) == SMESH.VOLUME:
4974             ftype = SMESH.FT_MaxElementLength3D
4975         else:
4976             ftype = SMESH.FT_MaxElementLength2D
4977         return self.FunctorValue(ftype, elemId)
4978
4979     ## Get aspect ratio of 2D or 3D element.
4980     #  @param elemId mesh element ID
4981     #  @return element's aspect ratio value
4982     #  @ingroup l1_measurements
4983     def GetAspectRatio(self, elemId):
4984         if self.GetElementType(elemId, True) == SMESH.VOLUME:
4985             ftype = SMESH.FT_AspectRatio3D
4986         else:
4987             ftype = SMESH.FT_AspectRatio
4988         return self.FunctorValue(ftype, elemId)
4989
4990     ## Get warping angle of 2D element.
4991     #  @param elemId mesh element ID
4992     #  @return element's warping angle value
4993     #  @ingroup l1_measurements
4994     def GetWarping(self, elemId):
4995         return self.FunctorValue(SMESH.FT_Warping, elemId)
4996
4997     ## Get minimum angle of 2D element.
4998     #  @param elemId mesh element ID
4999     #  @return element's minimum angle value
5000     #  @ingroup l1_measurements
5001     def GetMinimumAngle(self, elemId):
5002         return self.FunctorValue(SMESH.FT_MinimumAngle, elemId)
5003
5004     ## Get taper of 2D element.
5005     #  @param elemId mesh element ID
5006     #  @return element's taper value
5007     #  @ingroup l1_measurements
5008     def GetTaper(self, elemId):
5009         return self.FunctorValue(SMESH.FT_Taper, elemId)
5010
5011     ## Get skew of 2D element.
5012     #  @param elemId mesh element ID
5013     #  @return element's skew value
5014     #  @ingroup l1_measurements
5015     def GetSkew(self, elemId):
5016         return self.FunctorValue(SMESH.FT_Skew, elemId)
5017
5018     ## Return minimal and maximal value of a given functor.
5019     #  @param funType a functor type, an item of SMESH.FunctorType enum
5020     #         (one of SMESH.FunctorType._items)
5021     #  @param meshPart a part of mesh (group, sub-mesh) to treat
5022     #  @return tuple (min,max)
5023     #  @ingroup l1_measurements
5024     def GetMinMax(self, funType, meshPart=None):
5025         unRegister = genObjUnRegister()
5026         if isinstance( meshPart, list ):
5027             meshPart = self.GetIDSource( meshPart, SMESH.ALL )
5028             unRegister.set( meshPart )
5029         if isinstance( meshPart, Mesh ):
5030             meshPart = meshPart.mesh
5031         fun = self.GetFunctor( funType )
5032         if fun:
5033             if meshPart:
5034                 if hasattr( meshPart, "SetMesh" ):
5035                     meshPart.SetMesh( self.mesh ) # set mesh to filter
5036                 hist = fun.GetLocalHistogram( 1, False, meshPart )
5037             else:
5038                 hist = fun.GetHistogram( 1, False )
5039             if hist:
5040                 return hist[0].min, hist[0].max
5041         return None
5042
5043     pass # end of Mesh class
5044
5045
5046 ## Class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility
5047 #  with old dump scripts which call SMESH_Mesh directly and not via smeshBuilder.Mesh
5048 #
5049 class meshProxy(SMESH._objref_SMESH_Mesh):
5050     def __init__(self):
5051         SMESH._objref_SMESH_Mesh.__init__(self)
5052     def __deepcopy__(self, memo=None):
5053         new = self.__class__()
5054         return new
5055     def CreateDimGroup(self,*args): # 2 args added: nbCommonNodes, underlyingOnly
5056         if len( args ) == 3:
5057             args += SMESH.ALL_NODES, True
5058         return SMESH._objref_SMESH_Mesh.CreateDimGroup( self, *args )
5059     pass
5060 omniORB.registerObjref(SMESH._objref_SMESH_Mesh._NP_RepositoryId, meshProxy)
5061
5062
5063 ## Class wrapping SMESH_SubMesh in order to add Compute()
5064 #
5065 class submeshProxy(SMESH._objref_SMESH_subMesh):
5066     def __init__(self):
5067         SMESH._objref_SMESH_subMesh.__init__(self)
5068         self.mesh = None
5069     def __deepcopy__(self, memo=None):
5070         new = self.__class__()
5071         return new
5072
5073     ## Computes the sub-mesh and returns the status of the computation
5074     #  @param refresh if @c True, Object browser is automatically updated (when running in GUI)
5075     #  @return True or False
5076     #  @ingroup l2_construct
5077     def Compute(self,refresh=False):
5078         if not self.mesh:
5079             self.mesh = Mesh( smeshBuilder(), None, self.GetMesh())
5080
5081         ok = self.mesh.Compute( self.GetSubShape(),refresh=[] )
5082
5083         if salome.sg.hasDesktop() and self.mesh.GetStudyId() >= 0:
5084             smeshgui = salome.ImportComponentGUI("SMESH")
5085             smeshgui.Init(self.mesh.GetStudyId())
5086             smeshgui.SetMeshIcon( salome.ObjectToID( self ), ok, (self.GetNumberOfElements()==0) )
5087             if refresh: salome.sg.updateObjBrowser(True)
5088             pass
5089
5090         return ok
5091     pass
5092 omniORB.registerObjref(SMESH._objref_SMESH_subMesh._NP_RepositoryId, submeshProxy)
5093
5094
5095 ## Class used to compensate change of CORBA API of SMESH_MeshEditor for backward compatibility
5096 #  with old dump scripts which call SMESH_MeshEditor directly and not via smeshBuilder.Mesh
5097 #
5098 class meshEditor(SMESH._objref_SMESH_MeshEditor):
5099     def __init__(self):
5100         SMESH._objref_SMESH_MeshEditor.__init__(self)
5101         self.mesh = None
5102     def __getattr__(self, name ): # method called if an attribute not found
5103         if not self.mesh:         # look for name() method in Mesh class
5104             self.mesh = Mesh( None, None, SMESH._objref_SMESH_MeshEditor.GetMesh(self))
5105         if hasattr( self.mesh, name ):
5106             return getattr( self.mesh, name )
5107         if name == "ExtrusionAlongPathObjX":
5108             return getattr( self.mesh, "ExtrusionAlongPathX" ) # other method name
5109         print "meshEditor: attribute '%s' NOT FOUND" % name
5110         return None
5111     def __deepcopy__(self, memo=None):
5112         new = self.__class__()
5113         return new
5114     def FindCoincidentNodes(self,*args): # a 2nd arg added (SeparateCornerAndMediumNodes)
5115         if len( args ) == 1: args += False,
5116         return SMESH._objref_SMESH_MeshEditor.FindCoincidentNodes( self, *args )
5117     def FindCoincidentNodesOnPart(self,*args): # a 3d arg added (SeparateCornerAndMediumNodes)
5118         if len( args ) == 2: args += False,
5119         return SMESH._objref_SMESH_MeshEditor.FindCoincidentNodesOnPart( self, *args )
5120     def MergeNodes(self,*args): # a 2nd arg added (NodesToKeep)
5121         if len( args ) == 1:
5122             return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], [] )
5123         NodesToKeep = args[1]
5124         unRegister  = genObjUnRegister()
5125         if NodesToKeep:
5126             if isinstance( NodesToKeep, list ) and isinstance( NodesToKeep[0], int ):
5127                 NodesToKeep = self.MakeIDSource( NodesToKeep, SMESH.NODE )
5128             if not isinstance( NodesToKeep, list ):
5129                 NodesToKeep = [ NodesToKeep ]
5130         return SMESH._objref_SMESH_MeshEditor.MergeNodes( self, args[0], NodesToKeep )
5131     pass
5132 omniORB.registerObjref(SMESH._objref_SMESH_MeshEditor._NP_RepositoryId, meshEditor)
5133
5134 ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class
5135 #
5136 class Pattern(SMESH._objref_SMESH_Pattern):
5137
5138     def LoadFromFile(self, patternTextOrFile ):
5139         text = patternTextOrFile
5140         if os.path.exists( text ):
5141             text = open( patternTextOrFile ).read()
5142             pass
5143         return SMESH._objref_SMESH_Pattern.LoadFromFile( self, text )
5144
5145     def ApplyToMeshFaces(self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse):
5146         decrFun = lambda i: i-1
5147         theNodeIndexOnKeyPoint1,Parameters,hasVars = ParseParameters(theNodeIndexOnKeyPoint1, decrFun)
5148         theMesh.SetParameters(Parameters)
5149         return SMESH._objref_SMESH_Pattern.ApplyToMeshFaces( self, theMesh, theFacesIDs, theNodeIndexOnKeyPoint1, theReverse )
5150
5151     def ApplyToHexahedrons(self, theMesh, theVolumesIDs, theNode000Index, theNode001Index):
5152         decrFun = lambda i: i-1
5153         theNode000Index,theNode001Index,Parameters,hasVars = ParseParameters(theNode000Index,theNode001Index, decrFun)
5154         theMesh.SetParameters(Parameters)
5155         return SMESH._objref_SMESH_Pattern.ApplyToHexahedrons( self, theMesh, theVolumesIDs, theNode000Index, theNode001Index )
5156
5157     def MakeMesh(self, mesh, CreatePolygons=False, CreatePolyhedra=False):
5158         if isinstance( mesh, Mesh ):
5159             mesh = mesh.GetMesh()
5160         return SMESH._objref_SMESH_Pattern.MakeMesh( self, mesh, CreatePolygons, CreatePolyhedra )
5161
5162 # Registering the new proxy for Pattern
5163 omniORB.registerObjref(SMESH._objref_SMESH_Pattern._NP_RepositoryId, Pattern)
5164
5165 ## Private class used to bind methods creating algorithms to the class Mesh
5166 #
5167 class algoCreator:
5168     def __init__(self):
5169         self.mesh = None
5170         self.defaultAlgoType = ""
5171         self.algoTypeToClass = {}
5172
5173     # Stores a python class of algorithm
5174     def add(self, algoClass):
5175         if type( algoClass ).__name__ == 'classobj' and \
5176            hasattr( algoClass, "algoType"):
5177             self.algoTypeToClass[ algoClass.algoType ] = algoClass
5178             if not self.defaultAlgoType and \
5179                hasattr( algoClass, "isDefault") and algoClass.isDefault:
5180                 self.defaultAlgoType = algoClass.algoType
5181             #print "Add",algoClass.algoType, "dflt",self.defaultAlgoType
5182
5183     # creates a copy of self and assign mesh to the copy
5184     def copy(self, mesh):
5185         other = algoCreator()
5186         other.defaultAlgoType = self.defaultAlgoType
5187         other.algoTypeToClass  = self.algoTypeToClass
5188         other.mesh = mesh
5189         return other
5190
5191     # creates an instance of algorithm
5192     def __call__(self,algo="",geom=0,*args):
5193         algoType = self.defaultAlgoType
5194         for arg in args + (algo,geom):
5195             if isinstance( arg, geomBuilder.GEOM._objref_GEOM_Object ):
5196                 geom = arg
5197             if isinstance( arg, str ) and arg:
5198                 algoType = arg
5199         if not algoType and self.algoTypeToClass:
5200             algoType = self.algoTypeToClass.keys()[0]
5201         if self.algoTypeToClass.has_key( algoType ):
5202             #print "Create algo",algoType
5203             return self.algoTypeToClass[ algoType ]( self.mesh, geom )
5204         raise RuntimeError, "No class found for algo type %s" % algoType
5205         return None
5206
5207 ## Private class used to substitute and store variable parameters of hypotheses.
5208 #
5209 class hypMethodWrapper:
5210     def __init__(self, hyp, method):
5211         self.hyp    = hyp
5212         self.method = method
5213         #print "REBIND:", method.__name__
5214         return
5215
5216     # call a method of hypothesis with calling SetVarParameter() before
5217     def __call__(self,*args):
5218         if not args:
5219             return self.method( self.hyp, *args ) # hypothesis method with no args
5220
5221         #print "MethWrapper.__call__",self.method.__name__, args
5222         try:
5223             parsed = ParseParameters(*args)     # replace variables with their values
5224             self.hyp.SetVarParameter( parsed[-2], self.method.__name__ )
5225             result = self.method( self.hyp, *parsed[:-2] ) # call hypothesis method
5226         except omniORB.CORBA.BAD_PARAM: # raised by hypothesis method call
5227             # maybe there is a replaced string arg which is not variable
5228             result = self.method( self.hyp, *args )
5229         except ValueError, detail: # raised by ParseParameters()
5230             try:
5231                 result = self.method( self.hyp, *args )
5232             except omniORB.CORBA.BAD_PARAM:
5233                 raise ValueError, detail # wrong variable name
5234
5235         return result
5236     pass
5237
5238 ## A helper class that call UnRegister() of SALOME.GenericObj'es stored in it
5239 #
5240 class genObjUnRegister:
5241
5242     def __init__(self, genObj=None):
5243         self.genObjList = []
5244         self.set( genObj )
5245         return
5246
5247     def set(self, genObj):
5248         "Store one or a list of of SALOME.GenericObj'es"
5249         if isinstance( genObj, list ):
5250             self.genObjList.extend( genObj )
5251         else:
5252             self.genObjList.append( genObj )
5253         return
5254
5255     def __del__(self):
5256         for genObj in self.genObjList:
5257             if genObj and hasattr( genObj, "UnRegister" ):
5258                 genObj.UnRegister()
5259
5260
5261 ## Bind methods creating mesher plug-ins to the Mesh class
5262 #
5263 for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
5264     #
5265     #print "pluginName: ", pluginName
5266     pluginBuilderName = pluginName + "Builder"
5267     try:
5268         exec( "from salome.%s.%s import *" % (pluginName, pluginBuilderName))
5269     except Exception, e:
5270         from salome_utils import verbose
5271         if verbose(): print "Exception while loading %s: %s" % ( pluginBuilderName, e )
5272         continue
5273     exec( "from salome.%s import %s" % (pluginName, pluginBuilderName))
5274     plugin = eval( pluginBuilderName )
5275     #print "  plugin:" , str(plugin)
5276
5277     # add methods creating algorithms to Mesh
5278     for k in dir( plugin ):
5279         if k[0] == '_': continue
5280         algo = getattr( plugin, k )
5281         #print "             algo:", str(algo)
5282         if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
5283             #print "                     meshMethod:" , str(algo.meshMethod)
5284             if not hasattr( Mesh, algo.meshMethod ):
5285                 setattr( Mesh, algo.meshMethod, algoCreator() )
5286                 pass
5287             getattr( Mesh, algo.meshMethod ).add( algo )
5288             pass
5289         pass
5290     pass
5291 del pluginName