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