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