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