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