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