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