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