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