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